Last active
June 14, 2017 19:25
-
-
Save Pum-purum/1cfcae61a4791b5b0c28d41e33b8d4d8 to your computer and use it in GitHub Desktop.
Битрикс: Как посчитать стоимость товара или предложения со всеми скидками
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?//Функция принимает как параметр ID товара, | |
//возвращает цену со всеми скидками. | |
//Автор - Максим с сайта alittlebit.ru. | |
function getFinalPriceInCurrency($item_id, $sale_currency = 'RUB') { | |
CModule::IncludeModule("iblock"); | |
CModule::IncludeModule("catalog"); | |
CModule::IncludeModule("sale"); | |
global $USER; | |
$currency_code = 'RUB'; | |
// Простой товар, без торговых предложений (для количества равному 1) | |
$price = CCatalogProduct::GetOptimalPrice($item_id, 1, $USER->GetUserGroupArray(), 'N'); | |
// Получили цену? | |
if(!$price || !isset($price['PRICE'])) { | |
return false; | |
} | |
// Меняем код валюты, если нашли | |
if(isset($price['CURRENCY'])) { | |
$currency_code = $price['CURRENCY']; | |
} | |
if(isset($price['PRICE']['CURRENCY'])) { | |
$currency_code = $price['PRICE']['CURRENCY']; | |
} | |
// Получаем итоговую цену | |
$final_price = $price['PRICE']['PRICE']; | |
// Ищем скидки и пересчитываем цену товара с их учетом | |
$arDiscounts = CCatalogDiscount::GetDiscountByProduct($item_id, $USER->GetUserGroupArray(), "N", 2); | |
if(is_array($arDiscounts) && sizeof($arDiscounts) > 0) { | |
$final_price = CCatalogProduct::CountPriceWithDiscount($final_price, $currency_code, $arDiscounts); | |
} | |
// Если необходимо, конвертируем в нужную валюту | |
if($currency_code != $sale_currency) { | |
$final_price = CCurrencyRates::ConvertCurrency($final_price, $currency_code, $sale_currency); | |
} | |
return $final_price; | |
} ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment