Magento 2 - Category page `addAttributeToSort` not working on custom product attribute
-
27-02-2021 - |
Domanda
I used the following code for sorting
on category page
.
if($this->getCurrentOrder() =="latest_products")
{
$collection->addAttributeToSort('significance', 'DESC')->getSelect()->order("e.entity_id desc");
}
In order to debug, I use following on my local instance
but surprisingly there is no ORDER BY significance DESC
in query as well
$collection->getSelect(); die;
This is my configuration settings
Soluzione
I faced similar kind of problem because I was working on category page product sorting. As I understand, you made custom product attribute significance
for sorting. So please make you have set Used in Product Listing
to Yes
in your custom product attribute. It is one of the possible cause.
As I look your configuration setting, the reason is because you set the Use Flat Catalog Product
to Yes
. So you have to set Used in Product Listing
to Yes
.
I hope this will help
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a magento.stackexchange