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"]); } } $result["TEXT"] = $calcResult->isSuccess() ? $calcResult->getDescription() : implode("<br>\n", $calcResult->getErrorMessages()); if ($calcResult->isNextStep()) { $result["RESULT"] = "NEXT_STEP"; } if ($calcResult->isSuccess() && strlen($calcResult->getDescription()) > 0) { $result["RESULT"] = "NOTE"; } if (intval($calcResult->getPacksCount()) > 0) { $result["PACKS_COUNT"] = $calcResult->getPacksCount(); }
public function getBasketItems() { global $APPLICATION; if (self::$catalogIncluded === null) { self::$catalogIncluded = Loader::includeModule('catalog'); } self::$iblockIncluded = self::$catalogIncluded; CSaleBasket::UpdateBasketPrices(CSaleBasket::GetBasketUserID(), SITE_ID); $bShowReady = false; $bShowDelay = false; $bShowSubscribe = false; $bShowNotAvail = false; $allSum = 0; $allWeight = 0; $allCurrency = CSaleLang::GetLangCurrency(SITE_ID); $allVATSum = 0; $arParents = array(); $arResult["ITEMS"]["AnDelCanBuy"] = array(); $arResult["ITEMS"]["DelDelCanBuy"] = array(); $arResult["ITEMS"]["nAnCanBuy"] = array(); $arResult["ITEMS"]["ProdSubscribe"] = array(); $DISCOUNT_PRICE_ALL = 0; // BASKET PRODUCTS (including measures, ratio, iblock properties data) $arImgFields = array("PREVIEW_PICTURE", "DETAIL_PICTURE"); $arBasketItems = array(); $basketKey = 0; $basketIds = array(); $arSku2Parent = array(); $arSetParentWeight = array(); $arElementId = array(); $dbItems = CSaleBasket::GetList(array("ID" => "ASC"), array("FUSER_ID" => CSaleBasket::GetBasketUserID(), "LID" => SITE_ID, "ORDER_ID" => "NULL"), false, false, array("ID", "NAME", "CALLBACK_FUNC", "MODULE", "PRODUCT_ID", "QUANTITY", "DELAY", "CAN_BUY", "PRICE", "WEIGHT", "DETAIL_PAGE_URL", "NOTES", "CURRENCY", "VAT_RATE", "CATALOG_XML_ID", "PRODUCT_XML_ID", "SUBSCRIBE", "DISCOUNT_PRICE", "PRODUCT_PROVIDER_CLASS", "TYPE", "SET_PARENT_ID")); while ($arItem = $dbItems->GetNext()) { $arItem['PROPS'] = array(); $arBasketItems[$basketKey] = $arItem; $basketIds[$arItem['ID']] =& $arBasketItems[$basketKey]; $basketKey++; if (CSaleBasketHelper::isSetItem($arItem)) { continue; } $arElementId[] = $arItem["PRODUCT_ID"]; } if (!empty($arElementId) && self::$catalogIncluded) { $productList = CCatalogSKU::getProductList($arElementId); if (!empty($productList)) { foreach ($productList as $offerId => $offerInfo) { $offerInfo['PRODUCT_ID'] = $offerInfo['ID']; $arElementId[] = $offerInfo['ID']; $arSku2Parent[$offerId] = $offerInfo['ID']; $arParents[$offerId] = $offerInfo; } unset($offerInfo, $offerId); } unset($productList); // get measures, ratio, sku props data and available quantity $arBasketItems = getMeasures($arBasketItems); $arBasketItems = getRatio($arBasketItems); $arBasketItems = $this->getAvailableQuantity($arBasketItems); $propsIterator = CSaleBasket::GetPropsList(array('BASKET_ID' => 'ASC', 'SORT' => 'ASC', 'ID' => 'ASC'), array('BASKET_ID' => array_keys($basketIds))); while ($property = $propsIterator->GetNext()) { $property['CODE'] = (string) $property['CODE']; if ($property['CODE'] == 'CATALOG.XML_ID' || $property['CODE'] == 'PRODUCT.XML_ID') { continue; } if (!isset($basketIds[$property['BASKET_ID']])) { continue; } $basketIds[$property['BASKET_ID']]['PROPS'][] = $property; } unset($property, $propsIterator, $basketIds); } // get product properties data $arProductData = getProductProps($arElementId, array_merge(array("ID"), $arImgFields, $this->arCustomSelectFields)); foreach ($arBasketItems as &$arItem) { $quantityIsFloat = false; if (number_format(doubleval($arItem['QUANTITY']), 2, '.', '') != intval($arItem['QUANTITY'])) { $quantityIsFloat = true; } $arItem["QUANTITY"] = $quantityIsFloat === false && $this->quantityFloat != "Y" ? intval($arItem['QUANTITY']) : number_format(doubleval($arItem['QUANTITY']), 2, '.', ''); $arItem["PRICE_VAT_VALUE"] = $arItem["PRICE"] / ($arItem["VAT_RATE"] + 1) * $arItem["VAT_RATE"]; $arItem["PRICE_FORMATED"] = CCurrencyLang::CurrencyFormat($arItem["PRICE"], $arItem["CURRENCY"], true); $arItem["WEIGHT"] = doubleval($arItem["WEIGHT"]); $arItem["WEIGHT_FORMATED"] = roundEx(doubleval($arItem["WEIGHT"] / $this->weightKoef), SALE_WEIGHT_PRECISION) . " " . $this->weightUnit; if (CSaleBasketHelper::isSetItem($arItem)) { $arSetParentWeight[$arItem["SET_PARENT_ID"]] += $arItem["WEIGHT"] * $arItem["QUANTITY"]; } if (isset($arProductData[$arItem['PRODUCT_ID']]) && is_array($arProductData[$arItem['PRODUCT_ID']])) { foreach ($arProductData[$arItem["PRODUCT_ID"]] as $key => $value) { if (strpos($key, "PROPERTY_") !== false || in_array($key, $arImgFields)) { $arItem[$key] = $value; } } } if (array_key_exists($arItem["PRODUCT_ID"], $arSku2Parent)) { $arFieldsToFill = array_merge($this->arCustomSelectFields, $arImgFields); // fields to be filled with parents' values if empty foreach ($arFieldsToFill as $field) { $fieldVal = in_array($field, $arImgFields) ? $field : $field . "_VALUE"; $parentId = $arSku2Parent[$arItem["PRODUCT_ID"]]; if ((!isset($arItem[$fieldVal]) || isset($arItem[$fieldVal]) && strlen($arItem[$fieldVal]) == 0) && (isset($arProductData[$parentId][$fieldVal]) && !empty($arProductData[$parentId][$fieldVal]))) { $arItem[$fieldVal] = $arProductData[$parentId][$fieldVal]; } } } foreach ($arItem as $key => $value) { if (strpos($key, "PROPERTY_", 0) === 0 && strrpos($key, "_VALUE") == strlen($key) - 6) { $code = str_replace(array("PROPERTY_", "_VALUE"), "", $key); $propData = $this->arIblockProps[$code]; $arItem[$key] = CSaleHelper::getIblockPropInfo($value, $propData); } } $arItem["PREVIEW_PICTURE_SRC"] = ""; if (isset($arItem["PREVIEW_PICTURE"]) && intval($arItem["PREVIEW_PICTURE"]) > 0) { $arImage = CFile::GetFileArray($arItem["PREVIEW_PICTURE"]); if ($arImage) { $arFileTmp = CFile::ResizeImageGet($arImage, array("width" => "110", "height" => "110"), BX_RESIZE_IMAGE_PROPORTIONAL, true); $arItem["PREVIEW_PICTURE_SRC"] = $arFileTmp["src"]; } } $arItem["DETAIL_PICTURE_SRC"] = ""; if (isset($arItem["DETAIL_PICTURE"]) && intval($arItem["DETAIL_PICTURE"]) > 0) { $arImage = CFile::GetFileArray($arItem["DETAIL_PICTURE"]); if ($arImage) { $arFileTmp = CFile::ResizeImageGet($arImage, array("width" => "110", "height" => "110"), BX_RESIZE_IMAGE_PROPORTIONAL, true); $arItem["DETAIL_PICTURE_SRC"] = $arFileTmp["src"]; } } } unset($arItem); // get sku props data if (!empty($arBasketItems) && self::$catalogIncluded && isset($this->offersProps) && !empty($this->offersProps)) { $arBasketItems = $this->getSkuPropsData($arBasketItems, $arParents, $this->offersProps); } // count weight for set parent products foreach ($arBasketItems as &$arItem) { if (CSaleBasketHelper::isSetParent($arItem)) { $arItem["WEIGHT"] = $arSetParentWeight[$arItem["ID"]] / $arItem["QUANTITY"]; $arItem["WEIGHT_FORMATED"] = roundEx(doubleval($arItem["WEIGHT"] / $this->weightKoef), SALE_WEIGHT_PRECISION) . " " . $this->weightUnit; } } if (isset($arItem)) { unset($arItem); } // fill item arrays for old templates foreach ($arBasketItems as &$arItem) { if (CSaleBasketHelper::isSetItem($arItem)) { continue; } $arItem['DISCOUNT_PRICE'] = (double) $arItem['DISCOUNT_PRICE']; $arItem['PRICE'] = (double) $arItem['PRICE']; $arItem['DISCOUNT_PRICE_PERCENT'] = 0; $arItem['DISCOUNT_PRICE_PERCENT_FORMATED'] = ''; $arItem['FULL_PRICE'] = $arItem['PRICE']; if ($arItem['DISCOUNT_PRICE'] > 0) { if ($arItem['DISCOUNT_PRICE'] + $arItem['PRICE'] > 0) { $arItem['DISCOUNT_PRICE_PERCENT'] = $arItem['DISCOUNT_PRICE'] * 100 / ($arItem['DISCOUNT_PRICE'] + $arItem['PRICE']); $arItem['DISCOUNT_PRICE_PERCENT_FORMATED'] = roundEx($arItem['DISCOUNT_PRICE_PERCENT'], SALE_VALUE_PRECISION) . '%'; $arItem['FULL_PRICE'] = $arItem["PRICE"] + $arItem["DISCOUNT_PRICE"]; } } $arItem['FULL_PRICE_FORMATED'] = CCurrencyLang::CurrencyFormat($arItem['FULL_PRICE'], $arItem['CURRENCY'], true); if ($arItem["CAN_BUY"] == "Y" && $arItem["DELAY"] == "N") { $allSum += $arItem["PRICE"] * $arItem["QUANTITY"]; $allWeight += $arItem["WEIGHT"] * $arItem["QUANTITY"]; $allVATSum += roundEx($arItem["PRICE_VAT_VALUE"] * $arItem["QUANTITY"], SALE_VALUE_PRECISION); $bShowReady = true; if ($arItem["DISCOUNT_PRICE"] > 0) { $DISCOUNT_PRICE_ALL += $arItem["DISCOUNT_PRICE"] * $arItem["QUANTITY"]; } $arResult["ITEMS"]["AnDelCanBuy"][] = $arItem; } elseif ($arItem["CAN_BUY"] == "Y" && $arItem["DELAY"] == "Y") { $bShowDelay = true; $arResult["ITEMS"]["DelDelCanBuy"][] = $arItem; } elseif ($arItem["CAN_BUY"] == "N" && $arItem["SUBSCRIBE"] == "Y") { $bShowSubscribe = true; $arResult["ITEMS"]["ProdSubscribe"][] = $arItem; } else { $bShowNotAvail = true; $arItem["NOT_AVAILABLE"] = true; $arResult["ITEMS"]["nAnCanBuy"][] = $arItem; } } unset($arItem); $arResult["ShowReady"] = $bShowReady ? "Y" : "N"; $arResult["ShowDelay"] = $bShowDelay ? "Y" : "N"; $arResult["ShowNotAvail"] = $bShowNotAvail ? "Y" : "N"; $arResult["ShowSubscribe"] = $bShowSubscribe ? "Y" : "N"; $arOrder = array('SITE_ID' => SITE_ID, 'USER_ID' => $GLOBALS["USER"]->GetID(), 'ORDER_PRICE' => $allSum, 'ORDER_WEIGHT' => $allWeight, 'BASKET_ITEMS' => $arResult["ITEMS"]["AnDelCanBuy"]); $arOptions = array('COUNT_DISCOUNT_4_ALL_QUANTITY' => $this->countDiscount4AllQuantity); $arErrors = array(); CSaleDiscount::DoProcessOrder($arOrder, $arOptions, $arErrors); if (isset($arOrder['ORDER_PRICE'])) { $roundOrderFields = CSaleOrder::getRoundFields(); foreach ($arOrder as $fieldName => $fieldValue) { if (in_array($fieldName, $roundOrderFields)) { $arOrder[$fieldName] = roundEx($arOrder[$fieldName], SALE_VALUE_PRECISION); } } } if (!empty($arOrder['BASKET_ITEMS']) && is_array($arOrder['BASKET_ITEMS'])) { $arOrder['ORDER_PRICE'] = 0; $roundBasketFields = CSaleBasket::getRoundFields(); foreach ($arOrder['BASKET_ITEMS'] as &$basketItem) { foreach ($basketItem as $fieldName => $fieldValue) { if (in_array($fieldName, $roundBasketFields)) { if (isset($basketItem[$fieldName])) { $basketItem[$fieldName] = roundEx($basketItem[$fieldName], SALE_VALUE_PRECISION); } } } $arOrder['ORDER_PRICE'] += $basketItem['PRICE'] * $basketItem['QUANTITY']; } $arOrder['ORDER_PRICE'] = roundEx($arOrder['ORDER_PRICE'], SALE_VALUE_PRECISION); } $allSum = 0; $allWeight = 0; $allVATSum = 0; $DISCOUNT_PRICE_ALL = 0; $priceWithoutDiscount = 0; foreach ($arOrder["BASKET_ITEMS"] as &$arOneItem) { $allWeight += $arOneItem["WEIGHT"] * $arOneItem["QUANTITY"]; $allSum += $arOneItem["PRICE"] * $arOneItem["QUANTITY"]; if (array_key_exists('VAT_VALUE', $arOneItem)) { $arOneItem["PRICE_VAT_VALUE"] = $arOneItem["VAT_VALUE"]; } $allVATSum += roundEx($arOneItem["PRICE_VAT_VALUE"] * $arOneItem["QUANTITY"], SALE_VALUE_PRECISION); $arOneItem["PRICE_FORMATED"] = CCurrencyLang::CurrencyFormat($arOneItem["PRICE"], $arOneItem["CURRENCY"], true); $arOneItem["FULL_PRICE"] = $arOneItem["PRICE"] + $arOneItem["DISCOUNT_PRICE"]; $arOneItem["FULL_PRICE_FORMATED"] = CCurrencyLang::CurrencyFormat($arOneItem["FULL_PRICE"], $arOneItem["CURRENCY"], true); $arOneItem["SUM"] = CCurrencyLang::CurrencyFormat($arOneItem["PRICE"] * $arOneItem["QUANTITY"], $arOneItem["CURRENCY"], true); if (0 < doubleval($arOneItem["DISCOUNT_PRICE"] + $arOneItem["PRICE"])) { $arOneItem["DISCOUNT_PRICE_PERCENT"] = $arOneItem["DISCOUNT_PRICE"] * 100 / ($arOneItem["DISCOUNT_PRICE"] + $arOneItem["PRICE"]); } else { $arOneItem["DISCOUNT_PRICE_PERCENT"] = 0; } $arOneItem["DISCOUNT_PRICE_PERCENT_FORMATED"] = roundEx($arOneItem["DISCOUNT_PRICE_PERCENT"], SALE_VALUE_PRECISION) . "%"; $DISCOUNT_PRICE_ALL += $arOneItem["DISCOUNT_PRICE"] * $arOneItem["QUANTITY"]; } unset($arOneItem); $arResult["ITEMS"]["AnDelCanBuy"] = $arOrder["BASKET_ITEMS"]; // fill grid data (for new templates with custom columns) foreach ($arResult["ITEMS"] as $type => $arItems) { foreach ($arItems as $k => $arItem) { $arResult["GRID"]["ROWS"][$arItem["ID"]] = $arItem; } } $arResult["allSum"] = roundEx($allSum, SALE_VALUE_PRECISION); $arResult["allWeight"] = $allWeight; $arResult["allWeight_FORMATED"] = roundEx(doubleval($allWeight / $this->weightKoef), SALE_WEIGHT_PRECISION) . " " . $this->weightUnit; $arResult["allSum_FORMATED"] = CCurrencyLang::CurrencyFormat($allSum, $allCurrency, true); $arResult["DISCOUNT_PRICE_FORMATED"] = CCurrencyLang::CurrencyFormat($arResult["DISCOUNT_PRICE"], $allCurrency, true); $arResult["PRICE_WITHOUT_DISCOUNT"] = CCurrencyLang::CurrencyFormat($allSum + $DISCOUNT_PRICE_ALL, $allCurrency, true); if ($this->priceVatShowValue == 'Y') { $arResult["allVATSum"] = roundEx($allVATSum, SALE_VALUE_PRECISION); $arResult["allVATSum_FORMATED"] = CCurrencyLang::CurrencyFormat($allVATSum, $allCurrency, true); $arResult["allSum_wVAT_FORMATED"] = CCurrencyLang::CurrencyFormat(doubleval($arResult["allSum"] - $allVATSum), $allCurrency, true); } $arResult['COUPON_LIST'] = array(); $arResult['COUPON'] = ''; if ($this->hideCoupon != "Y") { $arCoupons = DiscountCouponsManager::get(true, array(), true, true); if (!empty($arCoupons)) { foreach ($arCoupons as &$oneCoupon) { if ($arResult['COUPON'] == '') { $arResult['COUPON'] = $oneCoupon['COUPON']; } if ($oneCoupon['STATUS'] == DiscountCouponsManager::STATUS_NOT_FOUND || $oneCoupon['STATUS'] == DiscountCouponsManager::STATUS_FREEZE) { $oneCoupon['JS_STATUS'] = 'BAD'; } elseif ($oneCoupon['STATUS'] == DiscountCouponsManager::STATUS_NOT_APPLYED || $oneCoupon['STATUS'] == DiscountCouponsManager::STATUS_ENTERED) { $oneCoupon['JS_STATUS'] = 'ENTERED'; } else { $oneCoupon['JS_STATUS'] = 'APPLYED'; } $oneCoupon['JS_CHECK_CODE'] = ''; if (isset($oneCoupon['CHECK_CODE_TEXT'])) { $oneCoupon['JS_CHECK_CODE'] = is_array($oneCoupon['CHECK_CODE_TEXT']) ? implode('<br>', $oneCoupon['CHECK_CODE_TEXT']) : $oneCoupon['CHECK_CODE_TEXT']; } $arResult['COUPON_LIST'][] = $oneCoupon; } unset($oneCoupon); $arResult['COUPON_LIST'] = array_values($arCoupons); } unset($arCoupons); } if (empty($arBasketItems)) { $arResult["ERROR_MESSAGE"] = Loc::getMessage("SALE_EMPTY_BASKET"); } $arResult["DISCOUNT_PRICE_ALL"] = $DISCOUNT_PRICE_ALL; $arResult["DISCOUNT_PRICE_ALL_FORMATED"] = CCurrencyLang::CurrencyFormat($DISCOUNT_PRICE_ALL, $allCurrency, true); if ($this->usePrepayment == "Y") { if (doubleval($arResult["allSum"]) > 0) { $personType = array(); $dbPersonType = CSalePersonType::GetList(array("SORT" => "ASC", "NAME" => "ASC"), array("LID" => SITE_ID, "ACTIVE" => "Y")); while ($arPersonType = $dbPersonType->Fetch()) { $personType[] = $arPersonType["ID"]; } if (!empty($personType)) { $dbPaySysAction = CSalePaySystemAction::GetList(array(), array("PS_ACTIVE" => "Y", "HAVE_PREPAY" => "Y", "PERSON_TYPE_ID" => $personType), false, false, array("ID", "PAY_SYSTEM_ID", "PERSON_TYPE_ID", "NAME", "ACTION_FILE", "RESULT_FILE", "NEW_WINDOW", "PARAMS", "ENCODING", "LOGOTIP")); if ($arPaySysAction = $dbPaySysAction->Fetch()) { CSalePaySystemAction::InitParamarrays(false, false, $arPaySysAction["PARAMS"]); $pathToAction = $_SERVER["DOCUMENT_ROOT"] . $arPaySysAction["ACTION_FILE"]; $pathToAction = str_replace("\\", "/", $pathToAction); while (substr($pathToAction, strlen($pathToAction) - 1, 1) == "/") { $pathToAction = substr($pathToAction, 0, strlen($pathToAction) - 1); } if (file_exists($pathToAction)) { if (is_dir($pathToAction) && file_exists($pathToAction . "/pre_payment.php")) { $pathToAction .= "/pre_payment.php"; } try { include_once $pathToAction; } catch (\Bitrix\Main\SystemException $e) { if ($e->getCode() == CSalePaySystemAction::GET_PARAM_VALUE) { $message = Loc::getMessage("SOA_TEMPL_ORDER_PS_ERROR"); } else { $message = $e->getMessage(); } $arResult["ERROR_MESSAGE"] = $message; } $psPreAction = new CSalePaySystemPrePayment(); if ($psPreAction->init()) { $orderData = array("PATH_TO_ORDER" => $this->pathToOrder, "AMOUNT" => $arResult["allSum"], "BASKET_ITEMS" => $arResult["ITEMS"]["AnDelCanBuy"]); if (!$psPreAction->BasketButtonAction($orderData)) { if ($e = $APPLICATION->GetException()) { $arResult["WARNING_MESSAGE"][] = $e->GetString(); } } $arResult["PREPAY_BUTTON"] = $psPreAction->BasketButtonShow(); } } } } } } return $arResult; }
static function DoCalculateOrder($siteId, $userId, $arShoppingCart, $personTypeId, $arOrderPropsValues, $deliveryId, $paySystemId, $arOptions, &$arErrors, &$arWarnings) { $siteId = trim($siteId); if (empty($siteId)) { $arErrors[] = array("CODE" => "PARAM", "TEXT" => GetMessage('SKGO_CALC_PARAM_ERROR')); return null; } $userId = intval($userId); if (!is_array($arShoppingCart) || count($arShoppingCart) <= 0) { $arErrors[] = array("CODE" => "PARAM", "TEXT" => GetMessage('SKGO_SHOPPING_CART_EMPTY')); return null; } $arOrder = array("ORDER_PRICE" => 0, "ORDER_WEIGHT" => 0, "CURRENCY" => CSaleLang::GetLangCurrency($siteId), "WEIGHT_UNIT" => htmlspecialcharsbx(COption::GetOptionString('sale', 'weight_unit', false, $siteId)), "WEIGHT_KOEF" => htmlspecialcharsbx(COption::GetOptionString('sale', 'weight_koef', 1, $siteId)), "BASKET_ITEMS" => $arShoppingCart, "SITE_ID" => $siteId, "LID" => $siteId, "USER_ID" => $userId, "USE_VAT" => false, "VAT_RATE" => 0, "VAT_SUM" => 0, "DELIVERY_ID" => false); foreach ($arShoppingCart as $arShoppingCartItem) { if (array_key_exists('CUSTOM_PRICE', $arShoppingCartItem) && 'Y' == $arShoppingCartItem['CUSTOM_PRICE']) { $arShoppingCartItem['DISCOUNT_PRICE'] = $arShoppingCartItem['DEFAULT_PRICE'] - $arShoppingCartItem['PRICE']; if (0 > $arShoppingCartItem['DISCOUNT_PRICE']) { $arShoppingCartItem['DISCOUNT_PRICE'] = 0; } $arShoppingCartItem['DISCOUNT_PRICE_PERCENT'] = $arShoppingCartItem['DISCOUNT_PRICE'] * 100 / $arShoppingCartItem['DEFAULT_PRICE']; if ($arShoppingCartItem["VAT_RATE"] > 0) { $arShoppingCartItem["VAT_VALUE"] = $arShoppingCartItem["PRICE"] / ($arShoppingCartItem["VAT_RATE"] + 1) * $arShoppingCartItem["VAT_RATE"]; } } $arOrder["ORDER_PRICE"] += $arShoppingCartItem["PRICE"] * $arShoppingCartItem["QUANTITY"]; $arOrder["ORDER_WEIGHT"] += $arShoppingCartItem["WEIGHT"] * $arShoppingCartItem["QUANTITY"]; if ($arShoppingCartItem["VAT_RATE"] > 0) { $arOrder["USE_VAT"] = true; if ($arShoppingCartItem["VAT_RATE"] > $arOrder["VAT_RATE"]) { $arOrder["VAT_RATE"] = $arShoppingCartItem["VAT_RATE"]; } $arOrder["VAT_SUM"] += $arShoppingCartItem["VAT_VALUE"] * $arShoppingCartItem["QUANTITY"]; } } foreach (GetModuleEvents("sale", "OnSaleCalculateOrderShoppingCart", true) as $arEvent) { ExecuteModuleEventEx($arEvent, array(&$arOrder)); } CSalePersonType::DoProcessOrder($arOrder, $personTypeId, $arErrors); if (count($arErrors) > 0) { return null; } foreach (GetModuleEvents("sale", "OnSaleCalculateOrderPersonType", true) as $arEvent) { ExecuteModuleEventEx($arEvent, array(&$arOrder)); } CSaleOrderProps::DoProcessOrder($arOrder, $arOrderPropsValues, $arErrors, $arWarnings); if (count($arErrors) > 0) { return null; } foreach (GetModuleEvents("sale", "OnSaleCalculateOrderProps", true) as $arEvent) { ExecuteModuleEventEx($arEvent, array(&$arOrder)); } CSaleDelivery::DoProcessOrder($arOrder, $deliveryId, $arErrors); if (count($arErrors) > 0) { return null; } $arOrder["PRICE_DELIVERY"] = $arOrder["DELIVERY_PRICE"]; foreach (GetModuleEvents("sale", "OnSaleCalculateOrderDelivery", true) as $arEvent) { ExecuteModuleEventEx($arEvent, array(&$arOrder)); } CSalePaySystem::DoProcessOrder($arOrder, $paySystemId, $arErrors); if (count($arErrors) > 0) { return null; } foreach (GetModuleEvents("sale", "OnSaleCalculateOrderPaySystem", true) as $arEvent) { ExecuteModuleEventEx($arEvent, array(&$arOrder)); } if (!array_key_exists('CART_FIX', $arOptions) || 'Y' != $arOptions['CART_FIX']) { CSaleDiscount::DoProcessOrder($arOrder, $arOptions, $arErrors); if (count($arErrors) > 0) { return null; } foreach (GetModuleEvents("sale", "OnSaleCalculateOrderDiscount", true) as $arEvent) { ExecuteModuleEventEx($arEvent, array(&$arOrder)); } } CSaleTax::DoProcessOrderBasket($arOrder, $arOptions, $arErrors); if (count($arErrors) > 0) { return null; } foreach (GetModuleEvents("sale", "OnSaleCalculateOrderShoppingCartTax", true) as $arEvent) { ExecuteModuleEventEx($arEvent, array(&$arOrder)); } CSaleTax::DoProcessOrderDelivery($arOrder, $arOptions, $arErrors); if (count($arErrors) > 0) { return null; } foreach (GetModuleEvents("sale", "OnSaleCalculateOrderDeliveryTax", true) as $arEvent) { ExecuteModuleEventEx($arEvent, array(&$arOrder)); } $arOrder["PRICE"] = $arOrder["ORDER_PRICE"] + $arOrder["DELIVERY_PRICE"] + $arOrder["TAX_PRICE"] - $arOrder["DISCOUNT_PRICE"]; $arOrder["TAX_VALUE"] = $arOrder["USE_VAT"] ? $arOrder["VAT_SUM"] : $arOrder["TAX_PRICE"]; foreach (GetModuleEvents("sale", "OnSaleCalculateOrder", true) as $arEvent) { ExecuteModuleEventEx($arEvent, array(&$arOrder)); } return $arOrder; }
} $bNotAvail = true; } elseif ($arItem["CAN_BUY"] == "N" && $arItem["SUBSCRIBE"] == "Y") { if ('N' == $arParams['SHOW_SUBSCRIBE']) { continue; } $bSubscribe = true; } if (!$boolOneReady) { $arItem["PRICE_FORMATED"] = SaleFormatCurrency($arItem["PRICE"], $arItem["CURRENCY"]); $arItems[] = $arItem; } else { $arReadyItems[] = $arItem; } } } if (!empty($arReadyItems)) { $arOrder = array('SITE_ID' => SITE_ID, 'USER_ID' => $USER->GetID(), 'ORDER_PRICE' => $allSum, 'ORDER_WEIGHT' => $allWeight, 'BASKET_ITEMS' => $arReadyItems); $arOptions = array(); $arErrors = array(); CSaleDiscount::DoProcessOrder($arOrder, $arOptions, $arErrors); foreach ($arOrder['BASKET_ITEMS'] as &$arOneItem) { $arOneItem["PRICE_FORMATED"] = SaleFormatCurrency($arOneItem["PRICE"], $arOneItem["CURRENCY"]); } if (isset($arOneItem)) { unset($arOneItem); } $arItems = array_merge($arOrder['BASKET_ITEMS'], $arItems); } $arResult = array('READY' => $bReady ? "Y" : "N", 'DELAY' => $bDelay ? "Y" : "N", 'NOTAVAIL' => $bNotAvail ? "Y" : "N", 'SUBSCRIBE' => $bSubscribe ? "Y" : "N", 'ITEMS' => $arItems); $this->IncludeComponentTemplate();
/** * событие вызывается перед отправкой письма о новом заказе * @param $orderID * @param $eventName * @param $arFields */ function bxModifySaleMails($order_id, &$eventName, &$arFieldsEmail) { //unset($_SESSION['OnBeforeOrderAddHandler']); //$_SESSION['OnBeforeOrderAddHandler']['bxModifySaleMails']='bxModifySaleMails'; //$_SESSION['OnBeforeOrderAddHandler']['id']=$order_id; //$_SESSION['OnBeforeOrderAddHandler']['arFields']=$arFieldsorder_old; $basket_props=""; $post['INFO']=""; $id_product=array(); if( (CModule::IncludeModule("main")) && (CModule::IncludeModule("iblock")) && (CModule::IncludeModule("catalog")) && (CModule::IncludeModule("sale")) ){ /** * получаем параметры сформировавшегося старого заказа */ $arFieldsorder_old = CSaleOrder::GetByID($order_id); /* echo "<pre>"; var_dump($arFieldsorder_old);die(); echo "</pre>";*/ /** * выборка свойства сформировавшегося заказа по id заказа */ $db_props = CSaleOrderPropsValue::GetOrderProps($order_id); $arFields_props = array(); while ($arProps = $db_props->Fetch()) { $arFields_props_old[$arProps['CODE']]=$arProps; } //_debug($arFields_props_old); /** * выборка из корзины по id заказа * получаем масси id продукта */ $rsUser = CUser::GetByID(CUser::GetID()); $arUser = $rsUser->Fetch(); /*if (!$ORDER_ID = CSaleOrder::Add(array( "LID" => SITE_ID, "PERSON_TYPE_ID" => 1, "PAYED" => "N", "CANCELED" => "N", "STATUS_ID" => "N", "PRICE" => 0, "CURRENCY" => CSaleLang::GetLangCurrency(SITE_ID), "USER_ID" => $arUser['ID'], "PAY_SYSTEM_ID" => $arFieldsorder_old['PAY_SYSTEM_ID'], "PRICE_DELIVERY" => 0, "DELIVERY_ID" => $arFieldsorder_old['DELIVERY_ID'], "DISCOUNT_VALUE" => $arFieldsorder_old['DISCOUNT_VALUE'], "TAX_VALUE" => $arFieldsorder_old['TAX_VALUE'], "USER_DESCRIPTION" => $post['INFO'] ))){ $rows['msg'] = 'Ошибка создания заказа'; $fail = true; }else{ $rows['msg']=$ORDER_ID; //continue; }*/ $dbBasketItems = CSaleBasket::GetList( array("ID" => "ASC"), array( "LID" => SITE_ID, "ORDER_ID" => $order_id ), false, false, array() ); while ($arItem = $dbBasketItems->Fetch()){ $id_product[] = $arItem['PRODUCT_ID']; $products_basket[$arItem['PRODUCT_ID']]=$arItem; } foreach($products_basket as $product){ $price_product+=$product['PRICE']*$product['QUANTITY']; $products_descriptions.=$product['NAME']." - ".$product['QUANTITY']." шт: ".intval($product['PRICE'])." руб <br/>"; } $price_product+=$arFieldsorder_old["PRICE_DELIVERY"]; //$_SESSION['OnBeforeOrderAddHandler']['products_basket']=$products_basket; /** * получаем массив id партнеров из продукта */ //var_dump($id_product);die(); if($id_product){ $id_partner=array(); $partner_product=array(); $arSelect = Array("ID", "NAME","IBLOCK_ID","PROPERTY_PARTNER"); $arFilter = Array("ID"=>$id_product, "ACTIVE"=>"Y"); $res = CIBlockElement::GetList(Array(), $arFilter, false, false, $arSelect); while($ob = $res->GetNextElement()) { $arFields = $ob->GetFields(); $partner_product[$arFields['PROPERTY_PARTNER_VALUE']][]=$products_basket[$arFields['ID']]; if($arFields['PROPERTY_PARTNER_VALUE']){ $id_partner[]=$arFields['PROPERTY_PARTNER_VALUE']; } } //$_SESSION['OnBeforeOrderAddHandler']['id_partner']=$id_partner; /** * получаем массив данных партнера */ if($id_partner){ $delivery_sum = null; $arSelect2 = Array("ID", "IBLOCK_ID", "NAME","PROPERTY_*"); $arFilter2 = Array("IBLOCK_ID"=>9, "ACTIVE"=>"Y","ID"=>$id_partner,); $res2 = CIBlockElement::GetList(Array(), $arFilter2, false, false, $arSelect2); /** * eсли в выборке корзине в продуктах больше чем один партнер * то разбиваем заказ по количеству партнеров */ if (intval($res2->SelectedRowsCount())>0){ while($ob2 = $res2->GetNextElement()){ $arFields_partners = $ob2->GetFields(); $arProperties_partners = $ob2->GetProperties(); //_debug($arProperties_partners); //$price_product=0; //$products_descriptions=""; $arEventFields=array(); //echo $arFields_partners['ID']; if($partner_product[$arFields_partners['ID']]){ $i=0; $size_of_productpartner=sizeof($partner_product[$arFields_partners['ID']]); foreach($partner_product[$arFields_partners['ID']] as $key_price=>$item_price){ //_debug($item_price); $quantity=1; /** * формируем новый пустой заказ */ if(!$i){ if (!$ORDER_ID = CSaleOrder::Add(array( "LID" => SITE_ID, "PERSON_TYPE_ID" => 1, "PAYED" => "N", "CANCELED" => "N", "STATUS_ID" => "N", "PRICE" => 0, "CURRENCY" => CSaleLang::GetLangCurrency(SITE_ID), "USER_ID" => $arUser['ID'], "PAY_SYSTEM_ID" => $arFieldsorder_old['PAY_SYSTEM_ID'], "PRICE_DELIVERY" => 0, "DELIVERY_ID" => $arFieldsorder_old['DELIVERY_ID'], "DISCOUNT_VALUE" => $arFieldsorder_old['DISCOUNT_VALUE'], "TAX_VALUE" => $arFieldsorder_old['TAX_VALUE'], "USER_DESCRIPTION" => $post['INFO'] ))){ $rows['msg'] = 'Ошибка создания заказа'; $fail = true; }else{ $rows['msg']=$ORDER_ID; //continue; } } /** * добавляем по id заказа в корзину товары партнера */ if (!Add2BasketByProductID($item_price['PRODUCT_ID'], $item_price['QUANTITY'], array( 'ORDER_ID' => $ORDER_ID, ), $basket_props)) { $rows['err'] = 'Ошибка добавления товара в заказ'; $fail = true; } /*$price_product+=$item_price['PRICE']*$item_price['QUANTITY']; $products_descriptions.=$item_price['NAME']." - ".$item_price['QUANTITY']." шт: ".intval($item_price['PRICE'])." руб <br/>"; */ $i++; /** * обновляем параметры нового заказа на актуальные */ if($size_of_productpartner==$i){ if (!$fail) { $dbBasketItems = CSaleBasket::GetList( array("NAME" => "ASC", "ID" => "ASC"), array( "LID" => SITE_ID, "ORDER_ID" => $ORDER_ID ), false, false, array( "ID", "NAME", "QUANTITY", "CURRENCY", "CAN_BUY", "PRICE", "WEIGHT", "DISCOUNT_PRICE" ) ); $summ = $weight = 0; $strOrderList = ""; $arBasket = array(); while ($arBasketItems = $dbBasketItems->GetNext()) { $strOrderList .= $arBasketItems["NAME"] . " - " . $arBasketItems["QUANTITY"] . " шт на " . SaleFormatCurrency($arBasketItems["PRICE"] * $arBasketItems["QUANTITY"], $arBasketItems["CURRENCY"]); $strOrderList .= "\n"; $rows['summ']=$summ += roundEx($arBasketItems["PRICE"], SALE_VALUE_PRECISION) * DoubleVal($arBasketItems["QUANTITY"]); $weight += doubleval($arBasketItems['WEIGHT']); $arBasket[] = $arBasketItems; } $arOrderForDiscount = array( 'SITE_ID' => SITE_ID, 'USER_ID' => $arUser['ID'], 'ORDER_PRICE' => $summ, 'ORDER_WEIGHT' => $weight, 'BASKET_ITEMS' => $arBasket, ); $arDiscountOptions = array(); $arDiscountErrors = array(); CSaleDiscount::DoProcessOrder($arOrderForDiscount, $arDiscountOptions, $arDiscountErrors); if($_REQUEST['comment']) $arOrderForDiscount['COMMENTS'] = $_REQUEST['comment']; if($arProperties_partners['DOSTAVKA']['VALUE']){ $arOrderForDiscount["PRICE_DELIVERY"] = $arProperties_partners['DOSTAVKA']['VALUE']; $arOrderForDiscount["DELIVERY_ID"] = 3; $summ += intval($arProperties_partners['DOSTAVKA']['VALUE']); $arOrderForDiscount['ORDER_PRICE']=$summ; } $arOrderForDiscount['PRICE_BEFORE'] = $summ; $arOrderForDiscount['PRICE'] = $summ; $arOrderForDiscount['WEIGHT'] = $arOrderForDiscount['ORDER_WEIGHT']; /** * обновляем заказ */ if (!CSaleOrder::Update($ORDER_ID, $arOrderForDiscount)) { $rows['err'] = 'Ошибка расчета цены заказа.'; $fail = true; }else{ /** * перезагружаем свойства заказ из старого */ $db_props_new = CSaleOrderPropsValue::GetOrderProps($ORDER_ID); $arFields_props_new = array(); while ($arProps_new = $db_props_new->Fetch()) { //_debug($arProps_new); foreach($arFields_props_old as $key_props_old=>$item_props_old){ if($arProps_new['CODE']==$key_props_old){ CSaleOrderPropsValue::Update($arProps_new['ID'], array("VALUE"=>$item_props_old['VALUE'])); unset($arFields_props_old[$key_props_old]); } } } if(sizeof($arFields_props_old)>0){ foreach($arFields_props_old as $key_props_old2=>$item_props_old2){ CSaleOrderPropsValue::Add(array( 'NAME' => $item_props_old2['NAME'], 'CODE' => $item_props_old2['CODE'], 'ORDER_PROPS_ID' => $item_props_old2['ORDER_PROPS_ID'], 'ORDER_ID' => $ORDER_ID, 'VALUE' => $item_props_old2['VALUE'] )); } } /** * добавляем в свойство заказа id партнера для дальнейшей фильтрации по партнерским заказам */ CSaleOrderPropsValue::Add(array( 'NAME' => "Привязка по партнеру", 'CODE' => "PATNERID", 'ORDER_PROPS_ID' => 21, 'ORDER_ID' => $ORDER_ID, 'VALUE' => $arFields_partners['ID'] )); //$price_product+=$arProperties_partners['DOSTAVKA']['VALUE']; //$price_product+=$arFieldsorder_old["PRICE_DELIVERY"]; /** * отправляем данные о товаре Партнерам */ if($arFields_partners['NAME']){ //если есть партнер у товара $arEventFields = Array( "ORDER_ID"=> $ORDER_ID, "ORDER_DATE"=> date("d.m.Y H:i:s"), "ORDER_USER"=> $arFields_partners['NAME'], "PRICE"=> $price_product, "EMAIL"=> $arProperties_partners['EMAIL']['VALUE'], "ORDER_LIST"=> $products_descriptions, //"DELIVERY_PRICE"=>$arProperties_partners['DOSTAVKA']['VALUE'] "DELIVERY_PRICE"=>$arFieldsorder_old["PRICE_DELIVERY"] ); $event = new CEvent; $event->SendImmediate("SALE_NEW_ORDERPARTNER", SITE_ID, $arEventFields); } } } // if(!$fail){ // $ar_res_product=CCatalogProduct::GetByID($PRODUCT['ID']); // $arFields_quant = array( // 'QUANTITY' => $ar_res_product['QUANTITY']-1 // ); // CCatalogProduct::Update($PRODUCT['ID'], $arFields_quant); // } } } } } /** * удаляем старый заказ после разбивки на новые */ if($ORDER_ID ){ CSaleOrder::Delete($order_id); } } } $arEventFields = Array( "ORDER_ID" =>$order_id, "ORDER_DATE" =>date("d.m.Y H:i:s"), "ORDER_USER" =>$arUser['NAME'], "PRICE" =>$price_product, "EMAIL" => $arUser['EMAIL'], "ORDER_LIST" =>$products_descriptions, "DELIVERY_PRICE"=>$arFieldsorder_old["PRICE_DELIVERY"] ); $event = new CEvent; $event->SendImmediate("SALE_NEW_BILET", SITE_ID, $arEventFields); } } //$_SESSION['OnBeforeOrderAddHandler']['rows']=$rows; return false; }
* show order props */ if (isset($display_props) and $display_props == "block") { $arParams['SHOW_BASKET_ORDER'] = "Y"; } if (isset($display_props) and $display_props == "none") { $arParams['SHOW_BASKET_ORDER'] = "N"; } $arResult["ORDER_DESCRIPTION"] = $ORDER_DESCRIPTION; if (strlen($COUPON) > 0) { $arResult["COUPON"] = htmlspecialcharsEx($COUPON); } $arOrderForDiscount = array('SITE_ID' => SITE_ID, 'USER_ID' => $currentUserId, 'ORDER_PRICE' => $arResult['ORDER_PRICE'], 'ORDER_WEIGHT' => $arResult["ORDER_WEIGHT"], 'PRICE_DELIVERY' => $arResult["DELIVERY_PRICE"], 'BASKET_ITEMS' => $arResult["ITEMS"]["AnDelCanBuy"], "PERSON_TYPE_ID" => $arUserResult['PERSON_TYPE_ID'], "PAY_SYSTEM_ID" => $arUserResult["PAY_SYSTEM_ID"], "DELIVERY_ID" => $arUserResult["DELIVERY_ID"]); $arDiscountOptions = array(); $arDiscountErrors = array(); CSaleDiscount::DoProcessOrder($arOrderForDiscount, $arDiscountOptions, $arDiscountErrors); $allSum = 0; $allVatSumm = 0; $allVatRate = 0; foreach ($arOrderForDiscount['BASKET_ITEMS'] as &$arOneItem) { $arOneItem["PRICE_FORMATED"] = SaleFormatCurrency($arOneItem["PRICE"], $arOneItem["CURRENCY"]); $arOneItem["DISCOUNT_PRICE_PERCENT"] = $arOneItem["DISCOUNT_PRICE"] * 100 / ($arOneItem["DISCOUNT_PRICE"] + $arOneItem["PRICE"]); $arOneItem["DISCOUNT_PRICE_PERCENT_FORMATED"] = roundEx($arOneItem["DISCOUNT_PRICE_PERCENT"], SALE_VALUE_PRECISION) . "%"; $allSum += $arOneItem["PRICE"] * $arOneItem["QUANTITY"]; $allVatSumm += 0; if (0 < $arOneItem["VAT_RATE"]) { $arResult["bUsingVat"] = "Y"; if ($arOneItem["VAT_RATE"] > $allVatRate) { $allVatRate = $arOneItem["VAT_RATE"]; } $arOneItem["VAT_VALUE"] = $arOneItem["PRICE"] / ($arOneItem["VAT_RATE"] + 1) * $arOneItem["VAT_RATE"];
/** * @param $siteId * @param $userId * @param $arShoppingCart * @param $personTypeId * @param $arOrderPropsValues * @param $deliveryId * @param $paySystemId * @param $arOptions * @param $arErrors * @param $arWarnings * @return array|null */ static function DoCalculateOrder($siteId, $userId, $arShoppingCart, $personTypeId, $arOrderPropsValues, $deliveryId, $paySystemId, $arOptions, &$arErrors, &$arWarnings) { if (!is_array($arOptions)) { $arOptions = array(); } $siteId = trim($siteId); if (empty($siteId)) { $arErrors[] = array("CODE" => "PARAM", "TEXT" => Loc::getMessage('SKGO_CALC_PARAM_ERROR')); return null; } $userId = intval($userId); if (!is_array($arShoppingCart) || count($arShoppingCart) <= 0) { $arErrors[] = array("CODE" => "PARAM", "TEXT" => Loc::getMessage('SKGO_SHOPPING_CART_EMPTY')); return null; } $arOrder = static::makeOrderArray($siteId, $userId, $arShoppingCart, $arOptions); foreach (GetModuleEvents("sale", "OnSaleCalculateOrderShoppingCart", true) as $arEvent) { ExecuteModuleEventEx($arEvent, array(&$arOrder)); } CSalePersonType::DoProcessOrder($arOrder, $personTypeId, $arErrors); if (count($arErrors) > 0) { return null; } foreach (GetModuleEvents("sale", "OnSaleCalculateOrderPersonType", true) as $arEvent) { ExecuteModuleEventEx($arEvent, array(&$arOrder)); } CSaleOrderProps::DoProcessOrder($arOrder, $arOrderPropsValues, $arErrors, $arWarnings, $paySystemId, $deliveryId, $arOptions); if (count($arErrors) > 0) { return null; } foreach (GetModuleEvents("sale", "OnSaleCalculateOrderProps", true) as $arEvent) { ExecuteModuleEventEx($arEvent, array(&$arOrder)); } CSaleDelivery::DoProcessOrder($arOrder, $deliveryId, $arErrors); if (count($arErrors) > 0) { return null; } $arOrder["PRICE_DELIVERY"] = $arOrder["DELIVERY_PRICE"]; foreach (GetModuleEvents("sale", "OnSaleCalculateOrderDelivery", true) as $arEvent) { ExecuteModuleEventEx($arEvent, array(&$arOrder)); } CSalePaySystem::DoProcessOrder($arOrder, $paySystemId, $arErrors); if (count($arErrors) > 0) { return null; } foreach (GetModuleEvents("sale", "OnSaleCalculateOrderPaySystem", true) as $arEvent) { ExecuteModuleEventEx($arEvent, array(&$arOrder)); } if (!array_key_exists('CART_FIX', $arOptions) || 'Y' != $arOptions['CART_FIX']) { CSaleDiscount::DoProcessOrder($arOrder, $arOptions, $arErrors); if (count($arErrors) > 0) { return null; } foreach (GetModuleEvents("sale", "OnSaleCalculateOrderDiscount", true) as $arEvent) { ExecuteModuleEventEx($arEvent, array(&$arOrder)); } if (isset($arOrder['ORDER_PRICE'])) { $roundOrderFields = static::getRoundFields(); foreach ($arOrder as $fieldName => $fieldValue) { if (in_array($fieldName, $roundOrderFields)) { $arOrder[$fieldName] = PriceMaths::roundPrecision($arOrder[$fieldName]); } } } if (!empty($arOrder['BASKET_ITEMS']) && is_array($arOrder['BASKET_ITEMS'])) { $arOrder['ORDER_PRICE'] = 0; $roundBasketFields = CSaleBasket::getRoundFields(); foreach ($arOrder['BASKET_ITEMS'] as &$basketItem) { foreach ($basketItem as $fieldName => $fieldValue) { if (in_array($fieldName, $roundBasketFields)) { if (isset($basketItem[$fieldName])) { $basketItem[$fieldName] = PriceMaths::roundPrecision($basketItem[$fieldName]); } } } if (CSaleBasketHelper::isSetItem($basketItem)) { continue; } $arOrder['ORDER_PRICE'] += CSaleBasketHelper::getFinalPrice($basketItem); } } } CSaleTax::DoProcessOrderBasket($arOrder, $arOptions, $arErrors); if (count($arErrors) > 0) { return null; } foreach (GetModuleEvents("sale", "OnSaleCalculateOrderShoppingCartTax", true) as $arEvent) { ExecuteModuleEventEx($arEvent, array(&$arOrder)); } CSaleTax::DoProcessOrderDelivery($arOrder, $arOptions, $arErrors); if (count($arErrors) > 0) { return null; } foreach (GetModuleEvents("sale", "OnSaleCalculateOrderDeliveryTax", true) as $arEvent) { ExecuteModuleEventEx($arEvent, array(&$arOrder)); } $arOrder["PRICE"] = $arOrder["ORDER_PRICE"] + $arOrder["DELIVERY_PRICE"] + $arOrder["TAX_PRICE"] - $arOrder["DISCOUNT_PRICE"]; $arOrder["TAX_VALUE"] = $arOrder["USE_VAT"] ? $arOrder["VAT_SUM"] : $arOrder["TAX_PRICE"]; foreach (GetModuleEvents("sale", "OnSaleCalculateOrder", true) as $arEvent) { ExecuteModuleEventEx($arEvent, array(&$arOrder)); } $arOrder["PRICE"] = \Bitrix\Sale\PriceMaths::roundPrecision($arOrder["PRICE"]); $arOrder["TAX_VALUE"] = \Bitrix\Sale\PriceMaths::roundPrecision($arOrder["TAX_VALUE"]); return $arOrder; }
/** * @param $siteId * @param $userId * @param $arShoppingCart * @param $personTypeId * @param $arOrderPropsValues * @param $deliveryId * @param $paySystemId * @param $arOptions * @param $arErrors * @param $arWarnings * @return array|null */ static function DoCalculateOrder($siteId, $userId, $arShoppingCart, $personTypeId, $arOrderPropsValues, $deliveryId, $paySystemId, $arOptions, &$arErrors, &$arWarnings) { if(!is_array($arOptions)) { $arOptions = array(); } $siteId = trim($siteId); if (empty($siteId)) { $arErrors[] = array("CODE" => "PARAM", "TEXT" => GetMessage('SKGO_CALC_PARAM_ERROR')); return null; } $userId = intval($userId); if (!is_array($arShoppingCart) || (count($arShoppingCart) <= 0)) { $arErrors[] = array("CODE" => "PARAM", "TEXT" => GetMessage('SKGO_SHOPPING_CART_EMPTY')); return null; } // calculate weight for set parent $arParentWeight = array(); foreach ($arShoppingCart as $arItem) { if (CSaleBasketHelper::isSetItem($arItem)) $arParentWeight[$arItem["SET_PARENT_ID"]]["WEIGHT"] += $arItem["WEIGHT"] * $arItem["QUANTITY"]; } foreach ($arShoppingCart as &$arItem) { if (CSaleBasketHelper::isSetParent($arItem) && isset($arParentWeight[$arItem["SET_PARENT_ID"]])) $arItem["WEIGHT"] = $arParentWeight[$arItem["SET_PARENT_ID"]]["WEIGHT"]; } unset($arItem); $currency = isset($arOptions['CURRENCY']) && is_string($arOptions['CURRENCY']) ? $arOptions['CURRENCY'] : ''; if($currency === '') { $currency = CSaleLang::GetLangCurrency($siteId); } $arOrder = array( "ORDER_PRICE" => 0, "ORDER_WEIGHT" => 0, "CURRENCY" => $currency, "WEIGHT_UNIT" => htmlspecialcharsbx(COption::GetOptionString('sale', 'weight_unit', false, $siteId)), "WEIGHT_KOEF" => htmlspecialcharsbx(COption::GetOptionString('sale', 'weight_koef', 1, $siteId)), "BASKET_ITEMS" => $arShoppingCart, "SITE_ID" => $siteId, "LID" => $siteId, "USER_ID" => $userId, "USE_VAT" => false, "VAT_RATE" => 0, "VAT_SUM" => 0, "DELIVERY_ID" => false, ); $arOrderPrices = CSaleOrder::CalculateOrderPrices($arShoppingCart); if (sizeof($arOrderPrices)>0 && isset($arOrderPrices['BASKET_ITEMS'])) $arShoppingCart = $arOrderPrices['BASKET_ITEMS']; $arOrder['ORDER_PRICE'] = $arOrderPrices['ORDER_PRICE']; $arOrder['ORDER_WEIGHT'] = $arOrderPrices['ORDER_WEIGHT']; $arOrder['VAT_RATE'] = $arOrderPrices['VAT_RATE']; $arOrder['VAT_SUM'] = $arOrderPrices['VAT_SUM']; $arOrder["USE_VAT"] = ($arOrderPrices['USE_VAT'] == "Y"?true:false); foreach(GetModuleEvents("sale", "OnSaleCalculateOrderShoppingCart", true) as $arEvent) ExecuteModuleEventEx($arEvent, array(&$arOrder)); CSalePersonType::DoProcessOrder($arOrder, $personTypeId, $arErrors); if (count($arErrors) > 0) return null; foreach(GetModuleEvents("sale", "OnSaleCalculateOrderPersonType", true) as $arEvent) ExecuteModuleEventEx($arEvent, array(&$arOrder)); CSaleOrderProps::DoProcessOrder($arOrder, $arOrderPropsValues, $arErrors, $arWarnings, $paySystemId, $deliveryId); if (count($arErrors) > 0) return null; foreach(GetModuleEvents("sale", "OnSaleCalculateOrderProps", true) as $arEvent) ExecuteModuleEventEx($arEvent, array(&$arOrder)); CSaleDelivery::DoProcessOrder($arOrder, $deliveryId, $arErrors); if (count($arErrors) > 0) return null; $arOrder["PRICE_DELIVERY"] = $arOrder["DELIVERY_PRICE"]; foreach(GetModuleEvents("sale", "OnSaleCalculateOrderDelivery", true) as $arEvent) ExecuteModuleEventEx($arEvent, array(&$arOrder)); CSalePaySystem::DoProcessOrder($arOrder, $paySystemId, $arErrors); if (count($arErrors) > 0) return null; foreach(GetModuleEvents("sale", "OnSaleCalculateOrderPaySystem", true) as $arEvent) ExecuteModuleEventEx($arEvent, array(&$arOrder)); if (!array_key_exists('CART_FIX', $arOptions) || 'Y' != $arOptions['CART_FIX']) { CSaleDiscount::DoProcessOrder($arOrder, $arOptions, $arErrors); if (count($arErrors) > 0) return null; foreach(GetModuleEvents("sale", "OnSaleCalculateOrderDiscount", true) as $arEvent) ExecuteModuleEventEx($arEvent, array(&$arOrder)); } CSaleTax::DoProcessOrderBasket($arOrder, $arOptions, $arErrors); if (count($arErrors) > 0) return null; foreach(GetModuleEvents("sale", "OnSaleCalculateOrderShoppingCartTax", true) as $arEvent) ExecuteModuleEventEx($arEvent, array(&$arOrder)); CSaleTax::DoProcessOrderDelivery($arOrder, $arOptions, $arErrors); if (count($arErrors) > 0) return null; foreach(GetModuleEvents("sale", "OnSaleCalculateOrderDeliveryTax", true) as $arEvent) ExecuteModuleEventEx($arEvent, array(&$arOrder)); $arOrder["PRICE"] = $arOrder["ORDER_PRICE"] + $arOrder["DELIVERY_PRICE"] + $arOrder["TAX_PRICE"] - $arOrder["DISCOUNT_PRICE"]; $arOrder["TAX_VALUE"] = ($arOrder["USE_VAT"] ? $arOrder["VAT_SUM"] : $arOrder["TAX_PRICE"]); foreach(GetModuleEvents("sale", "OnSaleCalculateOrder", true) as $arEvent) ExecuteModuleEventEx($arEvent, array(&$arOrder)); return $arOrder; }
private function calculateOrder($arBasketItems) { $totalPrice = 0; $totalWeight = 0; foreach ($arBasketItems as $arItem) { $totalPrice += $arItem["PRICE"] * $arItem["QUANTITY"]; $totalWeight += $arItem["WEIGHT"] * $arItem["QUANTITY"]; } $arOrder = array('SITE_ID' => SITE_ID, 'ORDER_PRICE' => $totalPrice, 'ORDER_WEIGHT' => $totalWeight, 'BASKET_ITEMS' => $arBasketItems); if (is_object($GLOBALS["USER"])) { $arOrder['USER_ID'] = $GLOBALS["USER"]->GetID(); $arErrors = array(); CSaleDiscount::DoProcessOrder($arOrder, array(), $arErrors); } return $arOrder; }
public function getBasketItems() { global $APPLICATION; $bUseCatalog = CModule::IncludeModule("catalog"); $bUseIblock = $bUseCatalog; $bShowReady = False; $bShowDelay = False; $bShowSubscribe = False; $bShowNotAvail = False; $allSum = 0; $allWeight = 0; $allCurrency = CSaleLang::GetLangCurrency($this->getSiteId()); $allVATSum = 0; $arParents = array(); $arResult["ITEMS"]["AnDelCanBuy"] = array(); $arResult["ITEMS"]["DelDelCanBuy"] = array(); $arResult["ITEMS"]["nAnCanBuy"] = array(); $arResult["ITEMS"]["ProdSubscribe"] = array(); $DISCOUNT_PRICE_ALL = 0; // BASKET PRODUCTS (including measures, ratio, iblock properties data) $arImgFields = array("PREVIEW_PICTURE", "DETAIL_PICTURE"); $arBasketItems = array(); $arSku2Parent = array(); $arSetParentWeight = array(); $basketItemsFilter = array("USER_ID" => $this->userId, "ORDER_ID" => "NULL"); if ($this->showDelay != 'Y') { $basketItemsFilter['DELAY'] = 'N'; } $dbItems = CSaleBasket::GetList(array("ID" => "ASC"), $basketItemsFilter, false, false, array("ID", "NAME", "CALLBACK_FUNC", "MODULE", "PRODUCT_ID", "QUANTITY", "DELAY", "CAN_BUY", "PRICE", "WEIGHT", "DETAIL_PAGE_URL", "NOTES", "CURRENCY", "VAT_RATE", "CATALOG_XML_ID", "PRODUCT_XML_ID", "SUBSCRIBE", "DISCOUNT_PRICE", "PRODUCT_PROVIDER_CLASS", "TYPE", "SET_PARENT_ID")); while ($arItem = $dbItems->GetNext()) { $arBasketItems[] = $arItem; if (CSaleBasketHelper::isSetItem($arItem)) { continue; } $arElementId[] = $arItem["PRODUCT_ID"]; if ($bUseCatalog) { $arParent = CCatalogSku::GetProductInfo($arItem["PRODUCT_ID"]); if ($arParent) { $arElementId[] = $arParent["ID"]; $arSku2Parent[$arItem["PRODUCT_ID"]] = $arParent["ID"]; $arParents[$arItem["PRODUCT_ID"]]["PRODUCT_ID"] = $arParent["ID"]; $arParents[$arItem["PRODUCT_ID"]]["IBLOCK_ID"] = $arParent["IBLOCK_ID"]; } } } // get measures, ratio, sku props data and available quantity if (!empty($arBasketItems) && $bUseCatalog) { $arBasketItems = getMeasures($arBasketItems); $arBasketItems = getRatio($arBasketItems); $arBasketItems = $this->getAvailableQuantity($arBasketItems); } // get product properties data $arProductData = getProductProps($arElementId, array_merge(array("ID"), $arImgFields, $this->arCustomSelectFields)); foreach ($arBasketItems as &$arItem) { $quantityIsFloat = false; if (number_format(doubleval($arItem['QUANTITY']), 2, '.', '') != intval($arItem['QUANTITY'])) { $quantityIsFloat = true; } $arItem["QUANTITY"] = $quantityIsFloat === false && $this->quantityFloat != "Y" ? intval($arItem['QUANTITY']) : number_format(doubleval($arItem['QUANTITY']), 2, '.', ''); $arItem["QUANTITY_FORMATED"] = $arItem["QUANTITY"] . " " . $arItem["MEASURE_TEXT"]; $arItem["PROPS"] = array(); $dbProp = CSaleBasket::GetPropsList(array("SORT" => "ASC", "ID" => "ASC"), array("BASKET_ID" => $arItem["ID"], "!CODE" => array("CATALOG.XML_ID", "PRODUCT.XML_ID"))); while ($arProp = $dbProp->GetNext()) { $arItem["PROPS"][] = $arProp; } $arItem["PRICE_VAT_VALUE"] = $arItem["PRICE"] / ($arItem["VAT_RATE"] + 1) * $arItem["VAT_RATE"]; $arItem["PRICE_FORMATED"] = $this->getSaleFormatCurrency($arItem["PRICE"], $arItem["CURRENCY"]); $arItem["WEIGHT"] = doubleval($arItem["WEIGHT"]); $arItem["WEIGHT_FORMATED"] = roundEx(doubleval($arItem["WEIGHT"] / $this->weightKoef), SALE_WEIGHT_PRECISION) . " " . $this->weightUnit; $arItem["DISCOUNT_FORMATED"] = $this->getSaleFormatCurrency($arItem["DISCOUNT_PRICE"], $arItem["CURRENCY"]); if (CSaleBasketHelper::isSetItem($arItem)) { $arSetParentWeight[$arItem["SET_PARENT_ID"]] += $arItem["WEIGHT"] * $arItem["QUANTITY"]; } if (array_key_exists($arItem["PRODUCT_ID"], $arProductData) && is_array($arProductData[$arItem["PRODUCT_ID"]])) { foreach ($arProductData[$arItem["PRODUCT_ID"]] as $key => $value) { if (strpos($key, "PROPERTY_") !== false || in_array($key, $arImgFields)) { $arItem[$key] = $value; } } } if (array_key_exists($arItem["PRODUCT_ID"], $arSku2Parent)) { $arFieldsToFill = array_merge($this->arCustomSelectFields, $arImgFields); // fields to be filled with parents' values if empty foreach ($arFieldsToFill as $field) { $fieldVal = in_array($field, $arImgFields) ? $field : $field . "_VALUE"; $parentId = $arSku2Parent[$arItem["PRODUCT_ID"]]; if ((!isset($arItem[$fieldVal]) || isset($arItem[$fieldVal]) && strlen($arItem[$fieldVal]) == 0) && (isset($arProductData[$parentId][$fieldVal]) && !empty($arProductData[$parentId][$fieldVal]))) { $arItem[$fieldVal] = $arProductData[$parentId][$fieldVal]; } } } foreach ($arItem as $key => $value) { if (strpos($key, "PROPERTY_", 0) === 0 && strrpos($key, "_VALUE") == strlen($key) - 6) { $code = str_replace(array("PROPERTY_", "_VALUE"), "", $key); $propData = $this->arIblockProps[$code]; $arItem[$key] = CSaleHelper::getIblockPropInfo($value, $propData); } } $arItem["PREVIEW_PICTURE_SRC"] = ""; if (isset($arItem["PREVIEW_PICTURE"]) && intval($arItem["PREVIEW_PICTURE"]) > 0) { $arImage = CFile::GetFileArray($arItem["PREVIEW_PICTURE"]); if ($arImage) { $arFileTmp = CFile::ResizeImageGet($arImage, array("width" => "110", "height" => "110"), BX_RESIZE_IMAGE_PROPORTIONAL, true); $arItem["PREVIEW_PICTURE_SRC"] = $arFileTmp["src"]; } } $arItem["DETAIL_PICTURE_SRC"] = ""; if (isset($arItem["DETAIL_PICTURE"]) && intval($arItem["DETAIL_PICTURE"]) > 0) { $arImage = CFile::GetFileArray($arItem["DETAIL_PICTURE"]); if ($arImage) { $arFileTmp = CFile::ResizeImageGet($arImage, array("width" => "110", "height" => "110"), BX_RESIZE_IMAGE_PROPORTIONAL, true); $arItem["DETAIL_PICTURE_SRC"] = $arFileTmp["src"]; } } } unset($arItem); // get sku props data if (!empty($arBasketItems) && $bUseCatalog && isset($this->offersProps) && !empty($this->offersProps)) { $arBasketItems = $this->getSkuPropsData($arBasketItems, $arParents, $this->offersProps); } // count weight for set parent products foreach ($arBasketItems as &$arItem) { if (CSaleBasketHelper::isSetParent($arItem)) { $arItem["WEIGHT"] = $arSetParentWeight[$arItem["ID"]] / $arItem["QUANTITY"]; $arItem["WEIGHT_FORMATED"] = roundEx(doubleval($arItem["WEIGHT"] / $this->weightKoef), SALE_WEIGHT_PRECISION) . " " . $this->weightUnit; } } if (isset($arItem)) { unset($arItem); } // fill item arrays for old templates foreach ($arBasketItems as &$arItem) { if (CSaleBasketHelper::isSetItem($arItem)) { continue; } if ($arItem["CAN_BUY"] == "Y" && $arItem["DELAY"] == "N") { $allSum += $arItem["PRICE"] * $arItem["QUANTITY"]; $allWeight += $arItem["WEIGHT"] * $arItem["QUANTITY"]; $allVATSum += roundEx($arItem["PRICE_VAT_VALUE"] * $arItem["QUANTITY"], SALE_VALUE_PRECISION); $bShowReady = True; if (doubleval($arItem["DISCOUNT_PRICE"]) > 0) { if (0 < doubleval($arItem["DISCOUNT_PRICE"] + $arItem["PRICE"])) { $arItem["DISCOUNT_PRICE_PERCENT"] = $arItem["DISCOUNT_PRICE"] * 100 / ($arItem["DISCOUNT_PRICE"] + $arItem["PRICE"]); } else { $arItem["DISCOUNT_PRICE_PERCENT"] = 0; } $arItem["DISCOUNT_PRICE_PERCENT_FORMATED"] = roundEx($arItem["DISCOUNT_PRICE_PERCENT"], SALE_VALUE_PRECISION) . "%"; $DISCOUNT_PRICE_ALL += $arItem["DISCOUNT_PRICE"] * $arItem["QUANTITY"]; } $arResult["ITEMS"]["AnDelCanBuy"][] = $arItem; } elseif ($arItem["CAN_BUY"] == "Y" && $arItem["DELAY"] == "Y") { $bShowDelay = True; $arResult["ITEMS"]["DelDelCanBuy"][] = $arItem; } elseif ($arItem["CAN_BUY"] == "N" && $arItem["SUBSCRIBE"] == "Y") { $bShowSubscribe = True; $arResult["ITEMS"]["ProdSubscribe"][] = $arItem; } else { $bShowNotAvail = True; $arItem["NOT_AVAILABLE"] = true; $arResult["ITEMS"]["nAnCanBuy"][] = $arItem; } } unset($arItem); $arResult["ShowReady"] = $bShowReady ? "Y" : "N"; $arResult["ShowDelay"] = $bShowDelay ? "Y" : "N"; $arResult["ShowNotAvail"] = $bShowNotAvail ? "Y" : "N"; $arResult["ShowSubscribe"] = $bShowSubscribe ? "Y" : "N"; $arOrder = array('SITE_ID' => $this->getSiteId(), 'USER_ID' => $this->userId, 'ORDER_PRICE' => $allSum, 'ORDER_WEIGHT' => $allWeight, 'BASKET_ITEMS' => $arResult["ITEMS"]["AnDelCanBuy"]); $arOptions = array('COUNT_DISCOUNT_4_ALL_QUANTITY' => $this->countDiscount4AllQuantity); $arErrors = array(); CSaleDiscount::DoProcessOrder($arOrder, $arOptions, $arErrors); $allSum = 0; $allWeight = 0; $allVATSum = 0; $DISCOUNT_PRICE_ALL = 0; $priceWithoutDiscount = 0; foreach ($arOrder["BASKET_ITEMS"] as &$arOneItem) { $allWeight += $arOneItem["WEIGHT"] * $arOneItem["QUANTITY"]; $allSum += $arOneItem["PRICE"] * $arOneItem["QUANTITY"]; if (array_key_exists('VAT_VALUE', $arOneItem)) { $arOneItem["PRICE_VAT_VALUE"] = $arOneItem["VAT_VALUE"]; } $allVATSum += roundEx($arOneItem["PRICE_VAT_VALUE"] * $arOneItem["QUANTITY"], SALE_VALUE_PRECISION); $arOneItem["PRICE_FORMATED"] = $this->getSaleFormatCurrency($arOneItem["PRICE"], $arOneItem["CURRENCY"]); $arOneItem["FULL_PRICE"] = $arOneItem["PRICE"] + $arOneItem["DISCOUNT_PRICE"]; $arOneItem["FULL_PRICE_FORMATED"] = $this->getSaleFormatCurrency($arOneItem["FULL_PRICE"], $arOneItem["CURRENCY"]); $arOneItem["SUM"] = $this->getSaleFormatCurrency($arOneItem["PRICE"] * $arOneItem["QUANTITY"], $arOneItem["CURRENCY"]); if (0 < doubleval($arOneItem["DISCOUNT_PRICE"] + $arOneItem["PRICE"])) { $arOneItem["DISCOUNT_PRICE_PERCENT"] = $arOneItem["DISCOUNT_PRICE"] * 100 / ($arOneItem["DISCOUNT_PRICE"] + $arOneItem["PRICE"]); } else { $arOneItem["DISCOUNT_PRICE_PERCENT"] = 0; } $arOneItem["DISCOUNT_PRICE_PERCENT_FORMATED"] = roundEx($arOneItem["DISCOUNT_PRICE_PERCENT"], SALE_VALUE_PRECISION) . "%"; $DISCOUNT_PRICE_ALL += $arOneItem["DISCOUNT_PRICE"] * $arOneItem["QUANTITY"]; } unset($arOneItem); $arResult["ITEMS"]["AnDelCanBuy"] = $arOrder["BASKET_ITEMS"]; // fill grid data (for new templates with custom columns) foreach ($arResult["ITEMS"] as $type => $arItems) { foreach ($arItems as $k => $arItem) { $arResult["GRID"]["ROWS"][$arItem["ID"]] = $arItem; } } $arResult["allSum"] = $allSum; $arResult["allWeight"] = $allWeight; $arResult["allWeight_FORMATED"] = roundEx(doubleval($allWeight / $this->weightKoef), SALE_WEIGHT_PRECISION) . " " . $this->weightUnit; $arResult["allSum_FORMATED"] = $this->getSaleFormatCurrency($allSum, $allCurrency); $arResult["DISCOUNT_PRICE_FORMATED"] = $this->getSaleFormatCurrency($arResult["DISCOUNT_PRICE"], $allCurrency); $arResult["PRICE_WITHOUT_DISCOUNT"] = $this->getSaleFormatCurrency($allSum + $DISCOUNT_PRICE_ALL, $allCurrency); if ($this->priceVatShowValue == 'Y') { $arResult["allVATSum"] = $allVATSum; $arResult["allVATSum_FORMATED"] = $this->getSaleFormatCurrency($allVATSum, $allCurrency); $arResult["allSum_wVAT_FORMATED"] = $this->getSaleFormatCurrency(doubleval($arResult["allSum"] - $allVATSum), $allCurrency); } if (!empty($arCoupons)) { $arResult["COUPON"] = htmlspecialcharsbx($arCoupons[0]); } if (count($arBasketItems) <= 0) { $arResult["ERROR_MESSAGE"] = GetMessage("SALE_EMPTY_BASKET"); } $arResult["DISCOUNT_PRICE_ALL"] = $DISCOUNT_PRICE_ALL; $arResult["DISCOUNT_PRICE_ALL_FORMATED"] = $this->getSaleFormatCurrency($DISCOUNT_PRICE_ALL, $allCurrency); return $arResult; }
public function getBasketItems() { global $APPLICATION; $bUseCatalog = CModule::IncludeModule("catalog"); $bUseIblock = $bUseCatalog; CSaleBasket::UpdateBasketPrices(CSaleBasket::GetBasketUserID(), SITE_ID); $bShowReady = False; $bShowDelay = False; $bShowSubscribe = False; $bShowNotAvail = False; $allSum = 0; $allWeight = 0; $allCurrency = CSaleLang::GetLangCurrency(SITE_ID); $allVATSum = 0; $arParents = array(); $arResult["ITEMS"]["AnDelCanBuy"] = array(); $arResult["ITEMS"]["DelDelCanBuy"] = array(); $arResult["ITEMS"]["nAnCanBuy"] = array(); $arResult["ITEMS"]["ProdSubscribe"] = array(); $DISCOUNT_PRICE_ALL = 0; // BASKET PRODUCTS (including measures, ratio, iblock properties data) $arImgFields = array("PREVIEW_PICTURE", "DETAIL_PICTURE"); $arBasketItems = array(); $arSku2Parent = array(); $arSetParentWeight = array(); $dbItems = CSaleBasket::GetList( array("ID" => "ASC"), array( "FUSER_ID" => CSaleBasket::GetBasketUserID(), "LID" => SITE_ID, "ORDER_ID" => "NULL" ), false, false, array( "ID", "NAME", "CALLBACK_FUNC", "MODULE", "PRODUCT_ID", "QUANTITY", "DELAY", "CAN_BUY", "PRICE", "WEIGHT", "DETAIL_PAGE_URL", "NOTES", "CURRENCY", "VAT_RATE", "CATALOG_XML_ID", "PRODUCT_XML_ID", "SUBSCRIBE", "DISCOUNT_PRICE", "PRODUCT_PROVIDER_CLASS", "TYPE", "SET_PARENT_ID" ) ); while ($arItem = $dbItems->GetNext()) { $arBasketItems[] = $arItem; if (CSaleBasketHelper::isSetItem($arItem)) continue; $arElementId[] = $arItem["PRODUCT_ID"]; if ($bUseCatalog) { $arParent = CCatalogSku::GetProductInfo($arItem["PRODUCT_ID"]); if ($arParent) { $arElementId[] = $arParent["ID"]; $arSku2Parent[$arItem["PRODUCT_ID"]] = $arParent["ID"]; $arParents[$arItem["PRODUCT_ID"]]["PRODUCT_ID"] = $arParent["ID"]; $arParents[$arItem["PRODUCT_ID"]]["IBLOCK_ID"] = $arParent["IBLOCK_ID"]; } } } // get measures, ratio, sku props data and available quantity if (!empty($arBasketItems) && $bUseCatalog) { $arBasketItems = getMeasures($arBasketItems); $arBasketItems = getRatio($arBasketItems); $arBasketItems = $this->getAvailableQuantity($arBasketItems); } // get product properties data $arProductData = getProductProps($arElementId, array_merge(array("ID"), $arImgFields, $this->arCustomSelectFields)); foreach ($arBasketItems as &$arItem) { $quantityIsFloat = false; if (number_format(doubleval($arItem['QUANTITY']), 2, '.', '') != intval($arItem['QUANTITY'])) { $quantityIsFloat = true; } $arItem["QUANTITY"] = ($quantityIsFloat === false && $this->quantityFloat != "Y") ? intval($arItem['QUANTITY']) : number_format(doubleval($arItem['QUANTITY']), 2, '.', ''); $arItem["PROPS"] = array(); $dbProp = CSaleBasket::GetPropsList( array("SORT" => "ASC", "ID" => "ASC"), array("BASKET_ID" => $arItem["ID"], "!CODE" => array("CATALOG.XML_ID", "PRODUCT.XML_ID")) ); while ($arProp = $dbProp->GetNext()) $arItem["PROPS"][] = $arProp; $arItem["PRICE_VAT_VALUE"] = (($arItem["PRICE"] / ($arItem["VAT_RATE"] +1)) * $arItem["VAT_RATE"]); $arItem["PRICE_FORMATED"] = SaleFormatCurrency($arItem["PRICE"], $arItem["CURRENCY"]); $arItem["WEIGHT"] = doubleval($arItem["WEIGHT"]); $arItem["WEIGHT_FORMATED"] = roundEx(doubleval($arItem["WEIGHT"] / $this->weightKoef), SALE_WEIGHT_PRECISION)." ".$this->weightUnit; if (CSaleBasketHelper::isSetItem($arItem)) $arSetParentWeight[$arItem["SET_PARENT_ID"]] += $arItem["WEIGHT"] * $arItem["QUANTITY"]; if (array_key_exists($arItem["PRODUCT_ID"], $arProductData) && is_array($arProductData[$arItem["PRODUCT_ID"]])) { foreach ($arProductData[$arItem["PRODUCT_ID"]] as $key => $value) { if (strpos($key, "PROPERTY_") !== false || in_array($key, $arImgFields)) $arItem[$key] = $value; } } if (array_key_exists($arItem["PRODUCT_ID"], $arSku2Parent)) // if sku element doesn't have value of some property - we'll show parent element value instead { $arFieldsToFill = array_merge($this->arCustomSelectFields, $arImgFields); // fields to be filled with parents' values if empty foreach ($arFieldsToFill as $field) { $fieldVal = (in_array($field, $arImgFields)) ? $field : $field."_VALUE"; $parentId = $arSku2Parent[$arItem["PRODUCT_ID"]]; if ((!isset($arItem[$fieldVal]) || (isset($arItem[$fieldVal]) && strlen($arItem[$fieldVal]) == 0)) && (isset($arProductData[$parentId][$fieldVal]) && !empty($arProductData[$parentId][$fieldVal]))) // can be array or string { $arItem[$fieldVal] = $arProductData[$parentId][$fieldVal]; } } } foreach ($arItem as $key => $value) // format properties' values { if ((strpos($key, "PROPERTY_", 0) === 0) && (strrpos($key, "_VALUE") == strlen($key) - 6)) { $code = str_replace(array("PROPERTY_", "_VALUE"), "", $key); $propData = $this->arIblockProps[$code]; $arItem[$key] = CSaleHelper::getIblockPropInfo($value, $propData); } } $arItem["PREVIEW_PICTURE_SRC"] = ""; if (isset($arItem["PREVIEW_PICTURE"]) && intval($arItem["PREVIEW_PICTURE"]) > 0) { $arImage = CFile::GetFileArray($arItem["PREVIEW_PICTURE"]); if ($arImage) { $arFileTmp = CFile::ResizeImageGet( $arImage, array("width" => "110", "height" =>"110"), BX_RESIZE_IMAGE_PROPORTIONAL, true ); $arItem["PREVIEW_PICTURE_SRC"] = $arFileTmp["src"]; } } $arItem["DETAIL_PICTURE_SRC"] = ""; if (isset($arItem["DETAIL_PICTURE"]) && intval($arItem["DETAIL_PICTURE"]) > 0) { $arImage = CFile::GetFileArray($arItem["DETAIL_PICTURE"]); if ($arImage) { $arFileTmp = CFile::ResizeImageGet( $arImage, array("width" => "110", "height" =>"110"), BX_RESIZE_IMAGE_PROPORTIONAL, true ); $arItem["DETAIL_PICTURE_SRC"] = $arFileTmp["src"]; } } } unset($arItem); // get sku props data if (!empty($arBasketItems) && $bUseCatalog && isset($this->offersProps) && !empty($this->offersProps)) { $arBasketItems = $this->getSkuPropsData($arBasketItems, $arParents, $this->offersProps); } // count weight for set parent products foreach ($arBasketItems as &$arItem) { if (CSaleBasketHelper::isSetParent($arItem)) { $arItem["WEIGHT"] = $arSetParentWeight[$arItem["ID"]] / $arItem["QUANTITY"]; $arItem["WEIGHT_FORMATED"] = roundEx(doubleval($arItem["WEIGHT"] / $this->weightKoef), SALE_WEIGHT_PRECISION)." ".$this->weightUnit; } } if (isset($arItem)) { unset($arItem); } // fill item arrays for old templates foreach ($arBasketItems as &$arItem) { if (CSaleBasketHelper::isSetItem($arItem)) continue; if ($arItem["CAN_BUY"] == "Y" && $arItem["DELAY"] == "N") { $allSum += ($arItem["PRICE"] * $arItem["QUANTITY"]); $allWeight += ($arItem["WEIGHT"] * $arItem["QUANTITY"]); $allVATSum += roundEx($arItem["PRICE_VAT_VALUE"] * $arItem["QUANTITY"], SALE_VALUE_PRECISION); $bShowReady = True; if(doubleval($arItem["DISCOUNT_PRICE"]) > 0) { if (0 < doubleval($arItem["DISCOUNT_PRICE"] + $arItem["PRICE"])) { $arItem["DISCOUNT_PRICE_PERCENT"] = $arItem["DISCOUNT_PRICE"]*100 / ($arItem["DISCOUNT_PRICE"] + $arItem["PRICE"]); } else { $arItem["DISCOUNT_PRICE_PERCENT"] = 0; } $arItem["DISCOUNT_PRICE_PERCENT_FORMATED"] = roundEx($arItem["DISCOUNT_PRICE_PERCENT"], SALE_VALUE_PRECISION)."%"; $DISCOUNT_PRICE_ALL += $arItem["DISCOUNT_PRICE"] * $arItem["QUANTITY"]; } $arResult["ITEMS"]["AnDelCanBuy"][] = $arItem; } elseif ($arItem["CAN_BUY"] == "Y" && $arItem["DELAY"] == "Y") { $bShowDelay = True; $arResult["ITEMS"]["DelDelCanBuy"][] = $arItem; } elseif ($arItem["CAN_BUY"] == "N" && $arItem["SUBSCRIBE"] == "Y") { $bShowSubscribe = True; $arResult["ITEMS"]["ProdSubscribe"][] = $arItem; } else { $bShowNotAvail = True; $arItem["NOT_AVAILABLE"] = true; $arResult["ITEMS"]["nAnCanBuy"][] = $arItem; } } unset($arItem); $arResult["ShowReady"] = (($bShowReady)?"Y":"N"); $arResult["ShowDelay"] = (($bShowDelay)?"Y":"N"); $arResult["ShowNotAvail"] = (($bShowNotAvail)?"Y":"N"); $arResult["ShowSubscribe"] = (($bShowSubscribe)?"Y":"N"); $arOrder = array( 'SITE_ID' => SITE_ID, 'USER_ID' => $GLOBALS["USER"]->GetID(), 'ORDER_PRICE' => $allSum, 'ORDER_WEIGHT' => $allWeight, 'BASKET_ITEMS' => $arResult["ITEMS"]["AnDelCanBuy"] ); $arOptions = array( 'COUNT_DISCOUNT_4_ALL_QUANTITY' => $this->countDiscount4AllQuantity, ); $arErrors = array(); CSaleDiscount::DoProcessOrder($arOrder, $arOptions, $arErrors); $allSum = 0; $allWeight = 0; $allVATSum = 0; $DISCOUNT_PRICE_ALL = 0; $priceWithoutDiscount = 0; foreach ($arOrder["BASKET_ITEMS"] as &$arOneItem) { $allWeight += ($arOneItem["WEIGHT"] * $arOneItem["QUANTITY"]); $allSum += ($arOneItem["PRICE"] * $arOneItem["QUANTITY"]); if (array_key_exists('VAT_VALUE', $arOneItem)) $arOneItem["PRICE_VAT_VALUE"] = $arOneItem["VAT_VALUE"]; $allVATSum += roundEx($arOneItem["PRICE_VAT_VALUE"] * $arOneItem["QUANTITY"], SALE_VALUE_PRECISION); $arOneItem["PRICE_FORMATED"] = SaleFormatCurrency($arOneItem["PRICE"], $arOneItem["CURRENCY"]); $arOneItem["FULL_PRICE"] = $arOneItem["PRICE"] + $arOneItem["DISCOUNT_PRICE"]; $arOneItem["FULL_PRICE_FORMATED"] = SaleFormatCurrency($arOneItem["FULL_PRICE"], $arOneItem["CURRENCY"]); $arOneItem["SUM"] = SaleFormatCurrency($arOneItem["PRICE"] * $arOneItem["QUANTITY"], $arOneItem["CURRENCY"]); if (0 < doubleval($arOneItem["DISCOUNT_PRICE"] + $arOneItem["PRICE"])) { $arOneItem["DISCOUNT_PRICE_PERCENT"] = $arOneItem["DISCOUNT_PRICE"]*100 / ($arOneItem["DISCOUNT_PRICE"] + $arOneItem["PRICE"]); } else { $arOneItem["DISCOUNT_PRICE_PERCENT"] = 0; } $arOneItem["DISCOUNT_PRICE_PERCENT_FORMATED"] = roundEx($arOneItem["DISCOUNT_PRICE_PERCENT"], SALE_VALUE_PRECISION)."%"; $DISCOUNT_PRICE_ALL += $arOneItem["DISCOUNT_PRICE"] * $arOneItem["QUANTITY"]; } unset($arOneItem); $arResult["ITEMS"]["AnDelCanBuy"] = $arOrder["BASKET_ITEMS"]; // fill grid data (for new templates with custom columns) foreach ($arResult["ITEMS"] as $type => $arItems) { foreach ($arItems as $k => $arItem) { $arResult["GRID"]["ROWS"][$arItem["ID"]] = $arItem; } } $arResult["allSum"] = $allSum; $arResult["allWeight"] = $allWeight; $arResult["allWeight_FORMATED"] = roundEx(doubleval($allWeight/$this->weightKoef), SALE_WEIGHT_PRECISION)." ".$this->weightUnit; $arResult["allSum_FORMATED"] = SaleFormatCurrency($allSum, $allCurrency); $arResult["DISCOUNT_PRICE_FORMATED"] = SaleFormatCurrency($arResult["DISCOUNT_PRICE"], $allCurrency); $arResult["PRICE_WITHOUT_DISCOUNT"] = SaleFormatCurrency($allSum + $DISCOUNT_PRICE_ALL, $allCurrency); if ($this->priceVatShowValue == 'Y') { $arResult["allVATSum"] = $allVATSum; $arResult["allVATSum_FORMATED"] = SaleFormatCurrency($allVATSum, $allCurrency); $arResult["allSum_wVAT_FORMATED"] = SaleFormatCurrency(doubleval($arResult["allSum"]-$allVATSum), $allCurrency); } if ($this->hideCoupon != "Y") $arCoupons = CCatalogDiscountCoupon::GetCoupons(); if (!empty($arCoupons)) $arResult["COUPON"] = htmlspecialcharsbx($arCoupons[0]); if(count($arBasketItems)<=0) $arResult["ERROR_MESSAGE"] = GetMessage("SALE_EMPTY_BASKET"); $arResult["DISCOUNT_PRICE_ALL"] = $DISCOUNT_PRICE_ALL; $arResult["DISCOUNT_PRICE_ALL_FORMATED"] = SaleFormatCurrency($DISCOUNT_PRICE_ALL, $allCurrency); if($this->usePrepayment == "Y") { if(doubleval($arResult["allSum"]) > 0) { $personType = array(); $dbPersonType = CSalePersonType::GetList(array("SORT" => "ASC", "NAME" => "ASC"), array("LID" => SITE_ID, "ACTIVE" => "Y")); while($arPersonType = $dbPersonType->Fetch()) { $personType[] = $arPersonType["ID"]; } if(!empty($personType)) { $dbPaySysAction = CSalePaySystemAction::GetList( array(), array( "PS_ACTIVE" => "Y", "HAVE_PREPAY" => "Y", "PERSON_TYPE_ID" => $personType, ), false, false, array("ID", "PAY_SYSTEM_ID", "PERSON_TYPE_ID", "NAME", "ACTION_FILE", "RESULT_FILE", "NEW_WINDOW", "PARAMS", "ENCODING", "LOGOTIP") ); if ($arPaySysAction = $dbPaySysAction->Fetch()) { CSalePaySystemAction::InitParamarrays(false, false, $arPaySysAction["PARAMS"]); $pathToAction = $_SERVER["DOCUMENT_ROOT"].$arPaySysAction["ACTION_FILE"]; $pathToAction = str_replace("\\", "/", $pathToAction); while (substr($pathToAction, strlen($pathToAction) - 1, 1) == "/") $pathToAction = substr($pathToAction, 0, strlen($pathToAction) - 1); if (file_exists($pathToAction)) { if (is_dir($pathToAction) && file_exists($pathToAction."/pre_payment.php")) $pathToAction .= "/pre_payment.php"; include_once($pathToAction); $psPreAction = new CSalePaySystemPrePayment; if($psPreAction->init()) { $orderData = array( "PATH_TO_ORDER" => $this->pathToOrder, "AMOUNT" => $arResult["allSum"], "BASKET_ITEMS" => $arResult["ITEMS"]["AnDelCanBuy"], ); if(!$psPreAction->BasketButtonAction($orderData)) { if($e = $APPLICATION->GetException()) $arResult["WARNING_MESSAGE"][] = $e->GetString(); } $arResult["PREPAY_BUTTON"] = $psPreAction->BasketButtonShow(); } } } } } } return $arResult; }