$_REQUEST
and the API API 1C-Bitrix GetCurPageParam()
to transfer data to this array.PAGE_ELEMENT_COUNT
. In it, we will pass the amount selected by the user using $_REQUEST
and GetCurPageParam()
.catalog.section
. If the complex catalog
component is used, then in the file in which the component catalog.section
component catalog.section
goods on the necessary page. <?php $pageElementCount = $arParams["PAGE_ELEMENT_COUNT"]; if (array_key_exists("showBy", $_REQUEST)) { if ( intVal($_REQUEST["showBy"]) && in_array(intVal($_REQUEST["showBy"]), array(18, 36, 54, 72)) ) { $pageElementCount = intVal($_REQUEST["showBy"]); $_SESSION["showBy"] = $pageElementCount; } elseif ($_SESSION["showBy"]) { $pageElementCount = intVal($_SESSION["showBy"]); } } ?> <div class="show_number"> <span class="show_title"> </span> <span class="number_list"> <? for( $i = 18; $i <= 72; $i+=18 ) : ?> <a rel="nofollow" <? if ($i == $pageElementCount): ?>class="current"<? endif; ?> href="<?= $APPLICATION->GetCurPageParam('showBy='.$i, array('showBy', 'mode')) ?>" > <span><?= $i ?></span> </a> <? endfor; ?> </span> </div>
<?php $APPLICATION->IncludeComponent( "bitrix:catalog.section", ... "PAGE_ELEMENT_COUNT" => $pageElementCount, ... ?>
GetCurPageParam()
method we will pass two parameters sortBy
and orderBy
. And then in the corresponding variables pass them to the parameters of the component "ELEMENT_SORT_FIELD"
and "ELEMENT_SORT_ORDER"
respectively. By default, sorting should be carried out using the internal sorting field 1C-Bitrix - sort
. <?php if (isset($_REQUEST['orderBy'])) { if ($_REQUEST['orderBy'] == 'asc') { $orderBy = 'desc'; } else { $orderBy = 'asc'; } } else { $orderBy = 'asc'; } ?>
<div class="sort-section"> : <a rel="nofollow" <? if ($sortBy == 'price') : ?> class="current-sort" <? endif; ?> href="<?= $APPLICATION->GetCurPageParam('sortBy=price&orderBy='.$orderBy, array('sortBy', 'orderBy')) ?>" > <span class="sort"></span> </a> <a rel="nofollow" <? if ($sortBy == 'name') : ?> class="current-sort" <? endif; ?> href="<?= $APPLICATION->GetCurPageParam('sortBy=name&orderBy='.$orderBy, array('sortBy', 'orderBy')) ?>" > <span class="sort"></span> </a> <a rel="nofollow" <? if ($sortBy == 'date') : ?> class="current-sort" <? endif; ?> href="<?= $APPLICATION->GetCurPageParam('sortBy=date&orderBy='.$orderBy, array('sortBy', 'orderBy')) ?>" > <span class="sort"></span> </a> </div>
"ELEMENT_SORT_FIELD"
field for sorting by product name without additional intervention, but for the date and price we need to clarify which of the information block element parameters we mean.'timestamp_x'
field, which is responsible for the change date. For the price, we need to find out the name of the price type, which is derived from the information block element field. To do this, print the array $arItem
in the component template (in my case catalog.section
) or with var_dump($arItem);
either echo ''; print_r($arItem); echo ' ';
echo ''; print_r($arItem); echo ' ';
. We find the array field responsible for the price output and copy its name, in my case it turned out to be CATALOG_PRICE_1
. It should be noted that in the case of the price you need to use the name of the field that contains the value of the price without a currency.$sortBy
variable: <?php if (isset($_REQUEST['sortBy'])) { $sortBy = $_REQUEST['sortBy']; } else { $sortBy = 'sort'; } if ($sortBy=='price') { $sortBy = 'CATALOG_PRICE_1'; } if ($sortBy=='date') { $sortBy = 'timestamp_x'; } ?>
<?php $APPLICATION->IncludeComponent( "bitrix:catalog.section", ... "ELEMENT_SORT_FIELD" => $sortBy, "ELEMENT_SORT_ORDER" => $orderBy, ... ?>
Source: https://habr.com/ru/post/271307/
All Articles