28 $profile = self::getProfileList([
29 'USER_ID' => $order->getUserId(),
30 'PERSON_TYPE_ID' => $order->getPersonTypeId()
34 'ORDER' => $order->toArray(),
35 'PERSON_TYPE' => self::getPersonTypeList([
36 'ID'=>$order->getPersonTypeId()
38 'USER_PROFILE' => $profile,
39 'USER_PROFILE_VALUES' => self::getProfileListValues([
40 'USER_PROPS_ID' => ($profile[
'ID'] ?? 0),
42 'BASKET_ITEMS' => self::getOrderProducts($order),
43 'ORDER_PRICE_TOTAL' => self::getTotal($order),
44 'PAY_SYSTEMS' => self::getPaySystemListWithRestrictions($order),
45 'DELIVERY_SERVICES' => self::getDeliveryServiceListWithRestrictions($order),
46 'PROPERTIES' => self::getOrderProperties($order),
47 'VARIANTS' => self::getVariants($order),
48 'PAYMENTS' => self::getPayments($order),
49 'CHECKS' => self::getChecks($order),
53 private static function getProfileList(array $filter = [])
56 $r = \CSaleOrderUserProps::GetList(
63 [
'ID',
'USER_ID',
'NAME',
'PERSON_TYPE_ID']
65 if ($profile = $r->fetch())
73 private static function getProfileListValues(array $filter = []): array
76 $r = \CSaleOrderUserPropsValue::GetList(
83 [
'ID',
'ORDER_PROPS_ID',
'VALUE',
'SORT']
85 while ($profileValue = $r->fetch())
87 $result[] = $profileValue;
93 private static function getPersonTypeList(array $filter = [])
97 $personTypeClassName = $registry->getPersonTypeClassName();
98 return $personTypeClassName::getList([
108 private static function getPaySystemListWithRestrictions(
Sale\Order $order): array
112 $paySystemList = Sale\PaySystem\Manager::getListWithRestrictionsByOrder($order);
113 foreach ($paySystemList as $paySystemItem)
115 $paySystemItem[
'LOGOTYPE'] = $paySystemItem[
'LOGOTIP'];
116 $paySystemItem[
'TARIFF'] = $paySystemItem[
'TARIF'];
118 $paySystemItem[
'LOGOTYPE_SRC'] =
'';
119 if (!empty($paySystemItem[
'LOGOTYPE']))
121 $paySystemItem[
'LOGOTYPE_SRC'] = \CFile::GetPath($paySystemItem[
'LOGOTYPE']);
125 $paySystemItem[
'PAY_SYSTEM_ID'],
126 $paySystemItem[
'PERSON_TYPE_ID'],
127 $paySystemItem[
'PARAMS'],
128 $paySystemItem[
'TARIF'],
129 $paySystemItem[
'LOGOTIP'],
130 $paySystemItem[
'ENTITY_REGISTRY_TYPE']
133 $result[] = $paySystemItem;
139 private static function getDeliveryServiceListWithRestrictions(
Sale\Order $order): array
142 foreach ($order->getShipmentCollection() as $shipment)
144 $deliveryList = Sale\Delivery\Services\Manager::getRestrictedObjectsList($shipment);
145 foreach ($deliveryList as $deliveryItem)
148 'ID' => $deliveryItem->getId(),
149 'SORT' => $deliveryItem->getSort(),
150 'NAME' => $deliveryItem->getName(),
151 'DESCRIPTION' => $deliveryItem->getDescription(),
152 'LOGOTYPE' => $deliveryItem->getLogotip(),
153 'LOGOTYPE_SRC' => \CFile::GetPath($deliveryItem->getLogotip()),
161 public static function getTotal(
Sale\Order $order)
166 $calculateBasket = $order->getBasket()->createClone();
168 $discounts = $order->getDiscount();
169 $showPrices = $discounts->getShowPrices();
170 if (!empty($showPrices[
'BASKET']))
172 foreach ($showPrices[
'BASKET'] as $basketCode => $data)
174 $basketItem = $calculateBasket->getItemByBasketCode($basketCode);
175 if ($basketItem instanceof
Sale\BasketItemBase)
177 $basketItem->setFieldNoDemand(
'BASE_PRICE', $data[
'SHOW_BASE_PRICE']);
178 $basketItem->setFieldNoDemand(
'PRICE', $data[
'SHOW_PRICE']);
179 $basketItem->setFieldNoDemand(
'DISCOUNT_PRICE', $data[
'SHOW_DISCOUNT']);
186 'WEIGHT_UNIT' => Config\Option::get(
'sale',
'weight_unit',
false, $order->getSiteId()),
187 'WEIGHT_KOEF' => Config\Option::get(
'sale',
'weight_koef', 1, $order->getSiteId()),
202 $result[
'BASKET_POSITIONS'] = $calculateBasket->count();
204 $result[
'ORDER_WEIGHT'] = $calculateBasket->getWeight();
206 $result[
'PRICE_WITHOUT_DISCOUNT_VALUE'] = $calculateBasket->getBasePrice();
208 $calculateBasket->getBasePrice() - $calculateBasket->getPrice()
211 $order->getDiscountPrice() + ($result[
'PRICE_WITHOUT_DISCOUNT_VALUE'] - $result[
'ORDER_PRICE'])
220 private static function getOrderProducts(
Sale\Order $order): array
224 $basket = $order->getBasket();
227 $result = static::getOrderProductsByBasket($basket);
233 public static function getOrderProductsByBasket(
Sale\BasketBase $basket): array
237 $basketClone = $basket->createClone();
239 $order = $basketClone->getOrder();
244 $orderClassName = $registry->getOrderClassName();
245 $order = $orderClassName::create($basketClone->getSiteId());
246 $order->setBasket($basketClone);
251 $discounts = $order->getDiscount();
252 $showPrices = $discounts->getShowPrices();
253 if (!empty($showPrices[
'BASKET']))
255 foreach ($showPrices[
'BASKET'] as $basketCode => $data)
257 $basketItem = $basketClone->getItemByBasketCode($basketCode);
258 if ($basketItem instanceof
Sale\BasketItemBase)
260 $basketItem->setFieldNoDemand(
'BASE_PRICE', $data[
'SHOW_BASE_PRICE']);
261 $basketItem->setFieldNoDemand(
'PRICE', $data[
'SHOW_PRICE']);
262 $basketItem->setFieldNoDemand(
'DISCOUNT_PRICE', $data[
'SHOW_DISCOUNT']);
268 $basketData = static::getBasketProducts($basketClone);
269 foreach ($basketClone as $item)
271 $result[] = array_merge(
272 $basketData[$item->getId()],
274 'CATALOG_PRODUCT' => static::getCatalogProduct($basketData[$item->getId()])
282 public static function getOrderProductByBasketItem(
Sale\BasketItemBase $basketItem): array
284 $basket = $basketItem->getBasket();
285 $basketClone = $basket->createClone();
286 $calculateBasketItem = $basketClone->getItemByBasketCode($basketItem->getBasketCode());
288 $order = $basketClone->getOrder();
293 $orderClassName = $registry->getOrderClassName();
294 $order = $orderClassName::create($basketClone->getSiteId());
295 $order->setBasket($basketClone);
298 if ($calculateBasketItem && $order)
300 $discounts = $order->getDiscount();
301 $showPrices = $discounts->getShowPrices();
302 if (!empty($showPrices[
'BASKET']))
304 $data = $showPrices[
'BASKET'][$calculateBasketItem->getBasketCode()] ??
null;
307 $calculateBasketItem->setFieldNoDemand(
'BASE_PRICE', $data[
'SHOW_BASE_PRICE']);
308 $calculateBasketItem->setFieldNoDemand(
'PRICE', $data[
'SHOW_PRICE']);
309 $calculateBasketItem->setFieldNoDemand(
'DISCOUNT_PRICE', $data[
'SHOW_DISCOUNT']);
314 $basketItemData = static::getBasketProduct($calculateBasketItem);
318 'CATALOG_PRODUCT' => static::getCatalogProduct($basketItemData)
323 private static function getCatalogProduct(array $basketItemData): array
327 $repositoryFacade = Catalog\v2\IoC\ServiceContainer::getRepositoryFacade();
328 $product = $repositoryFacade->loadVariation($basketItemData[
'PRODUCT_ID']);
331 $result = $product->getFields();
333 $result[
'TYPE'] = ($result[
'TYPE'] === Catalog\ProductTable::TYPE_SERVICE) ?
'service' :
'product';
335 $result[
'PREVIEW_PICTURE'] ??=
null;
336 if ((
int)$result[
'PREVIEW_PICTURE'] > 0)
338 $result[
'PREVIEW_PICTURE_SRC'] = \CFile::GetPath($result[
'PREVIEW_PICTURE']);
341 $result[
'DETAIL_PICTURE'] ??=
null;
342 if ((
int)$result[
'DETAIL_PICTURE'] > 0)
344 $result[
'DETAIL_PICTURE_SRC'] = \CFile::GetPath($result[
'DETAIL_PICTURE']);
347 $result[
'AVAILABLE_QUANTITY'] = $result[
'QUANTITY'];
348 unset($result[
'QUANTITY']);
352 $result[
'QUANTITY_TRACE'] = (Main\Config\Option::get(
'catalog',
'default_quantity_trace') ===
'Y') ?
'Y' :
'N';
356 $result[
'CAN_BUY_ZERO'] = (Main\Config\Option::get(
'catalog',
'default_can_buy_zero') ===
'Y') ?
'Y' :
'N';
359 $checkMaxQuantity = ($result[
'QUANTITY_TRACE'] ===
'Y' && $result[
'CAN_BUY_ZERO'] ===
'N') ?
'Y' :
'N';
360 $result[
'CHECK_MAX_QUANTITY'] = $checkMaxQuantity;
362 $result[
'RATIO'] = 1;
363 $ratioItem = $product->getMeasureRatioCollection()->findDefault();
366 $ratioItem = $product->getMeasureRatioCollection()->getFirst();
371 $result[
'RATIO'] = $ratioItem->getRatio();
375 $propertyCollection = $product->getPropertyCollection();
376 foreach ($propertyCollection as $propertyItem)
378 $values = $propertyItem->getPropertyValueCollection()->getValues();
380 if ($propertyItem->getPropertyType() === Iblock\PropertyTable::TYPE_LIST)
382 $enumPropData = Iblock\PropertyEnumerationTable::getList([
383 'select' => [
'ID',
'VALUE',
'SORT',
'XML_ID'],
386 '=PROPERTY_ID' => $propertyItem->getId(),
392 if (!$propertyItem->isMultiple())
394 $values = reset($enumPropData);
402 elseif ($propertyItem->getPropertyType() === Iblock\PropertyTable::TYPE_FILE)
404 $imageSrcValues =
null;
405 if ($propertyItem->isMultiple())
407 $imageSrcValues = [];
408 foreach ($values as $value)
410 $imageSrcValues[] = [
412 'SRC' => \CFile::GetPath($value),
419 'FILE_ID' => $values,
420 'SRC' => \CFile::GetPath($values),
424 $values = $imageSrcValues;
427 $result[
'PRODUCT_PROPERTIES'][$propertyItem->getId()] = [
428 'TYPE' => $propertyItem->getPropertyType(),
429 'CODE' => $propertyItem->getCode(),
430 'NAME' => $propertyItem->getName(),
436 $imageCollection = $product->getImageCollection();
437 $frontImage = $imageCollection->getFrontImage();
439 $frontImageData =
null;
442 $frontImageData = $frontImage->getFields();
447 $parent = $product->getParent();
450 $imageCollection = $parent->getImageCollection();
451 $parentFrontImage = $imageCollection->getFrontImage();
452 if ($parentFrontImage)
454 $frontImageData = $parentFrontImage->getFields();
459 $result[
'FRONT_IMAGE'] = $frontImageData;
461 $result[
'IMAGE_COLLECTION'] = [];
462 foreach ($imageCollection as $imageItem)
464 $result[
'IMAGE_COLLECTION'][] = $imageItem->getFields();
467 $result[
'SKU'] = self::getSkuTree($product->getIblockId(), $product->getId());
473 private static function getSkuTree(
int $iblockId,
int $productId): array
477 $skuRepository = Catalog\v2\IoC\ServiceContainer::getSkuRepository($iblockId);
480 $sku = $skuRepository->getEntityById($productId);
483 $parentProduct = $sku->getParent();
487 $skuTree = Catalog\v2\IoC\ServiceContainer::make(
'sku.tree', [
'iblockId' => $iblockId]);
489 $parentProductId = $parentProduct->getId();
490 $skuId = $sku->getId();
492 $tree = $skuTree->loadJsonOffers([$parentProductId => $skuId]);
493 if (isset($tree[$parentProductId][$skuId]))
496 'TREE' => $tree[$parentProductId][$skuId],
497 'PARENT_PRODUCT_ID' => $parentProductId,
507 private static function getBasketProducts(
Sale\BasketBase $basket): array
512 foreach ($basket as $basketItem)
514 $result[$basketItem->getId()] = self::getBasketProduct($basketItem);
520 private static function getBasketProduct(
Sale\BasketItemBase $basketItem)
522 $arBasketItem = $basketItem->getFieldValues();
523 if ($basketItem->getVatRate() > 0)
528 $arBasketItem[
'QUANTITY'] = $basketItem->getQuantity();
531 $arBasketItem[
'DISCOUNT_PRICE_PERCENT'] = 0;
532 if ($arBasketItem[
'CUSTOM_PRICE'] !==
'Y')
534 $arBasketItem[
'DISCOUNT_PRICE_PERCENT'] = Sale\Discount::calculateDiscountPercent(
535 $arBasketItem[
'BASE_PRICE'],
536 $arBasketItem[
'DISCOUNT_PRICE']
538 if ($arBasketItem[
'DISCOUNT_PRICE_PERCENT'] ===
null)
540 $arBasketItem[
'DISCOUNT_PRICE_PERCENT'] = 0;
548 $arBasketItem[
'PROPS'] = [];
550 $propertyCollection = $basketItem->getPropertyCollection();
551 $propList = $propertyCollection->getPropertyValues();
552 foreach ($propList as &$prop)
554 if ($prop[
'CODE'] ===
'CATALOG.XML_ID'
555 || $prop[
'CODE'] ===
'PRODUCT.XML_ID'
556 || $prop[
'CODE'] ===
'SUM_OF_CHARGE'
562 $prop = array_filter($prop, [
'CSaleBasketHelper',
'filterFields']);
563 $arBasketItem[
'PROPS'][] = $prop;
575 $dimension = $basketItem->getField(
'DIMENSIONS');
576 if($dimension && \is_string($dimension) && \CheckSerializedData($dimension))
578 $arBasketItem[
'DIMENSIONS'] = unserialize($dimension, [
'allowed_classes' =>
false]);
581 if (!empty($arBasketItem) && static::useCatalog())
583 $measure = getMeasures([$basketItem->getId() => $arBasketItem]);
584 $arBasketItem = $measure[$basketItem->getId()];
587 return $arBasketItem;
590 private static function useCatalog()
592 return Loader::includeModule(
'catalog');
595 private static function getOrderProperties(
Sale\Order $order): array
599 $propertyCollection = $order->getPropertyCollection();
600 if ($propertyCollection)
602 $propertyCollectionData = $propertyCollection->getArray();
603 foreach ($propertyCollectionData[
'properties'] as $property)
605 if ($property[
'UTIL'] ===
'Y')
610 $result[] = $property;
617 private static function getVariants(
Sale\Order $order): array
619 $propertyCollection = $order->getPropertyCollection();
620 if (!$propertyCollection)
625 $propertyCollectionData = $propertyCollection->getArray();
626 $propertyEnumIds = [];
627 foreach ($propertyCollectionData[
'properties'] as $property)
629 if ($property[
'TYPE'] ===
'ENUM')
631 $propertyEnumIds[] = $property[
'ID'];
635 if (empty($propertyEnumIds))
640 $variants = Sale\Internals\OrderPropsVariantTable::getList([
642 '=ORDER_PROPS_ID' => $propertyEnumIds,
644 'order' => [
'SORT' =>
'ASC'],
650 private static function getPayments(
Sale\Order $order): array
653 $orderClone = $order->createClone();
654 return $orderClone->getPaymentCollection()->toArray();
657 private static function getChecks(
Sale\Order $order): array
662 $orderClone = $order->createClone();
665 foreach ($orderClone->getPaymentCollection() as $payment)
667 $checkList = Sale\Cashbox\CheckManager::getCheckInfo($payment);
668 foreach ($checkList as $check)