Completed
Pull Request — master (#7)
by Rafael
03:49
created

Partner::findOrderByOrderNumber()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 2
crap 1
1
<?php
2
3
namespace Iris\SaleWrapper;
4
5
class Partner extends Base implements PartnerInterface
6
{
7
    private $mappingClasses;
8
9
    /**
10
     * {@inheritdoc}
11
     */
12
    public function getName()
13
    {
14 4
        return 'partner';
15
    }
16 4
17
    /**
18
     * Gets Venture service.
19
     * @return \Iris\Interfaces\IrisVenture
20
     */
21
    public function getVentureService()
22
    {
23 3
        return $this->getManager()->getService(\Iris\Factory::VENTURE);
24
    }
25 3
26
    /**
27
     * Gets Stock service.
28
     * @return \Iris\Interfaces\Stock
29
     */
30
    public function getStockService()
31
    {
32 2
        return $this->getManager()->getService(\Iris\Factory::STOCK);
33
    }
34 2
35
    /**
36
     * Gets Stock service.
37
     * @return \Iris\Interfaces\Catalog
38
     */
39
    public function getCatalogService()
40 2
    {
41
        return $this->getManager()->getService(\Iris\Factory::CATALOG);
42 2
    }
43 2
44 2
45
    //order
46
    /**
47
     * {@inheritdoc}
48
     */
49 1
    public function isVentureItem(\Iris\Transfer\Sales\Order\Item $item)
50
    {
51 1
        $irisVenture = $this->getVentureService()
52
            ->getIrisVentureBySalesOrderId($item->getFkSalesOrder());
53 1
54 1
        return ($irisVenture instanceof \Iris\Transfer\Venture);
55 1
    }
56 1
57
    /**
58 1
     * {@inheritdoc}
59
     */
60 1
    public function sendOrderToVenture(
61 1
        array $orderData,
62
        string $ventureCode
63
    ) {
64
        return $this->getPartnerApiClient()
65
            ->createOrderOnVenture($ventureCode, $orderData);
66 1
    }
67
68 1
    /**
69 1
     * {@inheritdoc}
70
     */
71
    public function dropReserveAndUpdateStock(
72
        \Iris\Transfer\Sales\Order\Item $orderItem,
73
        array $productsData,
74
        $ventureCode
75 1
    ) {
76
        $this->getStockService()->dropReserve($orderItem);
77 1
        $this->updateStockFromVenture($productsData, $ventureCode);
78 1
    }
79
80
    /**
81
     * {@inheritdoc}
82
     */
83
    public function confirmOrderPaidOnVenture(
84 4
        \Iris\Transfer\Sales\Order $order,
85
        \Iris\Transfer\Venture $venture
86 4
    ) {
87
        return $this->getPartnerApiClient()
88
            ->confirmPaymentOnVenture(
89
                $venture->getVentureCode(),
90
                $order->getOrderNr()
91
            );
92 1
    }
93
94 1
    /**
95
     * {@inheritdoc}
96 1
     */
97 1
    public function confirmOrderFromVenture(array $orderData, $ventureCode)
98
    {
99
        $order = $this->getMapping('Order')->assign($orderData);
100
        $this->getOrderService()->confirmOrderFromVenture($order);
101
    }
102
103 1
    /**
104
     * {@inheritdoc}
105 1
     */
106 1
    public function cancelOrderOnVenture(
107
        \Iris\Transfer\Sales\Order $order,
108
        \Iris\Transfer\Venture $venture
109
    ) {
110
        return $this->getPartnerApiClient()
111
            ->cancelOrderOnVenture(
112 1
                $venture->getVentureCode(),
113
                $order->getOrderNr()
114 1
            );
115 1
    }
116
117
    /**
118
     * {@inheritdoc}
119
     */
120
    public function cancelOrderFromVenture($orderNr, $ventureCode)
121 1
    {
122
123 1
        $order = $this->getOrderService()
124 1
            ->getOrderByOrderNumberAndVentureCode($orderNr, $ventureCode);
125 1
126 1
        $this->getOrderService()->cancelOrderFromVenture($order);
127 1
        return ['order_number' => $order->getOrderNr()];
128 1
    }
129 1
130
    /**
131
     * {@inheritdoc}
132
     */
133
    public function bindVentureOrder($orderNr, $ventureCode, $ventureorderNr)
134
    {
135 2
        $this->getOrderService()
136
            ->bindPartnerOrderWithVentureOrder(
137 2
                $orderNr,
138
                $ventureCode,
139
                $ventureOrderNr
0 ignored issues
show
Bug introduced by
The variable $ventureOrderNr does not exist. Did you mean $orderNr?

This check looks for variables that are accessed but have not been defined. It raises an issue if it finds another variable that has a similar name.

The variable may have been renamed without also renaming all references.

Loading history...
140
            );
141
    }
142
143
    /**
144
     * Gets an specific mapping classs
145
     *
146
     * @param string $mappingName
147
     */
148
    public function getMapping($mappingName)
149
    {
150
        if (!$this->mappingClasses[$mappingName]) {
151
            $mappingClass = '\Iris\Mapping\\' . $mappingName;
152
            $this->mappingClasses[$mappingName] =  $mappingClass::getInstance();
153
        }
154
155
        return $this->mappingClasses[$mappingName];
156
    }
157
158
    /**
159
     * Set an specific mapping classs
160
     *
161
     * @param string $mappingName
162
     * @param $mappingClass
163
     * @return \Iris\SaleWrapper\Partner
164
     */
165
    public function setMapping($mappingName, $mappingClass)
166
    {
167
        $this->mappingClasses[$mappingName] = $mappingClass;
168
        return $this;
169
    }
170
171
    //post payment
172
    /**
173
     * {@inheritdoc}
174
     */
175
    public function setOrderStatusToShippedFromVenture(array $postPaymentData)
176
    {
177
        $postPaymentCollection = $this->getMapping('PostPaymentCollection')
178
            ->assign($postPaymentData);
179
180
        foreach ($postPaymentCollection as $postPayment) {
181
            if (!$postPayment->getTrackingCode()) {
182
                $postPayment->setTrackingCode(md5($postPayment->getTrackingUrl()));
183
            }
184
        }
185
186
        return $this->getOrderService()->shippedByVenture($postPayment);
0 ignored issues
show
Bug introduced by
The variable $postPayment seems to be defined by a foreach iteration on line 180. Are you sure the iterator is never empty, otherwise this variable is not defined?

It seems like you are relying on a variable being defined by an iteration:

foreach ($a as $b) {
}

// $b is defined here only if $a has elements, for example if $a is array()
// then $b would not be defined here. To avoid that, we recommend to set a
// default value for $b.


// Better
$b = 0; // or whatever default makes sense in your context
foreach ($a as $b) {
}

// $b is now guaranteed to be defined here.
Loading history...
187
    }
188
189
    /**
190
     * {@inheritdoc}
191
     */
192
    public function setOrderStatusToDeliveredFromVenture(
193
        array $postPaymentData, 
194
        $ventureCode
195
    ) {
196
        $postPayment = $this->getMapping('PostPayment')->assign($postPaymentData);
197
        return $this->getOrderService()->deliveredByVenture($postPayment);
0 ignored issues
show
Bug introduced by
The call to deliveredByVenture() misses a required argument $venture.

This check looks for function calls that miss required arguments.

Loading history...
198
    }
199
200
    /**
201
     * {@inheritdoc}
202
     */
203
    public function setOrderStatusToDeliveryFailedFromVenture(
204
        array $orderData,
205
        $ventureCode
206
    ) {
207
        $postPayment = $this->getMapping('PostPayment')->assign($postPaymentData);
0 ignored issues
show
Bug introduced by
The variable $postPaymentData does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
208
        return $this->getOrderService()
209
            ->deliveryFailedByVenture($postPayment, $ventureCode);
0 ignored issues
show
Documentation introduced by
$ventureCode is of type string, but the function expects a object<Iris\Transfer\Venture>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
210
    }
211
212
    //products
213
    /**
214
     * {@inheritdoc}
215
     */
216
    public function updatePriceFromVenture(array $productsData, $ventureCode)
217
    {
218
        $configCollection = $this->getMapping('ConfigCollection')->assign($productsData);
219
        return $this->getCatalogService()->updatePrice($configCollection);
220
    }
221
222
    /**
223
     * {@inheritdoc}
224
     */
225
    public function updateStockFromVenture(array $productsData, $ventureCode)
226
    {
227
        $configCollection = $this->getMapping('SimpleCollection')
228
            ->assign($productsData);
229
230
        return $this->getStockService()->updateAbsoluteStock($configCollection);
231
    }
232
233
    /**
234
     * {@inheritdoc}
235
     */
236
    public function createProductsFromVenture(array $productsData, $ventureCode)
237
    {
238
        $configCollection = $this->getMapping('ConfigCollection')
239
            ->assign($productsData);
240
241
        return $this->getCatalogService()->createProducts($configCollection, $ventureCode);
242
    }
243
244
    /**
245
     * {@inheritdoc}
246
     */
247
    public function sendProductCreationConfirmationToVenture(
248
        \Iris\Transfer\Catalog\ConfigCollection $configCollection,
249
        \Iris\Transfer\Venture $venture
250
    ) {
251
        $productsData = $this->getMapping('ConfigCollection')
252
            ->map($configCollection);
253
254
        $this->getPartnerApiClient()
255
            ->sendProductCreationConfirmationToVenture(
256
                $productsData,
257
                $venture->getVentureCode()
258
            );
259
    }
260
261
    /**
262
     * {@inheritdoc}
263
     */
264
    public function updateProductsFromVenture(array $productsData, $ventureCode)
265
    {
266
        $configCollection = $this->getMapping('ConfigCollection')
267
            ->assign($productsData);
268
269
        return $this->getCatalogService()->updateProducts($configCollection, $ventureCode);
270
    }
271
272
    /**
273
     * {@inheritdoc}
274
     */
275
    public function updateProductImagesFromVenture(array $productsData, $ventureCode)
276
    {
277
        $configCollection = $this->getMapping('ConfigCollection')
278
            ->assign($productsData);
279
280
        return $this->getCatalogService()->updateImages($configCollection, $ventureCode);
281
    }
282
283
    /**
284
     * {@inheritdoc}
285
     */
286
    public function isInvalidOrder(\Iris\Transfer\Sales\Order $order)
287
    {
288
        return $this->getOrderService()->isInvalidOrder($order);
289
    }
290
}
291