Advertisement
Trigub_Ilia

Изменение типа цены в корзине

Jan 22nd, 2019
229
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.53 KB | None | 0 0
  1. AddEventHandler("catalog", "OnGetOptimalPrice", "MyGetOptimalPrice");
  2. function MyGetOptimalPrice($intProductID, $quantity = 1, $arUserGroups = array(), $renewal = "N", $arPrices = array(), $siteID = false, $arDiscountCoupons = false){
  3.  
  4.     //if(empty($_SESSION["REGION_PRICE_ID"]))$_SESSION["REGION_PRICE_ID"] = 17;
  5.  
  6.     //====================================================================================================================================
  7.  
  8.     if (!CModule::IncludeModule('iblock') or !CModule::IncludeModule('catalog') or !CModule::IncludeModule("sale"))
  9.     {
  10.         die('Ошибка в загрузки модулей...');
  11.     };
  12.  
  13.     $arResult = array();
  14.  
  15.     if(!empty($intProductID)) {
  16.         //Проверяем есль ли акционная цена
  17.         $resDiscount = CPrice::GetList(array(), array('PRODUCT_ID' => $intProductID, 'CATALOG_GROUP_ID' => 19));
  18.         if($arPriceDiscount = $resDiscount -> GetNext()){
  19.             $arDiscounts = CCatalogDiscount::GetDiscountByPrice($arPriceDiscount["ID"], $GLOBALS['USER'] -> GetUserGroupArray(), "N", SITE_ID);
  20.             if(!empty($arDiscounts[0])){
  21.                 $discountPrice = CCatalogProduct::CountPriceWithDiscount($arPriceDiscount["PRICE"], $arPriceDiscount["CURRENCY"], $arDiscounts);
  22.             }
  23.             $discount = $arPriceDiscount['PRICE'] - $discountPrice;
  24.             $arResult["PRICE"] = $arPriceDiscount['PRICE'];
  25.             $arResult["CATALOG_GROUP_ID"] = $_SESSION["REGION_PRICE_ID"];
  26.             $arResult["CURRENCY"] = $arPriceDiscount['CURRENCY'];
  27.             if($discountPrice){
  28.                 $arResult["DISCOUNT_PRICE"] = $discountPrice;
  29.             }
  30.             else{
  31.                 $arResult["DISCOUNT_PRICE"] = $arResult["PRICE"];
  32.             }
  33.         }
  34.         else{
  35.             //Если нету, ставим цену МСК
  36.             $res = CPrice::GetList(array(), array('PRODUCT_ID' => $intProductID, 'CATALOG_GROUP_ID' => 20));
  37.             if($arPrice = $res -> GetNext()){
  38.                 $arDiscounts = CCatalogDiscount::GetDiscountByPrice($arPrice["ID"], $GLOBALS['USER'] -> GetUserGroupArray(), "N", SITE_ID);
  39.                 if(!empty($arDiscounts[0])){
  40.                     $discountPrice = CCatalogProduct::CountPriceWithDiscount($arPrice["PRICE"], $arPrice["CURRENCY"], $arDiscounts);
  41.                 }
  42.                 $discount = $arPrice['PRICE'] - $discountPrice;
  43.                 $arResult["PRICE"] = $arPrice['PRICE'];
  44.                 $arResult["CATALOG_GROUP_ID"] = $_SESSION["REGION_PRICE_ID"];
  45.                 $arResult["CURRENCY"] = $arPrice['CURRENCY'];
  46.                 if($discountPrice){
  47.                     $arResult["DISCOUNT_PRICE"] = $discountPrice;
  48.                 }
  49.                 else{
  50.                     $arResult["DISCOUNT_PRICE"] = $arResult["PRICE"];
  51.                 }
  52.             }  
  53.         }
  54.     }
  55.  
  56.  
  57.     //file_put_contents($_SERVER['DOCUMENT_ROOT'].'/test-log2.txt', print_r($arResult["DISCOUNT_LIST"],1), FILE_APPEND);
  58.  
  59.     return array(
  60.         'PRICE' => array(
  61.             'CATALOG_GROUP_ID' => $arResult["CATALOG_GROUP_ID"],
  62.             'PRICE' => $arResult["PRICE"],
  63.             'CURRENCY' => $arResult["CURRENCY"],
  64.         ),
  65.         'RESULT_PRICE' => array(
  66.             'BASE_PRICE' => $arResult["PRICE"],
  67.             'DISCOUNT_PRICE' => $arResult["DISCOUNT_PRICE"],
  68.             'DISCOUNT' => $arResult["PRICE"] - $arResult["DISCOUNT_PRICE"],
  69.             'PERCENT' => ($arResult["PRICE"] > 0 ? roundEx((100*($arResult["PRICE"] - $arResult["DISCOUNT_PRICE"]))/$arResult["PRICE"], CATALOG_VALUE_PRECISION) : 0),
  70.             'CURRENCY' => $arResult["CURRENCY"],
  71.             'VAT_RATE' => false,
  72.             'VAT_INCLUDED' => 'Y'
  73.         ),
  74.         'DISCOUNT_PRICE' => $arResult["DISCOUNT_PRICE"],
  75.         'DISCOUNT_LIST' => $arResult["DISCOUNT_LIST"] // массив скидок действующих на товар в порядке применения
  76.     );
  77.  
  78.  
  79.     //====================================================================================================================================
  80. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement