1
|
|
|
<?php defined('SYSPATH') OR die('No direct script access.'); |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* @package openbuildings\promotions |
5
|
|
|
* @author Ivan Kerin <[email protected]> |
6
|
|
|
* @copyright (c) 2013 OpenBuildings Ltd. |
7
|
|
|
* @license http://spdx.org/licenses/BSD-3-Clause |
8
|
|
|
*/ |
9
|
|
|
class Kohana_Model_Promotion_Promocode_Giftcard extends Model_Promotion_Promocode { |
10
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* @codeCoverageIgnore |
13
|
|
|
*/ |
14
|
|
|
public static function initialize(Jam_Meta $meta) |
15
|
|
|
{ |
16
|
|
|
parent::initialize($meta); |
17
|
|
|
|
18
|
|
|
$meta |
19
|
|
|
->fields(array( |
20
|
|
|
'amount' => Jam::field('price'), |
21
|
|
|
'requirement' => Jam::field('price'), |
22
|
|
|
)) |
23
|
|
|
->validator('amount', array('price' => array('greater_than' => 0))) |
24
|
|
|
->validator('requirement', array('price' => array('greater_than_or_equal_to' => 0))); |
25
|
|
|
} |
26
|
|
|
|
27
|
2 |
|
public function validate_purchase(Model_Purchase $purchase) |
28
|
|
|
{ |
29
|
2 |
|
$purchase_price = $purchase->total_price('product'); |
30
|
|
|
|
31
|
2 |
|
if ($purchase_price->is(Jam_Price::LESS_THAN, $this->requirement)) |
|
|
|
|
32
|
|
|
{ |
33
|
1 |
|
$purchase->errors()->add('promo_code_text', 'requirement', array(':more_than' => $this->requirement->humanize())); |
|
|
|
|
34
|
|
|
} |
35
|
2 |
|
} |
36
|
|
|
|
37
|
1 |
|
public function price_for_purchase_item(Model_Purchase_Item $purchase_item) |
38
|
|
|
{ |
39
|
1 |
|
$brand_purchase = $purchase_item->get_insist('brand_purchase'); |
40
|
1 |
|
$brand_total = $brand_purchase->total_price('product'); |
41
|
|
|
|
42
|
1 |
|
$purchase = $brand_purchase->get_insist('purchase'); |
43
|
|
|
|
44
|
|
|
$totals = array_map(function ($brand_purchase) { |
45
|
1 |
|
return $this->applies_to($brand_purchase) |
46
|
1 |
|
? $brand_purchase->total_price('product') |
47
|
1 |
|
: 0; |
48
|
1 |
|
}, $purchase->brand_purchases->as_array()); |
49
|
|
|
|
50
|
1 |
|
$total = Jam_Price::sum($totals, $purchase_item->currency(), $purchase_item->monetary()); |
51
|
|
|
|
52
|
1 |
|
$multiplier = $total->is(Jam_Price::GREATER_THAN, 0) |
53
|
1 |
|
? $brand_total->amount() / $total->amount() |
54
|
1 |
|
: 1; |
55
|
|
|
|
56
|
1 |
|
return $this->amount |
|
|
|
|
57
|
1 |
|
->monetary($purchase_item->monetary()) |
58
|
1 |
|
->multiply_by(-$multiplier); |
59
|
|
|
} |
60
|
|
|
} |
61
|
|
|
|
Since your code implements the magic getter
_get
, this function will be called for any read access on an undefined variable. You can add the@property
annotation to your class or interface to document the existence of this variable.If the property has read access only, you can use the @property-read annotation instead.
Of course, you may also just have mistyped another name, in which case you should fix the error.
See also the PhpDoc documentation for @property.