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(); }); });
{ 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.