File manager - Edit - /home/web/vm-3fadc827.na4u.ru/www/bitrix/modules/sale/handlers/delivery/rest/dataproviders/shipment.php
Back
<?php namespace Sale\Handlers\Delivery\Rest\DataProviders; use Bitrix\Location\Entity\Address; use Bitrix\Main\Loader; use Bitrix\Sale; /** * Class Shipment * @package Sale\Handlers\Delivery\Rest\DataProviders * @final */ final class Shipment { /** * @param Sale\Shipment $shipment * @return array */ public static function getData(Sale\Shipment $shipment): array { return [ 'ID' => $shipment->getId() ?: null, 'DELIVERY_SERVICE' => self::getDeliveryService($shipment->getDeliveryId()), 'PRICE' => $shipment->getShipmentItemCollection()->getPrice(), 'CURRENCY' => $shipment->getCurrency(), 'WEIGHT' => $shipment->getWeight(), 'PROPERTY_VALUES' => self::getPropertyValues($shipment), 'ITEMS' => self::getItems($shipment), 'EXTRA_SERVICES_VALUES' => self::getExtraServices($shipment), 'RESPONSIBLE_CONTACT' => ResponsibleContact::getData($shipment), 'RECIPIENT_CONTACT' => RecipientContact::getData($shipment), ]; } /** * @param int $deliveryId * @return array */ private static function getDeliveryService(int $deliveryId): ?array { $delivery = Sale\Delivery\Services\Manager::getObjectById($deliveryId); if (!$delivery) { return null; } $result = [ 'ID' => (int)$delivery->getId(), 'CONFIG' => self::getConfigValues($delivery->getConfigValues()), ]; $parentDelivery = $delivery->getParentService(); if ($parentDelivery) { $result['PARENT'] = [ 'ID' => (int)$parentDelivery->getId(), 'CONFIG' => self::getConfigValues($parentDelivery->getConfigValues()), ]; } return $result; } /** * @param array $rawConfig * @return array */ private static function getConfigValues(array $rawConfig): array { $result = []; if (isset($rawConfig['MAIN']) && is_array($rawConfig['MAIN'])) { foreach ($rawConfig['MAIN'] as $name => $value) { if ($name === 'REST_CODE') { continue; } $result[] = [ 'CODE' => $name, 'VALUE' => $value ]; } } return $result; } /** * @param Sale\Shipment $shipment * @return array */ private static function getItems(Sale\Shipment $shipment): array { $result = []; foreach ($shipment->getShipmentItemCollection() as $shipmentItem) { if (!$basketItem = $shipmentItem->getBasketItem()) { continue; } $dimension = $basketItem->getField('DIMENSIONS'); $result[] = [ 'NAME' => $basketItem->getField('NAME'), 'PRICE' => $basketItem->getPrice(), 'WEIGHT' => $basketItem->getWeight(), 'CURRENCY' => $basketItem->getCurrency(), 'QUANTITY' => $shipmentItem->getQuantity(), 'DIMENSIONS' => ($dimension && is_string($dimension) && \CheckSerializedData($dimension)) ? unserialize($dimension, ['allowed_classes' => false]) : $dimension, ]; } return $result; } /** * @param Sale\Shipment $shipment * @return array */ private static function getExtraServices(Sale\Shipment $shipment): array { $result = []; $extraServiceManager = new Sale\Delivery\ExtraServices\Manager($shipment->getDeliveryId()); $extraServiceManager->setOperationCurrency($shipment->getField('CURRENCY')); $extraServiceManager->setValues($shipment->getExtraServices()); foreach ($extraServiceManager->getItems() as $extraService) { $result[] = [ 'ID' => (int)$extraService->getId(), 'CODE' => $extraService->getCode(), 'VALUE' => $extraService->getValue(), ]; } return $result; } /** * @param Sale\Shipment $shipment * @return array */ private static function getPropertyValues(Sale\Shipment $shipment): array { $result = []; $propertyCollection = $shipment->getPropertyCollection(); /** @var Sale\PropertyValue $property */ foreach ($propertyCollection as $property) { if (!in_array($property->getType(), ['STRING', 'ADDRESS'])) { continue; } $propertyId = $property->getPropertyId(); $result[] = [ 'ID' => (int)$propertyId, 'TYPE' => $property->getType(), 'VALUE' => self::getPropertyValue($property), ]; } return $result; } /** * @param Sale\EntityPropertyValue $propertyValue * @return mixed */ private static function getPropertyValue(Sale\EntityPropertyValue $propertyValue) { if ($propertyValue->getType() === 'ADDRESS') { return self::getAddressPropertyValue($propertyValue); } return $propertyValue->getValue(); } /** * @param Sale\EntityPropertyValue $propertyValue * @return array|null */ private static function getAddressPropertyValue(Sale\EntityPropertyValue $propertyValue): ?array { $value = $propertyValue->getValue(); if (!$value || !is_array($value)) { return null; } $fieldsTypeMap = self::getAddressFieldsTypeMap(); $address = Address::fromArray($value); $fieldCollection = $address->getFieldCollection(); $addressFields = []; /** @var Address\Field $field */ foreach ($fieldCollection as $field) { $fieldType = $field->getType(); if (!isset($fieldsTypeMap[$fieldType])) { continue; } $addressFields[$fieldsTypeMap[$fieldType]] = $field->getValue(); } return [ 'LATITUDE' => $address->getLatitude(), 'LONGITUDE' => $address->getLongitude(), 'FIELDS' => $addressFields, ]; } /** * @return array */ private static function getAddressFieldsTypeMap(): array { if (!Loader::includeModule('location')) { return []; } return array_flip((new \ReflectionClass(Address\FieldType::class))->getConstants()); } }
| ver. 1.4 |
Github
|
.
| PHP 7.4.33 | Generation time: 0.26 |
proxy
|
phpinfo
|
Settings