Created
February 14, 2018 09:54
-
-
Save gdecider/3dd55818d42450c52caa3581cc428949 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
/** | |
* Получения минимальной цены товара в категории | |
* возможно совмещение с дополнительными параметрами фильтрации | |
* @param $iblockId | |
* @param $sectionId | |
* @param array $arFilter | |
* @return mixed | |
*/ | |
static public function getSectionMinPrice($iblockId, $sectionId, $arFilter = []) | |
{ | |
Loader::includeModule('currency'); | |
$arFinalFilter = ['IBLOCK_ID' => $iblockId, "INCLUDE_SUBSECTIONS" => "Y", 'SECTION_ID' => $sectionId]; | |
if(count($arFilter) > 0) { | |
$arFinalFilter = array_merge($arFilter, $arFinalFilter); | |
} | |
$rsOffers = \CIBlockElement::GetList( | |
["CATALOG_PRICE_".Config::PRICE_BASE_ID => "ASC"], | |
$arFinalFilter, | |
false, false, ['CATALOG_PRICE_ID_'.Config::PRICE_BASE_ID]); | |
$arEl = array(); | |
while($arOffer = $rsOffers->GetNext()) { | |
$price = $arOffer["CATALOG_PRICE_".Config::PRICE_BASE_ID]; | |
if($arOffer["CATALOG_CURRENCY_".Config::PRICE_BASE_ID] == "USD") { | |
$price = \CCurrencyRates::ConvertCurrency($price, "USD", "RUB"); | |
} | |
if($price) { | |
$arEl[] = $price; | |
} | |
} | |
sort($arEl, SORT_NUMERIC); | |
return $arEl[0]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment