Completed
Pull Request — master (#8)
by Rafael
02:54
created

Venture::createOrder()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 23
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 15
CRAP Score 2

Importance

Changes 4
Bugs 0 Features 1
Metric Value
c 4
b 0
f 1
dl 0
loc 23
ccs 15
cts 15
cp 1
rs 9.0857
cc 2
eloc 14
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
        try {
43
            $irisOrder = $this->getOrderService()->getOrderNrByExternalshopNumberAndPartner(
44
                $orderData['order_number'],
45 2
                $partner->getPartnerCode()
46 2
            );
47 2
            $result = array('order_number' => $irisOrder);
48 2
49 1
        } catch (\Iris\Exceptions\OrderNotFound $exception) {
50
            $salesOrder = $this->getOrderService()->save($salesOrder);
51 2
            $this->getOrderService()->saveExternalData($customer, $salesOrder);
52 1
            $result = array('order_number' => $salesOrder->getOrderNr());
53 1
        }
54 1
55 1
        return $result;
56
    }
57
58 2
    /**
59
     * {@inheritdoc}
60
     */
61
    public function confirmPaymentOrder($orderNr, $originCode)
62
    {
63
        $partner = $this->getPartnerService()->findByCode($originCode);
64 2
        $order = $this->getOrderService()->getOrderByOrderNumberAndPartnerCode(
65
            $orderNr,
66 2
            $partner->getPartnerCode()
67 2
        );
68 2
        if (!$this->getOrderService()->confirmPayment($order)) {
69 2
            throw new \RuntimeException(sprintf('Order number %s can\'t be confirmed', $orderNr));
70 2
        }
71 2
        return array('order_number' => $order->getOrderNr());
72 1
    }
73
74 1
    /**
75
     * Send order confirmation to partner
76
     *
77
     * @param \Iris\Transfer\Sales\Order $order
78
     * @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...
79
     * @return void
80 1
     */
81
    public function confirmOrderOnPartner(
82 1
        \Iris\Transfer\Sales\Order $order 
83
    ) {
84
        $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...
85
    }
86
87
    /**
88 2
     * {@inheritdoc}
89
     */
90 2
    public function findOrderByOrderNumber($orderNr, $originCode)
91 2
    {
92 2
        return $this->getOrderService()
93 2
                    ->getOrderByOrderNumberAndPartnerCode($orderNr, $originCode);
94 2
    }
95 2
96 1
    /**
97
     * {@inheritdoc}
98 1
     */
99
    public function cancelOrder($orderNr, $originCode)
100
    {
101
        $partner = $this->getPartnerService()->findByCode($originCode);
102
        $order = $this->getOrderService()->getOrderByOrderNumberAndPartnerCode(
103
            $orderNr,
104 1
            $partner->getPartnerCode()
105
        );
106 1
        if (!$this->getOrderService()->cancel($order)) {
107 1
            throw new \RuntimeException(sprintf('Order number %s can\'t be canceled', $orderNr));
108
        }
109
        return array('order_number' => $order->getOrderNr());
110
    }
111
112 1
    /**
113
     * {@inheritdoc}
114 1
     */
115 1
    public function createProductsOnPartner(\Iris\Transfer\Catalog\ConfigCollection $products, $partnerCode)
116
    {
117
        $this->getVentureApiClient()->createProducts($products, $partnerCode);
118
    }
119
120 1
    /**
121
     * {@inheritdoc}
122 1
     */
123 1
    public function updateProductsOnPartner(\Iris\Transfer\Catalog\ConfigCollection $products)
124
    {
125
        $this->getVentureApiClient()->updateProducts($products);
126
    }
127
128 1
    /**
129
     * {@inheritdoc}
130
     */
131
    public function updateStockOnPartner($skuSimple, $stock)
132
    {
133
        $this->getVentureApiClient()->updateStock($skuSimple, $stock);
134
    }
135 1
136 1
    /**
137 1
     * {@inheritdoc}
138 1
     */
139 1
    public function updatePriceOnPartner(
140
        $skuSimple,
141 1
        $price,
142 1
        $specialPrice = null,
143
        $specialFromDate = null,
144
        $specialToDate = null
145
    ) {
146
        $this->getVentureApiClient()->updatePrice(
147 1
            $skuSimple,
148
            $price,
149 1
            $specialPrice ?: $price,
150 1
            $specialFromDate,
151
            $specialToDate
152
        );
153
    }
154
155
    /**
156 1
     * {@inheritdoc}
157
     */
158 1
    public function isPartnerItem(\Iris\Transfer\Sales\Order\Item $item)
159
    {
160
        $irisPartner = $this->getPartnerService()->findBySalesOrderId($item->getFkSalesOrder());
161
        return ($irisPartner instanceof \Iris\Transfer\Partner);
162
    }
163
164 1
    /**
165
     * {@inheritdoc}
166 1
     */
167
    public function setStatusToShippedOnPartner(\Iris\Transfer\Tracking\ShippedCollection $items)
168
    {
169
        return $this->getVentureApiClient()->setStatusToShippedOnPartner($items);
170
    }
171
172
    /**
173
     * {@inheritdoc}
174 1
     */
175
    public function setStatusToDeliveredOnPartner(\Iris\Transfer\Tracking\DeliveredCollection $items)
176 1
    {
177
        return $this->getVentureApiClient()->setStatusToDeliveredOnPartner($items);
178
    }
179
180
    /**
181
     * NOTE: Not implemented yet!
182 1
     *
183
     * {@inheritdoc}
184 1
     */
185
    public function setStatusToCanceledOnPartner(\Iris\Transfer\Tracking\CanceledCollection $items)
186
    {
187
        return $this->getVentureApiClient()->setStatusToCanceledOnPartner($items);
188
    }
189
190 1
    /**
191
     * {@inheritdoc}
192 1
     */
193
    public function setStatusToFailedDeliveryOnPartner(\Iris\Transfer\Tracking\FailedDeliveryCollection $items)
194
    {
195
        return $this->getVentureApiClient()->setStatusToFailedDeliveryOnPartner($items);
196
    }
197
198
    /**
199
     * {@inheritdoc}
200
     */
201
    public function getName()
202
    {
203
        return 'venture';
204
    }
205
}
206