0

I am trying to sort products as per the custom attribute value "new_sort_by" but unfortunately I could not filter. please check my code

  1. Create a product attribute "new_sort_by"

  2. add the below code for filter products.

     $productCollection = $block->getProductCollection();
     $productCollectionnewproducts = $productCollection->addAttributeToSort("new_sort_by","ASC")
                                     ->addAttributeToSort('name', 'ASC');
     echo $productCollectionnewproducts->getSelect()->__toString();
     $itemsnewproducts = $productCollectionnewproducts->getItems();
    
  3. Used for Sorting in Product Listing = Yes

save the attribute and clear the cache.

also re-index the data.

I am saving products with attribute (new_sort_by) value in number (1,2,3,4,5) and want to sort products with the attribute value in ASC order.

1 Answer 1

0

check below settings in attribute code

Used for Sorting in Product Listing = Yes

save the attribute and clear the cache.

also re-index the data.
3
  • I have already these data. Sep 16, 2020 at 7:29
  • check if setOrder() method is in your collection. Sep 16, 2020 at 8:40
  • I have already checked that but it's not working Sep 16, 2020 at 8:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.