コード例 #1
0
ファイル: product.php プロジェクト: andy-profi/bxApiDocs
 /**
  * <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" =&gt; "тип скидки (P - в процентах, F - фиксированная сумма)",
  * "VALUE" =&gt; "величина скидки", "CURRENCY" =&gt; "валюта", "MAX_DISCOUNT" =&gt;
  * "максимальный размер скидки" ), array( "VALUE_TYPE" =&gt; "тип скидки (P - в
  * процентах, F - фиксированная сумма)", "VALUE" =&gt; "величина скидки",
  * "CURRENCY" =&gt; "валюта", "MAX_DISCOUNT" =&gt; "максимальный размер скидки" ), * * * )
  * </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>
  * &lt;?
  * // Для товара с кодом $ID выведем различные цены (по типу и количеству), по
  * // которым данный товар может быть куплен текущим пользователем
  * 
  * $dbPrice = CPrice::GetList(
  *         array("QUANTITY_FROM" =&gt; "ASC", "QUANTITY_TO" =&gt; "ASC", "SORT" =&gt; "ASC"),
  *         array("PRODUCT_ID" =&gt; $ID),
  *         false,
  *         false,
  *         array("ID", "CATALOG_GROUP_ID", "PRICE", "CURRENCY", "QUANTITY_FROM", "QUANTITY_TO")
  *     );
  * while ($arPrice = $dbPrice-&gt;Fetch())
  * {
  *     $arDiscounts = CCatalogDiscount::GetDiscountByPrice(
  *             $arPrice["ID"],
  *             $USER-&gt;GetUserGroupArray(),
  *             "N",
  *             SITE_ID
  *         );
  *     $discountPrice = CCatalogProduct::CountPriceWithDiscount(
  *             $arPrice["PRICE"],
  *             $arPrice["CURRENCY"],
  *             $arDiscounts
  *         );
  *     $arPrice["DISCOUNT_PRICE"] = $discountPrice;
  * 
  *     echo "&lt;pre&gt;";
  *     print_r($arPrice);
  *     echo "&lt;/pre&gt;";
  * }
  * ?&gt;
  * </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;
 }