Prestashop: Faceted search indexing wrong prices and cannot be rebuilt by CRON

Created on 18 Jun 2020  路  17Comments  路  Source: PrestaShop/PrestaShop

Hi, investigating my issue https://github.com/PrestaShop/PrestaShop/issues/19810 I found out several issues with the price index of Faceted search. The result is, that product sorting is not working at all. Please, this is very important. Price order is the most used one, together with stock available.

Indexing only takes in effect specific prices

I have a product with following prices with tax:
Normal price: 1739
Specific price for group ID 4: 1394
Specific price for group ID 5: 1324

Resulting price index?
prices

Full price regeneration is not working from link

The link for full price index rebuild is only working if clicked from module settings, not by calling the URL. I cannot do full price regeneration by CRON.

https://drive.google.com/file/d/18VkSjmvoM2kBl_g3lrsSUta-Red4vH4t/view?usp=sharing

Additional information

  • PrestaShop version: 1.7.6.2
  • PHP version: 7.2
1.7.6.2 Bug Faceted search Fixed PR available

All 17 comments

Thanks for opening this issue! We will help you to keep its state consistent

Hi and thanks for your report.

About specific prices, there is already a pull request about it: https://github.com/PrestaShop/ps_facetedsearch/pull/159

Can you tell us more about why the CRON is not working? What errors do you have?

And to finish, about sorting, it's failing because there is already some issues with it :sweat_smile:

Kind regards

@PierreRambaud

About specific prices, there is already a pull request about it: PrestaShop/ps_facetedsearch#159

Yes, that could fix the issue. For now, I commented out specific prices in my stores.

Can you tell us more about why the CRON is not working? What errors do you have?

I cannot do full price regeneration by CRON.

https://www.domain.com/modules/ps_facetedsearch/ps_facetedsearch-price-indexer.php?token=XXXXXXXXXX works
https://www.domain.com/modules/ps_facetedsearch/ps_facetedsearch-price-indexer.php?token=XXXXXXXXXX&full=1 does not work

It works only if you click the button in the module config. It takes some time and goes through the products, but the prices are not regenerated. I believe it's due to $ajax variable set wrong.

And to finish, about sorting, it's failing because there is already some issues with it 馃槄

Yes, there are, but I think there is a major design flaw. It sorts product by price_min, am I right? But it cannot done be this way, everyone will have different prices calculated and shown.
For example, I have 2 different specific prices for my customer groups 4, 5. So, the order will be wrong, when group is set up1,2,3,4 in the context, because it sorts them by the price for group 5. And I am not even talking about specific rules for countries and whathever the hell Prestashop can be set up to 馃槃.

I was thinking about it _(maybe it's supposed to work that way)_ and I thought that when filtering products, min-max in the index could be used as a rough estimate of products to be selected from DB, and then you would precisely cut it by the final prices Product::priceCalculation() get you.

Not sure about price sorting though, it just has to be done by the final calculated price... Maybe a stupid question - The price for listed products is calculated anyway, so why is there even a price index?

Can you tell us more about why the CRON is not working? What errors do you have?

I cannot do full price regeneration by CRON.

https://www.domain.com/modules/ps_facetedsearch/ps_facetedsearch-price-indexer.php?token=XXXXXXXXXX works
https://www.domain.com/modules/ps_facetedsearch/ps_facetedsearch-price-indexer.php?token=XXXXXXXXXX&full=1 does not work

It works only if you click the button in the module config. It takes some time and goes through the products, but the prices are not regenerated. I believe it's due to $ajax variable set wrong.

Can you please show me how you run your cron's script? I just try and I'm not able to reproduce the error :thinking:

Yes, there are, but I think there is a major design flaw. It sorts product by price_min, am I right? But it cannot done be this way, everyone will have different prices calculated and shown.
For example, I have 2 different specific prices for my customer groups 4, 5. So, the order will be wrong, when group is set up1,2,3,4 in the context, because it sorts them by the price for group 5. And I am not even talking about specific rules for countries and whathever the hell Prestashop can be set up to smile.

I was thinking about it (maybe it's supposed to work that way) and I thought that when filtering products, min-max in the index could be used as a rough estimate of products to be selected from DB, and then you would precisely cut it by the final prices Product::priceCalculation() get you.

Not sure about price sorting though, it just has to be done by the final calculated price... Maybe a stupid question - The price for listed products is calculated anyway, so why is there even a price index?

I think the discussion should continue in the other issue ;)

@PierreRambaud I want to reindex all catalog every night, to prevent errors.

  1. Go to ps_layered_price_index and find one product. Set it's min and max price to zero.
  2. Go to faceted search settings and copy the URL from "regenerate price index" button.
    V媒st艡i啪ek
  3. Run it from your browser (or CRON, does not matter)
  4. It will run for the time it should, depending on the size of the catalog.
  5. Look to ps_layered_price_index, price of the product still zero.
  6. Now click on the "regenerate price index" button in the module. It will work.

@Hlavtox I did not manage to reproduce the issue.
From my terminal:

[3.6.8] got@got:~$ curl  'http://ps-develop.localhost/modules/ps_facetedsearch/ps_facetedsearch-price-indexer.php?token=22641c7d71&full=1'
19

Everything is ok in the database:
image

@PierreRambaud
https://drive.google.com/file/d/18VkSjmvoM2kBl_g3lrsSUta-Red4vH4t/view?usp=sharing

Coming back from vacation, I will try to have a look as soon as possible.

Ohhh, regarding the code, the ajax parameter is mandatory :thinking:

@PierreRambaud I updated the issue description for clarity. ;-)

@Hlavtox Tell me if everything is ok with https://github.com/PrestaShop/ps_facetedsearch/pull/177 ? :)

@PierreRambaud No difference. It indexes only first 100 products.
Without your PR, it outputs 1 at the end, with your PR, it outputs ID of the last product indexed.

Make 500 products, index them, then go to DB, set zeroes everywhere. If you then run it by link, only first 100 are indexed. If you click button, all of them.

@Hlavtox I tried with more than 100 products, and all products are properly indexed :/

@PierreRambaud Tried your PR with the updated changes. Outputs number of products to be processed.
Still indexes only first 100 products.

The second pass of indexPrices is called without $smart = true enabled and it makes the indexing not to work.

Adding $smart = true;after private function indexPrices($cursor = 0, $full = false, $ajax = false, $smart = false) {seems to make it work properly in both link and ajax mode.

@PierreRambaud Tried your PR with the updated changes. Outputs number of products to be processed.
Still indexes only first 100 products.

The second pass of indexPrices is called without $smart = true enabled and it makes the indexing not to work.

Adding $smart = true;after private function indexPrices($cursor = 0, $full = false, $ajax = false, $smart = false) {seems to make it work properly in both link and ajax mode.

Nice catch :+1:
Could you have a new check?

@PierreRambaud Works properly now!!!
All zeroes, HTTP -> fine
All, zeroes, AJAX-> fine
Empty table, HTTP -> fine
Empty table, AJAX -> fine

You can merge it 馃殌

@PierreRambaud Works properly now!!!
All zeroes, HTTP -> fine
All, zeroes, AJAX-> fine
Empty table, HTTP -> fine
Empty table, AJAX -> fine

You can merge it

Hell yeah!

Was this page helpful?
0 / 5 - 0 ratings