Skip to content

Instantly share code, notes, and snippets.

@stansidel
Forked from tikijian/php_sample.php
Created May 29, 2013 11:01
Show Gist options
  • Save stansidel/5669498 to your computer and use it in GitHub Desktop.
Save stansidel/5669498 to your computer and use it in GitHub Desktop.
<?php
//событие подмены нужной цены для покупки услуг
AddEventHandler("catalog", "OnGetOptimalPrice", 'OnGetOptimalPriceHandler');
function OnGetOptimalPriceHandler($productID)
{
//получаем id инфоблока покупаемого товара. Если это услуга, то подменяем цену.
$db_iblock = CIBlockElement::GetList(array(), array("ID" => $productID), false, false, array("IBLOCK_ID"));
$iblock = $db_iblock->Fetch();
if( $iblock['IBLOCK_ID'] == CATALOG_SERV ){
if (isset($GLOBALS['COMPLEXITY_AR']) && !empty($GLOBALS['COMPLEXITY_AR']['NAME']))
$complexity = $GLOBALS['COMPLEXITY_AR']['NAME']; //устанавливается при выборе автомобиля
else
return true;
$dbPrice = CCatalogGroup::GetList(
array(),
array("NAME" => $complexity),
false, false,
array("ID")
);
$priceID = $dbPrice->Fetch();
$db_res = CPrice::GetList(
array(),
array(
"PRODUCT_ID" => $productID,
"CATALOG_GROUP_ID" => $priceID['ID']
), false, false,
array()
);
$price = $db_res->Fetch();
$arFields['PRICE'] = array("ID" => $price['ID'],
"CATALOG_GROUP_ID" => $price['CATALOG_GROUP_ID'],
"PRICE" => $price['PRICE'],
"ELEMENT_IBLOCK_ID" => $price['PRODUCT_ID'],
"CURRENCY" => $price['CURRENCY'],
"VAT_RATE" => "",
"VAT_INCLUDED" => 'N'
);
return $arFields;
}else{
//это обычный товар - значит стандартное поведение
return true;
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment