Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?
- require_once($_SERVER['DOCUMENT_ROOT'] . '/bitrix/modules/main/include/prolog_before.php');
- use Bitrix\Main\Loader;
- use Bitrix\Main\Context;
- $request = Context::getCurrent()->getRequest();
- $values = $request->getPostList();
- if ($values["action"] == "getShops") {
- Loader::includeModule("iblock");
- Loader::includeModule("sale");
- Loader::includeModule("catalog");
- $res = CSaleDelivery::GetList(
- array(
- "SORT" => "ASC",
- "NAME" => "ASC"
- ),
- array(
- "LID" => SITE_ID,
- "ACTIVE" => "Y",
- "LOCATION" => $values["locationId"],
- "NAME" => "Самовывоз из магазина",
- ),
- false,
- false,
- array()
- );
- if ($ob = $res->Fetch()) {
- preg_match_all('#\"(\d{1,6})\"#usi', $ob['STORE'], $match);
- echo $ob['ID'] . '###';
- if ($match[1]) {
- $rsStore = \Bitrix\Catalog\StoreTable::getList(array(
- 'filter' => array('ACTIVE'>='Y', 'ID' => $match[1]),
- ));
- while($arStore=$rsStore->fetch())
- {
- echo $arStore['TITLE'] . '%' . $arStore['ID'] . ':::';
- }
- }
- } else {
- echo false;
- }
- } else if ($values["action"] == "getMethods") {
- Loader::includeModule("iblock");
- Loader::includeModule("sale");
- Loader::includeModule("catalog");
- \Bitrix\Main\Loader::includeModule('sale');
- $order = \Bitrix\Sale\Order::create(SITE_ID, 1);
- $basket = \Bitrix\Sale\Basket::create(SITE_ID);
- $item = $basket->createItem('catalog', $values['productId']);
- $item->setFields(array(
- 'QUANTITY' => 1,
- 'CURRENCY' => \Bitrix\Currency\CurrencyManager::getBaseCurrency(),
- 'LID' => SITE_ID,
- 'PRODUCT_PROVIDER_CLASS' => 'CCatalogProductProvider',
- ));
- $order->setBasket($basket);
- $order->setPersonTypeId(1);
- $shipmentCollection = $order->getShipmentCollection();
- $shipment = $shipmentCollection->createItem();
- $shipment->setFields(array(
- 'CURRENCY' => $order->getCurrency()
- ));
- $shipmentItemCollection = $shipment->getShipmentItemCollection();
- foreach ($order->getBasket() as $item) {
- $shipmentItem = $shipmentItemCollection->createItem($item);
- $shipmentItem->setQuantity($item->getQuantity());
- }
- $propertyCollection = $order->getPropertyCollection();
- $property = $propertyCollection->getDeliveryLocation();
- $property->setValue($values['locationId']);
- $arDeliveries = array();
- $deliveries = \Bitrix\Sale\Delivery\Services\Manager::getRestrictedObjectsList($shipment);
- foreach ($deliveries as $key => $deliveryObj) {
- $clonedOrder = $order->createClone();
- $shipment->setField('DELIVERY_ID', $deliveryObj->getId());
- $clonedOrder->getShipmentCollection()->calculateDelivery();
- $calcResult = \Bitrix\Sale\Delivery\Services\Manager::calculateDeliveryPrice($shipment, $deliveryObj->getId(), array());
- $calcOrder = $clonedOrder;
- if ($calcResult->isSuccess()) {
- $arDelivery['id'] = $deliveryObj->getId();
- $arDelivery['logo_path'] = $deliveryObj->getLogotipPath();
- $arDelivery['price'] = \Bitrix\Sale\PriceMaths::roundByFormatCurrency($calcResult->getPrice(), $calcOrder->getCurrency());
- $arDelivery['price_formated'] = \SaleFormatCurrency($arDelivery['price'], $calcOrder->getCurrency());
- $arDelivery['description'] = $deliveryObj->getDescription();
- $currentCalcDeliveryPrice = \Bitrix\Sale\PriceMaths::roundByFormatCurrency($calcOrder->getDeliveryPrice(), $calcOrder->getCurrency());
- if ($currentCalcDeliveryPrice >= 0 && $arDelivery['price'] != $currentCalcDeliveryPrice) {
- $arDelivery['discount_price'] = $currentCalcDeliveryPrice;
- $arDelivery['discount_price_formated'] = \SaleFormatCurrency($arDelivery['DELIVERY_DISCOUNT_PRICE'], $calcOrder->getCurrency());
- }
- if (strlen($calcResult->getPeriodDescription()) > 0) {
- $arDelivery['period_text'] = $calcResult->getPeriodDescription();
- } else {
- $arDelivery['period_text'] = "0";
- }
- $arDelivery["name"] = $deliveryObj->getNameWithParent();
- $arDeliveries[] = $arDelivery;
- }
- }
- foreach ($arDeliveries as $delivery) {
- echo $delivery['name'] . '%' . $delivery['description'] . '%' . $delivery['price'] . '%' . $delivery['logo_path'] . ':::';
- }
- $locationName = CSaleLocation::GetByID($values["locationId"], LANGUAGE_ID);
- if ($locationName['CITY_NAME']) {
- echo $locationName['CITY_NAME'];
- } else {
- echo $locationName['REGION_NAME'];
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement