@@ -14,13 +14,13 @@ |
||
14 | 14 | Route4Me::setApiKey(Constants::API_KEY); |
15 | 15 | |
16 | 16 | $orderParameters = Order::fromArray([ |
17 | - 'address_1' => '1358 E Luzerne St, Philadelphia, PA 19124, US', |
|
18 | - 'cached_lat' => 48.335991, |
|
19 | - 'cached_lng' => 31.18287, |
|
20 | - 'address_alias' => 'Auto test address', |
|
21 | - 'address_city' => 'Philadelphia', |
|
22 | - 'day_scheduled_for_YYMMDD' => date('Y-m-d'), |
|
23 | - 'address_stop_type' => AddressType::VISIT, |
|
17 | + 'address_1' => '1358 E Luzerne St, Philadelphia, PA 19124, US', |
|
18 | + 'cached_lat' => 48.335991, |
|
19 | + 'cached_lng' => 31.18287, |
|
20 | + 'address_alias' => 'Auto test address', |
|
21 | + 'address_city' => 'Philadelphia', |
|
22 | + 'day_scheduled_for_YYMMDD' => date('Y-m-d'), |
|
23 | + 'address_stop_type' => AddressType::VISIT, |
|
24 | 24 | ]); |
25 | 25 | |
26 | 26 | $order = new Order(); |
@@ -4,8 +4,8 @@ |
||
4 | 4 | |
5 | 5 | use Route4Me\Enum\AddressType; |
6 | 6 | |
7 | -$root = realpath(dirname(__FILE__) . '/../../'); |
|
8 | -require $root . '/vendor/autoload.php'; |
|
7 | +$root = realpath(dirname(__FILE__).'/../../'); |
|
8 | +require $root.'/vendor/autoload.php'; |
|
9 | 9 | |
10 | 10 | // Example refers to creating a new Order. |
11 | 11 |
@@ -4,11 +4,11 @@ |
||
4 | 4 | |
5 | 5 | class AddressType |
6 | 6 | { |
7 | - const PICKUP = 'PICKUP'; |
|
8 | - const DELIVERY = 'DELIVERY'; |
|
9 | - const BREAK = 'BREAK'; |
|
10 | - const MEETUP = 'MEETUP'; |
|
11 | - const VISIT = 'VISIT'; |
|
12 | - const SERVICE = 'SERVICE'; |
|
13 | - const DRIVEBY = 'DRIVEBY'; |
|
7 | + const PICKUP = 'PICKUP'; |
|
8 | + const DELIVERY = 'DELIVERY'; |
|
9 | + const BREAK = 'BREAK'; |
|
10 | + const MEETUP = 'MEETUP'; |
|
11 | + const VISIT = 'VISIT'; |
|
12 | + const SERVICE = 'SERVICE'; |
|
13 | + const DRIVEBY = 'DRIVEBY'; |
|
14 | 14 | } |
15 | 15 | \ No newline at end of file |
@@ -6,351 +6,351 @@ |
||
6 | 6 | |
7 | 7 | class Order extends Common |
8 | 8 | { |
9 | - public $address_1; |
|
10 | - public $address_2; |
|
11 | - public $cached_lat; |
|
12 | - public $cached_lng; |
|
13 | - public $curbside_lat; |
|
14 | - public $curbside_lng; |
|
15 | - public $address_alias; |
|
16 | - public $address_city; |
|
17 | - public $EXT_FIELD_first_name; |
|
18 | - public $EXT_FIELD_last_name; |
|
19 | - public $EXT_FIELD_email; |
|
20 | - public $EXT_FIELD_phone; |
|
21 | - public $EXT_FIELD_custom_data; |
|
22 | - |
|
23 | - public $color; |
|
24 | - public $order_icon; |
|
25 | - public $local_time_window_start; |
|
26 | - public $local_time_window_end; |
|
27 | - public $local_time_window_start_2; |
|
28 | - public $local_time_window_end_2; |
|
29 | - public $service_time; |
|
30 | - |
|
31 | - public $day_scheduled_for_YYMMDD; |
|
32 | - |
|
33 | - public $route_id; |
|
34 | - public $redirect; |
|
35 | - public $optimization_problem_id; |
|
36 | - public $order_id; |
|
37 | - public $order_uuid; |
|
38 | - public $order_ids; |
|
39 | - |
|
40 | - public $day_added_YYMMDD; |
|
41 | - public $scheduled_for_YYMMDD; |
|
42 | - public $fields; |
|
43 | - public $offset; |
|
44 | - public $limit; |
|
45 | - public $query; |
|
46 | - |
|
47 | - public $created_timestamp; |
|
48 | - public $order_status_id; |
|
49 | - public $member_id; |
|
50 | - public $address_state_id; |
|
51 | - public $address_country_id; |
|
52 | - public $address_zip; |
|
53 | - public $in_route_count; |
|
54 | - public $last_visited_timestamp; |
|
55 | - public $last_routed_timestamp; |
|
56 | - public $local_timezone_string; |
|
57 | - public $is_validated; |
|
58 | - public $is_pending; |
|
59 | - public $is_accepted; |
|
60 | - public $is_started; |
|
61 | - public $is_completed; |
|
62 | - public $custom_user_fields; |
|
63 | - |
|
64 | - public $address_stop_type = \Route4Me\Enum\AddressType::DELIVERY; |
|
65 | - |
|
66 | - public $addresses = []; |
|
67 | - |
|
68 | - /** |
|
69 | - * Weight of the order. |
|
70 | - * @since 1.2.11 |
|
71 | - */ |
|
72 | - public $EXT_FIELD_weight; |
|
73 | - |
|
74 | - /** |
|
75 | - * Cost of the order. |
|
76 | - * @since 1.2.11 |
|
77 | - */ |
|
78 | - public $EXT_FIELD_cost; |
|
79 | - |
|
80 | - /** |
|
81 | - * The total revenue for the order. |
|
82 | - * @since 1.2.11 |
|
83 | - */ |
|
84 | - public $EXT_FIELD_revenue; |
|
85 | - |
|
86 | - /** |
|
87 | - * The cubic volume of the cargo. |
|
88 | - * @since 1.2.11 |
|
89 | - */ |
|
90 | - public $EXT_FIELD_cube; |
|
91 | - |
|
92 | - /** |
|
93 | - *The item quantity of the cargo. |
|
94 | - * @since 1.2.11 |
|
95 | - */ |
|
96 | - public $EXT_FIELD_pieces; |
|
97 | - |
|
98 | - public function __construct() |
|
99 | - { |
|
100 | - Route4Me::setBaseUrl(Endpoint::BASE_URL); |
|
101 | - } |
|
102 | - |
|
103 | - /** |
|
104 | - * @param Order $params |
|
105 | - */ |
|
106 | - public static function addOrder($params) |
|
107 | - { |
|
108 | - $excludeFields = ['route_id', 'redirect', 'optimization_problem_id', 'order_id', |
|
109 | - 'order_ids', 'fields', 'offset', 'limit', 'query', 'created_timestamp', 'order_uuid']; |
|
110 | - |
|
111 | - $allBodyFields = Route4Me::getObjectProperties(new self(), $excludeFields); |
|
112 | - |
|
113 | - $response = Route4Me::makeRequst([ |
|
114 | - 'url' => Endpoint::ORDER_V4, |
|
115 | - 'method' => 'POST', |
|
116 | - 'body' => Route4Me::generateRequestParameters($allBodyFields, $params), |
|
117 | - ]); |
|
118 | - |
|
119 | - return $response; |
|
120 | - } |
|
121 | - |
|
122 | - public static function addOrder2Route($params) |
|
123 | - { |
|
124 | - $allQueryFields = ['route_id', 'redirect']; |
|
125 | - $allBodyFields = ['addresses']; |
|
126 | - |
|
127 | - $response = Route4Me::makeRequst([ |
|
128 | - 'url' => Endpoint::ROUTE_V4, |
|
129 | - 'method' => 'PUT', |
|
130 | - 'query' => Route4Me::generateRequestParameters($allQueryFields, $params), |
|
131 | - 'body' => Route4Me::generateRequestParameters($allBodyFields, $params), |
|
132 | - ]); |
|
133 | - |
|
134 | - return $response; |
|
135 | - } |
|
136 | - |
|
137 | - public static function addOrder2Optimization($params) |
|
138 | - { |
|
139 | - $allQueryFields = ['optimization_problem_id', 'redirect', 'device_type']; |
|
140 | - $allBodyFields = ['addresses']; |
|
141 | - |
|
142 | - $response = Route4Me::makeRequst([ |
|
143 | - 'url' => Endpoint::OPTIMIZATION_PROBLEM, |
|
144 | - 'method' => 'PUT', |
|
145 | - 'query' => Route4Me::generateRequestParameters($allQueryFields, $params), |
|
146 | - 'body' => Route4Me::generateRequestParameters($allBodyFields, $params), |
|
147 | - ]); |
|
148 | - |
|
149 | - return $response; |
|
150 | - } |
|
151 | - |
|
152 | - public static function getOrder($params) |
|
153 | - { |
|
154 | - $allQueryFields = ['order_id', 'fields', 'day_added_YYMMDD', 'scheduled_for_YYMMDD', 'query', |
|
155 | - 'offset', 'limit']; |
|
156 | - |
|
157 | - $response = Route4Me::makeRequst([ |
|
158 | - 'url' => Endpoint::ORDER_V4, |
|
159 | - 'method' => 'GET', |
|
160 | - 'query' => Route4Me::generateRequestParameters($allQueryFields, $params), |
|
161 | - ]); |
|
162 | - |
|
163 | - return $response; |
|
164 | - } |
|
165 | - |
|
166 | - public static function getOrders($params) |
|
167 | - { |
|
168 | - $allQueryFields = ['offset', 'limit']; |
|
169 | - |
|
170 | - $response = Route4Me::makeRequst([ |
|
171 | - 'url' => Endpoint::ORDER_V4, |
|
172 | - 'method' => 'GET', |
|
173 | - 'query' => Route4Me::generateRequestParameters($allQueryFields, $params), |
|
174 | - ]); |
|
175 | - |
|
176 | - return $response; |
|
177 | - } |
|
178 | - |
|
179 | - public function getRandomOrderId($offset, $limit) |
|
180 | - { |
|
181 | - $randomOrder = $this->getRandomOrder($offset, $limit); |
|
182 | - |
|
183 | - if (is_null($randomOrder) || !isset($randomOrder)) { |
|
184 | - return null; |
|
185 | - } |
|
186 | - |
|
187 | - return $randomOrder['order_id']; |
|
188 | - } |
|
189 | - |
|
190 | - public function getRandomOrder($offset, $limit) |
|
191 | - { |
|
192 | - $params = ['offset' => $offset, 'limit' => $limit]; |
|
193 | - |
|
194 | - $orders = self::getOrders($params); |
|
195 | - |
|
196 | - if (is_null($orders) || !isset($orders['results'])) { |
|
197 | - return null; |
|
198 | - } |
|
199 | - |
|
200 | - $randomIndex = rand(0, sizeof($orders['results']) - 1); |
|
201 | - |
|
202 | - $order = $orders['results'][$randomIndex]; |
|
203 | - |
|
204 | - return $order; |
|
205 | - } |
|
206 | - |
|
207 | - public static function removeOrder($params) |
|
208 | - { |
|
209 | - $allBodyFields = ['order_ids']; |
|
210 | - |
|
211 | - $response = Route4Me::makeRequst([ |
|
212 | - 'url' => Endpoint::ORDER_V4, |
|
213 | - 'method' => 'DELETE', |
|
214 | - 'body' => Route4Me::generateRequestParameters($allBodyFields, $params), |
|
215 | - ]); |
|
216 | - |
|
217 | - return $response; |
|
218 | - } |
|
219 | - |
|
220 | - public static function updateOrder($params) |
|
221 | - { |
|
222 | - $excludeFields = ['route_id', 'redirect', 'optimization_problem_id', 'order_ids', |
|
223 | - 'fields', 'offset', 'limit', 'query', 'created_timestamp', 'route_uuid']; |
|
224 | - |
|
225 | - $allBodyFields = Route4Me::getObjectProperties(new self(), $excludeFields); |
|
226 | - |
|
227 | - $response = Route4Me::makeRequst([ |
|
228 | - 'url' => Endpoint::ORDER_V4, |
|
229 | - 'method' => 'PUT', |
|
230 | - 'body' => Route4Me::generateRequestParameters($allBodyFields, $params), |
|
231 | - ]); |
|
232 | - |
|
233 | - return $response; |
|
234 | - } |
|
235 | - |
|
236 | - public static function searchOrder($params) |
|
237 | - { |
|
238 | - $allQueryFields = ['fields', 'day_added_YYMMDD', 'scheduled_for_YYMMDD', 'query', 'offset', 'limit']; |
|
239 | - |
|
240 | - $response = Route4Me::makeRequst([ |
|
241 | - 'url' => Endpoint::ORDER_V4, |
|
242 | - 'method' => 'GET', |
|
243 | - 'query' => Route4Me::generateRequestParameters($allQueryFields, $params), |
|
244 | - ]); |
|
245 | - |
|
246 | - return $response; |
|
247 | - } |
|
9 | + public $address_1; |
|
10 | + public $address_2; |
|
11 | + public $cached_lat; |
|
12 | + public $cached_lng; |
|
13 | + public $curbside_lat; |
|
14 | + public $curbside_lng; |
|
15 | + public $address_alias; |
|
16 | + public $address_city; |
|
17 | + public $EXT_FIELD_first_name; |
|
18 | + public $EXT_FIELD_last_name; |
|
19 | + public $EXT_FIELD_email; |
|
20 | + public $EXT_FIELD_phone; |
|
21 | + public $EXT_FIELD_custom_data; |
|
22 | + |
|
23 | + public $color; |
|
24 | + public $order_icon; |
|
25 | + public $local_time_window_start; |
|
26 | + public $local_time_window_end; |
|
27 | + public $local_time_window_start_2; |
|
28 | + public $local_time_window_end_2; |
|
29 | + public $service_time; |
|
30 | + |
|
31 | + public $day_scheduled_for_YYMMDD; |
|
32 | + |
|
33 | + public $route_id; |
|
34 | + public $redirect; |
|
35 | + public $optimization_problem_id; |
|
36 | + public $order_id; |
|
37 | + public $order_uuid; |
|
38 | + public $order_ids; |
|
39 | + |
|
40 | + public $day_added_YYMMDD; |
|
41 | + public $scheduled_for_YYMMDD; |
|
42 | + public $fields; |
|
43 | + public $offset; |
|
44 | + public $limit; |
|
45 | + public $query; |
|
46 | + |
|
47 | + public $created_timestamp; |
|
48 | + public $order_status_id; |
|
49 | + public $member_id; |
|
50 | + public $address_state_id; |
|
51 | + public $address_country_id; |
|
52 | + public $address_zip; |
|
53 | + public $in_route_count; |
|
54 | + public $last_visited_timestamp; |
|
55 | + public $last_routed_timestamp; |
|
56 | + public $local_timezone_string; |
|
57 | + public $is_validated; |
|
58 | + public $is_pending; |
|
59 | + public $is_accepted; |
|
60 | + public $is_started; |
|
61 | + public $is_completed; |
|
62 | + public $custom_user_fields; |
|
63 | + |
|
64 | + public $address_stop_type = \Route4Me\Enum\AddressType::DELIVERY; |
|
65 | + |
|
66 | + public $addresses = []; |
|
67 | + |
|
68 | + /** |
|
69 | + * Weight of the order. |
|
70 | + * @since 1.2.11 |
|
71 | + */ |
|
72 | + public $EXT_FIELD_weight; |
|
73 | + |
|
74 | + /** |
|
75 | + * Cost of the order. |
|
76 | + * @since 1.2.11 |
|
77 | + */ |
|
78 | + public $EXT_FIELD_cost; |
|
79 | + |
|
80 | + /** |
|
81 | + * The total revenue for the order. |
|
82 | + * @since 1.2.11 |
|
83 | + */ |
|
84 | + public $EXT_FIELD_revenue; |
|
85 | + |
|
86 | + /** |
|
87 | + * The cubic volume of the cargo. |
|
88 | + * @since 1.2.11 |
|
89 | + */ |
|
90 | + public $EXT_FIELD_cube; |
|
91 | + |
|
92 | + /** |
|
93 | + *The item quantity of the cargo. |
|
94 | + * @since 1.2.11 |
|
95 | + */ |
|
96 | + public $EXT_FIELD_pieces; |
|
97 | + |
|
98 | + public function __construct() |
|
99 | + { |
|
100 | + Route4Me::setBaseUrl(Endpoint::BASE_URL); |
|
101 | + } |
|
102 | + |
|
103 | + /** |
|
104 | + * @param Order $params |
|
105 | + */ |
|
106 | + public static function addOrder($params) |
|
107 | + { |
|
108 | + $excludeFields = ['route_id', 'redirect', 'optimization_problem_id', 'order_id', |
|
109 | + 'order_ids', 'fields', 'offset', 'limit', 'query', 'created_timestamp', 'order_uuid']; |
|
110 | + |
|
111 | + $allBodyFields = Route4Me::getObjectProperties(new self(), $excludeFields); |
|
112 | + |
|
113 | + $response = Route4Me::makeRequst([ |
|
114 | + 'url' => Endpoint::ORDER_V4, |
|
115 | + 'method' => 'POST', |
|
116 | + 'body' => Route4Me::generateRequestParameters($allBodyFields, $params), |
|
117 | + ]); |
|
118 | + |
|
119 | + return $response; |
|
120 | + } |
|
121 | + |
|
122 | + public static function addOrder2Route($params) |
|
123 | + { |
|
124 | + $allQueryFields = ['route_id', 'redirect']; |
|
125 | + $allBodyFields = ['addresses']; |
|
126 | + |
|
127 | + $response = Route4Me::makeRequst([ |
|
128 | + 'url' => Endpoint::ROUTE_V4, |
|
129 | + 'method' => 'PUT', |
|
130 | + 'query' => Route4Me::generateRequestParameters($allQueryFields, $params), |
|
131 | + 'body' => Route4Me::generateRequestParameters($allBodyFields, $params), |
|
132 | + ]); |
|
133 | + |
|
134 | + return $response; |
|
135 | + } |
|
136 | + |
|
137 | + public static function addOrder2Optimization($params) |
|
138 | + { |
|
139 | + $allQueryFields = ['optimization_problem_id', 'redirect', 'device_type']; |
|
140 | + $allBodyFields = ['addresses']; |
|
141 | + |
|
142 | + $response = Route4Me::makeRequst([ |
|
143 | + 'url' => Endpoint::OPTIMIZATION_PROBLEM, |
|
144 | + 'method' => 'PUT', |
|
145 | + 'query' => Route4Me::generateRequestParameters($allQueryFields, $params), |
|
146 | + 'body' => Route4Me::generateRequestParameters($allBodyFields, $params), |
|
147 | + ]); |
|
148 | + |
|
149 | + return $response; |
|
150 | + } |
|
151 | + |
|
152 | + public static function getOrder($params) |
|
153 | + { |
|
154 | + $allQueryFields = ['order_id', 'fields', 'day_added_YYMMDD', 'scheduled_for_YYMMDD', 'query', |
|
155 | + 'offset', 'limit']; |
|
156 | + |
|
157 | + $response = Route4Me::makeRequst([ |
|
158 | + 'url' => Endpoint::ORDER_V4, |
|
159 | + 'method' => 'GET', |
|
160 | + 'query' => Route4Me::generateRequestParameters($allQueryFields, $params), |
|
161 | + ]); |
|
162 | + |
|
163 | + return $response; |
|
164 | + } |
|
165 | + |
|
166 | + public static function getOrders($params) |
|
167 | + { |
|
168 | + $allQueryFields = ['offset', 'limit']; |
|
169 | + |
|
170 | + $response = Route4Me::makeRequst([ |
|
171 | + 'url' => Endpoint::ORDER_V4, |
|
172 | + 'method' => 'GET', |
|
173 | + 'query' => Route4Me::generateRequestParameters($allQueryFields, $params), |
|
174 | + ]); |
|
175 | + |
|
176 | + return $response; |
|
177 | + } |
|
178 | + |
|
179 | + public function getRandomOrderId($offset, $limit) |
|
180 | + { |
|
181 | + $randomOrder = $this->getRandomOrder($offset, $limit); |
|
182 | + |
|
183 | + if (is_null($randomOrder) || !isset($randomOrder)) { |
|
184 | + return null; |
|
185 | + } |
|
186 | + |
|
187 | + return $randomOrder['order_id']; |
|
188 | + } |
|
189 | + |
|
190 | + public function getRandomOrder($offset, $limit) |
|
191 | + { |
|
192 | + $params = ['offset' => $offset, 'limit' => $limit]; |
|
193 | + |
|
194 | + $orders = self::getOrders($params); |
|
195 | + |
|
196 | + if (is_null($orders) || !isset($orders['results'])) { |
|
197 | + return null; |
|
198 | + } |
|
199 | + |
|
200 | + $randomIndex = rand(0, sizeof($orders['results']) - 1); |
|
201 | + |
|
202 | + $order = $orders['results'][$randomIndex]; |
|
203 | + |
|
204 | + return $order; |
|
205 | + } |
|
206 | + |
|
207 | + public static function removeOrder($params) |
|
208 | + { |
|
209 | + $allBodyFields = ['order_ids']; |
|
210 | + |
|
211 | + $response = Route4Me::makeRequst([ |
|
212 | + 'url' => Endpoint::ORDER_V4, |
|
213 | + 'method' => 'DELETE', |
|
214 | + 'body' => Route4Me::generateRequestParameters($allBodyFields, $params), |
|
215 | + ]); |
|
216 | + |
|
217 | + return $response; |
|
218 | + } |
|
219 | + |
|
220 | + public static function updateOrder($params) |
|
221 | + { |
|
222 | + $excludeFields = ['route_id', 'redirect', 'optimization_problem_id', 'order_ids', |
|
223 | + 'fields', 'offset', 'limit', 'query', 'created_timestamp', 'route_uuid']; |
|
224 | + |
|
225 | + $allBodyFields = Route4Me::getObjectProperties(new self(), $excludeFields); |
|
226 | + |
|
227 | + $response = Route4Me::makeRequst([ |
|
228 | + 'url' => Endpoint::ORDER_V4, |
|
229 | + 'method' => 'PUT', |
|
230 | + 'body' => Route4Me::generateRequestParameters($allBodyFields, $params), |
|
231 | + ]); |
|
232 | + |
|
233 | + return $response; |
|
234 | + } |
|
235 | + |
|
236 | + public static function searchOrder($params) |
|
237 | + { |
|
238 | + $allQueryFields = ['fields', 'day_added_YYMMDD', 'scheduled_for_YYMMDD', 'query', 'offset', 'limit']; |
|
239 | + |
|
240 | + $response = Route4Me::makeRequst([ |
|
241 | + 'url' => Endpoint::ORDER_V4, |
|
242 | + 'method' => 'GET', |
|
243 | + 'query' => Route4Me::generateRequestParameters($allQueryFields, $params), |
|
244 | + ]); |
|
245 | + |
|
246 | + return $response; |
|
247 | + } |
|
248 | 248 | |
249 | - public static function validateCoordinate($coord) |
|
250 | - { |
|
251 | - $key = key($coord); |
|
252 | - |
|
253 | - if (!is_numeric($coord[$key])) { |
|
254 | - return false; |
|
255 | - } |
|
256 | - |
|
257 | - switch ($key) { |
|
258 | - case 'cached_lat': |
|
259 | - case 'curbside_lat': |
|
260 | - if ($coord[$key] > 90 || $coord[$key] < -90) { |
|
261 | - return false; |
|
262 | - } |
|
263 | - break; |
|
264 | - case 'cached_lng': |
|
265 | - case 'curbside_lng': |
|
266 | - if ($coord[$key] > 180 || $coord[$key] < -180) { |
|
267 | - return false; |
|
268 | - } |
|
269 | - break; |
|
270 | - } |
|
271 | - |
|
272 | - return true; |
|
273 | - } |
|
249 | + public static function validateCoordinate($coord) |
|
250 | + { |
|
251 | + $key = key($coord); |
|
252 | + |
|
253 | + if (!is_numeric($coord[$key])) { |
|
254 | + return false; |
|
255 | + } |
|
256 | + |
|
257 | + switch ($key) { |
|
258 | + case 'cached_lat': |
|
259 | + case 'curbside_lat': |
|
260 | + if ($coord[$key] > 90 || $coord[$key] < -90) { |
|
261 | + return false; |
|
262 | + } |
|
263 | + break; |
|
264 | + case 'cached_lng': |
|
265 | + case 'curbside_lng': |
|
266 | + if ($coord[$key] > 180 || $coord[$key] < -180) { |
|
267 | + return false; |
|
268 | + } |
|
269 | + break; |
|
270 | + } |
|
271 | + |
|
272 | + return true; |
|
273 | + } |
|
274 | 274 | |
275 | - public function addOrdersFromCsvFile($csvFileHandle, $ordersFieldsMapping) |
|
276 | - { |
|
277 | - $max_line_length = 512; |
|
278 | - $delemietr = ','; |
|
279 | - |
|
280 | - $results = []; |
|
281 | - $results['fail'] = []; |
|
282 | - $results['success'] = []; |
|
283 | - |
|
284 | - $columns = fgetcsv($csvFileHandle, $max_line_length, $delemietr); |
|
275 | + public function addOrdersFromCsvFile($csvFileHandle, $ordersFieldsMapping) |
|
276 | + { |
|
277 | + $max_line_length = 512; |
|
278 | + $delemietr = ','; |
|
279 | + |
|
280 | + $results = []; |
|
281 | + $results['fail'] = []; |
|
282 | + $results['success'] = []; |
|
283 | + |
|
284 | + $columns = fgetcsv($csvFileHandle, $max_line_length, $delemietr); |
|
285 | 285 | |
286 | - $excludeFields = ['route_id', 'redirect', 'optimization_problem_id', 'order_id', 'order_ids', |
|
287 | - 'fields', 'offset', 'limit', 'query', 'created_timestamp', 'order_uuid']; |
|
288 | - |
|
289 | - $allOrderFields = Route4Me::getObjectProperties(new self(), $excludeFields); |
|
290 | - |
|
291 | - if (!empty($columns)) { |
|
292 | - array_push($results['fail'], 'Empty CSV table'); |
|
286 | + $excludeFields = ['route_id', 'redirect', 'optimization_problem_id', 'order_id', 'order_ids', |
|
287 | + 'fields', 'offset', 'limit', 'query', 'created_timestamp', 'order_uuid']; |
|
288 | + |
|
289 | + $allOrderFields = Route4Me::getObjectProperties(new self(), $excludeFields); |
|
290 | + |
|
291 | + if (!empty($columns)) { |
|
292 | + array_push($results['fail'], 'Empty CSV table'); |
|
293 | 293 | |
294 | - return $results; |
|
295 | - } |
|
296 | - |
|
297 | - $iRow = 1; |
|
298 | - |
|
299 | - while (false !== ($rows = fgetcsv($csvFileHandle, $max_line_length, $delemietr))) { |
|
300 | - if ($rows[$ordersFieldsMapping['cached_lat']] && $rows[$ordersFieldsMapping['cached_lng']] && $rows[$ordersFieldsMapping['address_1']] && [null] !== $rows) { |
|
301 | - $cached_lat = 0.000; |
|
302 | - $cached_lng = 0.000; |
|
303 | - |
|
304 | - foreach (['cached_lat', 'cached_lng', 'curbside_lat', 'curbside_lng'] as $coord) { |
|
305 | - if (!$this->validateCoordinate([$coord => $rows[$ordersFieldsMapping[$coord]]])) { |
|
306 | - array_push($results['fail'], "$iRow --> Wrong " + $coord); |
|
307 | - ++$iRow; |
|
308 | - continue; |
|
309 | - } else { |
|
310 | - switch ($coord) { |
|
311 | - case 'cached_lat': |
|
312 | - $cached_lat = doubleval($rows[$ordersFieldsMapping[$coord]]); |
|
313 | - break; |
|
314 | - case 'cached_lng': |
|
315 | - $cached_lng = doubleval($rows[$ordersFieldsMapping[$coord]]); |
|
316 | - break; |
|
317 | - } |
|
318 | - } |
|
319 | - } |
|
320 | - |
|
321 | - $address = $rows[$ordersFieldsMapping['address_1']]; |
|
322 | - |
|
323 | - foreach (['order_city', 'order_state_id', 'order_zip_code', 'order_country_id'] as $addressPart) { |
|
324 | - if (isset($ordersFieldsMapping[$addressPart])) { |
|
325 | - $address .= ', '.$rows[$ordersFieldsMapping[$addressPart]]; |
|
326 | - } |
|
327 | - } |
|
328 | - |
|
329 | - echo "$iRow --> ".$ordersFieldsMapping['day_scheduled_for_YYMMDD'].', '.$rows[$ordersFieldsMapping['day_scheduled_for_YYMMDD']].'<br>'; |
|
330 | - |
|
331 | - $parametersArray = []; |
|
332 | - |
|
333 | - $parametersArray['cached_lat'] = $cached_lat; |
|
334 | - $parametersArray['cached_lng'] = $cached_lng; |
|
335 | - |
|
336 | - foreach ($allOrderFields as $orderField) { |
|
337 | - if (isset($ordersFieldsMapping[$orderField])) { |
|
338 | - $parametersArray[$orderField] = $rows[$ordersFieldsMapping[$orderField]]; |
|
339 | - } |
|
340 | - } |
|
341 | - |
|
342 | - $orderParameters = self::fromArray($parametersArray); |
|
343 | - |
|
344 | - $order = new self(); |
|
345 | - |
|
346 | - $orderResults = $order->addOrder($orderParameters); |
|
347 | - |
|
348 | - array_push($results['success'], 'The order with order_id = '.strval($orderResults['order_id']).' added successfuly.'); |
|
349 | - } else { |
|
350 | - array_push($results['fail'], "$iRow --> one of the parameters cached_lat, cached_lng, address_1 is not set"); |
|
351 | - } |
|
352 | - |
|
353 | - ++$iRow; |
|
354 | - } |
|
355 | - } |
|
294 | + return $results; |
|
295 | + } |
|
296 | + |
|
297 | + $iRow = 1; |
|
298 | + |
|
299 | + while (false !== ($rows = fgetcsv($csvFileHandle, $max_line_length, $delemietr))) { |
|
300 | + if ($rows[$ordersFieldsMapping['cached_lat']] && $rows[$ordersFieldsMapping['cached_lng']] && $rows[$ordersFieldsMapping['address_1']] && [null] !== $rows) { |
|
301 | + $cached_lat = 0.000; |
|
302 | + $cached_lng = 0.000; |
|
303 | + |
|
304 | + foreach (['cached_lat', 'cached_lng', 'curbside_lat', 'curbside_lng'] as $coord) { |
|
305 | + if (!$this->validateCoordinate([$coord => $rows[$ordersFieldsMapping[$coord]]])) { |
|
306 | + array_push($results['fail'], "$iRow --> Wrong " + $coord); |
|
307 | + ++$iRow; |
|
308 | + continue; |
|
309 | + } else { |
|
310 | + switch ($coord) { |
|
311 | + case 'cached_lat': |
|
312 | + $cached_lat = doubleval($rows[$ordersFieldsMapping[$coord]]); |
|
313 | + break; |
|
314 | + case 'cached_lng': |
|
315 | + $cached_lng = doubleval($rows[$ordersFieldsMapping[$coord]]); |
|
316 | + break; |
|
317 | + } |
|
318 | + } |
|
319 | + } |
|
320 | + |
|
321 | + $address = $rows[$ordersFieldsMapping['address_1']]; |
|
322 | + |
|
323 | + foreach (['order_city', 'order_state_id', 'order_zip_code', 'order_country_id'] as $addressPart) { |
|
324 | + if (isset($ordersFieldsMapping[$addressPart])) { |
|
325 | + $address .= ', '.$rows[$ordersFieldsMapping[$addressPart]]; |
|
326 | + } |
|
327 | + } |
|
328 | + |
|
329 | + echo "$iRow --> ".$ordersFieldsMapping['day_scheduled_for_YYMMDD'].', '.$rows[$ordersFieldsMapping['day_scheduled_for_YYMMDD']].'<br>'; |
|
330 | + |
|
331 | + $parametersArray = []; |
|
332 | + |
|
333 | + $parametersArray['cached_lat'] = $cached_lat; |
|
334 | + $parametersArray['cached_lng'] = $cached_lng; |
|
335 | + |
|
336 | + foreach ($allOrderFields as $orderField) { |
|
337 | + if (isset($ordersFieldsMapping[$orderField])) { |
|
338 | + $parametersArray[$orderField] = $rows[$ordersFieldsMapping[$orderField]]; |
|
339 | + } |
|
340 | + } |
|
341 | + |
|
342 | + $orderParameters = self::fromArray($parametersArray); |
|
343 | + |
|
344 | + $order = new self(); |
|
345 | + |
|
346 | + $orderResults = $order->addOrder($orderParameters); |
|
347 | + |
|
348 | + array_push($results['success'], 'The order with order_id = '.strval($orderResults['order_id']).' added successfuly.'); |
|
349 | + } else { |
|
350 | + array_push($results['fail'], "$iRow --> one of the parameters cached_lat, cached_lng, address_1 is not set"); |
|
351 | + } |
|
352 | + |
|
353 | + ++$iRow; |
|
354 | + } |
|
355 | + } |
|
356 | 356 | } |