/** * @param $siteId * @param null $userId * @param $shoppingCart * @param array $options * * @return array */ static function makeOrderArray($siteId, $userId = null, array $shoppingCart, array $options = array()) { // calculate weight for set parent $parentWeight = array(); foreach ($shoppingCart as $item) { if (CSaleBasketHelper::isSetItem($item)) { $parentWeight[$item["SET_PARENT_ID"]]["WEIGHT"] += $item["WEIGHT"] * $item["QUANTITY"]; } } foreach ($shoppingCart as &$item) { if (CSaleBasketHelper::isSetParent($item) && isset($parentWeight[$item["SET_PARENT_ID"]])) { $item["WEIGHT"] = $parentWeight[$item["SET_PARENT_ID"]]["WEIGHT"]; } } unset($item); $currency = isset($options['CURRENCY']) && is_string($options['CURRENCY']) ? $options['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" => $shoppingCart, "SITE_ID" => $siteId, "LID" => $siteId, "USER_ID" => $userId, "USE_VAT" => false, "VAT_RATE" => 0, "VAT_SUM" => 0, "DELIVERY_ID" => false); if (isset($options["DELIVERY_EXTRA_SERVICES"])) { $arOrder["DELIVERY_EXTRA_SERVICES"] = $options["DELIVERY_EXTRA_SERVICES"]; } $orderPrices = CSaleOrder::CalculateOrderPrices($shoppingCart); $arOrder['ORDER_PRICE'] = $orderPrices['ORDER_PRICE']; $arOrder['ORDER_WEIGHT'] = $orderPrices['ORDER_WEIGHT']; $arOrder['VAT_RATE'] = $orderPrices['VAT_RATE']; $arOrder['VAT_SUM'] = $orderPrices['VAT_SUM']; $arOrder["USE_VAT"] = $orderPrices['USE_VAT'] == "Y"; return $arOrder; }
$arCols["DETAIL_PICTURE"] = CSaleHelper::getFileInfo($arItem["DETAIL_PICTURE"], array("WIDTH" => 110, "HEIGHT" => 110)); } if (isset($arItem["MEASURE_TEXT"]) && strlen($arItem["MEASURE_TEXT"]) > 0) { $arCols["QUANTITY"] = $arItem["QUANTITY"] . " " . $arItem["MEASURE_TEXT"]; } foreach ($arItem as $tmpKey => $value) { if (strpos($tmpKey, "PROPERTY_", 0) === 0 && strrpos($tmpKey, "_VALUE") == strlen($tmpKey) - 6) { $code = str_replace(array("PROPERTY_", "_VALUE"), "", $tmpKey); $propData = $arIblockProps[$code]; $arCols[$tmpKey] = getIblockProps($value, $propData, array("WIDTH" => 110, "HEIGHT" => 110)); } } $arResult["GRID"]["ROWS"][$arItem["ID"]] = array("id" => $arItem["ID"], "data" => $arItem, "actions" => array(), "columns" => $arCols, "editable" => true); } unset($arItem); $oldOrder = CSaleOrder::CalculateOrderPrices($arResult["BASKET_ITEMS"]); if (!empty($oldOrder)) { $arResult['ORDER_PRICE'] = $oldOrder['ORDER_PRICE']; $arResult["ORDER_PRICE_FORMATED"] = SaleFormatCurrency($arResult["ORDER_PRICE"], $arResult["BASE_LANG_CURRENCY"]); $arResult["ORDER_WEIGHT"] = $oldOrder["ORDER_WEIGHT"]; $arResult['VAT_SUM'] = $oldOrder['VAT_SUM']; $arResult["USE_VAT"] = $oldOrder['USE_VAT'] == "Y"; $arResult["VAT_SUM_FORMATED"] = SaleFormatCurrency($arResult["VAT_SUM"], $arResult["BASE_LANG_CURRENCY"]); } unset($oldOrder); } } else { $arResult["ORDER_PRICE"] = $arOrderDat['ORDER_PRICE']; $arResult["ORDER_PRICE_FORMATED"] = SaleFormatCurrency($arResult["ORDER_PRICE"], $arResult["BASE_LANG_CURRENCY"]); $arResult["USE_VAT"] = $arOrderDat['USE_VAT']; $arResult["VAT_SUM"] = $arOrderDat["VAT_SUM"];
/** * @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; }