1 | <?php defined('SYSPATH') OR die('No direct script access.'); |
||
9 | class Kohana_Model_Shipping extends Jam_Model { |
||
10 | |||
11 | 4 | public static function format_shipping_time($min, $max) |
|
12 | { |
||
13 | 4 | if ($min === NULL AND $max === NULL) |
|
14 | 1 | return '-'; |
|
15 | |||
16 | 3 | if ($min == 0 AND $max == 0) |
|
17 | 1 | return 'same day'; |
|
18 | |||
19 | 2 | if ($min == 1 AND $max == 1) |
|
20 | return '1 day'; |
||
21 | |||
22 | 2 | return $min == $max ? "{$min} days" : "{$min} - {$max} days"; |
|
23 | } |
||
24 | |||
25 | /** |
||
26 | * @codeCoverageIgnore |
||
27 | */ |
||
28 | public static function initialize(Jam_Meta $meta) |
||
72 | |||
73 | /** |
||
74 | * Use this currency throughout all the shipping calculations |
||
75 | * @return string ISO currency code |
||
76 | */ |
||
77 | 3 | public function currency() |
|
81 | |||
82 | 4 | protected function groups_in(Model_Location $location) |
|
83 | { |
||
84 | 4 | $location = $this->most_specific_location_containing($location); |
|
85 | |||
86 | 4 | if ( ! $location) |
|
87 | return NULL; |
||
88 | |||
89 | return array_filter($this->groups->as_array(), function($group) use ($location) { |
||
90 | 4 | return ($group->location_id == $location->id() AND $group->price); |
|
91 | 4 | }); |
|
92 | } |
||
93 | |||
94 | 2 | public function cheapest_group_in(Model_Location $location) |
|
105 | |||
106 | 4 | public function group_for(Model_Location $location, Model_Shipping_Method $method) |
|
107 | { |
||
108 | 4 | $location = $this->most_specific_location_containing($location); |
|
109 | |||
110 | 4 | if ( ! $location) |
|
111 | return NULL; |
||
112 | |||
113 | 4 | foreach ($this->groups->as_array() as $group) |
|
114 | { |
||
115 | 4 | if ($group->location_id == $location->id() AND $group->method_id == $method->id()) |
|
116 | 4 | return $group; |
|
117 | } |
||
118 | 1 | } |
|
119 | |||
120 | 1 | public function methods_for($location) |
|
121 | { |
||
122 | 1 | $groups = $location ? $this->groups_in($location) : $this->groups; |
|
123 | 1 | $methods = array(); |
|
124 | 1 | foreach ($groups as $group) |
|
125 | { |
||
126 | 1 | $methods[$group->method_id] = $group->method; |
|
127 | } |
||
128 | 1 | return $methods; |
|
129 | } |
||
130 | |||
131 | 5 | public function ships_to(Model_Location $location) |
|
135 | |||
136 | 1 | public function total_delivery_time_for(Model_Location $location) |
|
140 | |||
141 | 1 | public function delivery_time_for(Model_Location $location) |
|
154 | |||
155 | 1 | public function delivery_time() |
|
156 | { |
||
157 | 1 | $delivery_times = $this->groups->as_array(NULL, 'delivery_time'); |
|
158 | |||
159 | 1 | if ( ! $delivery_times) |
|
160 | return NULL; |
||
161 | |||
162 | 1 | return Jam_Range::merge(array_filter($delivery_times), 'Model_Shipping::format_shipping_time'); |
|
163 | } |
||
164 | |||
165 | 4 | public function locations_containing(Model_Location $location) |
|
174 | |||
175 | 4 | public function most_specific_location_containing(Model_Location $location) |
|
185 | |||
186 | 2 | public function new_shipping_item_from(array $fields, Model_Location $location, Model_Shipping_Method $method = NULL) |
|
192 | |||
193 | 1 | public function price_for_location(Model_Location $location) |
|
202 | |||
203 | 1 | public function additional_price_for_location(Model_Location $location) |
|
212 | |||
213 | 1 | public function discount_threshold_for_location(Model_Location $location) |
|
222 | } |
||
223 |
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.