Skip to content

Instantly share code, notes, and snippets.

@timkelty
Last active August 29, 2015 14:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save timkelty/09b42e50105b6c420c5b to your computer and use it in GitHub Desktop.
Save timkelty/09b42e50105b6c420c5b to your computer and use it in GitHub Desktop.
namespace Craft;
class Recurly_PlanModel extends BaseModel
{
protected function defineAttributes() {
return array(
'sortOrder' => AttributeType::SortOrder,
'code' => AttributeType::String,
'max' => AttributeType::Number,
'min' => AttributeType::Number,
'baseEndpoints' => AttributeType::Number,
'endpointCost' => AttributeType::String,
'annual' => array('type' => AttributeType::Bool, 'default' => false),
'baseCost' => array('type' => AttributeType::Number, 'decimals' => 2),
'endpointCost' => array('type' => AttributeType::Number, 'decimals' => 2),
);
}
protected function getAnnualSavings() {
return $this->annual ? $this->baseCost + $endpointCost * $baseEndpoints : 0;
}
}
public function actionGetPlans()
{
$plans = craft()->recurly->getPlans();
$this->returnJson($plans);
}
public function getPlans()
{
$records = Recurly_PlanRecord::model()->findAll();
$models = Recurly_PlanModel::PopulateModels($records);
return $models;
}
@timkelty
Copy link
Author

So with this, I can do $model->annualSavings to get exactly what I want, but since it isn't defined as attribute, I don't get it in $this->returnJson($plans).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment