|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Iris\SaleWrapper; |
|
4
|
|
|
|
|
5
|
|
|
class Venture extends Base implements VentureInterface |
|
6
|
|
|
{ |
|
7
|
|
|
/** |
|
8
|
|
|
* @return \Iris\Interfaces\IrisPartner |
|
9
|
|
|
*/ |
|
10
|
7 |
|
public function getPartnerService() |
|
11
|
|
|
{ |
|
12
|
7 |
|
return $this->getManager()->getService(\Iris\Factory::PARTNER); |
|
13
|
|
|
} |
|
14
|
|
|
|
|
15
|
|
|
/** |
|
16
|
|
|
* @return \Iris\Interfaces\IrisVenture |
|
17
|
|
|
*/ |
|
18
|
2 |
|
public function getVentureService() |
|
19
|
|
|
{ |
|
20
|
2 |
|
return $this->getManager()->getService(\Iris\Factory::VENTURE); |
|
21
|
|
|
} |
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* @return \Iris\Interfaces\Customer |
|
25
|
|
|
*/ |
|
26
|
2 |
|
public function getCustomerService() |
|
27
|
|
|
{ |
|
28
|
2 |
|
return $this->getManager()->getService(\Iris\Factory::CUSTOMER); |
|
29
|
|
|
} |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* {@inheritdoc} |
|
33
|
|
|
*/ |
|
34
|
2 |
|
public function createOrder(array $orderData, $originCode) |
|
35
|
|
|
{ |
|
36
|
2 |
|
$partner = $this->getPartnerService()->findByCode($originCode); |
|
37
|
|
|
|
|
38
|
2 |
|
$salesOrder = $this->getOrderMapping()->assign($orderData); |
|
39
|
|
|
|
|
40
|
2 |
|
$customer = $this->getCustomerService()->createByExternalData($salesOrder->getCustomer()); |
|
41
|
|
|
|
|
42
|
2 |
|
$idIrisCustomer = $customer->getIdIrisCustomer(); |
|
43
|
|
|
|
|
44
|
|
|
try { |
|
45
|
2 |
|
$irisOrder = $this->getOrderService()->getOrderNrByExternalshopNumberAndPartner( |
|
46
|
2 |
|
$orderData['order_number'], |
|
47
|
2 |
|
$partner->getPartnerCode() |
|
48
|
2 |
|
); |
|
49
|
1 |
|
$result = array('order_number' => $irisOrder); |
|
50
|
|
|
|
|
51
|
2 |
|
} catch (\Iris\Exceptions\OrderNotFound $exception) { |
|
52
|
1 |
|
$salesOrder = $this->getOrderService()->save($salesOrder); |
|
53
|
1 |
|
$orderData['id_iris_customer'] = $idIrisCustomer; |
|
54
|
1 |
|
$this->getVentureService()->saveExternalData($orderData, $salesOrder); |
|
55
|
1 |
|
$result = array('order_number' => $salesOrder->getOrderNr()); |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
2 |
|
return $result; |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
/** |
|
62
|
|
|
* {@inheritdoc} |
|
63
|
|
|
*/ |
|
64
|
2 |
|
public function confirmPaymentOrder($orderNumber, $originCode) |
|
65
|
|
|
{ |
|
66
|
2 |
|
$partner = $this->getPartnerService()->findByCode($originCode); |
|
67
|
2 |
|
$order = $this->getOrderService()->getOrderByOrderNumberAndPartnerCode( |
|
68
|
2 |
|
$orderNumber, |
|
69
|
2 |
|
$partner->getPartnerCode() |
|
70
|
2 |
|
); |
|
71
|
2 |
|
if (!$this->getOrderService()->confirmPayment($order)) { |
|
72
|
1 |
|
throw new \RuntimeException(sprintf('Order number %s can\'t be confirmed', $orderNumber)); |
|
73
|
|
|
} |
|
74
|
1 |
|
return array('order_number' => $order->getOrderNr()); |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
/** |
|
78
|
|
|
* {@inheritdoc} |
|
79
|
|
|
*/ |
|
80
|
1 |
|
public function findOrderByOrderNumber($orderNumber, $originCode) |
|
81
|
|
|
{ |
|
82
|
1 |
|
return $this->getOrderService()->getOrderByOrderNumberAndPartnerCode($orderNumber, $originCode); |
|
|
|
|
|
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
|
|
/** |
|
86
|
|
|
* {@inheritdoc} |
|
87
|
|
|
*/ |
|
88
|
2 |
|
public function cancelOrder($orderNumber, $originCode) |
|
89
|
|
|
{ |
|
90
|
2 |
|
$partner = $this->getPartnerService()->findByCode($originCode); |
|
91
|
2 |
|
$order = $this->getOrderService()->getOrderByOrderNumberAndPartnerCode( |
|
92
|
2 |
|
$orderNumber, |
|
93
|
2 |
|
$partner->getPartnerCode() |
|
94
|
2 |
|
); |
|
95
|
2 |
|
if (!$this->getOrderService()->cancel($order)) { |
|
96
|
1 |
|
throw new \RuntimeException(sprintf('Order number %s can\'t be canceled', $orderNumber)); |
|
97
|
|
|
} |
|
98
|
1 |
|
return array('order_number' => $order->getOrderNr()); |
|
99
|
|
|
} |
|
100
|
|
|
|
|
101
|
|
|
/** |
|
102
|
|
|
* {@inheritdoc} |
|
103
|
|
|
*/ |
|
104
|
1 |
|
public function createProductsOnPartner(\Iris\Transfer\Catalog\ConfigCollection $products, $partnerCode) |
|
105
|
|
|
{ |
|
106
|
1 |
|
$this->getVentureApiClient()->createProducts($products, $partnerCode); |
|
107
|
1 |
|
} |
|
108
|
|
|
|
|
109
|
|
|
/** |
|
110
|
|
|
* {@inheritdoc} |
|
111
|
|
|
*/ |
|
112
|
1 |
|
public function updateProductsOnPartner(\Iris\Transfer\Catalog\ConfigCollection $products) |
|
113
|
|
|
{ |
|
114
|
1 |
|
$this->getVentureApiClient()->updateProducts($products); |
|
115
|
1 |
|
} |
|
116
|
|
|
|
|
117
|
|
|
/** |
|
118
|
|
|
* {@inheritdoc} |
|
119
|
|
|
*/ |
|
120
|
1 |
|
public function updateStockOnPartner($skuSimple, $stock) |
|
121
|
|
|
{ |
|
122
|
1 |
|
$this->getVentureApiClient()->updateStock($skuSimple, $stock); |
|
123
|
1 |
|
} |
|
124
|
|
|
|
|
125
|
|
|
/** |
|
126
|
|
|
* {@inheritdoc} |
|
127
|
|
|
*/ |
|
128
|
1 |
|
public function updatePriceOnPartner( |
|
129
|
|
|
$skuSimple, |
|
130
|
|
|
$price, |
|
131
|
|
|
$specialPrice = null, |
|
132
|
|
|
$specialFromDate = null, |
|
133
|
|
|
$specialToDate = null |
|
134
|
|
|
) { |
|
135
|
1 |
|
$this->getVentureApiClient()->updatePrice( |
|
136
|
1 |
|
$skuSimple, |
|
137
|
1 |
|
$price, |
|
138
|
1 |
|
$specialPrice ?: $price, |
|
139
|
1 |
|
$specialFromDate, |
|
140
|
|
|
$specialToDate |
|
141
|
1 |
|
); |
|
142
|
1 |
|
} |
|
143
|
|
|
|
|
144
|
|
|
/** |
|
145
|
|
|
* {@inheritdoc} |
|
146
|
|
|
*/ |
|
147
|
|
|
public function isPartnerItem(\Iris\Transfer\Sales\Order\Item $item) |
|
148
|
|
|
{ |
|
149
|
|
|
$irisPartner = $this->getPartnerService()->findBySalesOrderId($item->getFkSalesOrder()); |
|
150
|
|
|
return ($irisPartner instanceof \Iris\Transfer\Partner); |
|
151
|
|
|
} |
|
152
|
|
|
|
|
153
|
|
|
/** |
|
154
|
|
|
* {@inheritdoc} |
|
155
|
|
|
*/ |
|
156
|
1 |
|
public function setStatusToShippedOnPartner(\Iris\Transfer\Tracking\ShippedCollection $items) |
|
157
|
|
|
{ |
|
158
|
1 |
|
return $this->getVentureApiClient()->setStatusToShippedOnPartner($items); |
|
|
|
|
|
|
159
|
|
|
} |
|
160
|
|
|
|
|
161
|
|
|
/** |
|
162
|
|
|
* {@inheritdoc} |
|
163
|
|
|
*/ |
|
164
|
1 |
|
public function setStatusToDeliveredOnPartner(\Iris\Transfer\Tracking\DeliveredCollection $items) |
|
165
|
|
|
{ |
|
166
|
1 |
|
return $this->getVentureApiClient()->setStatusToDeliveredOnPartner($items); |
|
|
|
|
|
|
167
|
|
|
} |
|
168
|
|
|
|
|
169
|
|
|
/** |
|
170
|
|
|
* NOTE: Not implemented yet! |
|
171
|
|
|
* |
|
172
|
|
|
* {@inheritdoc} |
|
173
|
|
|
*/ |
|
174
|
1 |
|
public function setStatusToCanceledOnPartner(\Iris\Transfer\Tracking\CanceledCollection $items) |
|
175
|
|
|
{ |
|
176
|
1 |
|
return $this->getVentureApiClient()->setStatusToCanceledOnPartner($items); |
|
|
|
|
|
|
177
|
|
|
} |
|
178
|
|
|
|
|
179
|
|
|
/** |
|
180
|
|
|
* {@inheritdoc} |
|
181
|
|
|
*/ |
|
182
|
1 |
|
public function setStatusToFailedDeliveryOnPartner(\Iris\Transfer\Tracking\FailedDeliveryCollection $items) |
|
183
|
|
|
{ |
|
184
|
1 |
|
return $this->getVentureApiClient()->setStatusToFailedDeliveryOnPartner($items); |
|
|
|
|
|
|
185
|
|
|
} |
|
186
|
|
|
|
|
187
|
|
|
/** |
|
188
|
|
|
* {@inheritdoc} |
|
189
|
|
|
*/ |
|
190
|
1 |
|
public function getName() |
|
191
|
|
|
{ |
|
192
|
1 |
|
return 'venture'; |
|
193
|
|
|
} |
|
194
|
|
|
} |
|
195
|
|
|
|
If you return a value from a function or method, it should be a sub-type of the type that is given by the parent type f.e. an interface, or abstract method. This is more formally defined by the Lizkov substitution principle, and guarantees that classes that depend on the parent type can use any instance of a child type interchangably. This principle also belongs to the SOLID principles for object oriented design.
Let’s take a look at an example:
Our function
my_functionexpects aPostobject, and outputs the author of the post. The base classPostreturns a simple string and outputting a simple string will work just fine. However, the child classBlogPostwhich is a sub-type ofPostinstead decided to return anobject, and is therefore violating the SOLID principles. If aBlogPostwere passed tomy_function, PHP would not complain, but ultimately fail when executing thestrtouppercall in its body.