Пример #1
0
 /**
  * @param \Bitrix\Sale\BasketItem $basketItem
  * @param string $reserved
  * @param array $basketStoreData
  * @param null $quantity
  * @return \Bitrix\Sale\Result
  */
 public static function tryShipmentProduct(\Bitrix\Sale\BasketItem $basketItem, $reserved = 'N', array $basketStoreData = array(), $quantity = null)
 {
     $result = new \Bitrix\Sale\Result();
     $storesList = array();
     $strUseStoreControl = COption::GetOptionString('catalog', 'default_use_store_control');
     $disableReservation = COption::GetOptionString("catalog", "enable_reservation") == "N" && COption::GetOptionString("sale", "product_reserve_condition", "O") != "S" && $strUseStoreControl != "Y";
     if ($disableReservation) {
         return $result;
     }
     $productId = $basketItem->getProductId();
     //		if ((int)$arParams["PRODUCT_ID"] <= 0)
     //		{
     //			$APPLICATION->ThrowException(Loc::getMessage("RSRV_INCORRECT_ID"), "NO_ORDER_ID");
     //			$arRes["RESULT"] = false;
     //			return $arRes;
     //		}
     $rsProducts = CCatalogProduct::GetList(array(), array('ID' => $productId), false, false, array('ID', 'QUANTITY', 'QUANTITY_RESERVED', 'QUANTITY_TRACE', 'CAN_BUY_ZERO'));
     if ($arProduct = $rsProducts->Fetch()) {
         if ($strUseStoreControl == "Y") {
             if (empty($basketStoreData)) {
                 $countStores = static::GetStoresCount(array('SITE_ID' => $basketItem->getField('LID')));
                 $defaultDeductionStore = Main\Config\Option::get("sale", "deduct_store_id", "", $basketItem->getField('LID'));
                 if (($countStores == 1 || $countStores == -1 || $defaultDeductionStore > 0) && !$basketItem->isBarcodeMulti()) {
                     if ($productStore = static::GetProductStores(array('PRODUCT_ID' => $productId, 'SITE_ID' => $basketItem->getField('LID')))) {
                         $productStore = reset($productStore);
                         $basketStoreData = array($productStore['STORE_ID'] => array('QUANTITY' => $quantity));
                     }
                 }
             }
             if (!empty($basketStoreData)) {
                 $totalAmount = 0;
                 foreach ($basketStoreData as $storeId => $basketStore) {
                     if (intval($storeId) < -1 || intval($storeId) == 0 || !isset($basketStore["QUANTITY"]) || intval($basketStore["QUANTITY"]) < 0) {
                         $result->addError(new \Bitrix\Sale\ResultError(Loc::getMessage("DDCT_DEDUCTION_STORE_ERROR", self::GetProductCatalogInfo($productId)), "DDCT_DEDUCTION_STORE_ERROR"));
                         return $result;
                     }
                     if (intval($storeId) == -1) {
                         $totalAmount = intval($basketStore["QUANTITY"]);
                     } else {
                         $rsProps = CCatalogStoreProduct::GetList(array(), array("PRODUCT_ID" => $productId, "STORE_ID" => $storeId), false, false, array('ID', 'AMOUNT'));
                         if ($arProp = $rsProps->Fetch()) {
                             if ($arProp["AMOUNT"] < $basketStore["QUANTITY"]) {
                                 $result->addError(new \Bitrix\Sale\ResultError(Loc::getMessage("DDCT_DEDUCTION_QUANTITY_STORE_ERROR", array_merge(self::GetProductCatalogInfo($productId), array("#STORE_ID#" => $storeId))), "DDCT_DEDUCTION_QUANTITY_STORE_ERROR"));
                                 return $result;
                             } else {
                                 $storesList[$storeId] = $basketStore["QUANTITY"];
                                 $totalAmount += $basketStore["QUANTITY"];
                                 //check barcodes
                                 if (isset($basketStore["BARCODE"]) && is_array($basketStore["BARCODE"]) && count($basketStore["BARCODE"]) > 0) {
                                     foreach ($basketStore["BARCODE"] as $barcodeId => $barcodeValue) {
                                         if (strval(trim($barcodeValue)) == "") {
                                             if ($basketItem->isBarcodeMulti()) {
                                                 $result->addError(new \Bitrix\Sale\ResultError(Loc::getMessage("DDCT_DEDUCTION_MULTI_BARCODE_EMPTY", array_merge(self::GetProductCatalogInfo($productId), array("#STORE_ID#" => $basketStore['STORE_ID']))), "DDCT_DEDUCTION_MULTI_BARCODE_EMPTY"));
                                             }
                                             continue;
                                         }
                                         $arFields = array("STORE_ID" => static::CATALOG_PROVIDER_EMPTY_STORE_ID, "BARCODE" => $barcodeValue, "PRODUCT_ID" => $productId);
                                         if ($basketItem->isBarcodeMulti()) {
                                             $arFields['STORE_ID'] = $storeId;
                                         }
                                         $dbres = CCatalogStoreBarcode::GetList(array(), $arFields, false, false, array("ID", "STORE_ID", "BARCODE", "PRODUCT_ID"));
                                         if (!($arRes = $dbres->Fetch())) {
                                             $result->addError(new \Bitrix\Sale\ResultError(Loc::getMessage("DDCT_DEDUCTION_BARCODE_ERROR", array_merge(self::GetProductCatalogInfo($productId), array("#BARCODE#" => $barcodeValue))), "DDCT_DEDUCTION_BARCODE_ERROR"));
                                         }
                                     }
                                 } elseif ($basketItem->isBarcodeMulti()) {
                                     $result->addError(new \Bitrix\Sale\ResultError(Loc::getMessage("DDCT_DEDUCTION_MULTI_BARCODE_EMPTY", array_merge(self::GetProductCatalogInfo($productId), array("#STORE_ID#" => $basketStore['STORE_ID']))), "DDCT_DEDUCTION_MULTI_BARCODE_EMPTY"));
                                 }
                             }
                         }
                     }
                     if (!$result->isSuccess(true)) {
                         return $result;
                     }
                     if ($reserved == 'Y') {
                         $reservedPoolQuantity = static::getProductPoolQuantityByBasketItem($basketItem);
                         $reservedQuantity = $arProduct["QUANTITY_RESERVED"] + floatval($reservedPoolQuantity);
                     }
                     $productQuantity = $reserved == 'Y' ? $reservedQuantity : $arProduct["QUANTITY"];
                     /*if (($totalAmount > $productQuantity)
                     		|| ($totalAmount > $reservedQuantity + $arProduct["QUANTITY"]))*/
                     if ($totalAmount > $arProduct["QUANTITY_RESERVED"] + $arProduct["QUANTITY"]) {
                         $result->addError(new \Bitrix\Sale\ResultError(Loc::getMessage("SALE_PROVIDER_SHIPMENT_QUANTITY_NOT_ENOUGH", self::GetProductCatalogInfo($productId)), "SALE_PROVIDER_SHIPMENT_QUANTITY_NOT_ENOUGH"));
                         return $result;
                     }
                 }
             } else {
                 $result->addError(new \Bitrix\Sale\ResultError(Loc::getMessage("DDCT_DEDUCTION_STORE_ERROR", self::GetProductCatalogInfo($productId)), "DEDUCTION_STORE_ERROR1"));
                 return $result;
             }
         } else {
             $reservedPoolQuantity = static::getProductPoolQuantityByBasketItem($basketItem);
             $reservedQuantity = $arProduct["QUANTITY_RESERVED"] + floatval($reservedPoolQuantity);
             if ($quantity > $reservedQuantity + $arProduct["QUANTITY"]) {
                 $result->addError(new \Bitrix\Sale\ResultError(Loc::getMessage("DDCT_DEDUCTION_QUANTITY_ERROR", self::GetProductCatalogInfo($productId)), "DDCT_DEDUCTION_QUANTITY_ERROR"));
                 return $result;
             }
             //				$arRes["RESULT"] = true;
         }
         //store control
     }
     return $result;
 }
Пример #2
0
 /**
  * @return \Bitrix\Sale\Result|bool
  * @throws Exception
  * @throws \Bitrix\Main\SystemException
  */
 public static function convertToNew($renameTable = false)
 {
     $result = new \Bitrix\Sale\Result();
     $con = \Bitrix\Main\Application::getConnection();
     if (!$con->isTableExists("b_sale_delivery_handler")) {
         return true;
     }
     $sqlHelper = $con->getSqlHelper();
     $deliveryRes = $con->query('SELECT * FROM b_sale_delivery_handler WHERE CONVERTED != \'Y\'');
     $tablesToUpdate = array('b_sale_order', 'b_sale_order_history');
     \CSaleDeliveryHandler::Initialize();
     $handlers = \CSaleDeliveryHandler::__getRegisteredHandlers();
     while ($delivery = $deliveryRes->fetch()) {
         if (strlen($delivery["PROFILES"]) > 0) {
             $delivery["PROFILES"] = unserialize($delivery["PROFILES"]);
         } else {
             $delivery["PROFILES"] = $handlers[$delivery["HID"]]["PROFILES"];
             foreach ($delivery["PROFILES"] as $id => $params) {
                 $delivery["PROFILES"][$id]["ACTIVE"] = $delivery["ACTIVE"];
             }
         }
         // Something strange it probably not used
         if ($delivery["PROFILES"] == false || !is_array($delivery["PROFILES"]) || empty($delivery["PROFILES"])) {
             $result->addError(new \Bitrix\Main\Entity\EntityError("Can't receive info about profiles. Delivery HID: \"" . $delivery["HID"] . "\""));
             continue;
         }
         unset($delivery["ID"]);
         $delivery["CONFIG"] = array();
         if (strlen($delivery["SETTINGS"]) > 0) {
             if (isset($handlers[$delivery["HID"]]["DBGETSETTINGS"]) && is_callable($handlers[$delivery["HID"]]["DBGETSETTINGS"])) {
                 $delivery["CONFIG"] = call_user_func($handlers[$delivery["HID"]]["DBGETSETTINGS"], $delivery["SETTINGS"]);
             } else {
                 $delivery["CONFIG"] = $delivery["SETTINGS"];
             }
         } elseif (is_callable($handlers[$delivery["HID"]]["GETCONFIG"])) {
             $config = call_user_func($handlers[$delivery["HID"]]["GETCONFIG"], strlen($delivery["LID"]) > 0 ? $delivery["LID"] : false);
             foreach ($config["CONFIG"] as $key => $arConfig) {
                 if (!empty($arConfig["DEFAULT"])) {
                     $delivery["CONFIG"][$key] = $arConfig["DEFAULT"];
                 }
             }
         }
         $delivery["SID"] = $handlers[$delivery["HID"]]["SID"];
         $id = \CSaleDeliveryHandler::Set($delivery["HID"], $delivery, strlen($delivery["LID"]) > 0 ? $delivery["LID"] : false);
         if (intval($id) <= 0) {
             $result->addError(new \Bitrix\Main\Entity\EntityError("Can't convert delivery handler with hid: " . $delivery["HID"] . (strlen($delivery["LID"]) > 0 ? " for site: " . $delivery["LID"] : "")));
             continue;
         }
         $con->queryExecute('UPDATE b_sale_delivery_handler SET CONVERTED="Y" WHERE HID="' . $sqlHelper->forSql($delivery["HID"]) . '"');
         $ids = array($id);
         foreach ($delivery["PROFILES"] as $profileName => $profileData) {
             $fullSid = $delivery["HID"] . ":" . $profileName;
             $profileId = \Bitrix\Sale\Delivery\Services\Table::getIdByCode($fullSid);
             $ids[] = $profileId;
             if (intval($profileId) > 0) {
                 foreach ($tablesToUpdate as $table) {
                     $con->queryExecute("UPDATE " . $table . " SET DELIVERY_ID=" . $sqlHelper->forSql($profileId) . " WHERE DELIVERY_ID = '" . $sqlHelper->forSql($fullSid) . "'");
                 }
                 $con->queryExecute("UPDATE b_sale_delivery2paysystem SET DELIVERY_ID=" . $sqlHelper->forSql($profileId) . ", DELIVERY_PROFILE_ID='' WHERE DELIVERY_ID = '" . $sqlHelper->forSql($delivery["HID"]) . "' AND DELIVERY_PROFILE_ID='" . $profileName . "'");
             } else {
                 $result->addError(new \Bitrix\Main\Entity\EntityError("Cant determine id for profile code: " . $fullSid));
             }
         }
         $con->queryExecute("UPDATE b_sale_delivery2paysystem SET DELIVERY_ID=" . $sqlHelper->forSql($id) . ", DELIVERY_PROFILE_ID='' WHERE DELIVERY_ID = '" . $sqlHelper->forSql($delivery["HID"]) . "' AND (DELIVERY_PROFILE_ID='' OR DELIVERY_PROFILE_ID IS NULL)");
         $d2pRes = \Bitrix\Sale\Internals\DeliveryPaySystemTable::getList(array('filter' => array('DELIVERY_ID' => $ids), 'select' => array("DELIVERY_ID"), 'group' => array("DELIVERY_ID")));
         while ($d2p = $d2pRes->fetch()) {
             $res = \Bitrix\Sale\Delivery\Restrictions\Table::add(array("DELIVERY_ID" => $d2p["DELIVERY_ID"], "CLASS_NAME" => '\\Bitrix\\Sale\\Delivery\\Restrictions\\ByPaySystem', "SORT" => 100));
             if (!$res->isSuccess()) {
                 $result->addErrors($res->getErrors());
             }
         }
     }
     if ($renameTable && $result->isSuccess()) {
         $con->queryExecute("ALTER TABLE b_sale_delivery_handler RENAME b_sale_delivery_handler_old");
     }
     return $result;
 }
Пример #3
0
    LocalRedirect("/bitrix/admin/sale_order.php?lang=" . LANGUAGE_ID . GetFilterParams("filter_", false));
}
$allowedStatusesEdit = \Bitrix\Sale\OrderStatus::getStatusesUserCanDoOperations($USER->GetID(), array('edit'));
if (!in_array($order->getField("STATUS_ID"), $allowedStatusesEdit)) {
    LocalRedirect("/bitrix/admin/sale_order_view.php?ID=" . $ID . "&lang=" . LANGUAGE_ID . GetFilterParams("filter_"));
}
$userId = isset($_POST["USER_ID"]) ? intval($_POST["USER_ID"]) : $order->getUserId();
OrderEdit::initCouponsData($userId, $ID, isset($_POST["OLD_USER_ID"]) ? intval($_POST["USER_ID"]) : $userId);
if (!$boolLocked) {
    \Bitrix\Sale\Order::lock($ID);
}
$isSavingOperation = $_SERVER["REQUEST_METHOD"] == "POST" && (isset($_POST["apply"]) || isset($_POST["save"]));
$isRefreshDataAndSaveOperation = $_SERVER["REQUEST_METHOD"] == "POST" && isset($_POST["refresh_data_and_save"]) && $_POST["refresh_data_and_save"] == "Y";
$isNeedFieldsRestore = $_SERVER["REQUEST_METHOD"] == "POST" && !$isSavingOperation && !$isRefreshDataAndSaveOperation;
//save order params
if (($isSavingOperation || $isNeedFieldsRestore || $isRefreshDataAndSaveOperation) && $saleModulePermissions >= "U" && check_bitrix_sessid() && $result->isSuccess()) {
    if ($isSavingOperation || $isRefreshDataAndSaveOperation) {
        $order = OrderEdit::editOrderByFormData($_POST, $order, $USER->GetID(), true, $_FILES, $result);
    }
    if ($isRefreshDataAndSaveOperation) {
        /** @var \Bitrix\Sale\Basket $basket */
        if (!($basket = $order->getBasket())) {
            throw new \Bitrix\Main\ObjectNotFoundException('Entity "Basket" not found');
        }
        $res = $basket->refreshData(array('PRICE', 'QUANTITY', 'COUPONS'));
        if (!$res->isSuccess()) {
            $result->addErrors($res->getErrors());
        }
    }
    if (($isSavingOperation || $isRefreshDataAndSaveOperation) && $result->isSuccess()) {
        if ($order) {
Пример #4
0
    /**
     * @param bool|false $renameTable
     * @return \Bitrix\Sale\Result
     * @throws Exception
     * @throws \Bitrix\Main\ArgumentException
     * @internal
     */
    public static function convertToNew($renameTable = false)
    {
        $result = new \Bitrix\Sale\Result();
        $con = \Bitrix\Main\Application::getConnection();
        if (!$con->isTableExists("b_sale_delivery")) {
            return $result;
        }
        if (!$con->isTableExists("b_sale_delivery2location_tmp")) {
            $fields = $con->getTableFields('b_sale_delivery2location');
            $con->createTable('b_sale_delivery2location_tmp', $fields, array('DELIVERY_ID', 'LOCATION_CODE', 'LOCATION_TYPE'));
            $con->queryExecute('
				INSERT INTO
					b_sale_delivery2location_tmp(DELIVERY_ID, LOCATION_CODE, LOCATION_TYPE)
				SELECT
					DELIVERY_ID, LOCATION_CODE, LOCATION_TYPE FROM b_sale_delivery2location
			');
            $con->queryExecute('DELETE FROM b_sale_delivery2location');
        }
        $sqlHelper = $con->getSqlHelper();
        $deliveryRes = $con->query('SELECT * FROM b_sale_delivery WHERE CONVERTED != \'Y\'');
        while ($delivery = $deliveryRes->fetch()) {
            $delivery["CODE"] = $delivery["ID"];
            unset($delivery["ID"]);
            $newId = \CSaleDelivery::Add($delivery);
            if (intval($newId) <= 0) {
                $result->addError(new \Bitrix\Main\Entity\EntityError("Can't convert old delivery id: " . $delivery["CODE"]));
                continue;
            }
            $res = \Bitrix\Sale\Delivery\Restrictions\Table::add(array("DELIVERY_ID" => $newId, "CLASS_NAME" => '\\Bitrix\\Sale\\Delivery\\Restrictions\\ByLocation', "SORT" => 100));
            $result->addErrors($res->getErrors());
            if ($result->isSuccess()) {
                $con->queryExecute('UPDATE b_sale_delivery SET CONVERTED=\'Y\' WHERE ID=' . $sqlHelper->forSql($delivery["CODE"]));
                $con->queryExecute("UPDATE b_sale_order SET DELIVERY_ID=" . $sqlHelper->forSql($newId) . " WHERE DELIVERY_ID = " . $sqlHelper->forSql($delivery["CODE"]));
                $con->queryExecute("UPDATE b_sale_order_history SET DELIVERY_ID=" . $sqlHelper->forSql($newId) . " WHERE DELIVERY_ID = " . $sqlHelper->forSql($delivery["CODE"]));
                $con->queryExecute("UPDATE b_sale_delivery2paysystem SET DELIVERY_ID=" . $sqlHelper->forSql($newId) . ", LINK_DIRECTION='" . DeliveryPaySystemTable::LINK_DIRECTION_DELIVERY_PAYSYSTEM . "' WHERE DELIVERY_ID = " . $sqlHelper->forSql($delivery["CODE"]));
                $con->queryExecute('
					INSERT INTO
						b_sale_delivery2location(DELIVERY_ID, LOCATION_CODE, LOCATION_TYPE)
					SELECT
						' . $sqlHelper->forSql($newId) . ', LOCATION_CODE, LOCATION_TYPE FROM b_sale_delivery2location_tmp
					WHERE
						DELIVERY_ID = ' . $sqlHelper->forSql($delivery["CODE"]) . '
				');
                $con->queryExecute('DELETE FROM b_sale_delivery2location_tmp WHERE DELIVERY_ID = ' . $sqlHelper->forSql($delivery["CODE"]));
                $d2pRes = \Bitrix\Sale\Internals\DeliveryPaySystemTable::getList(array('filter' => array('DELIVERY_ID' => $newId), 'select' => array("DELIVERY_ID"), 'group' => array("DELIVERY_ID")));
                if ($d2p = $d2pRes->fetch()) {
                    $res = \Bitrix\Sale\Delivery\Restrictions\Table::add(array("DELIVERY_ID" => $d2p["DELIVERY_ID"], "CLASS_NAME" => '\\Bitrix\\Sale\\Delivery\\Restrictions\\ByPaySystem', "SORT" => 100));
                    if (!$res->isSuccess()) {
                        $result->addErrors($res->getErrors());
                    }
                }
            }
        }
        if ($result->isSuccess()) {
            $con->dropTable('b_sale_delivery2location_tmp');
            if ($renameTable) {
                $con->renameTable("b_sale_delivery", "b_sale_delivery_old");
            }
        }
        return $result;
    }
Пример #5
0
 /**
  * @return \Bitrix\Sale\Result
  * @throws Exception
  * @throws \Bitrix\Main\SystemException
  */
 public static function convertToNew($renameTable = false)
 {
     $result = new \Bitrix\Sale\Result();
     $con = \Bitrix\Main\Application::getConnection();
     if (!$con->isTableExists("b_sale_delivery_handler")) {
         return $result;
     }
     $sqlHelper = $con->getSqlHelper();
     $deliveryRes = $con->query('SELECT * FROM b_sale_delivery_handler WHERE CONVERTED != \'Y\'');
     $tablesToUpdate = array('b_sale_order', 'b_sale_order_history');
     \CSaleDeliveryHandler::Initialize();
     $handlers = \CSaleDeliveryHandler::__getRegisteredHandlers();
     while ($delivery = $deliveryRes->fetch()) {
         if (strlen($delivery["HID"]) <= 0) {
             $result->addError(new \Bitrix\Main\Entity\EntityError("Can't find delivery HID. ID: \"" . $delivery["ID"] . "\""));
             continue;
         }
         if (!isset($handlers[$delivery["HID"]])) {
             \CEventLog::Add(array("SEVERITY" => "ERROR", "AUDIT_TYPE_ID" => "SALE_CONVERTER_ERROR", "MODULE_ID" => "sale", "ITEM_ID" => "CAllSaleDeliveryHandler::convertToNew()", "DESCRIPTION" => "Can't find delivery handler for registered HID: \"" . $delivery["HID"] . "\""));
             //$result->addError( new \Bitrix\Main\Entity\EntityError("Can't find delivery handler for registered HID: \"".$delivery["HID"]."\""));
             continue;
         }
         if (strlen($delivery["PROFILES"]) > 0) {
             //get from base
             $delivery["PROFILES"] = unserialize($delivery["PROFILES"]);
         } else {
             //or default.
             $delivery["PROFILES"] = $handlers[$delivery["HID"]]["PROFILES"];
         }
         // Something strange it probably not used
         if ($delivery["PROFILES"] == false || !is_array($delivery["PROFILES"]) || empty($delivery["PROFILES"])) {
             $result->addError(new \Bitrix\Main\Entity\EntityError("Can't receive info about profiles. Delivery HID: \"" . $delivery["HID"] . "\""));
             continue;
         }
         //Set profiles activity
         foreach ($delivery["PROFILES"] as $id => $params) {
             if (!isset($delivery["PROFILES"][$id]["ACTIVE"]) || $delivery["ACTIVE"] == "N") {
                 $delivery["PROFILES"][$id]["ACTIVE"] = $delivery["ACTIVE"];
             }
         }
         unset($delivery["ID"]);
         $delivery["CONFIG"] = array();
         if (strlen($delivery["SETTINGS"]) > 0) {
             if (isset($handlers[$delivery["HID"]]["DBGETSETTINGS"]) && is_callable($handlers[$delivery["HID"]]["DBGETSETTINGS"])) {
                 $delivery["CONFIG"] = call_user_func($handlers[$delivery["HID"]]["DBGETSETTINGS"], $delivery["SETTINGS"]);
             } else {
                 $delivery["CONFIG"] = $delivery["SETTINGS"];
             }
         } elseif (isset($handlers[$delivery["HID"]]["GETCONFIG"]) && is_callable($handlers[$delivery["HID"]]["GETCONFIG"])) {
             $config = call_user_func($handlers[$delivery["HID"]]["GETCONFIG"], strlen($delivery["LID"]) > 0 ? $delivery["LID"] : false);
             foreach ($config["CONFIG"] as $key => $arConfig) {
                 if (!empty($arConfig["DEFAULT"])) {
                     $delivery["CONFIG"][$key] = $arConfig["DEFAULT"];
                 }
             }
         }
         if (empty($delivery["NAME"])) {
             if (!empty($handlers[$delivery["HID"]]["NAME"])) {
                 $delivery["NAME"] = $handlers[$delivery["HID"]]["NAME"];
             } else {
                 $delivery["NAME"] = "-";
             }
         }
         $delivery["SID"] = $handlers[$delivery["HID"]]["SID"];
         $id = \CSaleDeliveryHandler::Set($delivery["HID"], $delivery, strlen($delivery["LID"]) > 0 ? $delivery["LID"] : false);
         if (intval($id) <= 0) {
             $result->addError(new \Bitrix\Main\Entity\EntityError("Can't convert delivery handler with hid: " . $delivery["HID"] . (strlen($delivery["LID"]) > 0 ? " for site: " . $delivery["LID"] : "")));
             continue;
         }
         $con->queryExecute("UPDATE b_sale_delivery_handler SET CONVERTED='Y' WHERE HID LIKE '" . $sqlHelper->forSql($delivery["HID"]) . "'");
         $ids = array($id);
         foreach ($delivery["PROFILES"] as $profileName => $profileData) {
             $fullSid = $delivery["HID"] . ":" . $profileName;
             $profileId = \CSaleDelivery::getIdByCode($fullSid);
             $ids[] = $profileId;
             if (intval($profileId) > 0) {
                 foreach ($tablesToUpdate as $table) {
                     $con->queryExecute("UPDATE " . $table . " SET DELIVERY_ID='" . $sqlHelper->forSql($profileId) . "' WHERE DELIVERY_ID = '" . $sqlHelper->forSql($fullSid) . "'");
                 }
                 $con->queryExecute("UPDATE b_sale_delivery2paysystem SET DELIVERY_ID='" . $sqlHelper->forSql($profileId) . "', DELIVERY_PROFILE_ID='##CONVERTED##' WHERE DELIVERY_ID = '" . $sqlHelper->forSql($delivery["HID"]) . "' AND DELIVERY_PROFILE_ID='" . $profileName . "'");
             } else {
                 $result->addError(new \Bitrix\Main\Entity\EntityError("Cant determine id for profile code: " . $fullSid));
             }
         }
         $con->queryExecute("UPDATE b_sale_delivery2paysystem SET DELIVERY_ID='" . $sqlHelper->forSql($id) . "', DELIVERY_PROFILE_ID='##CONVERTED##' WHERE DELIVERY_ID = '" . $sqlHelper->forSql($delivery["HID"]) . "' AND (DELIVERY_PROFILE_ID='' OR DELIVERY_PROFILE_ID IS NULL)");
         $d2pRes = \Bitrix\Sale\Internals\DeliveryPaySystemTable::getList(array('filter' => array('DELIVERY_ID' => $ids), 'select' => array("DELIVERY_ID"), 'group' => array("DELIVERY_ID")));
         while ($d2p = $d2pRes->fetch()) {
             $res = \Bitrix\Sale\Internals\ServiceRestrictionTable::add(array("SERVICE_ID" => $d2p["DELIVERY_ID"], "SERVICE_TYPE" => \Bitrix\Sale\Services\Base\RestrictionManager::SERVICE_TYPE_SHIPMENT, "CLASS_NAME" => '\\Bitrix\\Sale\\Delivery\\Restrictions\\ByPaySystem', "SORT" => 100));
             if (!$res->isSuccess()) {
                 $result->addErrors($res->getErrors());
             }
         }
     }
     if ($renameTable && $result->isSuccess()) {
         $con->renameTable('b_sale_delivery_handler', 'b_sale_delivery_handler_old');
     }
     return $result;
 }