Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
exportonecpackagesale.php
1<?php
3
4
13
15{
19 protected function convertDocumentFields(array $documents)
20 {
21 parent::convertDocumentFields($documents);
22
23 foreach ($documents as $document)
24 {
25 if($document instanceof ShipmentDocument || $document instanceof PaymentDocument)
26 {
27 $fields = $document->getFieldValues();
28 $fields['AGENT'] = $this->getDocumentByTypeId(EntityType::USER_PROFILE, $documents)
29 ->getFieldValues();
30
31 $document->setFields($fields);
32 }
33 }
34
35 //region shipment.fields delivery address
37 $documentProfile = $this->getDocumentByTypeId(EntityType::USER_PROFILE, $documents);
38 foreach ($documents as $document)
39 {
40 if($document instanceof ShipmentDocument)
41 {
42 $this->prepareDocumentFieldsDeliveryAddress($document, $documentProfile);
43 }
44 }
45 //endregion
46
47 //region order.fields delivery address
48 $documentOrder = $this->getDocumentByTypeId(DocumentType::ORDER, $documents);
49 $this->prepareDocumentFieldsDeliveryAddress($documentOrder, $documentProfile);
50 //endregion
51 }
52
57 protected function convertEntityFields(array $items)
58 {
59 $orderImport = $this->getEntityByTypeId(static::getParentEntityTypeId(), $items);
60
61 //region order stories
62 $orderFields = $orderImport->getFieldValues();
63 foreach ($items as $item)
64 {
65 if($item instanceof ShipmentImport)
66 {
67 $shipmentFields = $item->getFieldValues();
68 $orderFields['STORIES'][] = $shipmentFields['STORIES'];
69 }
70 }
71 $orderImport->setFields($orderFields);
72 //endregion
73
74 //region shipment taxes from order taxes
75 foreach ($items as $item)
76 {
77 if($item instanceof ShipmentImport)
78 {
79 $shipmentFields = $item->getFieldValues();
80 $shipmentFields['TAXES'] = $orderFields['TAXES'];
81 $item->setFields($shipmentFields);
82 }
83 }
84 //endregion
85
86 //region cash box checks payment
87 foreach ($items as $item)
88 {
89 if($item instanceof PaymentImport)
90 {
91 $this->prepareEntityFieldsCashBoxChecks($item, $orderFields['CASH_BOX_CHECKS']);
92 }
93 }
94 //endregion
95
96 //region order.shipment fields
97 $shipmentImport = $this->getEntityByTypeId(static::getShipmentEntityTypeId(), $items);
98 if($shipmentImport instanceof ShipmentImport)
99 {
100 $shipmentFields = $shipmentImport->getFieldValues();
101
102 $orderFields = $orderImport->getFieldValues();
103 $orderFields['TRAITS']['DELIVERY_SERVICE'] = $shipmentFields['TRAITS']['DELIVERY_NAME'];
104 $orderFields['TRAITS']['DELIVERY_ID'] = $shipmentFields['TRAITS']['DELIVERY_ID'];
105 $orderImport->setFields($orderFields);
106 }
107 //endregion
108
109 //region order.payment fields
110 $orderFields = $orderImport->getFieldValues();
111 $paymentFields = array();
112 foreach ($items as $item)
113 {
114 if($item instanceof PaymentImport)
115 {
116 $paymentFields = $item->getFieldValues();
117 break;
118 }
119 }
120 if(count($paymentFields)>0)
121 {
122 $orderFields['TRAITS']['PAY_SYSTEM'] = $paymentFields['TRAITS']['PAY_SYSTEM_NAME'];
123 $orderFields['TRAITS']['PAY_SYSTEM_ID'] = $paymentFields['TRAITS']['PAY_SYSTEM_ID'];
124 $orderImport->setFields($orderFields);
125 }
126 //endregion
127
128 return parent::convertEntityFields($items);
129 }
130
135 protected function prepareEntityFieldsCashBoxChecks(PaymentImport $item, $checks)
136 {
137 $paymentFields = $item->getFieldValues();
138 $paymentFields['CASH_BOX_CHECKS'] = array();
139 foreach ($checks as $checkId=>$check)
140 {
141 if($check['PAYMENT_ID'] == $item->getId())
142 {
143 $paymentFields['CASH_BOX_CHECKS'][$checkId] = $check;
144 }
145 }
146 $item->setFields($paymentFields);
147 }
148
154 protected function outputXmlDocuments(array $documents, $level = 0)
155 {
156 $result = new Result();
157 $containers = array();
158 $r = parent::outputXmlDocuments($documents, 1);
159 if($r->isSuccess())
160 $containers[] = $this->outputXmlContainer(implode('', $r->getData()));
161
162 $result->setData($containers);
163
164 return $result;
165 }
166
171 public function outputXmlContainer($xml)
172 {
173 $document = new DocumentBase();
174 $result = $document->openNodeDirectory(0, $document::getLangByCodeField('CONTAINER'));
175 $result .= $xml;
176 $result .= $document->closeNodeDirectory(0, $document::getLangByCodeField('CONTAINER'));
177 return $result;
178 }
179
183 protected function getShemVersion()
184 {
185 return static::SHEM_VERSION_3_1;
186 }
187}
prepareDocumentFieldsDeliveryAddress(DocumentBase $document, UserProfileDocument $documentProfile)
prepareEntityFieldsCashBoxChecks(PaymentImport $item, $checks)