Ejemplo n.º 1
0
 /**
  * @param \DDelivery\Order\DDeliveryOrder $order
  * @throws \Bitrix\Main\ArgumentException
  */
 public function onFinishChange($order)
 {
     global $APPLICATION;
     $point = $order->getPoint();
     if ($order->type == DDeliverySDK::TYPE_SELF) {
         $replaceData = array('%1' => $order->cityName, '%2' => $point['address'], '%3' => $point['delivery_company_name'], '%4' => $point['_id'], '%5' => $point['type'] == 1 ? 'Постомат' : 'ПВЗ');
         $replaceData = $APPLICATION->ConvertCharsetArray($replaceData, 'UTF-8', SITE_CHARSET);
         $comment = GetMessage('DDELIVERY_ABOUT_SELF', $replaceData);
     } else {
         if ($order->type == DDeliverySDK::TYPE_COURIER) {
             $replaceData = array('%1' => $order->getFullAddress(), '%2' => $point['delivery_company_name']);
             $replaceData = $APPLICATION->ConvertCharsetArray($replaceData, 'UTF-8', SITE_CHARSET);
             $comment = GetMessage('DDELIVERY_ABOUT_COURIER', $replaceData);
         } else {
             $comment = 'error';
         }
     }
     $orderId = $this->formData['bx_order_id'];
     $params = array('DD_ABOUT' => $comment, 'DD_LOCAL_ID' => $order->localId);
     $orderDeliveryTableData = OrderDeliveryTable::getList(array('filter' => array('ORDER_ID' => $orderId)))->fetch();
     if ($orderDeliveryTableData) {
         OrderDeliveryTable::update($orderDeliveryTableData['ID'], array('PARAMS' => serialize($params)));
     } else {
         OrderDeliveryTable::add(array('ORDER_ID' => $orderId, 'PARAMS' => serialize($params)));
     }
     $order = CSaleOrder::GetByID($orderId);
     $arDeliveryResult = CSaleDeliveryHandler::CalculateFull('ddelivery', 'ddelivery:all', $order, CSaleLang::GetLangCurrency(SITE_ID), SITE_ID);
     if ($arDeliveryResult['RESULT'] == 'OK') {
         CSaleOrder::Update($orderId, array('PRICE_DELIVERY' => $arDeliveryResult['VALUE']));
     }
 }
Ejemplo n.º 2
0
				{
					$arDeliveryId = explode(":", $arOrder["DELIVERY_ID"]);
					$profileId = $arDeliveryId[1];

					$arDeliveryOrder = array(
						"PRICE" => $orderTotalPrice,
						"WEIGHT" => $orderTotalWeight,
						"LOCATION_FROM" => COption::GetOptionString('sale', 'location', '', $LID),
						"LOCATION_TO" => $locationData,
						"LOCATION_ZIP" => $locationZip,
						"ITEMS" => $arBasketItems
					);


					$depList = \Bitrix\Sale\Delivery\OrderDeliveryTable::getList(array(
						'filter'=>array('=ORDER_ID' => $ID),
					));

					if($dep = $depList->fetch())
					{
						$arDeliveryOrder["EXTRA_PARAMS"] = unserialize($dep["PARAMS"]);
					}

					$arPacks = CSaleDeliveryHelper::getBoxesFromConfig($profileId, $arDeliveryData["CONFIG"]["CONFIG"]);
					$arDeliveryResult = CSaleDeliveryHandler::CalculateFull($arDeliveryData["SID"], $profileId, $arDeliveryOrder, $arOrder["CURRENCY"], $LID);
					$delDiscountDiff = roundEx($arDeliveryResult["VALUE"] - $arOrder["PRICE_DELIVERY"], SALE_VALUE_PRECISION);

					$tabControl->BeginCustomField("ORDER_DELIVERY_ADDITIONAL_INFO", "");

					if (!empty($arPacks)):
						$arBox = array_shift(array_values($arPacks));
Ejemplo n.º 3
0
 public static function execHandlerAction($orderId, $actionId)
 {
     global $DB, $USER;
     $arResult = array();
     $arOrder = CSaleOrder::GetById($orderId);
     $handlerActions = CSaleDeliveryHandler::getActionsList($arOrder["DELIVERY_ID"]);
     if (!array_key_exists($actionId, $handlerActions)) {
         $arResult = array("RESULT" => "ERROR", "TEXT" => GetMessage("SALE_DHLP_HANDLER_HAS_NO_ACTION"));
     }
     $dt = new \Bitrix\Main\Type\DateTime();
     $depList = \Bitrix\Sale\Delivery\OrderDeliveryTable::getList(array('filter' => array('=ORDER_ID' => $orderId)));
     $dep = $depList->fetch();
     if ($dep && !is_null($dep["DATE_REQUEST"])) {
         $arResult = array("RESULT" => "ERROR", "TEXT" => GetMessage("SALE_DHLP_HANDLER_REQUEST_ALREADY_SENT"));
     }
     if (empty($arResult)) {
         $arUserGroups = $USER->GetUserGroupArray();
         $arOrder["ITEMS"] = array();
         $dbItemsList = CSaleBasket::GetList(array("SET_PARENT_ID" => "DESC", "TYPE" => "DESC", "NAME" => "ASC"), array("ORDER_ID" => $orderId));
         while ($arItem = $dbItemsList->GetNext()) {
             $arItem["DIMENSIONS"] = unserialize($arItem["~DIMENSIONS"]);
             unset($arItem["~DIMENSIONS"]);
             $arOrder["ITEMS"][] = $arItem;
         }
         $arResult = CSaleDeliveryHandler::executeAction($arOrder["DELIVERY_ID"], $actionId, $arOrder);
         if ($actionId == "REQUEST_SELF" && isset($arResult["TRACKING_NUMBER"])) {
             $bUserCanEditOrder = CSaleOrder::CanUserUpdateOrder($orderId, $arUserGroups);
             if ($bUserCanEditOrder) {
                 if ($dep) {
                     \Bitrix\Sale\Delivery\OrderDeliveryTable::update($dep["ID"], array("DATE_REQUEST" => $dt));
                 } else {
                     \Bitrix\Sale\Delivery\OrderDeliveryTable::add(array("ORDER_ID" => $orderId, "DATE_REQUEST" => $dt));
                 }
                 $fields = array();
                 if (isset($arResult["TRACKING_NUMBER"])) {
                     $fields["TRACKING_NUMBER"] = $arResult["TRACKING_NUMBER"];
                 }
                 if (isset($arResult["DELIVERY_DOC_NUM"])) {
                     $fields["DELIVERY_DOC_NUM"] = $arResult["DELIVERY_DOC_NUM"];
                     $fields["DELIVERY_DOC_DATE"] = Date($DB->DateFormatToPHP(CLang::GetDateFormat("SHORT", $arOrder["LID"])));
                 }
                 CSaleOrder::Update($orderId, $fields);
             }
         }
         CSaleOrderChange::AddRecord($orderId, "ORDER_DELIVERY_REQUEST_SENT", $arResult);
     }
     return $arResult;
 }
Ejemplo n.º 4
0
 /**
  *
  * @param $orderId
  * @param $statusID
  * @return bool
  * @throws Bitrix\Main\DB\Exception
  */
 static function OnSaleBeforeStatusOrder($orderId, $statusID)
 {
     $orderDeliveryTableData = OrderDeliveryTable::getList(array('filter' => array('ORDER_ID' => $orderId)))->fetch();
     if (empty($orderDeliveryTableData)) {
         return true;
     }
     $property = unserialize($orderDeliveryTableData['PARAMS']);
     if (empty($property) || empty($property['DD_LOCAL_ID'])) {
         $property = CSaleOrderPropsValue::GetList(array(), array("ORDER_ID" => $orderId, 'CODE' => 'DDELIVERY_ID'))->Fetch();
         if (!$property) {
             return true;
         } else {
             $ddLocalId = $property['VALUE'];
         }
     } else {
         $ddLocalId = $property['DD_LOCAL_ID'];
     }
     global $APPLICATION;
     try {
         $DDConfig = CSaleDeliveryHandler::GetBySID('ddelivery')->Fetch();
         if ($statusID != $DDConfig['CONFIG']['CONFIG']['SEND_STATUS']['VALUE']) {
             return true;
         }
         $cmsOrder = CSaleOrder::GetByID($orderId);
         if ($cmsOrder['DELIVERY_ID'] != 'ddelivery:all') {
             return true;
         }
         $IntegratorShop = self::getShopObject($DDConfig['CONFIG']['CONFIG'], array(), array());
         $ddeliveryUI = new DdeliveryUI($IntegratorShop, true);
         $order = $ddeliveryUI->initOrder($ddLocalId);
         $bxOrder = CSaleBasket::GetList(array(), array('ORDER_ID' => $orderId), false, false, array('PRODUCT_ID', 'PRICE', 'QUANTITY', 'NAME'));
         $bxItems = array();
         while ($bxItem = $bxOrder->Fetch()) {
             $bxItems[] = $bxItem;
         }
         $order->setProducts($IntegratorShop->itemListToDDCart($bxItems));
         $point = $order->getPoint();
         $newPoint = false;
         if ($order->type == DDeliverySDK::TYPE_SELF) {
             $newPoint = $ddeliveryUI->calculateSelfPointPrice($order, $point['_id']);
             $newPoint = isset($newPoint[0]) ? $newPoint[0] : false;
         } else {
             if ($order->type == DDeliverySDK::TYPE_COURIER) {
                 $resultPoints = $ddeliveryUI->calculateCourierPrices($order);
                 foreach ($resultPoints as $resultPoint) {
                     if ($resultPoint['delivery_company'] == $point['delivery_company']) {
                         $newPoint = $resultPoint;
                     }
                 }
             }
         }
         if ($newPoint) {
             $order->setPoint($newPoint);
         } else {
             $APPLICATION->ThrowException(GetMessage('DDELIVERY_SAVE_STATUS_ERROR_ORDER_NOT_LOAD'));
             return false;
         }
         if (empty($order) || $order->ddeliveryID) {
             $APPLICATION->ThrowException(GetMessage('DDELIVERY_SAVE_STATUS_ERROR_ORDER_NOT_LOAD'));
             return false;
         }
         $order->localStatus = $statusID;
         /**
          * @var \DDelivery\Order\DDeliveryOrder $order
          */
         $order->shopRefnum = $orderId;
         $order->paymentVariant = $cmsOrder['PAY_SYSTEM_ID'];
         $ddeliveryOrderID = $ddeliveryUI->sendOrderToDD($order);
         $ddeliveryUI->saveFullOrder($order);
         if (!$ddeliveryOrderID) {
             $APPLICATION->ThrowException(GetMessage('DDELIVERY_SAVE_STATUS_ERROR_NOT_SAVE'));
             return false;
         }
         CSaleOrder::Update($orderId, array("TRACKING_NUMBER" => $ddeliveryOrderID));
         return true;
     } catch (\DDelivery\DDeliveryException $e) {
         $APPLICATION->ThrowException(GetMessage('DDELIVERY_SAVE_STATUS_ERROR_EXCEPTION', array('%1' => $APPLICATION->ConvertCharset($e->getMessage(), 'UTF-8', SITE_CHARSET))));
         return false;
     }
 }
Ejemplo n.º 5
0
    $APPLICATION->AuthForm(GetMessage("ACCESS_DENIED"));
}
$orderId = (int) isset($_REQUEST['order_id']) ? $_REQUEST['order_id'] : 0;
if (!$orderId) {
    LocalRedirect('/bitrix/admin/sale_order.php?lang=' . LANG);
}
IncludeModuleLangFile(__FILE__);
$MODULE_ID = 'ddelivery.ddelivery';
$APPLICATION->SetTitle(GetMessage("DDELIVERY_NAME"));
require $_SERVER["DOCUMENT_ROOT"] . BX_ROOT . "/modules/main/include/prolog_admin_after.php";
$ddeliveryConfig = CSaleDeliveryHandler::GetBySID('ddelivery')->Fetch();
$dbBasketItems = CSaleBasket::GetList(array("ID" => "ASC"), array("ORDER_ID" => $_REQUEST['bx_order_id']), false, false, array('PRODUCT_ID', 'PRICE', 'QUANTITY', 'NAME'));
while ($arBasket = $dbBasketItems->Fetch()) {
    $itemList[] = $arBasket;
}
$orderDeliveryTableData = OrderDeliveryTable::getList(array('filter' => array('ORDER_ID' => $orderId)))->fetch();
if ($orderDeliveryTableData) {
    $orderDeliveryParams = unserialize($orderDeliveryTableData['PARAMS']);
    $IntegratorShop = new DDeliveryAdminShop($ddeliveryConfig['CONFIG']['CONFIG'], $itemList, $formData);
    try {
        $ddeliveryUI = new DdeliveryUI($IntegratorShop);
        $order = $ddeliveryUI->initOrder($orderDeliveryParams['DD_LOCAL_ID']);
        if ($order->ddStatus == DDStatusProvider::ORDER_CONFIRMED) {
            CAdminMessage::ShowMessage(array('MESSAGE' => GetMessage("DDELIVERY_ORDER_IN_PROGRESS"), 'TYPE' => 'ERROR'));
            $orderDeliveryTableData = false;
        }
    } catch (Exception $e) {
        CAdminMessage::ShowMessage(array('MESSAGE' => $APPLICATION->ConvertCharset($e->getMessage(), 'utf-8', SITE_CHARSET), 'TYPE' => 'ERROR'));
    }
} else {
    $orderDeliveryParams = false;