When uploading the catalog to Yandex, an error occurred that for each SKU you need a unique link, when you click on it, the sales offer will be immediately active. Because an individual template, the solutions that exist on the Bitrix forum does not help. There is a link to the example of a magazine.ru / car, but this car has properties (red, green, blue) and each property has its own id. I need that when I click on the link shop.ru / car /? Pid = 111, the experts of Bitrix will understand me. I found a piece of code that is responsible for all these actions, but nothing happens. Here is a piece of module code.

<div class="offers"> <ul class="offer-list"> <? foreach ($arResult['OFFERS'] as $iKey => $arOffer): ?> <li data-id="<?= $arOffer['ID']; ?>"<?= ($iKey == 0) ? ' class="active"' : ''; ?>> <? if ($arOffer['PRICES'][$sPriceCode]['CAN_BUY'] == 'Y' && $arOffer['CATALOG_AVAILABLE'] == 'Y'): ?> <span><?= $arOffer['PRICES'][$sPriceCode]['PRINT_DISCOUNT_VALUE']; ?></span> <? endif; ?> <?= $arOffer['NAME']; ?> </li> <? endforeach; ?> </ul> </div> <?$this->setFrameMode(true);?> </div> 

Here is a piece of code js script which is responsible for choosing SKU

  var offers = $('.b-element .offer-list li'); offers.on('click', function(){ var element = $(this).closest('.b-buy'), id = $(this).data('id'); offers.removeClass('active'); $(this).addClass('active'); $('.offer', element).hide().removeClass('active'); $('.offer-' + id, element).show(); }); }); 

Tried to do something like that

  var offers = $('.b-element .offer-list li'); offers.on('click', function(){ var element = $(this).closest('.b-buy'), id = $(this).data('id'); offers.removeClass('active'); $(this).addClass('active'); loc = '?pid=' + this.offers[this.offerNum].ID; history.pushState({}, '', loc); $('.offer', element).hide().removeClass('active'); $('.offer-' + id, element).show(); }); }); 
But nothing comes out, on the Bitrix forum there are solutions for the standard template and it looks like this

 { var i = 0, j = 0, strName = '', arShowValues = false, arCanBuyValues = [], arFilter = {}, tmpFilter = [], current = this.offers[this.offerNum].TREE, //CUSTOM START paramsUrl = window.location.search, pidRegExp = new RegExp(/[?&]pid=(\d+)/), pid = pidRegExp.exec(paramsUrl); if (pid && pid[1]) { for (i = 0; i < this.offers.length; i++) { if (this.offers[i].ID == pid[1]) { current = this.offers[i].TREE; } } } //CUSTOM END 

But how to rewrite it for my needs is not enough knowledge, maybe someone will tell that I will be very grateful.

    1 answer 1

    Hello! You need to go to the component settings and tabs:

    Basic parameters - Infoblock to write something like BLOCK_ID
    Page URL Management - Item ID Write ELEMENT_ID

    And when you access the directory, you pass your values ​​in the parameters,
    eg:

     магазин.ру/машина/?ELEMENT_ID=111&BLOCK_ID=3 ELEMENT_ID=111 - Элемент каталога BLOCK_ID=3 - Инфоблок каталога 

    Link generation templates are set in the information block setting on the first tab.

    This trick will work without component customization.
    But I would prefer the option to refine the component.

    • that's right, but I need the link not to the catalog or item, but to the item's sales offer (sku). These are different things, and references to sales offers are not set via the component setting - Evgen
    • I described to you an algorithm in which you can specify links to trade offers - tsx
    • You have described an algorithm for setting links to directories and items. the BLOCK property is responsible for the directories and the ELEMENT property is responsible not only for the element itself, but not for the sales offer of this element. - Evgen
    • so can be done for the offer - tsx