Пример #1
0
 function OrderBasket($orderID, $fuserID = 0, $strLang = SITE_ID, $arDiscounts = False)
 {
     $orderID = (int) $orderID;
     if ($orderID <= 0) {
         return false;
     }
     $fuserID = (int) $fuserID;
     if ($fuserID <= 0) {
         $fuserID = (int) CSaleBasket::GetBasketUserID(true);
     }
     if ($fuserID <= 0) {
         return false;
     }
     $isOrderConverted = \Bitrix\Main\Config\Option::get("main", "~sale_converted_15", 'N');
     $arOrder = array();
     if (empty($arOrder)) {
         $rsOrders = CSaleOrder::GetList(array(), array('ID' => $orderID), false, false, array('ID', 'USER_ID', 'RECURRING_ID', 'LID', 'RESERVED'));
         if (!($arOrder = $rsOrders->Fetch())) {
             return false;
         }
         $arOrder['RECURRING_ID'] = (int) $arOrder['RECURRING_ID'];
     }
     $boolRecurring = $arOrder['RECURRING_ID'] > 0;
     $needSaveCoupons = false;
     $dbBasketList = CSaleBasket::GetList(array("PRICE" => "DESC"), array("FUSER_ID" => $fuserID, "LID" => $strLang, "ORDER_ID" => 0), false, false, array('ID', 'ORDER_ID', 'PRODUCT_ID', 'MODULE', 'CAN_BUY', 'DELAY', 'ORDER_CALLBACK_FUNC', 'PRODUCT_PROVIDER_CLASS', 'QUANTITY', 'CUSTOM_PRICE'));
     while ($arBasket = $dbBasketList->Fetch()) {
         $arFields = array();
         if ($arBasket["DELAY"] == "N" && $arBasket["CAN_BUY"] == "Y") {
             if (!empty($arBasket["ORDER_CALLBACK_FUNC"]) || !empty($arBasket["PRODUCT_PROVIDER_CLASS"])) {
                 /** @var $productProvider IBXSaleProductProvider */
                 if ($productProvider = CSaleBasket::GetProductProvider($arBasket)) {
                     $arQuery = array("PRODUCT_ID" => $arBasket["PRODUCT_ID"], "QUANTITY" => $arBasket["QUANTITY"], 'BASKET_ID' => $arBasket['ID']);
                     if ($boolRecurring) {
                         $arQuery['RENEWAL'] = 'Y';
                         $arQuery['USER_ID'] = $arOrder['USER_ID'];
                         $arQuery['SITE_ID'] = $strLang;
                     }
                     $arFields = $productProvider::OrderProduct($arQuery);
                 } else {
                     if ($boolRecurring) {
                         $arFields = CSaleBasket::ExecuteCallbackFunction($arBasket["ORDER_CALLBACK_FUNC"], $arBasket["MODULE"], $arBasket["PRODUCT_ID"], $arBasket["QUANTITY"], 'Y', $arOrder['USER_ID'], $strLang);
                     } else {
                         $arFields = CSaleBasket::ExecuteCallbackFunction($arBasket["ORDER_CALLBACK_FUNC"], $arBasket["MODULE"], $arBasket["PRODUCT_ID"], $arBasket["QUANTITY"]);
                     }
                 }
                 if (!empty($arFields) && is_array($arFields)) {
                     $arFields["CAN_BUY"] = "Y";
                     $arFields["ORDER_ID"] = $orderID;
                     $arBasket['CUSTOM_PRICE'] = (string) $arBasket['CUSTOM_PRICE'];
                     if ($arBasket['CUSTOM_PRICE'] == 'Y') {
                         if (array_key_exists('PRICE', $arFields)) {
                             unset($arFields['PRICE']);
                         }
                         if (array_key_exists('DISCOUNT_PRICE', $arFields)) {
                             unset($arFields['DISCOUNT_PRICE']);
                         }
                         if (array_key_exists('CURRENCY', $arFields)) {
                             unset($arFields['CURRENCY']);
                         }
                         if (array_key_exists('DISCOUNT_VALUE', $arFields)) {
                             unset($arFields['DISCOUNT_VALUE']);
                         }
                         if (array_key_exists('DISCOUNT_NAME', $arFields)) {
                             unset($arFields['DISCOUNT_NAME']);
                         }
                         if (array_key_exists('DISCOUNT_COUPON', $arFields)) {
                             unset($arFields['DISCOUNT_COUPON']);
                         }
                         if (array_key_exists('DISCOUNT_LIST', $arFields)) {
                             unset($arFields['DISCOUNT_LIST']);
                         }
                         if (array_key_exists('DISCOUNT', $arFields)) {
                             unset($arFields['DISCOUNT']);
                         }
                     }
                     $needSaveCoupons = true;
                 } else {
                     $arFields = array('CAN_BUY' => 'N');
                     $removeCoupon = DiscountCouponsManager::deleteApplyByProduct(array('MODULE' => $arBasket['MODULE'], 'PRODUCT_ID' => $arBasket['PRODUCT_ID'], 'BASKET_ID' => $arBasket['ID']));
                 }
             } else {
                 $arFields["ORDER_ID"] = $orderID;
                 $needSaveCoupons = true;
             }
             if (!empty($arFields)) {
                 if ($isOrderConverted == 'Y') {
                     if (!\Bitrix\Sale\Compatible\DiscountCompatibility::isInited()) {
                         \Bitrix\Sale\Compatible\DiscountCompatibility::init();
                     }
                     if (\Bitrix\Sale\Compatible\DiscountCompatibility::usedByClient()) {
                         \Bitrix\Sale\Compatible\DiscountCompatibility::setRepeatSave(true);
                     }
                 }
                 if (CSaleBasket::Update($arBasket["ID"], $arFields)) {
                     $_SESSION["SALE_BASKET_NUM_PRODUCTS"][SITE_ID]--;
                 }
             }
         }
     }
     //end of while
     if ($isOrderConverted == 'Y') {
         if (!\Bitrix\Sale\Compatible\DiscountCompatibility::isInited()) {
             \Bitrix\Sale\Compatible\DiscountCompatibility::init();
         }
         if (\Bitrix\Sale\Compatible\DiscountCompatibility::usedByClient()) {
             \Bitrix\Sale\Compatible\DiscountCompatibility::setRepeatSave(false);
         }
     }
     if ($_SESSION["SALE_BASKET_NUM_PRODUCTS"][SITE_ID] < 0) {
         $_SESSION["SALE_BASKET_NUM_PRODUCTS"][SITE_ID] = 0;
     }
     foreach (GetModuleEvents("sale", "OnBasketOrder", true) as $arEvent) {
         ExecuteModuleEventEx($arEvent, array($orderID, $fuserID, $strLang, $arDiscounts));
     }
     if ($needSaveCoupons) {
         DiscountCouponsManager::finalApply();
         DiscountCouponsManager::saveApplied();
     }
     //reservation
     if ($arOrder['RESERVED'] != "Y" && COption::GetOptionString("sale", "product_reserve_condition") == "O") {
         if (!CSaleOrder::ReserveOrder($orderID, "Y")) {
             return false;
         }
     }
     return true;
 }