Completed
Push — master ( 288216...e3ed33 )
by
unknown
09:26
created

Venture   A

Complexity

Total Complexity 21

Size/Duplication

Total Lines 190
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 12

Test Coverage

Coverage 100%

Importance

Changes 16
Bugs 3 Features 5
Metric Value
wmc 21
c 16
b 3
f 5
lcom 2
cbo 12
dl 0
loc 190
ccs 72
cts 72
cp 1
rs 10

17 Methods

Rating   Name   Duplication   Size   Complexity  
A getPartnerService() 0 4 1
A getVentureService() 0 4 1
A getCustomerService() 0 4 1
B createOrder() 0 26 2
A confirmPaymentOrder() 0 12 2
A findOrderByOrderNumber() 0 4 1
A cancelOrder() 0 12 2
A createProductsOnPartner() 0 4 1
A updateProductsOnPartner() 0 4 1
A updateStockOnPartner() 0 4 1
A updatePriceOnPartner() 0 15 2
A setStatusToShippedOnPartner() 0 4 1
A setStatusToDeliveredOnPartner() 0 4 1
A setStatusToCanceledOnPartner() 0 4 1
A setStatusToFailedDeliveryOnPartner() 0 4 1
A getName() 0 4 1
A isPartnerItem() 0 5 1
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($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 1
    public function isPartnerItem(\Iris\Transfer\Sales\Order\Item $item)
148
    {
149 1
        $irisPartner = $this->getPartnerService()->findBySalesOrderId($item->getFkSalesOrder());
150 1
        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