Skip to content

Instantly share code, notes, and snippets.

@noff
Created October 28, 2014 07:09
Show Gist options
  • Save noff/e035487c5f6926dfaf44 to your computer and use it in GitHub Desktop.
Save noff/e035487c5f6926dfaf44 to your computer and use it in GitHub Desktop.
Определение цены товара
$item_id = intval($item_id);
$item = $libCatalogProduct->GetByIDEx($item_id);
$currency_code = 'RUB';
$picture = null;
// Получаем цену товара или товарного предложения
if(CCatalogSku::IsExistOffers($item_id)) {
// Для товарных предложений просто не показываем цену
$final_price = null;
// Пытаемся найти цену среди торговых предложений
$res = CIBlockElement::GetByID($item_id);
if($ar_res = $res->GetNext()) {
if(isset($ar_res['IBLOCK_ID']) && $ar_res['IBLOCK_ID']) {
$offers = CIBlockPriceTools::GetOffersArray(array(
'IBLOCK_ID' => $ar_res['IBLOCK_ID'],
'HIDE_NOT_AVAILABLE' => 'Y',
'CHECK_PERMISSIONS' => 'Y'
), array($item_id));
foreach($offers as $offer) {
// Ищем фото
if(isset($offer['DETAIL_PICTURE']) && (int)$offer['DETAIL_PICTURE'] > 0 ) {
$picture = $offer['DETAIL_PICTURE'];
}
$offer_price_info = CatalogGetPriceTableEx($offer['ID']);
if($offer_price_info && isset($offer_price_info['AVAILABLE']) && $offer_price_info['AVAILABLE'] == 'Y') {
if(isset($offer_price_info['MATRIX'])) {
$price_info = array_pop($offer_price_info['MATRIX']);
$price_info = array_pop($price_info);
if($price_info['PRICE'] && intval($price_info['PRICE']) > 0) {
if($final_price == null || intval($price_info['PRICE']) < $final_price) {
$final_price = intval($price_info['PRICE']);
if(isset($price_info['CURRENCY']) && $price_info['CURRENCY'] != '') {
$currency_code = $price_info['CURRENCY'];
}
}
}
}
}
}
}
}
} else {
// У товара нет товарных предложений, значит находим именно его цену по его скидкам
$price = CCatalogProduct::GetOptimalPrice(
$item_id,
1,
$USER->GetUserGroupArray(),
'N'
// array arPrices = array()[,
// string siteID = false[,
// array arDiscountCoupons = false]]]]]]
);
if(!$price || !isset($price['DISCOUNT_PRICE'])) {
continue;
}
if(isset($price['CURRENCY'])) {
$currency_code = $price['CURRENCY'];
}
if(isset($price['PRICE']['CURRENCY'])) {
$currency_code = $price['PRICE']['CURRENCY'];
}
$final_price = $price['DISCOUNT_PRICE'];
}
$link = $item['DETAIL_PAGE_URL'] . $recommended_by;
if($picture == null) {
$picture = $item['DETAIL_PICTURE'] ?: $item['PREVIEW_PICTURE'];
}
if($currency_code != $base_currency) {
$final_price = CCurrencyRates::ConvertCurrency($final_price, $currency_code, $base_currency);
$currency_code = $base_currency;
}
if ($picture === null) {
continue;
}
$file = $libFile->ResizeImageGet($picture, array(
'width' => Options::getImageWidth(),
'height' => Options::getImageHeight()
), BX_RESIZE_IMAGE_PROPORTIONAL, true);
$html .= '<div class="recommended-item">
<div class="recommended-item-photo"><a href="' . $link . '"><img src="' . $file['src'] . '" class="item_img"/></a></div>
<div class="recommended-item-title"><a href="' . $link . '">' . $item['NAME'] . '</a></div>
' . ( $final_price ? '<div class="recommended-item-price">' . CCurrencyLang::CurrencyFormat($final_price, $currency_code, true) . '</div>' : '') . '
<div class="recommended-item-action"><a href="' . $link . '">' . GetMessage('REES_INCLUDE_MORE') . '</a></div>
</div>';
$found_items++;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment