N
N
nikita_falcon2020-08-08 15:03:51
PHP
nikita_falcon, 2020-08-08 15:03:51

How can I display a product review for this product?

There are two infoblocks "Reviews" and "Products", in the reviews there is a property "Product" that is linked to the product element.
I need to write down, as I understand it, two conditions both in the template for the component and in the place where the component itself is called, if you write just the id of the product, everything works.

if ($arResult["ID"] ==  125) { // 125 это id товара
  вывод компонента // тут используется инфоблок товаров
}

if ($arItem["PROPERTIES"]["ID_PRODUCT"]["VALUE"] == 125) {  // 125 это id товара
тут шаблон // тут используется инфоблок отзывов
}

I'm not sure what is needed exactly, but at least it works, I need to pass the product id there instead of 125.
Maybe I need to somehow pass the element id through $_POST $_GET, but I can't figure out how.
if(!CModule::IncludeModule("iblock"))
return; 
$res = CIBlockElement::GetByID($_GET["PID"]);
if($ar_res = $res->GetNext())
  echo $ar_res['NAME'];

Answer the question

In order to leave comments, you need to log in

2 answer(s)
N
nikita_falcon, 2020-08-13
@nikita_falcon

In general, I found the answer myself, everything is much easier than writing conditions

global $arrFilter;
$arrFilter = array("property_ID_PRODUCT" => $arResult["ID"]); // свойство которое нужно и чему оно должно быть равно

and then we just pass the value to the component in the filter
$APPLICATION->IncludeComponent(
      "bitrix:news.list",
      "reviews",
          Array(
                               // поля до
             "FILTER_NAME" => "arrFilter",
                              // поля после
        )							
      );

A
Andrey Nikolaev, 2020-08-08
@gromdron

And what's the problem instead of 125 use this very "$arResult["ID"]", which already contains the ID of the product you are looking at?
Those. in fact, you write the following:
1) Develop a component that, based on the product ID, will display its reviews
2) In the component output template, add a call to your component.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question