1 | <?php defined('SYSPATH') OR die('No direct script access.'); |
||
12 | class Kohana_Model_Shipping_Item extends Jam_Model implements FreezableInterface { |
||
13 | |||
14 | use FreezableTrait; |
||
15 | |||
16 | /** |
||
17 | * @codeCoverageIgnore |
||
18 | */ |
||
19 | public static function initialize(Jam_Meta $meta) |
||
47 | |||
48 | /** |
||
49 | * Filter out Model_Shipping_Item's of shipping_groups that are discounted, |
||
50 | * based on the provided total price |
||
51 | * @param array $items array of Model_Shipping_Item objects |
||
52 | * @param Jam_Price $total |
||
53 | * @return array Model_Shipping_Item objects |
||
54 | */ |
||
55 | 4 | public static function filter_discounted_items(array $items, Jam_Price $total) |
|
63 | |||
64 | /** |
||
65 | * Sort Model_Shipping_Item by price, biggest price first |
||
66 | * @param array $items |
||
67 | * @return array |
||
68 | */ |
||
69 | 3 | public static function sort_by_price(array $items) |
|
82 | |||
83 | /** |
||
84 | * Sort and get all the realtive prices of Model_Shipping_Item object (using relative_price method) |
||
85 | * @param array $items |
||
86 | * @return array Jam_Price objects |
||
87 | */ |
||
88 | 2 | public static function relative_prices(array $items) |
|
100 | |||
101 | /** |
||
102 | * Get the shipping object associated with this item |
||
103 | * @return Model_Shipping |
||
104 | * @throws Kohana_Exception If shipping_group or its shipping is NULL |
||
105 | */ |
||
106 | 1 | public function shipping_insist() |
|
114 | |||
115 | 1 | public function purchase_item_shipping() |
|
119 | |||
120 | /** |
||
121 | * Return the date the purchase was paid |
||
122 | */ |
||
123 | 1 | public function paid_at() |
|
127 | |||
128 | /** |
||
129 | * Get the currency for pricing calculations |
||
130 | * @return string |
||
131 | * @throws Kohana_Exception If brand_purchase_shipping is NULL |
||
132 | */ |
||
133 | 2 | public function currency() |
|
137 | |||
138 | /** |
||
139 | * Get the monetary object for currency calculations |
||
140 | * @return Monetary |
||
141 | * @throws Kohana_Exception If brand_purchase_shipping is NULL |
||
142 | */ |
||
143 | 2 | public function monetary() |
|
147 | |||
148 | /** |
||
149 | * Generate a key based on which shipping groups will be devided. |
||
150 | * The items in the same group are shipped toggether, allowing us to use |
||
151 | * additional_item_price instead of price. |
||
152 | * |
||
153 | * Groups by method and ships_from |
||
154 | * @return string |
||
155 | * @throws Kohana_Exception If shipping_group or shipping is NULL |
||
156 | */ |
||
157 | 2 | public function group_key() |
|
166 | |||
167 | /** |
||
168 | * Get the price from shipping_group, converted into purchase's currency / monetary |
||
169 | * @return Jam_Price |
||
170 | * @throws Kohana_Exception If shipping_group is NULL |
||
171 | */ |
||
172 | 2 | public function price() |
|
180 | |||
181 | /** |
||
182 | * Get the additional_item_price from shipping_group, converted into purchase's currency / monetary |
||
183 | * If there is no additional_item_price, return price instead |
||
184 | * @return Jam_Price |
||
185 | * @throws Kohana_Exception If shipping_group is NULL |
||
186 | */ |
||
187 | 2 | public function additional_item_price() |
|
197 | |||
198 | /** |
||
199 | * Get shipping_group's is_discounted |
||
200 | * If there is no additional_item_price, return price instead |
||
201 | * @return boolean |
||
202 | * @throws Kohana_Exception If shipping_group is NULL |
||
203 | */ |
||
204 | 2 | public function is_discounted(Jam_Price $total) |
|
208 | |||
209 | /** |
||
210 | * Get purchase_item's quantity |
||
211 | * @return Jam_Price |
||
212 | * @throws Kohana_Exception If shipping_group is NULL |
||
213 | */ |
||
214 | 2 | public function quantity() |
|
218 | |||
219 | /** |
||
220 | * Return price(), if quantity() > 1 the nany additional items are summed using additional_items_price() |
||
221 | * @return Jam_Price |
||
222 | * @throws Kohana_Exception If shipping_group is NULL |
||
223 | */ |
||
224 | 3 | public function total_price() |
|
230 | |||
231 | /** |
||
232 | * Shipping group's delivery_time |
||
233 | * Freezable |
||
234 | * |
||
235 | * @return Jam_Range |
||
236 | */ |
||
237 | 2 | public function total_delivery_time() |
|
243 | |||
244 | /** |
||
245 | * Return the shipping date for this item |
||
246 | * @return Jam_Range |
||
247 | */ |
||
248 | 1 | public function shipping_date() |
|
258 | |||
259 | /** |
||
260 | * Return additional_items_price() multiplied by quantity() |
||
261 | * @return Jam_Price |
||
262 | * @throws Kohana_Exception If shipping_group or purchase_item is NULL |
||
263 | */ |
||
264 | 3 | public function total_additional_item_price() |
|
268 | |||
269 | /** |
||
270 | * Use paranoid for shipping group |
||
271 | */ |
||
272 | 2 | public function shipping_group_insist() |
|
273 | { |
||
274 | 2 | $self = $this; |
|
275 | |||
276 | return Jam_Behavior_Paranoid::with_filter(Jam_Behavior_Paranoid::ALL, function() use ($self) { |
||
277 | 2 | return $self->get_insist('shipping_group'); |
|
278 | 2 | }); |
|
279 | } |
||
280 | |||
281 | 1 | public function shipping_method() |
|
288 | |||
289 | 4 | public function update_address(Model_Brand_Purchase_Shipping $brand_purchase_shipping) |
|
301 | |||
302 | 1 | public function isFrozen() |
|
306 | |||
307 | 1 | public function setFrozen($frozen) |
|
311 | |||
312 | 2 | public function performFreeze() |
|
316 | |||
317 | 1 | public function performUnfreeze() |
|
321 | } |
||
322 |
If you suppress an error, we recommend checking for the error condition explicitly: