2

I want to display featured product of category at top of the product list with all filters, pagination and sorting.

For Example: I have an array of ID's that should show first in collection when category page open.

3 Answers 3

2

You can give the position of product which you have display top of the product list.

Go Adminpanel >> Catalog >> Categories.

After that edit that category that you want to show featured product on top. And click on "Product in Category"

Add position of that particular product which you want to show in top like below screen shot.

enter image description here

And check that product. And also one more thing if you don't get the product that run commands and check after that.

Thanks.

5
  • Thanks but i don't want in this way, i have an array of ID's those should show on top when category load.
    – Waqar
    Feb 21, 2019 at 5:02
  • Then post your code here so we can understand and give answer of that. Feb 21, 2019 at 5:25
  • Here is my code : $this->_collection->getSelect()->order(new \Zend_Db_Expr('FIELD(e.entity_id, ' . implode(',', $productIds).')'));
    – Waqar
    Feb 21, 2019 at 8:16
  • It is working but adding the required products at the end of the list
    – Waqar
    Feb 21, 2019 at 8:17
  • @Waqar Yes , have you got any solution to show on top of the listing page
    – Mahendra
    Dec 4, 2020 at 9:12
0

You can give the position of the productby using below way

$productIds = array(35731,35562, 35622, 35631);
    $collection->getSelect()->order(new \Zend_Db_Expr('FIELD(e.entity_id, ' . implode(',', $productIds).') DESC'));
0

Try this

$productIds = array(35731,35562, 35622);
            $collection->getSelect()->order(new \Zend_Db_Expr('FIELD(e.entity_id, ' . implode(',', $productIds).') DESC'));

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.