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

Venture::createOrder()   B

Complexity

Conditions 2
Paths 2

Size

Total Lines 26
Code Lines 16

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 16
CRAP Score 2

Importance

Changes 3
Bugs 0 Features 1
Metric Value
c 3
b 0
f 1
dl 0
loc 26
ccs 16
cts 16
cp 1
rs 8.8571
cc 2
eloc 16
nc 2
nop 2
crap 2
1
<?php
2
3
namespace Iris\SaleWrapper;
4
5
class Venture extends Base implements VentureInterface
6
{
7
    /**
8
     * @return \Iris\Interfaces\IrisPartner
9
     */
10 8
    public function getPartnerService()
11
    {
12 8
        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($orderNr, $originCode)
65
    {
66 2
        $partner = $this->getPartnerService()->findByCode($originCode);
67 2
        $order = $this->getOrderService()->getOrderByOrderNumberAndPartnerCode(
68 2
            $orderNr,
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', $orderNr));
73
        }
74 1
        return array('order_number' => $order->getOrderNr());
75
    }
76
77
    /**
78
     * Send order confirmation to partner
79
     *
80 1
     * @param \Iris\Transfer\Sales\Order $order
81
     * @param string $partnerCode
0 ignored issues
show
Bug introduced by
There is no parameter named $partnerCode. 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...
82 1
     * @return void
83
     */
84
    public function confirmOrderOnPartner(
85
        \Iris\Transfer\Sales\Order $order 
86
    ) {
87
        $this->getVentureApiClient()->confirmOrderOnPartner($order);
0 ignored issues
show
Bug introduced by
The call to confirmOrderOnPartner() misses a required argument $partnerCode.

This check looks for function calls that miss required arguments.

Loading history...
88 2
    }
89
90 2
    /**
91 2
     * {@inheritdoc}
92 2
     */
93 2
    public function findOrderByOrderNumber($orderNr, $originCode)
94 2
    {
95 2
        return $this->getOrderService()
96 1
                    ->getOrderByOrderNumberAndPartnerCode($orderNr, $originCode);
97
    }
98 1
99
    /**
100
     * {@inheritdoc}
101
     */
102
    public function cancelOrder($orderNr, $originCode)
103
    {
104 1
        $partner = $this->getPartnerService()->findByCode($originCode);
105
        $order = $this->getOrderService()->getOrderByOrderNumberAndPartnerCode(
106 1
            $orderNr,
107 1
            $partner->getPartnerCode()
108
        );
109
        if (!$this->getOrderService()->cancel($order)) {
110
            throw new \RuntimeException(sprintf('Order number %s can\'t be canceled', $orderNr));
111
        }
112 1
        return array('order_number' => $order->getOrderNr());
113
    }
114 1
115 1
    /**
116
     * {@inheritdoc}
117
     */
118
    public function createProductsOnPartner(\Iris\Transfer\Catalog\ConfigCollection $products, $partnerCode)
119
    {
120 1
        $this->getVentureApiClient()->createProducts($products, $partnerCode);
121
    }
122 1
123 1
    /**
124
     * {@inheritdoc}
125
     */
126
    public function updateProductsOnPartner(\Iris\Transfer\Catalog\ConfigCollection $products)
127
    {
128 1
        $this->getVentureApiClient()->updateProducts($products);
129
    }
130
131
    /**
132
     * {@inheritdoc}
133
     */
134
    public function updateStockOnPartner($skuSimple, $stock)
135 1
    {
136 1
        $this->getVentureApiClient()->updateStock($skuSimple, $stock);
137 1
    }
138 1
139 1
    /**
140
     * {@inheritdoc}
141 1
     */
142 1
    public function updatePriceOnPartner(
143
        $skuSimple,
144
        $price,
145
        $specialPrice = null,
146
        $specialFromDate = null,
147 1
        $specialToDate = null
148
    ) {
149 1
        $this->getVentureApiClient()->updatePrice(
150 1
            $skuSimple,
151
            $price,
152
            $specialPrice ?: $price,
153
            $specialFromDate,
154
            $specialToDate
155
        );
156 1
    }
157
158 1
    /**
159
     * {@inheritdoc}
160
     */
161
    public function isPartnerItem(\Iris\Transfer\Sales\Order\Item $item)
162
    {
163
        $irisPartner = $this->getPartnerService()->findBySalesOrderId($item->getFkSalesOrder());
164 1
        return ($irisPartner instanceof \Iris\Transfer\Partner);
165
    }
166 1
167
    /**
168
     * {@inheritdoc}
169
     */
170
    public function setStatusToShippedOnPartner(\Iris\Transfer\Tracking\ShippedCollection $items)
171
    {
172
        return $this->getVentureApiClient()->setStatusToShippedOnPartner($items);
173
    }
174 1
175
    /**
176 1
     * {@inheritdoc}
177
     */
178
    public function setStatusToDeliveredOnPartner(\Iris\Transfer\Tracking\DeliveredCollection $items)
179
    {
180
        return $this->getVentureApiClient()->setStatusToDeliveredOnPartner($items);
181
    }
182 1
183
    /**
184 1
     * NOTE: Not implemented yet!
185
     *
186
     * {@inheritdoc}
187
     */
188
    public function setStatusToCanceledOnPartner(\Iris\Transfer\Tracking\CanceledCollection $items)
189
    {
190 1
        return $this->getVentureApiClient()->setStatusToCanceledOnPartner($items);
191
    }
192 1
193
    /**
194
     * {@inheritdoc}
195
     */
196
    public function setStatusToFailedDeliveryOnPartner(\Iris\Transfer\Tracking\FailedDeliveryCollection $items)
197
    {
198
        return $this->getVentureApiClient()->setStatusToFailedDeliveryOnPartner($items);
199
    }
200
201
    /**
202
     * {@inheritdoc}
203
     */
204
    public function getName()
205
    {
206
        return 'venture';
207
    }
208
}
209