1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of PHP CS Fixer. |
5
|
|
|
* |
6
|
|
|
* (c) Fabien Potencier <[email protected]> |
7
|
|
|
* Dariusz Rumiński <[email protected]> |
8
|
|
|
* |
9
|
|
|
* This source file is subject to the MIT license that is bundled |
10
|
|
|
* with this source code in the file LICENSE. |
11
|
|
|
*/ |
12
|
|
|
|
13
|
|
|
namespace Etrias\PaazlConnector\Services; |
14
|
|
|
|
15
|
|
|
use DateTime; |
16
|
|
|
use Etrias\PaazlConnector\Client\PaazlClientInterface; |
17
|
|
|
use Etrias\PaazlConnector\Exceptions\NoShippingOptionsAvailableException; |
18
|
|
|
use Etrias\PaazlConnector\SoapTypes\CancelShipmentsRequest; |
19
|
|
|
use Etrias\PaazlConnector\SoapTypes\DateRangeType; |
20
|
|
|
use Etrias\PaazlConnector\SoapTypes\ExistingLabelType; |
21
|
|
|
use Etrias\PaazlConnector\SoapTypes\OrdersToShipRequest; |
22
|
|
|
use Etrias\PaazlConnector\SoapTypes\ShippingOptionRequest; |
23
|
|
|
use Etrias\PaazlConnector\SoapTypes\ShippingOptionResponse; |
24
|
|
|
use Etrias\PaazlConnector\SoapTypes\ShippingOptions; |
25
|
|
|
use Etrias\PaazlConnector\SoapTypes\Source; |
26
|
|
|
use Etrias\PaazlConnector\SoapTypes\Sources; |
27
|
|
|
use RuntimeException; |
28
|
|
|
|
29
|
|
|
class ShippingService implements ShippingServiceInterface |
30
|
|
|
{ |
31
|
|
|
/** |
32
|
|
|
* @var PaazlClientInterface |
33
|
|
|
*/ |
34
|
|
|
protected $client; |
35
|
|
|
/** |
36
|
|
|
* @var SecurityServiceInterface |
37
|
|
|
*/ |
38
|
|
|
protected $security; |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* DocumentService constructor. |
42
|
|
|
* |
43
|
|
|
* @param PaazlClientInterface $client |
44
|
|
|
* @param SecurityServiceInterface $security |
45
|
|
|
*/ |
46
|
|
|
public function __construct(PaazlClientInterface $client, SecurityServiceInterface $security) |
47
|
|
|
{ |
48
|
|
|
$this->security = $security; |
49
|
|
|
$this->client = $client; |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* {@inheritdoc} |
54
|
|
|
*/ |
55
|
|
|
public function generateShippingManifest() |
56
|
|
|
{ |
57
|
|
|
throw new RuntimeException('Not Implemented'); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* {@inheritdoc} |
62
|
|
|
*/ |
63
|
|
View Code Duplication |
public function getOrdersToShip(DateTime $date = null, $targetWebShop = null) |
|
|
|
|
64
|
|
|
{ |
65
|
|
|
if ($date === null) { |
66
|
|
|
$date = new DateTime(); |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
$request = new OrdersToShipRequest( |
70
|
|
|
$this->security->getHash($date->format('Ymd')), |
71
|
|
|
$this->client->getWebShopId(), |
72
|
|
|
$targetWebShop, |
73
|
|
|
$date |
74
|
|
|
); |
75
|
|
|
|
76
|
|
|
return $this->client->ordersToShip($request); |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* {@inheritdoc} |
81
|
|
|
*/ |
82
|
|
View Code Duplication |
public function cancelShipments(array $barCodes, $targetWebShop = null) |
|
|
|
|
83
|
|
|
{ |
84
|
|
|
$labels = []; |
85
|
|
|
|
86
|
|
|
foreach ($barCodes as $barCode) { |
87
|
|
|
$labels[] = new ExistingLabelType( |
88
|
|
|
$this->security->getHash($barCode->getOrderReference()), |
89
|
|
|
$targetWebShop, |
90
|
|
|
$barCode->getOrderReference(), |
91
|
|
|
$barCode->getBarcode() |
92
|
|
|
); |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
$request = new CancelShipmentsRequest( |
96
|
|
|
$this->client->getWebShopId(), |
97
|
|
|
$labels |
98
|
|
|
); |
99
|
|
|
|
100
|
|
|
return $this->client->cancelShipments($request); |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
/** |
104
|
|
|
* {@inheritdoc} |
105
|
|
|
*/ |
106
|
|
|
public function getShippingOptions( |
107
|
|
|
$orderReference, |
108
|
|
|
$country, |
109
|
|
|
DateRangeType $deliveryDateRange = null, |
110
|
|
|
$postcode = null, |
111
|
|
|
$extendedDeliveryDateDetails = null, |
112
|
|
|
$shippingOption = null, |
113
|
|
|
array $sources = [], |
114
|
|
|
$targetWebShop = null |
115
|
|
|
) { |
116
|
|
|
$sources = new Sources($sources); |
117
|
|
|
|
118
|
|
|
$request = new ShippingOptionRequest( |
119
|
|
|
$this->security->getHash($orderReference), |
120
|
|
|
$this->client->getWebShopId(), |
121
|
|
|
$targetWebShop, |
122
|
|
|
$orderReference, |
123
|
|
|
$postcode, |
124
|
|
|
$country, |
125
|
|
|
null, |
126
|
|
|
null, |
127
|
|
|
$extendedDeliveryDateDetails, |
128
|
|
|
$shippingOption, |
129
|
|
|
$deliveryDateRange, |
130
|
|
|
$deliveryDateRange, |
131
|
|
|
$sources |
132
|
|
|
); |
133
|
|
|
|
134
|
|
|
try { |
135
|
|
|
return $this->client->shippingOption($request); |
136
|
|
|
} catch (NoShippingOptionsAvailableException $e) { |
137
|
|
|
$response = new ShippingOptionResponse(); |
138
|
|
|
$response->setShippingOptions(new ShippingOptions()); |
139
|
|
|
|
140
|
|
|
return $response; |
141
|
|
|
} |
142
|
|
|
} |
143
|
|
|
} |
144
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.