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

Manual sort gets set back to automatic sort #2948

Closed
mstoiber opened this issue May 23, 2023 · 8 comments · Fixed by #3386
Closed

Manual sort gets set back to automatic sort #2948

mstoiber opened this issue May 23, 2023 · 8 comments · Fixed by #3386
Assignees
Labels

Comments

@mstoiber
Copy link

Our customer has a problem where when they change the sort order and/or change some products back to automatic search many products automatically get set back to automatic sort only some remain in manual sort.

We found out that a reload of the site may change it back.
Also sometimes after rearranging the sort order, the category does not show all products.

Environment

Magento Version: 2.4.5-p1
ElasticSuite Version: 2.10.15.1

Steps to reproduce

  1. Change the sort order of products
  2. Repeat as often as necessary

Expected result

  1. Manual sort order remaining

Actual result

  1. Many products get set back to automatic sort
@vahonc
Copy link
Collaborator

vahonc commented May 31, 2023

Hello @mstoiber,

We have already encountered similar problems and each time it is very difficult to reproduce them in a standard environment. Therefore, we need more information. You can specify in what time interval the sorting changed back, within a few minutes or hours, or maybe days. Maybe you can provide more detailed steps for reproducing, with a mention of how exactly you do it.

BR,
Vadym

@mstoiber
Copy link
Author

mstoiber commented Jun 1, 2023

Hello, thanks for the reply!

It is also very difficult to reproduce for us.
The sorting disappeared right away and by reloading I managed to get it back instantly.

For reproduction of the error, I changed the sorting order multiple times and saved it, also sometimes I just changed a few items to automatic sort myself. After some tries, the occurred.

@pointia
Copy link

pointia commented Jun 30, 2023

Are there any news on this topic?
To me it looks like as if there are some problems with the backend javascript.

I figured out that in all the previous request I had about 410 items in the productPositions Array
\Smile\ElasticsuiteVirtualCategory\Plugin\Catalog\Category\SaveProductsPositions::unserializeProductPositions

But suddenly there were only 95.

I checked the payload that was sent to the server and there were only 95 items in there, so there must be a problem with the javascript.

I'will try to investigate that further and it would be highly appreciated if you @vahonc could also take a look into this problem.

@pointia
Copy link

pointia commented Jul 5, 2023

@vahonc I figured out that this is not a JS-Related issue. The issue possibly lies within Elasticsearch or PHP.

When loading the Category Page I debugged how many manually sorted products get posted to the preview controller \Smile\ElasticsuiteVirtualCategory\Controller\Adminhtml\Category\Virtual\Preview
this controller does receive the correct amount. I checked that by adding a logging statement to \Smile\ElasticsuiteVirtualCategory\Controller\Adminhtml\Category\Virtual\Preview::setSortedProducts.

Most of the time everything is ok, but sometimes it happens that the $responseData from the getPreviewObject() in the execute function returns a significantly lower amount of products. And this is what causes the problem.

I tried to call the preview with xhr request (to eliminate Magento JS-logic) and also while indexing Elasticsearch, but I was not able to reproduce the behavior consistently.

@MTheProgrammer
Copy link
Contributor

Same here, but it is really hard to reproduce.

One possibility is that when jsonDecode throws an exception $productPositions is set to an empty array. In case of a large POST request payload, the "sorted_products" JSON field may be truncated.

https://github.com/Smile-SA/elasticsuite/blob/2.11.x/src/module-elasticsuite-virtual-category/Plugin/Catalog/Category/SaveProductsPositions.php

    private function unserializeProductPositions(\Magento\Catalog\Model\Category $category)
    {
        $productPositions = $category->getSortedProducts() ? $category->getSortedProducts() : [];

        if (is_string($productPositions)) {
            try {
                $productPositions = $this->jsonHelper->jsonDecode($productPositions);
            } catch (\Exception $e) {
                $productPositions = []; // This will reset products on exception
            }
        }

        $category->setSortedProducts($productPositions);

        return $this;
    }

@ganeddact
Copy link

We've incurred in a similar issue when upgrading from Magento 2.4.3-p3 with Elasticsuite 2.10, to Magento 2.4.6-p3 with Elasticsuite 2.11.
Categories with manually ordered items reverted back to automatic order, losing a lot of effort spent in ordering.
Not sure what could be the cause, if the Magento upgrade or the Elasticsuite upgrade.

@lytesaber
Copy link

Having a similar issue with a client trying to manually sort around 100 product items within their sale category. Every so often the sale category will randomly revert back to automatic sort clearing the manual sort positions. The only solution we've been able to offer is to just persist with reconfiguring the manual sorting positions, this isn't ideal as it takes a fair amount of time to reconfigure 100+ product positions.

Not that this has any definitive basis but could this issue be due to the quantity of product items being manually sorted within a category? Our client doesn't experience this issue on any other category where they manually sort a smaller collection of product items whereas in their sale category, they sort 100+ products with manual positioning.

Magento Version: 2.4.5-p7
Elasticusuite Version: 2.10.19.3

@rbayet rbayet assigned vahonc and unassigned mstoiber Jul 8, 2024
@romainruaud
Copy link
Collaborator

@MTheProgrammer is right, this occurs when truncated data get sent to the backend.

As a security mechanism, @vahonc can you implement the following :

on this line : https://github.com/Smile-SA/elasticsuite/blob/2.11.x/src/module-elasticsuite-virtual-category/Plugin/Catalog/Category/SaveProductsPositions.php#L158

Instead of setting the array to empty, just fallback to the previously existing list of Products. Maybe the existing list is in $category->getSortedProducts() or you'll have to fetch it from here : https://github.com/Smile-SA/elasticsuite/blob/2.11.x/src/module-elasticsuite-virtual-category/Model/ResourceModel/Category/Product/Position.php#L78

And add a warning message saying something like "Something went wrong while saving your product positions, they have been switched back to their last known state".

Regards

@romainruaud romainruaud added bug priority Priority and removed help wanted labels Aug 2, 2024
vahonc added a commit to vahonc/elasticsuite that referenced this issue Sep 4, 2024
rbayet pushed a commit to rbayet/elasticsuite that referenced this issue Sep 16, 2024
rbayet added a commit that referenced this issue Sep 16, 2024
…ck-to-last-valid-product-positions-2.10-fix

[Catalog] Fix #2948 fallback to the last known valid product positions
@rbayet rbayet closed this as completed in 2143600 Sep 16, 2024
vahonc added a commit to vahonc/elasticsuite that referenced this issue Nov 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment