/** * <p>Метод применяет к цене <i>price</i> в валюте <i>currency</i> цепочку скидок из массива <i>arDiscounts</i>. Метод динамичный.</p> <p></p> <div class="note"> <b>Примечание:</b> до версии модуля <b>12.0</b> метод применял к цене <i>price</i> в валюте <i>currency</i> наибольшую скидку из массива <i>arDiscounts</i>.</div> * * * @param double $price Цена.</b * * @param string $currency Валюта цены. * * @param array $arDiscounts массив ассоциативных массивов скидок. Имеет вид: <pre class="syntax">array( * array( "VALUE_TYPE" => "тип скидки (P - в процентах, F - фиксированная сумма)", * "VALUE" => "величина скидки", "CURRENCY" => "валюта", "MAX_DISCOUNT" => * "максимальный размер скидки" ), array( "VALUE_TYPE" => "тип скидки (P - в * процентах, F - фиксированная сумма)", "VALUE" => "величина скидки", * "CURRENCY" => "валюта", "MAX_DISCOUNT" => "максимальный размер скидки" ), * * * ) * </pre> * * @return array <p>Метод возвращает цену, получившуюся после применения цепочки * скидок.</p> <p></p><div class="note"> <b>Примечание:</b> до версии модуля <b>12.0.0</b> * метод возвращал наименьшую цену, которую можно было получить с * помощью наибольшей скидки.</div> <a name="examples"></a> * * <h4>Example</h4> * <pre> * <? * // Для товара с кодом $ID выведем различные цены (по типу и количеству), по * // которым данный товар может быть куплен текущим пользователем * * $dbPrice = CPrice::GetList( * array("QUANTITY_FROM" => "ASC", "QUANTITY_TO" => "ASC", "SORT" => "ASC"), * array("PRODUCT_ID" => $ID), * false, * false, * array("ID", "CATALOG_GROUP_ID", "PRICE", "CURRENCY", "QUANTITY_FROM", "QUANTITY_TO") * ); * while ($arPrice = $dbPrice->Fetch()) * { * $arDiscounts = CCatalogDiscount::GetDiscountByPrice( * $arPrice["ID"], * $USER->GetUserGroupArray(), * "N", * SITE_ID * ); * $discountPrice = CCatalogProduct::CountPriceWithDiscount( * $arPrice["PRICE"], * $arPrice["CURRENCY"], * $arDiscounts * ); * $arPrice["DISCOUNT_PRICE"] = $discountPrice; * * echo "<pre>"; * print_r($arPrice); * echo "</pre>"; * } * ?> * </pre> * * * @static * @link http://dev.1c-bitrix.ru/api_help/catalog/classes/ccatalogproduct/ccatalogproduct__countpricewithdiscount.9c16046d.php * @author Bitrix */ public static function CountPriceWithDiscount($price, $currency, $arDiscounts) { static $eventOnGetExists = null; static $eventOnResultExists = null; if ($eventOnGetExists === true || $eventOnGetExists === null) { foreach (GetModuleEvents('catalog', 'OnCountPriceWithDiscount', true) as $arEvent) { $eventOnGetExists = true; $mxResult = ExecuteModuleEventEx($arEvent, array($price, $currency, $arDiscounts)); if ($mxResult !== true) { return $mxResult; } } if ($eventOnGetExists === null) { $eventOnGetExists = false; } } $currency = CCurrency::checkCurrencyID($currency); if ($currency === false) { return false; } $price = (double) $price; if ($price <= 0) { return $price; } if (empty($arDiscounts) || !is_array($arDiscounts)) { return $price; } $result = CCatalogDiscount::applyDiscountList($price, $currency, $arDiscounts); if ($result === false) { return false; } $currentMinPrice = $result['PRICE']; if ($eventOnResultExists === true || $eventOnResultExists === null) { foreach (GetModuleEvents('catalog', 'OnCountPriceWithDiscountResult', true) as $arEvent) { $eventOnResultExists = true; if (ExecuteModuleEventEx($arEvent, array(&$currentMinPrice)) === false) { return false; } } if ($eventOnResultExists === null) { $eventOnResultExists = false; } } return $currentMinPrice; }