/** * @param $arOrder * @param $deliveryCode * @param $arErrors * @return bool * @throws \Bitrix\Main\ArgumentNullException * @throws \Bitrix\Main\SystemException * @internal * @deprecated */ static function DoProcessOrder(&$arOrder, $deliveryCode, &$arErrors) { if (strlen($deliveryCode) <= 0 || $deliveryCode == '0') { return false; } if (CSaleDeliveryHandler::isSidNew($deliveryCode)) { $service = \Bitrix\Sale\Delivery\Services\Manager::getObjectById(CSaleDeliveryHandler::getIdFromNewSid($deliveryCode)); } else { $service = \Bitrix\Sale\Delivery\Services\Manager::getObjectByCode($deliveryCode); } if ($service) { $isOrderConverted = \Bitrix\Main\Config\Option::get("main", "~sale_converted_15", 'N'); $arOrderTmpDel = array("PRICE" => $arOrder["ORDER_PRICE"] + $arOrder["TAX_PRICE"] - $arOrder["DISCOUNT_PRICE"], "WEIGHT" => $arOrder["ORDER_WEIGHT"], "LOCATION_FROM" => COption::GetOptionString('sale', 'location', '2961', $arOrder["SITE_ID"]), "LOCATION_TO" => isset($arOrder["DELIVERY_LOCATION"]) ? $arOrder["DELIVERY_LOCATION"] : 0, "LOCATION_ZIP" => $arOrder["DELIVERY_LOCATION_ZIP"], "ITEMS" => $arOrder["BASKET_ITEMS"], "CURRENCY" => $arOrder["CURRENCY"]); if ($isOrderConverted == "Y" && !empty($arOrder['ORDER_PROP']) && is_array($arOrder['ORDER_PROP'])) { $arOrderTmpDel['PROPERTIES'] = $arOrder['ORDER_PROP']; } //$r = $propCollection->setValuesFromPost($fields, $_FILES); $arOrder["DELIVERY_ID"] = $deliveryCode; $shipment = self::convertOrderOldToNew($arOrderTmpDel); if (isset($arOrder["DELIVERY_EXTRA_SERVICES"])) { $shipment->setExtraServices($arOrder["DELIVERY_EXTRA_SERVICES"]); } $calculationResult = $service->calculate($shipment); if (!$calculationResult->isSuccess()) { $arErrors[] = array("CODE" => "CALCULATE", "TEXT" => implode("<br>\n", $calculationResult->getErrorMessages())); } else { $arOrder["DELIVERY_PRICE"] = roundEx($calculationResult->getPrice(), SALE_VALUE_PRECISION); } } else { $arErrors[] = array("CODE" => "CALCULATE", "TEXT" => GetMessage('SKGD_DELIVERY_NOT_FOUND')); } }
$arParams["LOCATION_TO"] = intval($arParams["LOCATION_TO"]); $arParams["LOCATION_FROM"] = intval($arParams["LOCATION_FROM"]); if ($arParams["LOCATION_FROM"] <= 0) { $arParams["LOCATION_FROM"] = COption::GetOptionString('sale', 'location'); } $arParams["STEP"] = intval($arParams["STEP"]); if ($arParams["STEP"] <= 0) { $arParams["AJAX_CALL"] = 'N'; } if (is_set($arParams["START_VALUE"])) { $arParams["START_VALUE"] = doubleval($arParams["START_VALUE"]); } if ($arParams["AJAX_CALL"] == "Y") { $shipment = CSaleDelivery::convertOrderOldToNew(array("WEIGHT" => $arParams["ORDER_WEIGHT"], "PRICE" => $arParams["ORDER_PRICE"], "LOCATION_TO" => $arParams["LOCATION_TO"], "LOCATION_ZIP" => $arParams['LOCATION_ZIP'], "ITEMS" => $arParams["ITEMS"], "CURRENCY" => $arParams["CURRENCY"])); /** @var \Bitrix\Sale\Delivery\Services\Base $deliveryObj */ $deliveryObj = \Bitrix\Sale\Delivery\Services\Manager::getObjectById($arParams["DELIVERY_ID"]); if (!$deliveryObj) { ShowError(GetMessage("SALE_DELIVERY_HANDLER_NOT_INSTALL")); return; } $calcResult = $deliveryObj->calculate($shipment); $result = array("VALUE" => $calcResult->getPrice(), "TRANSIT" => $calcResult->getPeriodDescription(), "RESULT" => $calcResult->isSuccess() ? "OK" : "ERROR"); if (!empty($arParams["ORDER_DATA"]) && is_array($arParams["ORDER_DATA"])) { $orderDeliveryPriceData = $arParams["ORDER_DATA"]; $orderDeliveryPriceData['BASKET_ITEMS'] = !empty($arParams['ITEMS']) && is_array($arParams['ITEMS']) ? $arParams['ITEMS'] : array(); $orderDeliveryPriceData['PRICE_DELIVERY'] = $orderDeliveryPriceData['DELIVERY_PRICE'] = $calcResult->getPrice(); $orderDeliveryPriceData['DELIVERY_ID'] = $arParams["DELIVERY_ID"]; CSaleDiscount::DoProcessOrder($orderDeliveryPriceData, array(), $arErrors); if (floatval($orderDeliveryPriceData['DELIVERY_PRICE']) >= 0 && $orderDeliveryPriceData['PRICE_DELIVERY'] != $calcResult->getPrice()) { $result['DELIVERY_DISCOUNT_PRICE'] = $orderDeliveryPriceData['DELIVERY_PRICE']; $result["DELIVERY_DISCOUNT_PRICE_FORMATED"] = SaleFormatCurrency($orderDeliveryPriceData['DELIVERY_PRICE'], $arParams["CURRENCY"]);
public static function execOldEventWithNewParams(Bitrix\Main\Event $params) { /** @var \Bitrix\Sale\Shipment $shipment*/ if (!($shipment = $params->getParameter("SHIPMENT"))) { return new \Bitrix\Main\EventResult(\Bitrix\Main\EventResult::ERROR, null, 'sale'); } $deliveryId = $shipment->getDeliveryId(); if (intval($deliveryId) <= 0 && intval($params->getParameter("DELIVERY_ID")) > 0) { $deliveryId = intval($params->getParameter("DELIVERY_ID")); } if (intval($deliveryId) <= 0) { return new \Bitrix\Main\EventResult(\Bitrix\Main\EventResult::ERROR, null, 'sale'); } /** @var \Bitrix\Sale\Delivery\Services\Base $deliverySrv */ if (!($deliverySrv = \Bitrix\Sale\Delivery\Services\Manager::getObjectById($deliveryId))) { return new \Bitrix\Main\EventResult(\Bitrix\Main\EventResult::ERROR, null, 'sale'); } if (get_class($deliverySrv) != 'Bitrix\\Sale\\Delivery\\Services\\AutomaticProfile') { return new \Bitrix\Main\EventResult(\Bitrix\Main\EventResult::ERROR, null, 'sale'); } if (!($code = $deliverySrv->getCode())) { return new \Bitrix\Main\EventResult(\Bitrix\Main\EventResult::ERROR, null, 'sale'); } $sidAndProfile = \CSaleDeliveryHelper::getDeliverySIDAndProfile($code); /** @var \Bitrix\Sale\Delivery\CalculationResult $result*/ if (!($result = $params->getParameter("RESULT"))) { throw new \Bitrix\Main\ArgumentNullException("params[RESULT]"); } if (!($collection = $shipment->getCollection())) { return new \Bitrix\Main\EventResult(\Bitrix\Main\EventResult::ERROR, null, 'sale'); } /** @var \Bitrix\Sale\Order $order */ if (!($order = $collection->getOrder())) { return new \Bitrix\Main\EventResult(\Bitrix\Main\EventResult::ERROR, null, 'sale'); } $oldOrder = \Bitrix\Sale\Compatible\OrderCompatibility::convertOrderToArray($order); $oldResult = array("VALUE" => $result->getPrice(), "TRANSIT" => $result->getPeriodDescription(), "TEXT" => $result->isSuccess() ? $result->getDescription() : implode("<br>\n", $result->getErrorMessages()), "RESULT" => $result->isSuccess() ? "OK" : "ERROR"); if ($result->isNextStep()) { $oldResult["RESULT"] = "NEXT_STEP"; } if ($result->isSuccess() && strlen($result->getDescription()) > 0) { $oldResult["RESULT"] = "NOTE"; } if (intval($result->getPacksCount()) > 0) { $oldResult["PACKS_COUNT"] = $result->getPacksCount(); } if ($result->isNextStep() && strlen($result->getTmpData()) > 0) { $oldResult["TEMP"] = CUtil::JSEscape($result->getTmpData()); } $oldResult = self::__executeCalculateEvents($sidAndProfile["SID"], $sidAndProfile["PROFILE"], $oldOrder, $oldResult); $result->setDeliveryPrice($oldResult["VALUE"]); if ($oldResult["RESULT"] == "ERROR") { $result->addError(new \Bitrix\Main\Entity\EntityError($oldResult["TEXT"])); } elseif ($oldResult["RESULT"] == "NEXT_STEP") { $result->setAsNextStep(); } if (isset($oldResult["TRANSIT"])) { $result->setPeriodDescription($oldResult["TRANSIT"]); } if (isset($oldResult["TEXT"])) { $result->setDescription($oldResult["TEXT"]); } if (isset($oldResult["PACKS_COUNT"])) { $result->setPacksCount($oldResult["PACKS_COUNT"]); } if (isset($oldResult["TEMP"])) { $result->setTmpData($oldResult["TEMP"]); } return $result; }