Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
director.php
1<?
3
4use Bitrix\Crm\Order\Shipment;
5
6final class Director
7{
8 public function createOrder(OrderBuilder $builder, array $fields)
9 {
10 try{
11 $builder->build($fields);
12 }
13 catch(BuildingException $e)
14 {
15 return null;
16 }
17
18 return $builder->getOrder();
19 }
20
27 public function getUpdatedShipment(OrderBuilder $builder, array $shipmentData)
28 {
29 try{
30 $builder->initFields(array(
31 'ID' => $shipmentData['ORDER_ID'],
32 'SITE_ID' => $shipmentData['SITE_ID'],
33 'SHIPMENT' => array($shipmentData)
34 ))
35 ->delegate()
36 ->createOrder()
37 ->setDiscounts() //?
38 ->buildShipments()
39 ->setDiscounts() //?
40 ->finalActions();
41 }
42 catch(BuildingException $e)
43 {
44 return null;
45 }
46
47 $order = $builder->getOrder();
48 $collection = $order->getShipmentCollection();
49
50 if((int)$shipmentData['ID'] > 0)
51 {
52 return $collection->getItemById($shipmentData['ID']);
53 }
54 else
55 {
56 foreach($collection as $shipment)
57 {
58 if($shipment->getId() <= 0)
59 {
60 return $shipment;
61 }
62 }
63 }
64
65 return null;
66 }
67
74 public function getUpdatedPayment(OrderBuilder $builder, array $paymentData)
75 {
76 try{
77 $builder->initFields(array(
78 'ID' => $paymentData['ORDER_ID'],
79 'PAYMENT' => array($paymentData)
80 ))
81 ->delegate()
82 ->createOrder()
83 ->setDiscounts()
84 ->buildPayments()
85 ->setDiscounts()
86 ->finalActions();
87 }
88 catch(BuildingException $e)
89 {
90 return null;
91 }
92
93 $order = $builder->getOrder();
94 $collection = $order->getPaymentCollection();
95
96 $paymentId = (int)($paymentData['ID'] ?? 0);
97 if ($paymentId)
98 {
99 return $collection->getItemById($paymentId);
100 }
101 else
102 {
103 foreach ($collection as $payment)
104 {
105 if ($payment->getId() === 0)
106 {
107 return $payment;
108 }
109 }
110 }
111
112 return null;
113 }
114}
getUpdatedPayment(OrderBuilder $builder, array $paymentData)
Definition director.php:74
getUpdatedShipment(OrderBuilder $builder, array $shipmentData)
Definition director.php:27
createOrder(OrderBuilder $builder, array $fields)
Definition director.php:8