M
M
Maxim Volkov2020-06-23 10:21:49
1C-Bitrix
Maxim Volkov, 2020-06-23 10:21:49

How to get a list of catalog products by ID, with data on prices and discounts?

The task is to get a list of products with the given properties: Hit, Promotion, New, etc.

I use the method: CIBlockElement::GetList - with a selection by the "PROPERTY_STICKERS_VALUE" property. This is how I get data to display a list of goods, but I can’t imagine how to get data with prices with a discount, without a discount, and the size of the discount.

The GetList method allows you to get the base price of the product, but the base prices are set in Euros, and you need to display the price of the product on the site converted in rubles, with a discount and an indication of its size.

How to get a group of catalog products by ID with data on prices converted in rubles, prices with a discount and its size?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
Maxim Volkov, 2020-06-29
@voland700

Problem solved. I will describe the solution, maybe it will be useful to someone.
Initially, it was necessary to display a block with catalog products on the main page of the catalog, according to the PROPERTY_STICKERS property - a list type, which are set to Hit, Recommended, New, Promotions to display products with the corresponding stickers. In this case, the goods should be displayed with the size of discounts, indicating the old price, the price converted from the currency into rubles.
5ef994cd5227f620637405.jpeg
Bitrix methods CIBlockElement::GetList and CCatalogDiscount::GetList are not ideal for solving this problem. In my opinion, it is more appropriate to use the catalog.section component with a property filter. Why the filter is set in the component parameters:

"USE_FILTER" => "Y",
     "FILTER_NAME" => "arrFilterAdvice",

And to get all the products of the catalog, in which the values ​​of the PROPERTY_STICKERS property are set (the property is not empty), a filter is set.
<? $GLOBALS['arrFilterAdvice'] = array('ACTIVE' => 'Y', '!PROPERTY_STICKERS' => false);
$APPLICATION->IncludeComponent(
  "bitrix:catalog.section", 
  "shop_window", 
  array(
          …
          "USE_FILTER" => "Y",
          "FILTER_NAME" => "arrFilterAdvice", 
          …

Thus, I received a list of products with given values, and already in the result_modifier.php file I sort the received elements by arrays - Hit, Recommend, New, Promotions, add $arResult to the resulting array for caching.
if(!$arResult["ADVICE"]){
  foreach($arResult["ITEMS"] as $Element){
    foreach($Element["PROPERTIES"]["STICKERS"]["VALUE_XML_ID"] as $type){		
      if($type == "HIT") $arResult["ADVICE"]["HIT"][$Element["ID"]] = $Element;
      if($type == "RECOMMEND") $arResult["ADVICE"]["RECOMMEND"][$Element["ID"]] = $Element;
      if($type == "NEW") $arResult["ADVICE"]["NEW"][$Element["ID"]] = $Element;
      if($type == "STOCK") $arResult["ADVICE"]["STOCK"][$Element["ID"]] = $Element;
    }
  }
}

I display the received data in the template of the catalog.section component in the form of tabs.

Y
Yaroslav Alexandrov, 2020-06-23
@alexyarik

Use CCatalogDiscount::GetList and concatenate the resulting array of IDs, removing values ​​that are not in your CIBlockElement::GetList selection - with the selection by the "PROPERTY_STICKERS_VALUE" property.

$dbProductDiscounts = CCatalogDiscount::GetList(
      array("SORT" => "ASC"),
      array("ACTIVE" => "Y"),
      false,
      false,
      array("ID", "PRODUCT_ID")
      );
  while ($arProductDiscounts = $dbProductDiscounts->Fetch()) {
    $akcii_arr[] = $arProductDiscounts["PRODUCT_ID"];
  }
  foreach($akcii_arr as $ID) {
    	$akcii_arr_[] = $ID;
  }
  $GLOBALS['arrFilterAkcii'] = array("ID"=>$akcii_arr_);
  ?>
  <?$APPLICATION->IncludeComponent("bitrix:catalog.top", "", Array(
    "FILTER_NAME" => "arrFilterAkcii",	// Имя массива со значениями фильтра для фильтрации элементов

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question