GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Test Failed
Push — master ( e591c7...ce7ad9 )
by Igor
01:15 queued 15s
created
UnitTestFiles/Test/OrderTests.php 1 patch
Indentation   +581 added lines, -581 removed lines patch added patch discarded remove patch
@@ -20,585 +20,585 @@
 block discarded – undo
20 20
 
21 21
 class OrderTests extends \PHPUnit\Framework\TestCase
22 22
 {
23
-    public static $createdOrders = [];
24
-    public static $createdProblems = [];
25
-
26
-    public static function setUpBeforeClass()
27
-    {
28
-        Route4Me::setApiKey(Constants::API_KEY);
29
-
30
-        //region -- Create Test Optimization --
31
-
32
-        // Huge list of addresses
33
-        $json = json_decode(file_get_contents(dirname(__FILE__).'/data/addresses.json'), true);
34
-        $json = array_slice($json, 0, 10);
35
-
36
-        $addresses = [];
37
-        foreach ($json as $address) {
38
-            $addresses[] = Address::fromArray($address);
39
-        }
40
-
41
-        $parameters = RouteParameters::fromArray([
42
-            'algorithm_type'    => Algorithmtype::TSP,
43
-            'route_name'        => 'Single Driver Multiple TW 10 Stops '.date('Y-m-d H:i'),
44
-            'route_date'        => time() + 24 * 60 * 60,
45
-            'route_time'        => 5 * 3600 + 30 * 60,
46
-            'distance_unit'     => DistanceUnit::MILES,
47
-            'device_type'       => DeviceType::WEB,
48
-            'optimize'          => OptimizationType::DISTANCE,
49
-            'metric'            => Metric::GEODESIC,
50
-        ]);
51
-
52
-        $optimizationParams = new OptimizationProblemParams();
53
-        $optimizationParams->setAddresses($addresses);
54
-        $optimizationParams->setParameters($parameters);
55
-
56
-        $problem = OptimizationProblem::optimize($optimizationParams);
57
-
58
-        self::$createdProblems[] = $problem;
59
-
60
-        //endregion
61
-
62
-        //region -- Create Test Order --
63
-
64
-        $orderParameters = Order::fromArray([
65
-            'address_1'                 => '1358 E Luzerne St, Philadelphia, PA 19124, US',
66
-            'cached_lat'                => 48.335991,
67
-            'cached_lng'                => 31.18287,
68
-            'address_alias'             => 'Auto test address',
69
-            'address_city'              => 'Philadelphia',
70
-            'day_scheduled_for_YYMMDD'  => date('Y-m-d'),
71
-            'EXT_FIELD_first_name'      => 'Igor',
72
-            'EXT_FIELD_last_name'       => 'Progman',
73
-            'EXT_FIELD_email'           => '[email protected]',
74
-            'EXT_FIELD_phone'           => '380380380380',
75
-            'EXT_FIELD_custom_data'     => [
76
-                0 => [
77
-                    'order_id'  => '10',
78
-                    'name'      => 'Bill Soul',
79
-                ],
80
-            ],
81
-        ]);
82
-
83
-        $order = new Order();
84
-
85
-        $response = $order->addOrder($orderParameters);
86
-
87
-        self::assertNotNull($response);
88
-        self::assertInstanceOf(Order::class, Order::fromArray($response));
89
-
90
-        self::$createdOrders[] = $response;
91
-
92
-        //endregion
93
-    }
94
-
95
-    public function testFromArray()
96
-    {
97
-        $orderParameters = Order::fromArray([
98
-            'address_1'                 => '1358 E Luzerne St, Philadelphia, PA 19124, US',
99
-            'cached_lat'                => 48.335991,
100
-            'cached_lng'                => 31.18287,
101
-            'address_alias'             => 'Auto test address',
102
-            'address_city'              => 'Philadelphia',
103
-            'day_scheduled_for_YYMMDD'  => date('Y-m-d'),
104
-            'EXT_FIELD_first_name'      => 'Igor',
105
-            'EXT_FIELD_last_name'       => 'Progman',
106
-            'EXT_FIELD_email'           => '[email protected]',
107
-            'EXT_FIELD_phone'           => '380380380380',
108
-            'EXT_FIELD_custom_data'     => [
109
-                0 => [
110
-                    'order_id'  => '10',
111
-                    'name'      => 'Bill Soul',
112
-                ],
113
-            ],
114
-            'EXT_FIELD_cost'            => 50
115
-        ]);
116
-
117
-        $this->assertEquals('1358 E Luzerne St, Philadelphia, PA 19124, US', $orderParameters->address_1);
118
-        $this->assertEquals(48.335991, $orderParameters->cached_lat);
119
-        $this->assertEquals(31.18287, $orderParameters->cached_lng);
120
-        $this->assertEquals('Auto test address', $orderParameters->address_alias);
121
-        $this->assertEquals('Philadelphia', $orderParameters->address_city);
122
-        $this->assertEquals(date('Y-m-d'), $orderParameters->day_scheduled_for_YYMMDD);
123
-        $this->assertEquals('Igor', $orderParameters->EXT_FIELD_first_name);
124
-        $this->assertEquals('Progman', $orderParameters->EXT_FIELD_last_name);
125
-        $this->assertEquals('[email protected]', $orderParameters->EXT_FIELD_email);
126
-        $this->assertEquals('380380380380', $orderParameters->EXT_FIELD_phone);
127
-        $this->assertEquals([
128
-            0 => [
129
-                'order_id'  => '10',
130
-                'name'      => 'Bill Soul',
131
-            ],
132
-        ], $orderParameters->EXT_FIELD_custom_data);
133
-        $this->assertEquals(50, $orderParameters->EXT_FIELD_cost);
134
-    }
135
-
136
-    public function testToArray()
137
-    {
138
-        $orderParameters = Order::fromArray([
139
-            'address_1'                 => '1358 E Luzerne St, Philadelphia, PA 19124, US',
140
-            'cached_lat'                => 48.335991,
141
-            'cached_lng'                => 31.18287,
142
-            'address_alias'             => 'Auto test address',
143
-            'address_city'              => 'Philadelphia',
144
-            'day_scheduled_for_YYMMDD'  => date('Y-m-d'),
145
-            'EXT_FIELD_first_name'      => 'Igor',
146
-            'EXT_FIELD_last_name'       => 'Progman',
147
-            'EXT_FIELD_email'           => '[email protected]',
148
-            'EXT_FIELD_phone'           => '380380380380',
149
-            'EXT_FIELD_custom_data'     => [
150
-                0 => [
151
-                    'order_id'  => '10',
152
-                    'name'      => 'Bill Soul',
153
-                ],
154
-            ],
155
-        ]);
156
-
157
-        $this->assertEquals(
158
-            $orderParameters->toArray(),
159
-            [
160
-                'address_1'                 => '1358 E Luzerne St, Philadelphia, PA 19124, US',
161
-                'cached_lat'                => 48.335991,
162
-                'cached_lng'                => 31.18287,
163
-                'address_alias'             => 'Auto test address',
164
-                'address_city'              => 'Philadelphia',
165
-                'day_scheduled_for_YYMMDD'  => date('Y-m-d'),
166
-                'EXT_FIELD_first_name'      => 'Igor',
167
-                'EXT_FIELD_last_name'       => 'Progman',
168
-                'EXT_FIELD_email'           => '[email protected]',
169
-                'EXT_FIELD_phone'           => '380380380380',
170
-                'EXT_FIELD_custom_data'     => [
171
-                    0 => [
172
-                        'order_id'  => '10',
173
-                        'name'      => 'Bill Soul',
174
-                    ],
175
-                ],
176
-            ],
177
-        ]);
178
-    }
179
-
180
-    public function testGetOrders()
181
-    {
182
-        $order = new Order();
183
-
184
-        $orderParameters = Order::fromArray([
185
-            'offset'    => 0,
186
-            'limit'     => 5,
187
-        ]);
188
-
189
-        $response = $order->getOrders($orderParameters);
190
-
191
-        $this->assertNotNull($response);
192
-        $this->assertTrue(is_array($response));
193
-        $this->assertTrue(isset($response['total']));
194
-        $this->assertTrue(isset($response['results']));
195
-        $this->assertInstanceOf(
196
-            Order::class,
197
-            Order::fromArray($response['results'][0])
198
-        );
199
-    }
200
-
201
-    public function testCreateNewOrder()
202
-    {
203
-        $orderParameters = Order::fromArray([
204
-            'address_1'                 => '106 Liberty St, New York, NY 10006, USA',
205
-            'address_alias'             => 'BK Restaurant #: 2446',
206
-            'cached_lat'                => 40.709637,
207
-            'cached_lng'                => -74.011912,
208
-            'curbside_lat'              => 40.709637,
209
-            'curbside_lng'              => -74.011912,
210
-            'address_city'              => 'New York',
211
-            'EXT_FIELD_first_name'      => 'Lui',
212
-            'EXT_FIELD_last_name'       => 'Carol',
213
-            'EXT_FIELD_email'           => '[email protected]',
214
-            'EXT_FIELD_phone'           => '897946541',
215
-            'local_time_window_end'     => 39000,
216
-            'local_time_window_end_2'   => 46200,
217
-            'local_time_window_start'   => 37800,
218
-            'local_time_window_start_2' => 45000,
219
-            'local_timezone_string'     => 'America/New_York',
220
-            'order_icon'                => 'emoji/emoji-bank',
221
-        ]);
222
-
223
-        $order = new Order();
224
-
225
-        $response = $order->addOrder($orderParameters);
226
-
227
-        self::assertNotNull($response);
228
-        self::assertInstanceOf(Order::class, Order::fromArray($response));
229
-
230
-        self::$createdOrders[] = $response;
231
-    }
232
-
233
-    public function testAddOrdersToOptimization()
234
-    {
235
-        $body = json_decode(file_get_contents(dirname(__FILE__).'/data/add_order_to_optimization_data.json'), true);
236
-
237
-        $optimizationProblemId = self::$createdProblems[0]->optimization_problem_id;
238
-
239
-        $orderParameters = [
240
-            'optimization_problem_id'   => $optimizationProblemId,
241
-            'redirect'                  => 0,
242
-            'device_type'               => 'web',
243
-            'addresses'                 => $body['addresses'],
244
-        ];
245
-
246
-        $order = new Order();
247
-
248
-        $response = $order->addOrder2Optimization($orderParameters);
249
-
250
-        self::assertNotNull($response);
251
-        self::assertInstanceOf(OptimizationProblem::class, OptimizationProblem::fromArray($response));
252
-    }
253
-
254
-    public function testAddOrdersToRoute()
255
-    {
256
-        $this->markTestSkipped('Read old data.');
257
-
258
-        $body = json_decode(file_get_contents(dirname(__FILE__).'/data/add_order_to_route_data.json'), true);
259
-
260
-        $routeId = self::$createdProblems[0]->routes[0]->route_id;
261
-
262
-        $orderParameters = Order::fromArray([
263
-            'route_id'  => $routeId,
264
-            'redirect'  => 0,
265
-            'addresses' => $body['addresses'],
266
-        ]);
267
-
268
-        $order = new Order();
269
-
270
-        $response = $order->addOrder2Route($orderParameters);
271
-
272
-        self::assertNotNull($response);
273
-        self::assertInstanceOf(Route::class, Route::fromArray($response));
274
-    }
275
-
276
-    public function testAddScheduledOrder()
277
-    {
278
-        $orderParameters = Order::fromArray([
279
-            'address_1'                 => '318 S 39th St, Louisville, KY 40212, USA',
280
-            'cached_lat'                => 38.259326,
281
-            'cached_lng'                => -85.814979,
282
-            'curbside_lat'              => 38.259326,
283
-            'curbside_lng'              => -85.814979,
284
-            'address_alias'             => '318 S 39th St 40212',
285
-            'address_city'              => 'Louisville',
286
-            'EXT_FIELD_first_name'      => 'Lui',
287
-            'EXT_FIELD_last_name'       => 'Carol',
288
-            'EXT_FIELD_email'           => '[email protected]',
289
-            'EXT_FIELD_phone'           => '897946541',
290
-            'EXT_FIELD_custom_data'     => ['order_type' => 'scheduled order'],
291
-            'day_scheduled_for_YYMMDD'  => date('Y-m-d'),
292
-            'local_time_window_end'     => 39000,
293
-            'local_time_window_end_2'   => 46200,
294
-            'local_time_window_start'   => 37800,
295
-            'local_time_window_start_2' => 45000,
296
-            'local_timezone_string'     => 'America/New_York',
297
-            'order_icon'                => 'emoji/emoji-bank',
298
-        ]);
299
-
300
-        $order = new Order();
301
-
302
-        $response = $order->addOrder($orderParameters);
303
-
304
-        self::assertNotNull($response);
305
-        self::assertInstanceOf(Order::class, Order::fromArray($response));
306
-
307
-        self::$createdOrders[] = $response;
308
-    }
309
-
310
-    public function testCreateOrderWithCustomField()
311
-    {
312
-        $orderParameters = Order::fromArray([
313
-            'address_1'                => '1358 E Luzerne St, Philadelphia, PA 19124, US',
314
-            'cached_lat'               => 48.335991,
315
-            'cached_lng'               => 31.18287,
316
-            'day_scheduled_for_YYMMDD' => '2019-10-11',
317
-            'address_alias'            => 'Auto test address',
318
-            'custom_user_fields' => [
319
-                OrderCustomField::fromArray([
320
-                    'order_custom_field_id'    => 93,
321
-                    'order_custom_field_value' => 'false'
322
-                ])
323
-            ]
324
-        ]);
325
-
326
-        $order = new Order();
327
-
328
-        $response = $order->addOrder($orderParameters);
329
-
330
-        self::assertNotNull($response);
331
-        self::assertInstanceOf(Order::class, Order::fromArray($response));
332
-        $this->assertEquals(93, $response['custom_user_fields'][0]['order_custom_field_id']);
333
-        $this->assertEquals(false, $response['custom_user_fields'][0]['order_custom_field_value']);
334
-
335
-        self::$createdOrders[] = $response;
336
-    }
337
-
338
-    public function testGetOrderByID()
339
-    {
340
-        $order = new Order();
341
-
342
-        $orderID = self::$createdOrders[0]['order_id'];
343
-
344
-        // Get an order
345
-        $orderParameters = Order::fromArray([
346
-            'order_id' => $orderID,
347
-        ]);
348
-
349
-        $response = $order->getOrder($orderParameters);
350
-
351
-        self::assertNotNull($response);
352
-        self::assertInstanceOf(Order::class, Order::fromArray($response));
353
-    }
354
-
355
-    public function testGetOrderByUUID()
356
-    {
357
-        $order = new Order();
358
-
359
-        $orderUUID = self::$createdOrders[0]['order_uuid'];
360
-
361
-        // Get an order
362
-        $orderParameters = Order::fromArray([
363
-            'order_id' => $orderUUID,
364
-        ]);
365
-
366
-        $response = $order->getOrder($orderParameters);
367
-
368
-        self::assertNotNull($response);
369
-        self::assertInstanceOf(Order::class, Order::fromArray($response));
370
-    }
371
-
372
-    public function testGetOrderByInsertedDate()
373
-    {
374
-        $orderParameters = Order::fromArray([
375
-            'day_added_YYMMDD'  => date('Y-m-d', strtotime('0 days')),
376
-            'offset'            => 0,
377
-            'limit'             => 5,
378
-        ]);
379
-
380
-        $order = new Order();
381
-
382
-        $response = $order->getOrder($orderParameters);
383
-
384
-        $this->assertNotNull($response);
385
-        $this->assertTrue(is_array($response));
386
-        $this->assertTrue(isset($response['total']));
387
-        $this->assertTrue(isset($response['results']));
388
-        $this->assertInstanceOf(
389
-            Order::class,
390
-            Order::fromArray($response['results'][0])
391
-        );
392
-    }
393
-
394
-    public function testGetOrderByScheduledDate()
395
-    {
396
-        $orderParameters = Order::fromArray([
397
-            'day_scheduled_for_YYMMDD'  => date('Y-m-d', strtotime('0 days')),
398
-            'offset'                    => 0,
399
-            'limit'                     => 5,
400
-        ]);
401
-
402
-        $order = new Order();
403
-
404
-        $response = $order->getOrder($orderParameters);
405
-
406
-        $this->assertNotNull($response);
407
-        $this->assertTrue(is_array($response));
408
-        $this->assertTrue(isset($response['total']));
409
-        $this->assertTrue(isset($response['results']));
410
-        $this->assertInstanceOf(
411
-            Order::class,
412
-            Order::fromArray($response['results'][0])
413
-        );
414
-    }
415
-
416
-    public function testGetOrdersByCustomFields()
417
-    {
418
-        $orderParameters = Order::fromArray([
419
-            'fields'    => 'order_id,member_id',
420
-            'offset'    => 0,
421
-            'limit'     => 5,
422
-        ]);
423
-
424
-        $order = new Order();
425
-
426
-        $response = $order->getOrder($orderParameters);
427
-
428
-        $response = $order->getOrder($orderParameters);
429
-
430
-        $this->assertNotNull($response);
431
-        $this->assertTrue(is_array($response));
432
-        $this->assertTrue(isset($response['total']));
433
-        $this->assertTrue(isset($response['results']));
434
-        $this->assertTrue(isset($response['fields']));
435
-        $this->assertInstanceOf(
436
-            Order::class,
437
-            Order::fromArray($response['results'][0])
438
-        );
439
-    }
440
-
441
-    public function testGetOrdersByScheduleFilter()
442
-    {
443
-        $orderParameters = Order::fromArray([
444
-            'limit'  => 5,
445
-            'filter' => [
446
-                'display'               => 'all',
447
-                'scheduled_for_YYMMDD'  => [
448
-                    date('Y-m-d', strtotime('-1 days')),
449
-                    date('Y-m-d', strtotime('1 days'))
450
-                ]
451
-            ]
452
-        ]);
453
-
454
-        $order = new Order();
455
-
456
-        $response = $order->getOrder($orderParameters);
457
-
458
-        $this->assertNotNull($response);
459
-        $this->assertTrue(is_array($response));
460
-        $this->assertTrue(isset($response['total']));
461
-        $this->assertTrue(isset($response['results']));
462
-        $this->assertInstanceOf(
463
-            Order::class,
464
-            Order::fromArray($response['results'][0])
465
-        );
466
-    }
467
-
468
-    public function testGetOrdersBySpecifiedText()
469
-    {
470
-        $orderParameters = Order::fromArray([
471
-            'query'     => 'Auto test',
472
-            'offset'    => 0,
473
-            'limit'     => 5,
474
-        ]);
475
-
476
-        $order = new Order();
477
-
478
-        $response = $order->getOrder($orderParameters);
479
-
480
-        $this->assertNotNull($response);
481
-        $this->assertTrue(is_array($response));
482
-        $this->assertTrue(isset($response['total']));
483
-        $this->assertTrue(isset($response['results']));
484
-        $this->assertInstanceOf(
485
-            Order::class,
486
-            Order::fromArray($response['results'][0])
487
-        );
488
-    }
489
-
490
-    public function testUpdateOrder()
491
-    {
492
-        $order = new Order();
493
-
494
-        // Update the order
495
-        self::$createdOrders[0]['address_2'] = 'Lviv';
496
-        self::$createdOrders[0]['EXT_FIELD_phone'] = '032268593';
497
-        self::$createdOrders[0]['EXT_FIELD_custom_data'] = [
498
-            0 => [
499
-                'customer_no' => '11',
500
-            ],
501
-        ];
502
-
503
-        $response = $order->updateOrder(self::$createdOrders[0]);
504
-
505
-        $this->assertNotNull($response);
506
-        $this->assertInstanceOf(Order::class, Order::fromArray($response));
507
-        $this->assertEquals('Lviv', $response['address_2']);
508
-        $this->assertEquals('032268593', $response['EXT_FIELD_phone']);
509
-        $this->assertEquals(
510
-            [
511
-                0 => '{"order_id":"10","name":"Bill Soul"}'
512
-            ],
513
-            $response['EXT_FIELD_custom_data']
514
-        );
515
-    }
516
-
517
-    public function testUpdateOrderWithCustomFiel()
518
-    {
519
-        $orderParameters = Order::fromArray([
520
-            'order_id'              => self::$createdOrders[0]['order_id'],
521
-            'custom_user_fields'    => [
522
-                OrderCustomField::fromArray([
523
-                    'order_custom_field_id'    => 93,
524
-                    'order_custom_field_value' => 'true'
525
-                ])
526
-            ]
527
-        ]);
528
-
529
-        $order = new Order();
530
-
531
-        $response = $order->updateOrder($orderParameters);
532
-
533
-        $this->assertNotNull($response);
534
-        $this->assertInstanceOf(Order::class, Order::fromArray($response));
535
-        $this->assertEquals(93, $response['custom_user_fields'][0]['order_custom_field_id']);
536
-        $this->assertEquals(true, $response['custom_user_fields'][0]['order_custom_field_value']);
537
-    }
538
-
539
-    public function testDeleteOrderByUuid()
540
-    {
541
-        $lastOrder = array_pop(self::$createdOrders);
542
-        if ($lastOrder != null) {
543
-            $order = new Order();
544
-            $ids = [
545
-                "order_ids" => [$lastOrder['order_uuid']]
546
-            ];
547
-
548
-            $response = $order->removeOrder($ids);
549
-
550
-            if (!is_null($response) && isset($response['status']) && $response['status']) {
551
-                echo "The test order removed by UUID <br>";
552
-            }
553
-        }
554
-    }
555
-
556
-    public static function tearDownAfterClass()
557
-    {
558
-        if (sizeof(self::$createdOrders)) {
559
-            $orderIDs = [];
560
-
561
-            foreach (self::$createdOrders as $ord) {
562
-                $orderIDs[] = $ord['order_id'];
563
-            }
564
-
565
-            $orderParameters = Order::fromArray([
566
-                'order_ids' => $orderIDs
567
-            ]);
568
-
569
-            $order = new Order();
570
-
571
-            $response = $order->removeOrder($orderParameters);
572
-
573
-            if (!is_null($response) &&
574
-                isset($response['status']) &&
575
-                $response['status']) {
576
-                echo "The test orders removed <br>";
577
-            }
578
-        }
579
-
580
-        if (sizeof(self::$createdProblems)>0) {
581
-            $optimizationProblemIDs = [];
582
-
583
-            foreach (self::$createdProblems as $problem) {
584
-                $optimizationProblemId = $problem->optimization_problem_id;
585
-
586
-                $optimizationProblemIDs[] = $optimizationProblemId;
587
-            }
588
-
589
-            $params = [
590
-                'optimization_problem_ids' => $optimizationProblemIDs,
591
-                'redirect'                 => 0,
592
-            ];
593
-
594
-            $problem = new OptimizationProblem();
595
-            $result = $problem->removeOptimization($params);
596
-
597
-            if ($result!=null && $result['status']==true) {
598
-                echo "The test optimizations were removed <br>";
599
-            } else {
600
-                echo "Cannot remove the test optimizations <br>";
601
-            }
602
-        }
603
-    }
23
+	public static $createdOrders = [];
24
+	public static $createdProblems = [];
25
+
26
+	public static function setUpBeforeClass()
27
+	{
28
+		Route4Me::setApiKey(Constants::API_KEY);
29
+
30
+		//region -- Create Test Optimization --
31
+
32
+		// Huge list of addresses
33
+		$json = json_decode(file_get_contents(dirname(__FILE__).'/data/addresses.json'), true);
34
+		$json = array_slice($json, 0, 10);
35
+
36
+		$addresses = [];
37
+		foreach ($json as $address) {
38
+			$addresses[] = Address::fromArray($address);
39
+		}
40
+
41
+		$parameters = RouteParameters::fromArray([
42
+			'algorithm_type'    => Algorithmtype::TSP,
43
+			'route_name'        => 'Single Driver Multiple TW 10 Stops '.date('Y-m-d H:i'),
44
+			'route_date'        => time() + 24 * 60 * 60,
45
+			'route_time'        => 5 * 3600 + 30 * 60,
46
+			'distance_unit'     => DistanceUnit::MILES,
47
+			'device_type'       => DeviceType::WEB,
48
+			'optimize'          => OptimizationType::DISTANCE,
49
+			'metric'            => Metric::GEODESIC,
50
+		]);
51
+
52
+		$optimizationParams = new OptimizationProblemParams();
53
+		$optimizationParams->setAddresses($addresses);
54
+		$optimizationParams->setParameters($parameters);
55
+
56
+		$problem = OptimizationProblem::optimize($optimizationParams);
57
+
58
+		self::$createdProblems[] = $problem;
59
+
60
+		//endregion
61
+
62
+		//region -- Create Test Order --
63
+
64
+		$orderParameters = Order::fromArray([
65
+			'address_1'                 => '1358 E Luzerne St, Philadelphia, PA 19124, US',
66
+			'cached_lat'                => 48.335991,
67
+			'cached_lng'                => 31.18287,
68
+			'address_alias'             => 'Auto test address',
69
+			'address_city'              => 'Philadelphia',
70
+			'day_scheduled_for_YYMMDD'  => date('Y-m-d'),
71
+			'EXT_FIELD_first_name'      => 'Igor',
72
+			'EXT_FIELD_last_name'       => 'Progman',
73
+			'EXT_FIELD_email'           => '[email protected]',
74
+			'EXT_FIELD_phone'           => '380380380380',
75
+			'EXT_FIELD_custom_data'     => [
76
+				0 => [
77
+					'order_id'  => '10',
78
+					'name'      => 'Bill Soul',
79
+				],
80
+			],
81
+		]);
82
+
83
+		$order = new Order();
84
+
85
+		$response = $order->addOrder($orderParameters);
86
+
87
+		self::assertNotNull($response);
88
+		self::assertInstanceOf(Order::class, Order::fromArray($response));
89
+
90
+		self::$createdOrders[] = $response;
91
+
92
+		//endregion
93
+	}
94
+
95
+	public function testFromArray()
96
+	{
97
+		$orderParameters = Order::fromArray([
98
+			'address_1'                 => '1358 E Luzerne St, Philadelphia, PA 19124, US',
99
+			'cached_lat'                => 48.335991,
100
+			'cached_lng'                => 31.18287,
101
+			'address_alias'             => 'Auto test address',
102
+			'address_city'              => 'Philadelphia',
103
+			'day_scheduled_for_YYMMDD'  => date('Y-m-d'),
104
+			'EXT_FIELD_first_name'      => 'Igor',
105
+			'EXT_FIELD_last_name'       => 'Progman',
106
+			'EXT_FIELD_email'           => '[email protected]',
107
+			'EXT_FIELD_phone'           => '380380380380',
108
+			'EXT_FIELD_custom_data'     => [
109
+				0 => [
110
+					'order_id'  => '10',
111
+					'name'      => 'Bill Soul',
112
+				],
113
+			],
114
+			'EXT_FIELD_cost'            => 50
115
+		]);
116
+
117
+		$this->assertEquals('1358 E Luzerne St, Philadelphia, PA 19124, US', $orderParameters->address_1);
118
+		$this->assertEquals(48.335991, $orderParameters->cached_lat);
119
+		$this->assertEquals(31.18287, $orderParameters->cached_lng);
120
+		$this->assertEquals('Auto test address', $orderParameters->address_alias);
121
+		$this->assertEquals('Philadelphia', $orderParameters->address_city);
122
+		$this->assertEquals(date('Y-m-d'), $orderParameters->day_scheduled_for_YYMMDD);
123
+		$this->assertEquals('Igor', $orderParameters->EXT_FIELD_first_name);
124
+		$this->assertEquals('Progman', $orderParameters->EXT_FIELD_last_name);
125
+		$this->assertEquals('[email protected]', $orderParameters->EXT_FIELD_email);
126
+		$this->assertEquals('380380380380', $orderParameters->EXT_FIELD_phone);
127
+		$this->assertEquals([
128
+			0 => [
129
+				'order_id'  => '10',
130
+				'name'      => 'Bill Soul',
131
+			],
132
+		], $orderParameters->EXT_FIELD_custom_data);
133
+		$this->assertEquals(50, $orderParameters->EXT_FIELD_cost);
134
+	}
135
+
136
+	public function testToArray()
137
+	{
138
+		$orderParameters = Order::fromArray([
139
+			'address_1'                 => '1358 E Luzerne St, Philadelphia, PA 19124, US',
140
+			'cached_lat'                => 48.335991,
141
+			'cached_lng'                => 31.18287,
142
+			'address_alias'             => 'Auto test address',
143
+			'address_city'              => 'Philadelphia',
144
+			'day_scheduled_for_YYMMDD'  => date('Y-m-d'),
145
+			'EXT_FIELD_first_name'      => 'Igor',
146
+			'EXT_FIELD_last_name'       => 'Progman',
147
+			'EXT_FIELD_email'           => '[email protected]',
148
+			'EXT_FIELD_phone'           => '380380380380',
149
+			'EXT_FIELD_custom_data'     => [
150
+				0 => [
151
+					'order_id'  => '10',
152
+					'name'      => 'Bill Soul',
153
+				],
154
+			],
155
+		]);
156
+
157
+		$this->assertEquals(
158
+			$orderParameters->toArray(),
159
+			[
160
+				'address_1'                 => '1358 E Luzerne St, Philadelphia, PA 19124, US',
161
+				'cached_lat'                => 48.335991,
162
+				'cached_lng'                => 31.18287,
163
+				'address_alias'             => 'Auto test address',
164
+				'address_city'              => 'Philadelphia',
165
+				'day_scheduled_for_YYMMDD'  => date('Y-m-d'),
166
+				'EXT_FIELD_first_name'      => 'Igor',
167
+				'EXT_FIELD_last_name'       => 'Progman',
168
+				'EXT_FIELD_email'           => '[email protected]',
169
+				'EXT_FIELD_phone'           => '380380380380',
170
+				'EXT_FIELD_custom_data'     => [
171
+					0 => [
172
+						'order_id'  => '10',
173
+						'name'      => 'Bill Soul',
174
+					],
175
+				],
176
+			],
177
+		]);
178
+	}
179
+
180
+	public function testGetOrders()
181
+	{
182
+		$order = new Order();
183
+
184
+		$orderParameters = Order::fromArray([
185
+			'offset'    => 0,
186
+			'limit'     => 5,
187
+		]);
188
+
189
+		$response = $order->getOrders($orderParameters);
190
+
191
+		$this->assertNotNull($response);
192
+		$this->assertTrue(is_array($response));
193
+		$this->assertTrue(isset($response['total']));
194
+		$this->assertTrue(isset($response['results']));
195
+		$this->assertInstanceOf(
196
+			Order::class,
197
+			Order::fromArray($response['results'][0])
198
+		);
199
+	}
200
+
201
+	public function testCreateNewOrder()
202
+	{
203
+		$orderParameters = Order::fromArray([
204
+			'address_1'                 => '106 Liberty St, New York, NY 10006, USA',
205
+			'address_alias'             => 'BK Restaurant #: 2446',
206
+			'cached_lat'                => 40.709637,
207
+			'cached_lng'                => -74.011912,
208
+			'curbside_lat'              => 40.709637,
209
+			'curbside_lng'              => -74.011912,
210
+			'address_city'              => 'New York',
211
+			'EXT_FIELD_first_name'      => 'Lui',
212
+			'EXT_FIELD_last_name'       => 'Carol',
213
+			'EXT_FIELD_email'           => '[email protected]',
214
+			'EXT_FIELD_phone'           => '897946541',
215
+			'local_time_window_end'     => 39000,
216
+			'local_time_window_end_2'   => 46200,
217
+			'local_time_window_start'   => 37800,
218
+			'local_time_window_start_2' => 45000,
219
+			'local_timezone_string'     => 'America/New_York',
220
+			'order_icon'                => 'emoji/emoji-bank',
221
+		]);
222
+
223
+		$order = new Order();
224
+
225
+		$response = $order->addOrder($orderParameters);
226
+
227
+		self::assertNotNull($response);
228
+		self::assertInstanceOf(Order::class, Order::fromArray($response));
229
+
230
+		self::$createdOrders[] = $response;
231
+	}
232
+
233
+	public function testAddOrdersToOptimization()
234
+	{
235
+		$body = json_decode(file_get_contents(dirname(__FILE__).'/data/add_order_to_optimization_data.json'), true);
236
+
237
+		$optimizationProblemId = self::$createdProblems[0]->optimization_problem_id;
238
+
239
+		$orderParameters = [
240
+			'optimization_problem_id'   => $optimizationProblemId,
241
+			'redirect'                  => 0,
242
+			'device_type'               => 'web',
243
+			'addresses'                 => $body['addresses'],
244
+		];
245
+
246
+		$order = new Order();
247
+
248
+		$response = $order->addOrder2Optimization($orderParameters);
249
+
250
+		self::assertNotNull($response);
251
+		self::assertInstanceOf(OptimizationProblem::class, OptimizationProblem::fromArray($response));
252
+	}
253
+
254
+	public function testAddOrdersToRoute()
255
+	{
256
+		$this->markTestSkipped('Read old data.');
257
+
258
+		$body = json_decode(file_get_contents(dirname(__FILE__).'/data/add_order_to_route_data.json'), true);
259
+
260
+		$routeId = self::$createdProblems[0]->routes[0]->route_id;
261
+
262
+		$orderParameters = Order::fromArray([
263
+			'route_id'  => $routeId,
264
+			'redirect'  => 0,
265
+			'addresses' => $body['addresses'],
266
+		]);
267
+
268
+		$order = new Order();
269
+
270
+		$response = $order->addOrder2Route($orderParameters);
271
+
272
+		self::assertNotNull($response);
273
+		self::assertInstanceOf(Route::class, Route::fromArray($response));
274
+	}
275
+
276
+	public function testAddScheduledOrder()
277
+	{
278
+		$orderParameters = Order::fromArray([
279
+			'address_1'                 => '318 S 39th St, Louisville, KY 40212, USA',
280
+			'cached_lat'                => 38.259326,
281
+			'cached_lng'                => -85.814979,
282
+			'curbside_lat'              => 38.259326,
283
+			'curbside_lng'              => -85.814979,
284
+			'address_alias'             => '318 S 39th St 40212',
285
+			'address_city'              => 'Louisville',
286
+			'EXT_FIELD_first_name'      => 'Lui',
287
+			'EXT_FIELD_last_name'       => 'Carol',
288
+			'EXT_FIELD_email'           => '[email protected]',
289
+			'EXT_FIELD_phone'           => '897946541',
290
+			'EXT_FIELD_custom_data'     => ['order_type' => 'scheduled order'],
291
+			'day_scheduled_for_YYMMDD'  => date('Y-m-d'),
292
+			'local_time_window_end'     => 39000,
293
+			'local_time_window_end_2'   => 46200,
294
+			'local_time_window_start'   => 37800,
295
+			'local_time_window_start_2' => 45000,
296
+			'local_timezone_string'     => 'America/New_York',
297
+			'order_icon'                => 'emoji/emoji-bank',
298
+		]);
299
+
300
+		$order = new Order();
301
+
302
+		$response = $order->addOrder($orderParameters);
303
+
304
+		self::assertNotNull($response);
305
+		self::assertInstanceOf(Order::class, Order::fromArray($response));
306
+
307
+		self::$createdOrders[] = $response;
308
+	}
309
+
310
+	public function testCreateOrderWithCustomField()
311
+	{
312
+		$orderParameters = Order::fromArray([
313
+			'address_1'                => '1358 E Luzerne St, Philadelphia, PA 19124, US',
314
+			'cached_lat'               => 48.335991,
315
+			'cached_lng'               => 31.18287,
316
+			'day_scheduled_for_YYMMDD' => '2019-10-11',
317
+			'address_alias'            => 'Auto test address',
318
+			'custom_user_fields' => [
319
+				OrderCustomField::fromArray([
320
+					'order_custom_field_id'    => 93,
321
+					'order_custom_field_value' => 'false'
322
+				])
323
+			]
324
+		]);
325
+
326
+		$order = new Order();
327
+
328
+		$response = $order->addOrder($orderParameters);
329
+
330
+		self::assertNotNull($response);
331
+		self::assertInstanceOf(Order::class, Order::fromArray($response));
332
+		$this->assertEquals(93, $response['custom_user_fields'][0]['order_custom_field_id']);
333
+		$this->assertEquals(false, $response['custom_user_fields'][0]['order_custom_field_value']);
334
+
335
+		self::$createdOrders[] = $response;
336
+	}
337
+
338
+	public function testGetOrderByID()
339
+	{
340
+		$order = new Order();
341
+
342
+		$orderID = self::$createdOrders[0]['order_id'];
343
+
344
+		// Get an order
345
+		$orderParameters = Order::fromArray([
346
+			'order_id' => $orderID,
347
+		]);
348
+
349
+		$response = $order->getOrder($orderParameters);
350
+
351
+		self::assertNotNull($response);
352
+		self::assertInstanceOf(Order::class, Order::fromArray($response));
353
+	}
354
+
355
+	public function testGetOrderByUUID()
356
+	{
357
+		$order = new Order();
358
+
359
+		$orderUUID = self::$createdOrders[0]['order_uuid'];
360
+
361
+		// Get an order
362
+		$orderParameters = Order::fromArray([
363
+			'order_id' => $orderUUID,
364
+		]);
365
+
366
+		$response = $order->getOrder($orderParameters);
367
+
368
+		self::assertNotNull($response);
369
+		self::assertInstanceOf(Order::class, Order::fromArray($response));
370
+	}
371
+
372
+	public function testGetOrderByInsertedDate()
373
+	{
374
+		$orderParameters = Order::fromArray([
375
+			'day_added_YYMMDD'  => date('Y-m-d', strtotime('0 days')),
376
+			'offset'            => 0,
377
+			'limit'             => 5,
378
+		]);
379
+
380
+		$order = new Order();
381
+
382
+		$response = $order->getOrder($orderParameters);
383
+
384
+		$this->assertNotNull($response);
385
+		$this->assertTrue(is_array($response));
386
+		$this->assertTrue(isset($response['total']));
387
+		$this->assertTrue(isset($response['results']));
388
+		$this->assertInstanceOf(
389
+			Order::class,
390
+			Order::fromArray($response['results'][0])
391
+		);
392
+	}
393
+
394
+	public function testGetOrderByScheduledDate()
395
+	{
396
+		$orderParameters = Order::fromArray([
397
+			'day_scheduled_for_YYMMDD'  => date('Y-m-d', strtotime('0 days')),
398
+			'offset'                    => 0,
399
+			'limit'                     => 5,
400
+		]);
401
+
402
+		$order = new Order();
403
+
404
+		$response = $order->getOrder($orderParameters);
405
+
406
+		$this->assertNotNull($response);
407
+		$this->assertTrue(is_array($response));
408
+		$this->assertTrue(isset($response['total']));
409
+		$this->assertTrue(isset($response['results']));
410
+		$this->assertInstanceOf(
411
+			Order::class,
412
+			Order::fromArray($response['results'][0])
413
+		);
414
+	}
415
+
416
+	public function testGetOrdersByCustomFields()
417
+	{
418
+		$orderParameters = Order::fromArray([
419
+			'fields'    => 'order_id,member_id',
420
+			'offset'    => 0,
421
+			'limit'     => 5,
422
+		]);
423
+
424
+		$order = new Order();
425
+
426
+		$response = $order->getOrder($orderParameters);
427
+
428
+		$response = $order->getOrder($orderParameters);
429
+
430
+		$this->assertNotNull($response);
431
+		$this->assertTrue(is_array($response));
432
+		$this->assertTrue(isset($response['total']));
433
+		$this->assertTrue(isset($response['results']));
434
+		$this->assertTrue(isset($response['fields']));
435
+		$this->assertInstanceOf(
436
+			Order::class,
437
+			Order::fromArray($response['results'][0])
438
+		);
439
+	}
440
+
441
+	public function testGetOrdersByScheduleFilter()
442
+	{
443
+		$orderParameters = Order::fromArray([
444
+			'limit'  => 5,
445
+			'filter' => [
446
+				'display'               => 'all',
447
+				'scheduled_for_YYMMDD'  => [
448
+					date('Y-m-d', strtotime('-1 days')),
449
+					date('Y-m-d', strtotime('1 days'))
450
+				]
451
+			]
452
+		]);
453
+
454
+		$order = new Order();
455
+
456
+		$response = $order->getOrder($orderParameters);
457
+
458
+		$this->assertNotNull($response);
459
+		$this->assertTrue(is_array($response));
460
+		$this->assertTrue(isset($response['total']));
461
+		$this->assertTrue(isset($response['results']));
462
+		$this->assertInstanceOf(
463
+			Order::class,
464
+			Order::fromArray($response['results'][0])
465
+		);
466
+	}
467
+
468
+	public function testGetOrdersBySpecifiedText()
469
+	{
470
+		$orderParameters = Order::fromArray([
471
+			'query'     => 'Auto test',
472
+			'offset'    => 0,
473
+			'limit'     => 5,
474
+		]);
475
+
476
+		$order = new Order();
477
+
478
+		$response = $order->getOrder($orderParameters);
479
+
480
+		$this->assertNotNull($response);
481
+		$this->assertTrue(is_array($response));
482
+		$this->assertTrue(isset($response['total']));
483
+		$this->assertTrue(isset($response['results']));
484
+		$this->assertInstanceOf(
485
+			Order::class,
486
+			Order::fromArray($response['results'][0])
487
+		);
488
+	}
489
+
490
+	public function testUpdateOrder()
491
+	{
492
+		$order = new Order();
493
+
494
+		// Update the order
495
+		self::$createdOrders[0]['address_2'] = 'Lviv';
496
+		self::$createdOrders[0]['EXT_FIELD_phone'] = '032268593';
497
+		self::$createdOrders[0]['EXT_FIELD_custom_data'] = [
498
+			0 => [
499
+				'customer_no' => '11',
500
+			],
501
+		];
502
+
503
+		$response = $order->updateOrder(self::$createdOrders[0]);
504
+
505
+		$this->assertNotNull($response);
506
+		$this->assertInstanceOf(Order::class, Order::fromArray($response));
507
+		$this->assertEquals('Lviv', $response['address_2']);
508
+		$this->assertEquals('032268593', $response['EXT_FIELD_phone']);
509
+		$this->assertEquals(
510
+			[
511
+				0 => '{"order_id":"10","name":"Bill Soul"}'
512
+			],
513
+			$response['EXT_FIELD_custom_data']
514
+		);
515
+	}
516
+
517
+	public function testUpdateOrderWithCustomFiel()
518
+	{
519
+		$orderParameters = Order::fromArray([
520
+			'order_id'              => self::$createdOrders[0]['order_id'],
521
+			'custom_user_fields'    => [
522
+				OrderCustomField::fromArray([
523
+					'order_custom_field_id'    => 93,
524
+					'order_custom_field_value' => 'true'
525
+				])
526
+			]
527
+		]);
528
+
529
+		$order = new Order();
530
+
531
+		$response = $order->updateOrder($orderParameters);
532
+
533
+		$this->assertNotNull($response);
534
+		$this->assertInstanceOf(Order::class, Order::fromArray($response));
535
+		$this->assertEquals(93, $response['custom_user_fields'][0]['order_custom_field_id']);
536
+		$this->assertEquals(true, $response['custom_user_fields'][0]['order_custom_field_value']);
537
+	}
538
+
539
+	public function testDeleteOrderByUuid()
540
+	{
541
+		$lastOrder = array_pop(self::$createdOrders);
542
+		if ($lastOrder != null) {
543
+			$order = new Order();
544
+			$ids = [
545
+				"order_ids" => [$lastOrder['order_uuid']]
546
+			];
547
+
548
+			$response = $order->removeOrder($ids);
549
+
550
+			if (!is_null($response) && isset($response['status']) && $response['status']) {
551
+				echo "The test order removed by UUID <br>";
552
+			}
553
+		}
554
+	}
555
+
556
+	public static function tearDownAfterClass()
557
+	{
558
+		if (sizeof(self::$createdOrders)) {
559
+			$orderIDs = [];
560
+
561
+			foreach (self::$createdOrders as $ord) {
562
+				$orderIDs[] = $ord['order_id'];
563
+			}
564
+
565
+			$orderParameters = Order::fromArray([
566
+				'order_ids' => $orderIDs
567
+			]);
568
+
569
+			$order = new Order();
570
+
571
+			$response = $order->removeOrder($orderParameters);
572
+
573
+			if (!is_null($response) &&
574
+				isset($response['status']) &&
575
+				$response['status']) {
576
+				echo "The test orders removed <br>";
577
+			}
578
+		}
579
+
580
+		if (sizeof(self::$createdProblems)>0) {
581
+			$optimizationProblemIDs = [];
582
+
583
+			foreach (self::$createdProblems as $problem) {
584
+				$optimizationProblemId = $problem->optimization_problem_id;
585
+
586
+				$optimizationProblemIDs[] = $optimizationProblemId;
587
+			}
588
+
589
+			$params = [
590
+				'optimization_problem_ids' => $optimizationProblemIDs,
591
+				'redirect'                 => 0,
592
+			];
593
+
594
+			$problem = new OptimizationProblem();
595
+			$result = $problem->removeOptimization($params);
596
+
597
+			if ($result!=null && $result['status']==true) {
598
+				echo "The test optimizations were removed <br>";
599
+			} else {
600
+				echo "Cannot remove the test optimizations <br>";
601
+			}
602
+		}
603
+	}
604 604
 }
Please login to merge, or discard this patch.
examples/Order/NewOrderWithEXTFields.php 1 patch
Indentation   +15 added lines, -15 removed lines patch added patch discarded remove patch
@@ -12,21 +12,21 @@
 block discarded – undo
12 12
 Route4Me::setApiKey(Constants::API_KEY);
13 13
 
14 14
 $orderParameters = Order::fromArray([
15
-    'address_1'                 => '1358 E Luzerne St, Philadelphia, PA 19124, US',
16
-    'cached_lat'                => 48.335991,
17
-    'cached_lng'                => 31.18287,
18
-    'address_alias'             => 'Auto test address',
19
-    'address_city'              => 'Philadelphia',
20
-    'day_scheduled_for_YYMMDD'  => date('Y-m-d'),
21
-    'EXT_FIELD_first_name'      => 'Igor',
22
-    'EXT_FIELD_last_name'       => 'Progman',
23
-    'EXT_FIELD_email'           => '[email protected]',
24
-    'EXT_FIELD_phone'           => '380380380380',
25
-    'EXT_FIELD_weight'          => 100.0,
26
-    'EXT_FIELD_cost'            => 50,
27
-    'EXT_FIELD_revenue'         => 150,
28
-    'EXT_FIELD_cube'            => 5,
29
-    'EXT_FIELD_pieces'          => 10
15
+	'address_1'                 => '1358 E Luzerne St, Philadelphia, PA 19124, US',
16
+	'cached_lat'                => 48.335991,
17
+	'cached_lng'                => 31.18287,
18
+	'address_alias'             => 'Auto test address',
19
+	'address_city'              => 'Philadelphia',
20
+	'day_scheduled_for_YYMMDD'  => date('Y-m-d'),
21
+	'EXT_FIELD_first_name'      => 'Igor',
22
+	'EXT_FIELD_last_name'       => 'Progman',
23
+	'EXT_FIELD_email'           => '[email protected]',
24
+	'EXT_FIELD_phone'           => '380380380380',
25
+	'EXT_FIELD_weight'          => 100.0,
26
+	'EXT_FIELD_cost'            => 50,
27
+	'EXT_FIELD_revenue'         => 150,
28
+	'EXT_FIELD_cube'            => 5,
29
+	'EXT_FIELD_pieces'          => 10
30 30
 ]);
31 31
 
32 32
 $order = new Order();
Please login to merge, or discard this patch.
src/Route4Me/Order.php 1 patch
Indentation   +341 added lines, -341 removed lines patch added patch discarded remove patch
@@ -6,349 +6,349 @@
 block discarded – undo
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 $addresses = [];
65
-
66
-    /**
67
-     * Weight of the order.
68
-     * @since 1.2.11
69
-     */
70
-    public $EXT_FIELD_weight;
71
-
72
-    /**
73
-     * Cost of the order.
74
-     * @since 1.2.11
75
-     */
76
-    public $EXT_FIELD_cost;
77
-
78
-    /**
79
-     * The total revenue for the order.
80
-     * @since 1.2.11
81
-     */
82
-    public $EXT_FIELD_revenue;
83
-
84
-    /**
85
-     * The cubic volume of the cargo.
86
-     * @since 1.2.11
87
-     */
88
-    public $EXT_FIELD_cube;
89
-
90
-    /**
91
-     *The item quantity of the cargo.
92
-     * @since 1.2.11
93
-     */
94
-    public $EXT_FIELD_pieces;
95
-
96
-    public function __construct()
97
-    {
98
-        Route4Me::setBaseUrl(Endpoint::BASE_URL);
99
-    }
100
-
101
-    /**
102
-     * @param Order $params
103
-     */
104
-    public static function addOrder($params)
105
-    {
106
-        $excludeFields = ['route_id', 'redirect', 'optimization_problem_id', 'order_id',
107
-            'order_ids', 'fields', 'offset', 'limit', 'query', 'created_timestamp', 'order_uuid'];
108
-
109
-        $allBodyFields = Route4Me::getObjectProperties(new self(), $excludeFields);
110
-
111
-        $response = Route4Me::makeRequst([
112
-            'url'       => Endpoint::ORDER_V4,
113
-            'method'    => 'POST',
114
-            'body'      => Route4Me::generateRequestParameters($allBodyFields, $params),
115
-        ]);
116
-
117
-        return $response;
118
-    }
119
-
120
-    public static function addOrder2Route($params)
121
-    {
122
-        $allQueryFields = ['route_id', 'redirect'];
123
-        $allBodyFields = ['addresses'];
124
-
125
-        $response = Route4Me::makeRequst([
126
-            'url'       => Endpoint::ROUTE_V4,
127
-            'method'    => 'PUT',
128
-            'query'     => Route4Me::generateRequestParameters($allQueryFields, $params),
129
-            'body'      => Route4Me::generateRequestParameters($allBodyFields, $params),
130
-        ]);
131
-
132
-        return $response;
133
-    }
134
-
135
-    public static function addOrder2Optimization($params)
136
-    {
137
-        $allQueryFields = ['optimization_problem_id', 'redirect', 'device_type'];
138
-        $allBodyFields  = ['addresses'];
139
-
140
-        $response = Route4Me::makeRequst([
141
-            'url'       => Endpoint::OPTIMIZATION_PROBLEM,
142
-            'method'    => 'PUT',
143
-            'query'     => Route4Me::generateRequestParameters($allQueryFields, $params),
144
-            'body'      => Route4Me::generateRequestParameters($allBodyFields, $params),
145
-        ]);
146
-
147
-        return $response;
148
-    }
149
-
150
-    public static function getOrder($params)
151
-    {
152
-        $allQueryFields = ['order_id', 'fields', 'day_added_YYMMDD', 'scheduled_for_YYMMDD', 'query',
153
-            'offset', 'limit'];
154
-
155
-        $response = Route4Me::makeRequst([
156
-            'url'       => Endpoint::ORDER_V4,
157
-            'method'    => 'GET',
158
-            'query'     => Route4Me::generateRequestParameters($allQueryFields, $params),
159
-        ]);
160
-
161
-        return $response;
162
-    }
163
-
164
-    public static function getOrders($params)
165
-    {
166
-        $allQueryFields = ['offset', 'limit'];
167
-
168
-        $response = Route4Me::makeRequst([
169
-            'url'       => Endpoint::ORDER_V4,
170
-            'method'    => 'GET',
171
-            'query'     => Route4Me::generateRequestParameters($allQueryFields, $params),
172
-        ]);
173
-
174
-        return $response;
175
-    }
176
-
177
-    public function getRandomOrderId($offset, $limit)
178
-    {
179
-        $randomOrder = $this->getRandomOrder($offset, $limit);
180
-
181
-        if (is_null($randomOrder) || !isset($randomOrder)) {
182
-            return null;
183
-        }
184
-
185
-        return $randomOrder['order_id'];
186
-    }
187
-
188
-    public function getRandomOrder($offset, $limit)
189
-    {
190
-        $params = ['offset' => $offset, 'limit' => $limit];
191
-
192
-        $orders = self::getOrders($params);
193
-
194
-        if (is_null($orders) || !isset($orders['results'])) {
195
-            return null;
196
-        }
197
-
198
-        $randomIndex = rand(0, sizeof($orders['results']) - 1);
199
-
200
-        $order = $orders['results'][$randomIndex];
201
-
202
-        return $order;
203
-    }
204
-
205
-    public static function removeOrder($params)
206
-    {
207
-        $allBodyFields = ['order_ids'];
208
-
209
-        $response = Route4Me::makeRequst([
210
-            'url'       => Endpoint::ORDER_V4,
211
-            'method'    => 'DELETE',
212
-            'body'      => Route4Me::generateRequestParameters($allBodyFields, $params),
213
-        ]);
214
-
215
-        return $response;
216
-    }
217
-
218
-    public static function updateOrder($params)
219
-    {
220
-        $excludeFields = ['route_id', 'redirect', 'optimization_problem_id', 'order_ids',
221
-            'fields', 'offset', 'limit', 'query', 'created_timestamp', 'route_uuid'];
222
-
223
-        $allBodyFields = Route4Me::getObjectProperties(new self(), $excludeFields);
224
-
225
-        $response = Route4Me::makeRequst([
226
-            'url'       => Endpoint::ORDER_V4,
227
-            'method'    => 'PUT',
228
-            'body'      => Route4Me::generateRequestParameters($allBodyFields, $params),
229
-        ]);
230
-
231
-        return $response;
232
-    }
233
-
234
-    public static function searchOrder($params)
235
-    {
236
-        $allQueryFields = ['fields', 'day_added_YYMMDD', 'scheduled_for_YYMMDD', 'query', 'offset', 'limit'];
237
-
238
-        $response = Route4Me::makeRequst([
239
-            'url'       => Endpoint::ORDER_V4,
240
-            'method'    => 'GET',
241
-            'query'     => Route4Me::generateRequestParameters($allQueryFields, $params),
242
-        ]);
243
-
244
-        return $response;
245
-    }
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 $addresses = [];
65
+
66
+	/**
67
+	 * Weight of the order.
68
+	 * @since 1.2.11
69
+	 */
70
+	public $EXT_FIELD_weight;
71
+
72
+	/**
73
+	 * Cost of the order.
74
+	 * @since 1.2.11
75
+	 */
76
+	public $EXT_FIELD_cost;
77
+
78
+	/**
79
+	 * The total revenue for the order.
80
+	 * @since 1.2.11
81
+	 */
82
+	public $EXT_FIELD_revenue;
83
+
84
+	/**
85
+	 * The cubic volume of the cargo.
86
+	 * @since 1.2.11
87
+	 */
88
+	public $EXT_FIELD_cube;
89
+
90
+	/**
91
+	 *The item quantity of the cargo.
92
+	 * @since 1.2.11
93
+	 */
94
+	public $EXT_FIELD_pieces;
95
+
96
+	public function __construct()
97
+	{
98
+		Route4Me::setBaseUrl(Endpoint::BASE_URL);
99
+	}
100
+
101
+	/**
102
+	 * @param Order $params
103
+	 */
104
+	public static function addOrder($params)
105
+	{
106
+		$excludeFields = ['route_id', 'redirect', 'optimization_problem_id', 'order_id',
107
+			'order_ids', 'fields', 'offset', 'limit', 'query', 'created_timestamp', 'order_uuid'];
108
+
109
+		$allBodyFields = Route4Me::getObjectProperties(new self(), $excludeFields);
110
+
111
+		$response = Route4Me::makeRequst([
112
+			'url'       => Endpoint::ORDER_V4,
113
+			'method'    => 'POST',
114
+			'body'      => Route4Me::generateRequestParameters($allBodyFields, $params),
115
+		]);
116
+
117
+		return $response;
118
+	}
119
+
120
+	public static function addOrder2Route($params)
121
+	{
122
+		$allQueryFields = ['route_id', 'redirect'];
123
+		$allBodyFields = ['addresses'];
124
+
125
+		$response = Route4Me::makeRequst([
126
+			'url'       => Endpoint::ROUTE_V4,
127
+			'method'    => 'PUT',
128
+			'query'     => Route4Me::generateRequestParameters($allQueryFields, $params),
129
+			'body'      => Route4Me::generateRequestParameters($allBodyFields, $params),
130
+		]);
131
+
132
+		return $response;
133
+	}
134
+
135
+	public static function addOrder2Optimization($params)
136
+	{
137
+		$allQueryFields = ['optimization_problem_id', 'redirect', 'device_type'];
138
+		$allBodyFields  = ['addresses'];
139
+
140
+		$response = Route4Me::makeRequst([
141
+			'url'       => Endpoint::OPTIMIZATION_PROBLEM,
142
+			'method'    => 'PUT',
143
+			'query'     => Route4Me::generateRequestParameters($allQueryFields, $params),
144
+			'body'      => Route4Me::generateRequestParameters($allBodyFields, $params),
145
+		]);
146
+
147
+		return $response;
148
+	}
149
+
150
+	public static function getOrder($params)
151
+	{
152
+		$allQueryFields = ['order_id', 'fields', 'day_added_YYMMDD', 'scheduled_for_YYMMDD', 'query',
153
+			'offset', 'limit'];
154
+
155
+		$response = Route4Me::makeRequst([
156
+			'url'       => Endpoint::ORDER_V4,
157
+			'method'    => 'GET',
158
+			'query'     => Route4Me::generateRequestParameters($allQueryFields, $params),
159
+		]);
160
+
161
+		return $response;
162
+	}
163
+
164
+	public static function getOrders($params)
165
+	{
166
+		$allQueryFields = ['offset', 'limit'];
167
+
168
+		$response = Route4Me::makeRequst([
169
+			'url'       => Endpoint::ORDER_V4,
170
+			'method'    => 'GET',
171
+			'query'     => Route4Me::generateRequestParameters($allQueryFields, $params),
172
+		]);
173
+
174
+		return $response;
175
+	}
176
+
177
+	public function getRandomOrderId($offset, $limit)
178
+	{
179
+		$randomOrder = $this->getRandomOrder($offset, $limit);
180
+
181
+		if (is_null($randomOrder) || !isset($randomOrder)) {
182
+			return null;
183
+		}
184
+
185
+		return $randomOrder['order_id'];
186
+	}
187
+
188
+	public function getRandomOrder($offset, $limit)
189
+	{
190
+		$params = ['offset' => $offset, 'limit' => $limit];
191
+
192
+		$orders = self::getOrders($params);
193
+
194
+		if (is_null($orders) || !isset($orders['results'])) {
195
+			return null;
196
+		}
197
+
198
+		$randomIndex = rand(0, sizeof($orders['results']) - 1);
199
+
200
+		$order = $orders['results'][$randomIndex];
201
+
202
+		return $order;
203
+	}
204
+
205
+	public static function removeOrder($params)
206
+	{
207
+		$allBodyFields = ['order_ids'];
208
+
209
+		$response = Route4Me::makeRequst([
210
+			'url'       => Endpoint::ORDER_V4,
211
+			'method'    => 'DELETE',
212
+			'body'      => Route4Me::generateRequestParameters($allBodyFields, $params),
213
+		]);
214
+
215
+		return $response;
216
+	}
217
+
218
+	public static function updateOrder($params)
219
+	{
220
+		$excludeFields = ['route_id', 'redirect', 'optimization_problem_id', 'order_ids',
221
+			'fields', 'offset', 'limit', 'query', 'created_timestamp', 'route_uuid'];
222
+
223
+		$allBodyFields = Route4Me::getObjectProperties(new self(), $excludeFields);
224
+
225
+		$response = Route4Me::makeRequst([
226
+			'url'       => Endpoint::ORDER_V4,
227
+			'method'    => 'PUT',
228
+			'body'      => Route4Me::generateRequestParameters($allBodyFields, $params),
229
+		]);
230
+
231
+		return $response;
232
+	}
233
+
234
+	public static function searchOrder($params)
235
+	{
236
+		$allQueryFields = ['fields', 'day_added_YYMMDD', 'scheduled_for_YYMMDD', 'query', 'offset', 'limit'];
237
+
238
+		$response = Route4Me::makeRequst([
239
+			'url'       => Endpoint::ORDER_V4,
240
+			'method'    => 'GET',
241
+			'query'     => Route4Me::generateRequestParameters($allQueryFields, $params),
242
+		]);
243
+
244
+		return $response;
245
+	}
246 246
 
247
-    public static function validateCoordinate($coord)
248
-    {
249
-        $key = key($coord);
250
-
251
-        if (!is_numeric($coord[$key])) {
252
-            return false;
253
-        }
254
-
255
-        switch ($key) {
256
-            case 'cached_lat':
257
-            case 'curbside_lat':
258
-                if ($coord[$key] > 90 || $coord[$key] < -90) {
259
-                    return false;
260
-                }
261
-                break;
262
-            case 'cached_lng':
263
-            case 'curbside_lng':
264
-                if ($coord[$key] > 180 || $coord[$key] < -180) {
265
-                    return false;
266
-                }
267
-                break;
268
-        }
269
-
270
-        return true;
271
-    }
247
+	public static function validateCoordinate($coord)
248
+	{
249
+		$key = key($coord);
250
+
251
+		if (!is_numeric($coord[$key])) {
252
+			return false;
253
+		}
254
+
255
+		switch ($key) {
256
+			case 'cached_lat':
257
+			case 'curbside_lat':
258
+				if ($coord[$key] > 90 || $coord[$key] < -90) {
259
+					return false;
260
+				}
261
+				break;
262
+			case 'cached_lng':
263
+			case 'curbside_lng':
264
+				if ($coord[$key] > 180 || $coord[$key] < -180) {
265
+					return false;
266
+				}
267
+				break;
268
+		}
269
+
270
+		return true;
271
+	}
272 272
 
273
-    public function addOrdersFromCsvFile($csvFileHandle, $ordersFieldsMapping)
274
-    {
275
-        $max_line_length = 512;
276
-        $delemietr = ',';
277
-
278
-        $results = [];
279
-        $results['fail'] = [];
280
-        $results['success'] = [];
281
-
282
-        $columns = fgetcsv($csvFileHandle, $max_line_length, $delemietr);
273
+	public function addOrdersFromCsvFile($csvFileHandle, $ordersFieldsMapping)
274
+	{
275
+		$max_line_length = 512;
276
+		$delemietr = ',';
277
+
278
+		$results = [];
279
+		$results['fail'] = [];
280
+		$results['success'] = [];
281
+
282
+		$columns = fgetcsv($csvFileHandle, $max_line_length, $delemietr);
283 283
 
284
-        $excludeFields = ['route_id', 'redirect', 'optimization_problem_id', 'order_id', 'order_ids',
285
-            'fields', 'offset', 'limit', 'query', 'created_timestamp', 'order_uuid'];
286
-
287
-        $allOrderFields = Route4Me::getObjectProperties(new self(), $excludeFields);
288
-
289
-        if (!empty($columns)) {
290
-            array_push($results['fail'], 'Empty CSV table');
284
+		$excludeFields = ['route_id', 'redirect', 'optimization_problem_id', 'order_id', 'order_ids',
285
+			'fields', 'offset', 'limit', 'query', 'created_timestamp', 'order_uuid'];
286
+
287
+		$allOrderFields = Route4Me::getObjectProperties(new self(), $excludeFields);
288
+
289
+		if (!empty($columns)) {
290
+			array_push($results['fail'], 'Empty CSV table');
291 291
 
292
-            return $results;
293
-        }
294
-
295
-        $iRow = 1;
296
-
297
-        while (false !== ($rows = fgetcsv($csvFileHandle, $max_line_length, $delemietr))) {
298
-            if ($rows[$ordersFieldsMapping['cached_lat']] && $rows[$ordersFieldsMapping['cached_lng']] && $rows[$ordersFieldsMapping['address_1']] && [null] !== $rows) {
299
-                $cached_lat = 0.000;
300
-                $cached_lng = 0.000;
301
-
302
-                foreach (['cached_lat', 'cached_lng', 'curbside_lat', 'curbside_lng'] as $coord) {
303
-                    if (!$this->validateCoordinate([$coord => $rows[$ordersFieldsMapping[$coord]]])) {
304
-                        array_push($results['fail'], "$iRow --> Wrong " + $coord);
305
-                        ++$iRow;
306
-                        continue;
307
-                    } else {
308
-                        switch ($coord) {
309
-                            case 'cached_lat':
310
-                                $cached_lat = doubleval($rows[$ordersFieldsMapping[$coord]]);
311
-                                break;
312
-                            case 'cached_lng':
313
-                                $cached_lng = doubleval($rows[$ordersFieldsMapping[$coord]]);
314
-                                break;
315
-                        }
316
-                    }
317
-                }
318
-
319
-                $address = $rows[$ordersFieldsMapping['address_1']];
320
-
321
-                foreach (['order_city', 'order_state_id', 'order_zip_code', 'order_country_id'] as $addressPart) {
322
-                    if (isset($ordersFieldsMapping[$addressPart])) {
323
-                        $address .= ', '.$rows[$ordersFieldsMapping[$addressPart]];
324
-                    }
325
-                }
326
-
327
-                echo "$iRow --> ".$ordersFieldsMapping['day_scheduled_for_YYMMDD'].', '.$rows[$ordersFieldsMapping['day_scheduled_for_YYMMDD']].'<br>';
328
-
329
-                $parametersArray = [];
330
-
331
-                $parametersArray['cached_lat'] = $cached_lat;
332
-                $parametersArray['cached_lng'] = $cached_lng;
333
-
334
-                foreach ($allOrderFields as $orderField) {
335
-                    if (isset($ordersFieldsMapping[$orderField])) {
336
-                        $parametersArray[$orderField] = $rows[$ordersFieldsMapping[$orderField]];
337
-                    }
338
-                }
339
-
340
-                $orderParameters = self::fromArray($parametersArray);
341
-
342
-                $order = new self();
343
-
344
-                $orderResults = $order->addOrder($orderParameters);
345
-
346
-                array_push($results['success'], 'The order with order_id = '.strval($orderResults['order_id']).' added successfuly.');
347
-            } else {
348
-                array_push($results['fail'], "$iRow --> one of the parameters cached_lat, cached_lng, address_1 is not set");
349
-            }
350
-
351
-            ++$iRow;
352
-        }
353
-    }
292
+			return $results;
293
+		}
294
+
295
+		$iRow = 1;
296
+
297
+		while (false !== ($rows = fgetcsv($csvFileHandle, $max_line_length, $delemietr))) {
298
+			if ($rows[$ordersFieldsMapping['cached_lat']] && $rows[$ordersFieldsMapping['cached_lng']] && $rows[$ordersFieldsMapping['address_1']] && [null] !== $rows) {
299
+				$cached_lat = 0.000;
300
+				$cached_lng = 0.000;
301
+
302
+				foreach (['cached_lat', 'cached_lng', 'curbside_lat', 'curbside_lng'] as $coord) {
303
+					if (!$this->validateCoordinate([$coord => $rows[$ordersFieldsMapping[$coord]]])) {
304
+						array_push($results['fail'], "$iRow --> Wrong " + $coord);
305
+						++$iRow;
306
+						continue;
307
+					} else {
308
+						switch ($coord) {
309
+							case 'cached_lat':
310
+								$cached_lat = doubleval($rows[$ordersFieldsMapping[$coord]]);
311
+								break;
312
+							case 'cached_lng':
313
+								$cached_lng = doubleval($rows[$ordersFieldsMapping[$coord]]);
314
+								break;
315
+						}
316
+					}
317
+				}
318
+
319
+				$address = $rows[$ordersFieldsMapping['address_1']];
320
+
321
+				foreach (['order_city', 'order_state_id', 'order_zip_code', 'order_country_id'] as $addressPart) {
322
+					if (isset($ordersFieldsMapping[$addressPart])) {
323
+						$address .= ', '.$rows[$ordersFieldsMapping[$addressPart]];
324
+					}
325
+				}
326
+
327
+				echo "$iRow --> ".$ordersFieldsMapping['day_scheduled_for_YYMMDD'].', '.$rows[$ordersFieldsMapping['day_scheduled_for_YYMMDD']].'<br>';
328
+
329
+				$parametersArray = [];
330
+
331
+				$parametersArray['cached_lat'] = $cached_lat;
332
+				$parametersArray['cached_lng'] = $cached_lng;
333
+
334
+				foreach ($allOrderFields as $orderField) {
335
+					if (isset($ordersFieldsMapping[$orderField])) {
336
+						$parametersArray[$orderField] = $rows[$ordersFieldsMapping[$orderField]];
337
+					}
338
+				}
339
+
340
+				$orderParameters = self::fromArray($parametersArray);
341
+
342
+				$order = new self();
343
+
344
+				$orderResults = $order->addOrder($orderParameters);
345
+
346
+				array_push($results['success'], 'The order with order_id = '.strval($orderResults['order_id']).' added successfuly.');
347
+			} else {
348
+				array_push($results['fail'], "$iRow --> one of the parameters cached_lat, cached_lng, address_1 is not set");
349
+			}
350
+
351
+			++$iRow;
352
+		}
353
+	}
354 354
 }
Please login to merge, or discard this patch.