Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sorting not applied #431

Closed
diybook opened this issue May 28, 2017 · 7 comments
Closed

Sorting not applied #431

diybook opened this issue May 28, 2017 · 7 comments

Comments

@diybook
Copy link

diybook commented May 28, 2017

Changing the sort order on category page do not has any effect on the results.

Preconditions

Magento CE with custom theme and some custom modules. Disabling elastic search results in an collection with sort order in.

Magento Version : 2.1.6
ElasticSuite Version : 2.3.5
Environment : Development mode

Third party modules :
Amasty/Stockstatus
Apptrian/ImageOptimizer
Fooman/EmailAttachments
Fooman/PrintOrderPdf
Magenerds/BasePrice
Some custom Modules

Steps to reproduce

  1. Product Attribute Name is set to "Used for Sorting in Product Listing"
  2. Open Category Page and sort by name (default sort)
  3. Adding in echo $_productCollection->getSelect()->__toString(); after $_productCollection = $block->getLoadedProductCollection(); in Magento/Catalog/view/frontend/templates/product/list.phtml gives the following result:

SELECT e.*, price_index.price, price_index.tax_class_id, price_index.final_price, IF(price_index.tier_price IS NOT NULL, LEAST(price_index.min_price, price_index.tier_price), price_index.min_price) AS minimal_price, price_index.min_price, price_index.max_price, price_index.tier_price, stock_status_index.stock_status AS is_salable FROM catalog_product_entity AS e INNER JOIN catalog_product_index_price AS price_index ON price_index.entity_id = e.entity_id AND price_index.website_id = '1' AND price_index.customer_group_id = 0 LEFT JOIN cataloginventory_stock_status AS stock_status_index ON e.entity_id = stock_status_index.product_id AND stock_status_index.website_id = 0 AND stock_status_index.stock_id = 1 WHERE (e.entity_id IN (411695, 411694, 411142, 410357, 410309, 410277, 410271, 410177, 410160, 410159, 410120, 410035, 409949, 409909, 409908, 409893, 409802, 409766, 409751, 409743, 409728, 409712, 409634, 409305, 409302, 408907, 408906, 408701, 408686, 408682, 408672, 408655, 407829, 397393, 397324, 397316, 397258, 397254, 397178, 397177, 397176)) LIMIT 40

Limit is applied but not the order by.

  1. Neither Name, Price or any other sorting is ever applied.

Expected result

  1. Sort order should be set in collection.

Actual result

  1. Sort order is never set!

I've tried to debug this but not sure where to go on. Where the sort order is set to that collection? It seems that this collection is set externally by elastic search, but I've not found that piece of code.

I've also tried to inspect the event "catalog_block_product_list_collection" but the output of this sql is even worse. Not Limit, no order by no stock_status as is_salable...

SELECT e.*, price_index.price, price_index.tax_class_id, price_index.final_price, IF(price_index.tier_price IS NOT NULL, LEAST(price_index.min_price, price_index.tier_price), price_index.min_price) AS minimal_price, price_index.min_price, price_index.max_price, price_index.tier_price FROM catalog_product_entity AS e INNER JOIN catalog_product_index_price AS price_index ON price_index.entity_id = e.entity_id AND price_index.website_id = '1' AND price_index.customer_group_id = 0 WHERE (e.entity_id IN (411695, 411694, 411142, 410357, 410309, 410277, 410271, 410177, 410160, 410159, 410120, 410035, 409949, 409909, 409908, 409893, 409802, 409766, 409751, 409743, 409728, 409712, 409634, 409305, 409302, 408907, 408906, 408701, 408686, 408682, 408672, 408655, 407829, 397393, 397324, 397316, 397258, 397254, 397178, 397177, 397176))

Any ideas where to go on debugging?

Best regards

@romainruaud
Copy link
Collaborator

Hello,

the sort order is set on the ES query, you are right.

Since this error is not present on our demo environment (see http://demo.magento-elastic-suite.io/index.php/men/tops-men/jackets-men.html?product_list_order=name ), could you please ensure you still reproduce this bug when you de-activate your third party modules ?

Eg. : Do you have any modules which could be rewriting / pluggin-ing the Product Collection ?

@diybook
Copy link
Author

diybook commented May 29, 2017

Hi @romainruaud,

Thanks for your fast answer. You are right. Elasticsearch is not the cause of this issue. Deactivating all other modules helped. So I have to go on searching the problem. I thought I've done that already but it seems that I missed a module while deactivating. Sorry for the question, I did everything possible and got stuck with no idea how to go on.

Thanks again.

@romainruaud
Copy link
Collaborator

Hello @diybook

No problem, you are always welcome if you need more informations about how is working our module !

I close this issue for now, since the issue does not seem to be related to elasticsuite. Feel free to reopen it if needed.

Best regards

@diybook
Copy link
Author

diybook commented May 30, 2017

Hi @romainruaud,

I may have found the issue and maybe you can help. Maybe it's also relevant for ElasticSearch. We render the filters of the layered navigation before product.list on category page. Of course it is duplicated from sidebar but with images.

Therefore we get the filters and go through the items of the filters in our custom block. At that moment they are not initialized and will be initialized. For that (cause it is an Attribute) ElasticSearch is getting the productCollection through: $productCollection = $this->getLayer()->getProductCollection();

After that the collection of the product.list is wrong. It may be an Magento issue or it may be an ES issue. I'm not sure.

When moving that block below the product.list everything works. But the block should be displayed before. Any ideas?

Best regards,
Gerald

@romainruaud
Copy link
Collaborator

Oh well I see.

Unfortunately there is no solutions here. This is due to Magento behavior as I explained here : https://github.com/Smile-SA/elasticsuite/wiki/FAQ#i-have-problems-with-the-pagination--sorting

There is an issue on the Magento's repo describing the problem : magento/magento2#7253

Since the toolbar and product list are interdependants, there is not much we can do to fix this.

Best regards,

@PieterCappelle
Copy link

@diybook Just want to say thank you for your explanation. Was already some hours in trouble/debugging and your post pointed me in the right way. Thanks!!!

@galanis-a
Copy link

Hello all,

@PieterCappelle have solve this issue, cause I'm in that position myself right now. My custom sorting doesn't work after I started using ES.

Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants