Z
Z
zzakirow2020-08-26 19:28:57
1C-Bitrix
zzakirow, 2020-08-26 19:28:57

How to modify smart filter?

I would like to show round numbers in the smart filter in the slider (0, 100, 200, 300, 400).
Bitrix takes them from the database. There are different numbers.
Accordingly, they are calculated in the slider themselves.

In the template, I found where you can change these numbers:

$value1 = number_format($arItem["VALUES"]["MIN"]["VALUE"], $precision, ".", "");
$value2 = number_format($arItem["VALUES"]["MIN"]["VALUE"] + $step, $precision, ".", "");
$value3 = number_format($arItem["VALUES"]["MIN"]["VALUE"] + $step * 2, $precision, ".", "");
$value4 = number_format($arItem["VALUES"]["MIN"]["VALUE"] + $step * 3, $precision, ".", "");
$value5 = number_format($arItem["VALUES"]["MAX"]["VALUE"], $precision, ".", "");


But, when I move the slider, I see that it continues to be calculated according to the old scheme. Receiving data from the server.
Most likely this is all done in the template script.js.

How can this problem be solved without editing script.js?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
P
PetrPo, 2020-08-26
@zzakirow

Here I read, it seems that the question is normal and you are moving in the right direction, and you understand that you need to edit script.js. And in the end, advise how to fix javascript without editing javascript. Yes, no way!
Do you have a javascript phobia? )
1. Open template.php, look for where new BX.Iblock.SmartFilter is called there, parameters above this call

$arJsParams = array(
  "leftSlider" => 'left_slider_'.$key,
  // .............

  // добавляешь свой параметр, например step (значение = шаг)
  "step" => 100
);

2. Open script.js and look for BX.Iblock.SmartFilter = (function() there inside
var SmartFilter = function(arParams)
{
  if (typeof arParams === 'object')
  {
    this.leftSlider = BX(arParams.leftSlider);
    // ...........
    
    // где-нибудь здесь добавляешь
    this.step = arParams.step || 1;
  }
};

3. Looking for a feature
SmartFilter.prototype.recountMinPrice = function()
{
  var newMinPrice = (this.priceDiff*this.leftPercent)/100;
  newMinPrice = (this.minPrice + newMinPrice).toFixed(this.precision);
  
  // добавляешь эту строку
  newMinPrice = Math.round(newMinPrice/this.step) * this.step;

  if (newMinPrice != this.minPrice)
    this.minInput.value = newMinPrice;
  else
    this.minInput.value = "";
  /** @global JCSmartFilter smartFilter */
  smartFilter.keyup(this.minInput);
};

4. Looking for a feature
SmartFilter.prototype.recountMaxPrice = function()
{
  var newMaxPrice = (this.priceDiff*this.rightPercent)/100;
  newMaxPrice = (this.maxPrice - newMaxPrice).toFixed(this.precision);
  
  // добавляешь эту строку
  newMaxPrice = Math.round(newMaxPrice/this.step) * this.step;

  if (newMaxPrice != this.maxPrice)
    this.maxInput.value = newMaxPrice;
  else
    this.maxInput.value = "";
  /** @global JCSmartFilter smartFilter */
  smartFilter.keyup(this.maxInput);
};

PS in template.php there are two calls to new BX.Iblock.SmartFilter - first = prices, second = other sliders

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question