3namespace Sale\Handlers\Delivery\Rest\DataProviders;
5use Bitrix\Location\Entity\Address;
8use Bitrix\Sale\BasketItem;
21 public static function getData(Sale\Shipment $shipment):
array
24 'ID' => $shipment->getId() ?:
null,
25 'DELIVERY_SERVICE' => self::getDeliveryService($shipment->getDeliveryId()),
26 'PRICE' => $shipment->getShipmentItemCollection()->getPrice(),
27 'CURRENCY' => $shipment->getCurrency(),
28 'WEIGHT' => $shipment->getWeight(),
29 'PROPERTY_VALUES' => self::getPropertyValues($shipment),
30 'ITEMS' => self::getItems($shipment),
31 'EXTRA_SERVICES_VALUES' => self::getExtraServices($shipment),
32 'RESPONSIBLE_CONTACT' => ResponsibleContact::getData($shipment),
33 'RECIPIENT_CONTACT' => RecipientContact::getData($shipment),
41 private static function getDeliveryService(
int $deliveryId): ?
array
43 $delivery = Sale\Delivery\Services\Manager::getObjectById($deliveryId);
50 'ID' => (int)$delivery->getId(),
51 'CONFIG' => self::getConfigValues($delivery->getConfigValues()),
53 $parentDelivery = $delivery->getParentService();
57 'ID' => (int)$parentDelivery->getId(),
58 'CONFIG' => self::getConfigValues($parentDelivery->getConfigValues()),
69 private static function getConfigValues(
array $rawConfig):
array
73 if (isset($rawConfig[
'MAIN']) && is_array($rawConfig[
'MAIN']))
75 foreach ($rawConfig[
'MAIN'] as
$name => $value)
77 if (
$name ===
'REST_CODE')
96 private static function getItems(Sale\Shipment $shipment):
array
101 foreach ($shipment->getShipmentItemCollection()->getShippableItems() as $shipmentItem)
103 if (!$basketItem = $shipmentItem->getBasketItem())
108 $basketItemWeight = $basketItem->getWeight();
111 'NAME' => $basketItem->getField(
'NAME'),
112 'PRICE' => $basketItem->getPrice(),
113 'WEIGHT' => $basketItemWeight ===
'' || is_null($basketItemWeight) ? null : (float)$basketItemWeight,
114 'CURRENCY' => $basketItem->getCurrency(),
115 'QUANTITY' => $shipmentItem->getQuantity(),
116 'DIMENSIONS' => self::getDimensions($basketItem),
123 private static function getDimensions(BasketItem $basketItem): ?
array
125 $dimension = $basketItem->getField(
'DIMENSIONS');
128 $dimension && is_string($dimension) && \CheckSerializedData($dimension)
129 ? unserialize($dimension, [
'allowed_classes' =>
false])
134 isset($dimension[
'WIDTH'])
135 && isset($dimension[
'HEIGHT'])
136 && isset($dimension[
'LENGTH'])
140 'WIDTH' => (float)$dimension[
'WIDTH'],
141 'HEIGHT' => (
float)$dimension[
'HEIGHT'],
142 'LENGTH' => (float)$dimension[
'LENGTH'],
153 private static function getExtraServices(Sale\Shipment $shipment):
array
157 $extraServiceManager =
new Sale\Delivery\ExtraServices\Manager($shipment->getDeliveryId());
158 $extraServiceManager->setOperationCurrency($shipment->getField(
'CURRENCY'));
159 $extraServiceManager->setValues($shipment->getExtraServices());
161 foreach ($extraServiceManager->getItems() as $extraService)
164 'ID' => (int)$extraService->getId(),
165 'CODE' => $extraService->getCode(),
166 'VALUE' => $extraService->getValue(),
177 private static function getPropertyValues(Sale\Shipment $shipment):
array
181 $propertyCollection = $shipment->getPropertyCollection();
183 foreach ($propertyCollection as $property)
185 if (!in_array($property->getType(), [
'STRING',
'ADDRESS']))
190 $propertyId = $property->getPropertyId();
193 'ID' => (int)$propertyId,
194 'TYPE' => $property->getType(),
195 'VALUE' => self::getPropertyValue($property),
206 private static function getPropertyValue(Sale\EntityPropertyValue
$propertyValue)
220 private static function getAddressPropertyValue(Sale\EntityPropertyValue
$propertyValue): ?
array
223 if (!$value || !is_array($value))
228 $fieldsTypeMap = self::getAddressFieldsTypeMap();
229 $address = Address::fromArray($value);
231 $fieldCollection = $address->getFieldCollection();
235 foreach ($fieldCollection as $field)
237 $fieldType = $field->getType();
238 if (!isset($fieldsTypeMap[$fieldType]))
243 $addressFields[$fieldsTypeMap[$fieldType]] = $field->getValue();
246 $latitude = $address->getLatitude();
247 $longitude = $address->getLongitude();
250 'LATITUDE' => $latitude ===
'' ? null : (float)$latitude,
251 'LONGITUDE' => $longitude ===
'' ?
null : (float)$longitude,
252 'FIELDS' => $addressFields,
259 private static function getAddressFieldsTypeMap():
array
261 if (!Loader::includeModule(
'location'))
267 return array_flip((
new \ReflectionClass(Address\FieldType::class))->getConstants());
</td ></tr ></table ></td ></tr ><?endif?><? $propertyIndex=0;foreach( $arGlobalProperties as $propertyCode=> $propertyValue
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)