Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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

timkelty commented Nov 14, 2014

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