G
G
glem13372020-07-07 12:58:48
1C-Bitrix
glem1337, 2020-07-07 12:58:48

How to implement a unique sorting index for a product in a section?

Good day!

The client needs to manage the sorting of each product in all sections of the site. Management must be at the partition level. That is, if the sort value for a particular section is filled, then we use it, otherwise we use the standard sort index.

So far, only the creation of a custom field comes to mind, which will display all the products belonging to the section and additional. input field for the index opposite the product name.

Questions:

  1. Is it optimal to solve this with a custom field?
  2. The question follows from the first. Have you had experience with a similar problem and how did you solve it?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
Y
Yaroslav Alexandrov, 2020-07-07
@alexyarik

1) You can receive and process your custom section field in result_modifier.php
2) Starting from version 18.6.900, the inheritors of the \Bitrix\Iblock\Component\ElementList class
support sorting by element ID sequence.
You can modify the logic in result_modifier.php and pass $arElements // an array of IDs in the required order for the id field - by ID in the "ELEMENT_SORT_ORDER" key
https://dev.1c-bitrix.ru/user_help/components/cont...

A
Anton, 2020-07-07
@anton99zel

Let's add to the standard sorting fields, in our case "number of views, i.e. popularity - shows", our own sortings created on the properties of the element - PRIORITET - if we want to raise the element higher in the list and NOSKLAD - if we want to remove goods that are missing in stock below. We will not display, but we will take into account:

$arSort = array("PROPERTY_NOSKLAD"=>"ASC", "PROPERTY_PRIORITET"=>"DESC", "shows"=>"DESC");
if (
    isset($_GET["sort"]) && isset($_GET["method"]) && (
            $_GET["sort"] == "name" ||
            $_GET["sort"] == "catalog_PRICE_1" ||
            $_GET["sort"] == "shows" ||
            $_GET["sort"] == "created")){
$arSort = array($_GET["sort"]=>$_GET["method"]);
  }

As a result, in the component or using the api, you can pass an array describing the directions and sorting options.
$res = CIBlockElement::GetList($arSort, Array($arrFilter, $arFilter), false, Array("bShowAll"=>false, "nPageSize"=>18, "iNumPage"=>$pn), $arSelect);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question