Advertisement
Guest User

Untitled

a guest
Dec 12th, 2019
183
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.80 KB | None | 0 0
  1. <?
  2. require_once($_SERVER['DOCUMENT_ROOT'] . '/bitrix/modules/main/include/prolog_before.php');
  3.  
  4. use Bitrix\Main\Loader;
  5. use Bitrix\Main\Context;
  6.  
  7. $request = Context::getCurrent()->getRequest();
  8. $values = $request->getPostList();
  9.  
  10. if ($values["action"] == "getShops") {
  11. Loader::includeModule("iblock");
  12. Loader::includeModule("sale");
  13. Loader::includeModule("catalog");
  14. $res = CSaleDelivery::GetList(
  15. array(
  16. "SORT" => "ASC",
  17. "NAME" => "ASC"
  18. ),
  19. array(
  20. "LID" => SITE_ID,
  21. "ACTIVE" => "Y",
  22. "LOCATION" => $values["locationId"],
  23. "NAME" => "Самовывоз из магазина",
  24. ),
  25. false,
  26. false,
  27. array()
  28. );
  29. if ($ob = $res->Fetch()) {
  30. preg_match_all('#\"(\d{1,6})\"#usi', $ob['STORE'], $match);
  31. echo $ob['ID'] . '###';
  32. if ($match[1]) {
  33. $rsStore = \Bitrix\Catalog\StoreTable::getList(array(
  34. 'filter' => array('ACTIVE'>='Y', 'ID' => $match[1]),
  35. ));
  36. while($arStore=$rsStore->fetch())
  37. {
  38. echo $arStore['TITLE'] . '%' . $arStore['ID'] . ':::';
  39. }
  40. }
  41. } else {
  42. echo false;
  43. }
  44. } else if ($values["action"] == "getMethods") {
  45. Loader::includeModule("iblock");
  46. Loader::includeModule("sale");
  47. Loader::includeModule("catalog");
  48.  
  49. \Bitrix\Main\Loader::includeModule('sale');
  50. $order = \Bitrix\Sale\Order::create(SITE_ID, 1);
  51. $basket = \Bitrix\Sale\Basket::create(SITE_ID);
  52. $item = $basket->createItem('catalog', $values['productId']);
  53. $item->setFields(array(
  54. 'QUANTITY' => 1,
  55. 'CURRENCY' => \Bitrix\Currency\CurrencyManager::getBaseCurrency(),
  56. 'LID' => SITE_ID,
  57. 'PRODUCT_PROVIDER_CLASS' => 'CCatalogProductProvider',
  58. ));
  59. $order->setBasket($basket);
  60. $order->setPersonTypeId(1);
  61.  
  62. $shipmentCollection = $order->getShipmentCollection();
  63. $shipment = $shipmentCollection->createItem();
  64. $shipment->setFields(array(
  65. 'CURRENCY' => $order->getCurrency()
  66. ));
  67. $shipmentItemCollection = $shipment->getShipmentItemCollection();
  68.  
  69. foreach ($order->getBasket() as $item) {
  70. $shipmentItem = $shipmentItemCollection->createItem($item);
  71. $shipmentItem->setQuantity($item->getQuantity());
  72. }
  73.  
  74. $propertyCollection = $order->getPropertyCollection();
  75. $property = $propertyCollection->getDeliveryLocation();
  76. $property->setValue($values['locationId']);
  77. $arDeliveries = array();
  78.  
  79. $deliveries = \Bitrix\Sale\Delivery\Services\Manager::getRestrictedObjectsList($shipment);
  80. foreach ($deliveries as $key => $deliveryObj) {
  81. $clonedOrder = $order->createClone();
  82. $shipment->setField('DELIVERY_ID', $deliveryObj->getId());
  83. $clonedOrder->getShipmentCollection()->calculateDelivery();
  84. $calcResult = \Bitrix\Sale\Delivery\Services\Manager::calculateDeliveryPrice($shipment, $deliveryObj->getId(), array());
  85. $calcOrder = $clonedOrder;
  86.  
  87.  
  88. if ($calcResult->isSuccess()) {
  89. $arDelivery['id'] = $deliveryObj->getId();
  90. $arDelivery['logo_path'] = $deliveryObj->getLogotipPath();
  91. $arDelivery['price'] = \Bitrix\Sale\PriceMaths::roundByFormatCurrency($calcResult->getPrice(), $calcOrder->getCurrency());
  92. $arDelivery['price_formated'] = \SaleFormatCurrency($arDelivery['price'], $calcOrder->getCurrency());
  93. $arDelivery['description'] = $deliveryObj->getDescription();
  94.  
  95. $currentCalcDeliveryPrice = \Bitrix\Sale\PriceMaths::roundByFormatCurrency($calcOrder->getDeliveryPrice(), $calcOrder->getCurrency());
  96. if ($currentCalcDeliveryPrice >= 0 && $arDelivery['price'] != $currentCalcDeliveryPrice) {
  97. $arDelivery['discount_price'] = $currentCalcDeliveryPrice;
  98. $arDelivery['discount_price_formated'] = \SaleFormatCurrency($arDelivery['DELIVERY_DISCOUNT_PRICE'], $calcOrder->getCurrency());
  99. }
  100.  
  101. if (strlen($calcResult->getPeriodDescription()) > 0) {
  102. $arDelivery['period_text'] = $calcResult->getPeriodDescription();
  103. } else {
  104. $arDelivery['period_text'] = "0";
  105. }
  106.  
  107. $arDelivery["name"] = $deliveryObj->getNameWithParent();
  108. $arDeliveries[] = $arDelivery;
  109. }
  110. }
  111.  
  112. foreach ($arDeliveries as $delivery) {
  113. echo $delivery['name'] . '%' . $delivery['description'] . '%' . $delivery['price'] . '%' . $delivery['logo_path'] . ':::';
  114. }
  115.  
  116. $locationName = CSaleLocation::GetByID($values["locationId"], LANGUAGE_ID);
  117. if ($locationName['CITY_NAME']) {
  118. echo $locationName['CITY_NAME'];
  119. } else {
  120. echo $locationName['REGION_NAME'];
  121. }
  122. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement