-
Notifications
You must be signed in to change notification settings - Fork 9.3k
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
Magento 2.0.4 Layered Navigation Random Product Bug or Feature #4132
Comments
Is there any updates on this issue ? |
@choukalos please check this one |
This problem still persists in Magento 2.1.2. Is there any update on this? I noticed today that I cannot reproduce it locally, but only on the production environment. Could it be that it's some MYSQL setting that handles how entities with the same column value are sorted? (like, if you have 100 products in a category with position '0', are they ordered randomly or ordered by ID, or not at all and let the storage engine handle it (which seems the case right now)). |
Ok, so this is strange. I thought that the sortorder issue might be database related. So I wrote a script that would update all the positions of the products in each category. Something like this: $categoryIds = $this->connection->fetchCol(
$this->connection->select()->distinct()->from('catalog_category_product', 'category_id'));
foreach ($categoryIds as $categoryId) {
$entries = $this->connection->fetchAll(
$this->connection->select()
->from('catalog_category_product')
->where('category_id = ?', $categoryId)
->order('position ASC'),
[],
\PDO::FETCH_ASSOC
);
foreach ($entries as $idx => $entry) {
$this->connection->update(
'catalog_category_product',
['position' => $idx],
'entity_id = ' . $entry['entity_id']
);
}
} I also flushed cached and re-indexed everything after this. The strange partWhen I go to the category in question, the products are still sorted randomly. However, when I reverse the sortorder by clicking the arrow next to the sorter, the URL gets appended with When I click the arrow again, the But... now when I reload the page, so the URL doesn't change, the products are sorted randomly again. So there goes my theory about sorting that goes wrong when the positions are duplicate. I'll investigate it further... |
Okay, so I adjusted my script to filter out all products in my category that where set to be _'Not visibly Individually' by replacing the update script with the following: foreach ($entries as $idx => $entry) {
// Check if this product is allowed to be visible individually:
$visiblity = $this->connection->fetchOne(
$this->connection->select()
->from(['cpei' => 'catalog_product_entity_int'], 'value')
->join(['ea' => 'eav_attribute'], 'ea.attribute_id = cpei.attribute_id', null)
->where('cpei.entity_id = ?', $entry['product_id'])
->where('ea.attribute_code = ?', 'visibility')
->where('ea.entity_type_id = ?', 4)
);
if ((int) $visiblity === \Magento\Catalog\Model\Product\Visibility::VISIBILITY_NOT_VISIBLE) {
// Delete this entry:
$this->connection->delete('catalog_category_product', 'entity_id = ' . $entry['entity_id']);
} else {
// Update this entry:
$this->connection->update(
'catalog_category_product',
['position' => $idx],
'entity_id = ' . $entry['entity_id']
);
}
} But no luck there. Still the same behaviour is I write in my previous comment. But I guess we can now rule out the following:
I noticed that the sorting option on the catalog page (which shows the proper results) is done by an XHR request. I'm now going to analyse the SQL queries built by the template and by the XHR request to see if they can explain what might be going wrong. |
My previous comment made me wonder: Since I've noticed before that the URL changes, (with the addition of But no, reloading the page also resulted in the wrong results. It looks like the XHR request gets the sorting right, whereas the rendering from page initialisation doesn't. |
Another detail: sorting by page initialisation always seem to be by entity_id, ascending. Could it be that the sort direction is not taken into account at all? |
Hm, the only thing I notice when comparing SQL queries generated by ... is that when I sort the category with an XHR request, the line:
gets added to the SQL queries. Which makes a lot of sense why they are sorted correctly. So the main question is, why isn't this sorting added when navigating to the category from an URL? |
ARGH! Kill me please... Turns out there was an extension that did this to get the current product collection:
Turns out that if you invoke Well I hope this keeps anyone else from wasting 3 hours of debugging and backtracking. Still not sure if this ticket can be closed though... @YaguPatel @piotrekkaminski can you confirm if this is still an issue or can this ticket be closed? Edit: as for the 'why': the product list has some business logic in it's |
@kanduvisla closing this issue as related to third-party extension. Discussion is welcome in #8388 and related issue. |
For people coming across this, I'm still having this same issue when I import products (2.1.9). This is with flat categories enabled (not sure if that matters). I'll try to reproduce on a clean install. |
- reverting backward incompatible changes
Steps to reproduce
Make sure you have Order by "Position" selected. and i have tested this for all the product having "position value 1 or same for all the products"
Expected result
Actual result
I have also tested the same thing without selection of layered navigation option. It stick with the product order return first time. If you choose any option from layered navigation it shows random order for filtered product with each page reload.
Example:
Let say,
Hope you get my concern.
Thanks
The text was updated successfully, but these errors were encountered: