Completed
Push — master ( e3ed33...61d114 )
by
unknown
04:23
created

Venture::getName()   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 3
Bugs 1 Features 0
Metric Value
c 3
b 1
f 0
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 0
crap 1
1
<?php
2
3
namespace Iris\SaleWrapper;
4
5
class Venture extends Base
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\Customer
17
     */
18 2
    public function getCustomerService()
19
    {
20 2
        return $this->getManager()->getService(\Iris\Factory::CUSTOMER);
21
    }
22
23
    /**
24
     * Create order from partner
25
     *
26
     * @param array  $orderData
27
     * @param string $originCode
28
     * @return array returns an array with order_number like: ['order_number' => 123].
29
     * @throws \Iris\Exceptions\PartnerNotFound
30
     * @throws \Iris\Exceptions\UnableToCreateCustomer
31
     * @throws \Iris\Exceptions\UnableToCreateOrder
32
     * @throws \Iris\Exceptions\UnableToSaveExternalData
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
        $salesOrder->setCustomer(
41 2
            $this->getCustomerService()
42 2
                 ->create($salesOrder->getCustomer())
43 2
        );
44
45
        try {
46 2
            $order = $this->getOrderService()->getOrderByOrderNumberAndPartnerCode(
47 2
                $orderData['order_number'],
48 2
                $partner->getPartnerCode()
49 2
            );
50 1
            $result = array('order_number' => $order->getOrderNr());
51
52 2
        } catch (\Iris\Exceptions\OrderNotFound $exception) {
53 1
            $salesOrder = $this->getOrderService()->save($salesOrder);
54 1
            $result = array('order_number' => $salesOrder->getOrderNr());
55
        }
56
57 2
        return $result;
58
    }
59
60
    /**
61
     * Confirm payment from partner
62
     *
63
     * @param string $orderNr
64
     * @param string $originCode
65
     * @return array returns an array with order_number like: ['order_number' => 123].
66
     * @throws \Iris\Exceptions\OrderNotFound
67
     * @throws \Iris\Exceptions\PartnerNotFound
68
     * @throws \Iris\Exceptions\UnableToConfirmOrder
69
     */
70 2
    public function confirmPaymentOrder($orderNr, $originCode)
71
    {
72 2
        $partner = $this->getPartnerService()->findByCode($originCode);
73 2
        $order = $this->getOrderService()->getOrderByOrderNumberAndPartnerCode(
74 2
            $orderNr,
75 2
            $partner->getPartnerCode()
76 2
        );
77 2
        if (!$this->getOrderService()->confirmPayment($order)) {
78 1
            throw new \RuntimeException(sprintf('Order number %s can\'t be confirmed', $orderNr));
79
        }
80 1
        return array('order_number' => $order->getOrderNr());
81
    }
82
83
    /**
84
     * Cancel order from partner
85
     *
86
     * @param string $orderNr
87
     * @param string $originCode
88
     * @return array returns an array with order_number like: ['order_number' => 123].
89
     * @throws \Iris\Exceptions\OrderNotFound
90
     * @throws \Iris\Exceptions\PartnerNotFound
91
     * @throws \Iris\Exceptions\UnableToCancelOrder
92
     */
93 2
    public function cancelOrder($orderNr, $originCode)
94
    {
95 2
        $partner = $this->getPartnerService()->findByCode($originCode);
96 2
        $order = $this->getOrderService()->getOrderByOrderNumberAndPartnerCode(
97 2
            $orderNr,
98 2
            $partner->getPartnerCode()
99 2
        );
100 2
        if (!$this->getOrderService()->cancel($order)) {
101 1
            throw new \RuntimeException(sprintf('Order number %s can\'t be canceled', $orderNr));
102
        }
103 1
        return array('order_number' => $order->getOrderNr());
104
    }
105
106
    /**
107
     * Create products on partner
108
     *
109
     * @param \Iris\Transfer\Catalog\ConfigCollection $products
0 ignored issues
show
Bug introduced by
There is no parameter named $products. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
110
     * @param string $partnerCode
111
     * @return bool
112
     * @throws \Iris\Exceptions\RetryMessage
113
     */
114 1
    public function createProductsOnPartner(
115
        \Iris\Transfer\Catalog\ConfigCollection $configCollection,
116
        $partnerCode
117
    ) {
118 1
        $this->getVentureApiClient()->createProducts(
119 1
            $configCollection,
120
            $partnerCode
121 1
        );
122 1
    }
123
124
    /**
125
     * Update products on partner
126
     *
127
     * @param \Iris\Transfer\Catalog\ConfigCollection $products
0 ignored issues
show
Bug introduced by
There is no parameter named $products. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
128
     * @return bool
129
     * @throws \Iris\Exceptions\RetryMessage
130
     */
131 1
    public function updateProductsOnPartner(
132
        \Iris\Transfer\Catalog\ConfigCollection $configCollection
133
    ) {
134 1
        $this->getVentureApiClient()->updateProducts($configCollection);
135 1
    }
136
137
    /**
138
     * Update stock on partner
139
     *
140
     * @param string $skuSimple
141
     * @param int $stock
142
     * @return bool
143
     * @throws \Iris\Exceptions\RetryMessage
144
     */
145 1
    public function updateStockOnPartner($skuSimple, $stock)
146
    {
147 1
        $this->getVentureApiClient()->updateStock($skuSimple, $stock);
148 1
    }
149
150
    /**
151
     * Update price on partner
152
     *
153
     * @param string $skuSimple
154
     * @param float $price
155
     * @param float $specialPrice
156
     * @param string $specialFromDate
157
     * @param string $specialToDate
158
     * @return bool
159
     * @throws \Iris\Exceptions\RetryMessage
160
     */
161 1
    public function updatePriceOnPartner(
162
        $skuSimple,
163
        $price,
164
        $specialPrice = null,
165
        $specialFromDate = null,
166
        $specialToDate = null
167
    ) {
168 1
        $this->getVentureApiClient()->updatePrice(
169 1
            $skuSimple,
170 1
            $price,
171 1
            $specialPrice ?: $price,
172 1
            $specialFromDate,
173
            $specialToDate
174 1
        );
175 1
    }
176
177
    /**
178
     * Change order items to shipped status
179
     *
180
     * @param \Iris\Transfer\Tracking\ShippedCollection
181
     * @return bool|\GuzzleHttp\Message\Response
182
     * @throws \Iris\Exceptions\RetryMessage
183
     */
184 1
    public function setStatusToShippedOnPartner(
185
        \Iris\Transfer\Tracking\ShippedCollection $items
186
    ) {
187 1
        return $this->getVentureApiClient()->setStatusToShippedOnPartner($items);
188
    }
189
190
    /**
191
     * Change order items to delivered status
192
     *
193
     * @param \Iris\Transfer\Tracking\DeliveredCollection
194
     * @return bool|\GuzzleHttp\Message\Response
195
     * @throws \Iris\Exceptions\RetryMessage
196
     */
197 1
    public function setStatusToDeliveredOnPartner(
198
        \Iris\Transfer\Tracking\DeliveredCollection $items
199
    ) {
200 1
        return $this->getVentureApiClient()->setStatusToDeliveredOnPartner($items);
201
    }
202
203
    /**
204
     * Change order items canceled status
205
     *
206
     * @param \Iris\Transfer\Tracking\CanceledCollection
207
     * @return bool|\GuzzleHttp\Message\Response
208
     * @throws \Iris\Exceptions\RetryMessage
209
     */
210 1
    public function setStatusToCanceledOnPartner(
211
        \Iris\Transfer\Tracking\CanceledCollection $items
212
    ) {
213 1
        return $this->getVentureApiClient()->setStatusToCanceledOnPartner($items);
214
    }
215
216
    /**
217
     * Change order items to failed delivery status
218
     *
219
     * @param \Iris\Transfer\Tracking\FailedDeliveryCollection
220
     * @return bool|\GuzzleHttp\Message\Response
221
     * @throws \Iris\Exceptions\RetryMessage
222
     */
223 1
    public function setStatusToFailedDeliveryOnPartner(
224
        \Iris\Transfer\Tracking\FailedDeliveryCollection $items
225
    ) {
226 1
        return $this->getVentureApiClient()->setStatusToFailedDeliveryOnPartner($items);
227
    }
228
}
229