Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- AddEventHandler("catalog", "OnGetOptimalPrice", "MyGetOptimalPrice");
- function MyGetOptimalPrice($intProductID, $quantity = 1, $arUserGroups = array(), $renewal = "N", $arPrices = array(), $siteID = false, $arDiscountCoupons = false){
- //if(empty($_SESSION["REGION_PRICE_ID"]))$_SESSION["REGION_PRICE_ID"] = 17;
- //====================================================================================================================================
- if (!CModule::IncludeModule('iblock') or !CModule::IncludeModule('catalog') or !CModule::IncludeModule("sale"))
- {
- die('Ошибка в загрузки модулей...');
- };
- $arResult = array();
- if(!empty($intProductID)) {
- //Проверяем есль ли акционная цена
- $resDiscount = CPrice::GetList(array(), array('PRODUCT_ID' => $intProductID, 'CATALOG_GROUP_ID' => 19));
- if($arPriceDiscount = $resDiscount -> GetNext()){
- $arDiscounts = CCatalogDiscount::GetDiscountByPrice($arPriceDiscount["ID"], $GLOBALS['USER'] -> GetUserGroupArray(), "N", SITE_ID);
- if(!empty($arDiscounts[0])){
- $discountPrice = CCatalogProduct::CountPriceWithDiscount($arPriceDiscount["PRICE"], $arPriceDiscount["CURRENCY"], $arDiscounts);
- }
- $discount = $arPriceDiscount['PRICE'] - $discountPrice;
- $arResult["PRICE"] = $arPriceDiscount['PRICE'];
- $arResult["CATALOG_GROUP_ID"] = $_SESSION["REGION_PRICE_ID"];
- $arResult["CURRENCY"] = $arPriceDiscount['CURRENCY'];
- if($discountPrice){
- $arResult["DISCOUNT_PRICE"] = $discountPrice;
- }
- else{
- $arResult["DISCOUNT_PRICE"] = $arResult["PRICE"];
- }
- }
- else{
- //Если нету, ставим цену МСК
- $res = CPrice::GetList(array(), array('PRODUCT_ID' => $intProductID, 'CATALOG_GROUP_ID' => 20));
- if($arPrice = $res -> GetNext()){
- $arDiscounts = CCatalogDiscount::GetDiscountByPrice($arPrice["ID"], $GLOBALS['USER'] -> GetUserGroupArray(), "N", SITE_ID);
- if(!empty($arDiscounts[0])){
- $discountPrice = CCatalogProduct::CountPriceWithDiscount($arPrice["PRICE"], $arPrice["CURRENCY"], $arDiscounts);
- }
- $discount = $arPrice['PRICE'] - $discountPrice;
- $arResult["PRICE"] = $arPrice['PRICE'];
- $arResult["CATALOG_GROUP_ID"] = $_SESSION["REGION_PRICE_ID"];
- $arResult["CURRENCY"] = $arPrice['CURRENCY'];
- if($discountPrice){
- $arResult["DISCOUNT_PRICE"] = $discountPrice;
- }
- else{
- $arResult["DISCOUNT_PRICE"] = $arResult["PRICE"];
- }
- }
- }
- }
- //file_put_contents($_SERVER['DOCUMENT_ROOT'].'/test-log2.txt', print_r($arResult["DISCOUNT_LIST"],1), FILE_APPEND);
- return array(
- 'PRICE' => array(
- 'CATALOG_GROUP_ID' => $arResult["CATALOG_GROUP_ID"],
- 'PRICE' => $arResult["PRICE"],
- 'CURRENCY' => $arResult["CURRENCY"],
- ),
- 'RESULT_PRICE' => array(
- 'BASE_PRICE' => $arResult["PRICE"],
- 'DISCOUNT_PRICE' => $arResult["DISCOUNT_PRICE"],
- 'DISCOUNT' => $arResult["PRICE"] - $arResult["DISCOUNT_PRICE"],
- 'PERCENT' => ($arResult["PRICE"] > 0 ? roundEx((100*($arResult["PRICE"] - $arResult["DISCOUNT_PRICE"]))/$arResult["PRICE"], CATALOG_VALUE_PRECISION) : 0),
- 'CURRENCY' => $arResult["CURRENCY"],
- 'VAT_RATE' => false,
- 'VAT_INCLUDED' => 'Y'
- ),
- 'DISCOUNT_PRICE' => $arResult["DISCOUNT_PRICE"],
- 'DISCOUNT_LIST' => $arResult["DISCOUNT_LIST"] // массив скидок действующих на товар в порядке применения
- );
- //====================================================================================================================================
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement