public function validate_purchase(Model_Purchase $purchase) { $purchase_price = $purchase->total_price('product'); if ($purchase_price->is(Jam_Price::LESS_THAN, $this->requirement)) { $purchase->errors()->add('promo_code_text', 'requirement', array(':more_than' => $this->requirement->humanize())); } }
/** * If there is a new value in promo_code_text, try to load promo_code object. * If the new value is NULL, remove it * @param Model_Purchase $purchase */ public function model_after_check(Model_Purchase $purchase) { if ($purchase->changed('promo_code_text') and !$purchase->errors('promo_code_text')) { if ($purchase->promo_code_text) { $purchase->promo_code = Jam::find('promo_code', $purchase->promo_code_text); } else { $purchase->promo_code = NULL; } } }
public function model_call_shipping_country(Model_Purchase $purchase, Jam_Event_Data $data, Model_Location $shipping_country = NULL) { if ($shipping_country !== NULL) { if ($purchase->shipping_same_as_billing) { $purchase->billing_address->country = $shipping_country; $purchase->billing_address = $purchase->billing_address; } else { $purchase->shipping_address->country = $shipping_country; $purchase->shipping_address = $purchase->shipping_address; } $data->return = $purchase; } $address = $purchase->shipping_address(); if ($address and $address->country) { $data->return = $address->country; } }
public function available_for_purchase(Model_Purchase $purchase) { return $this->join('purchases', 'LEFT')->where_open()->where('allow_multiple', '=', TRUE)->or_where('purchase.id', '=', NULL)->or_where('purchase.id', '=', $purchase->id())->where_close(); }
function init() { parent::init(); $this->addCondition('atk_user_id', $this->api->getUserID()); }