1

I am creating a product loop on the homepage of our site. The site has smile elastic search running. I have set up the manual sort for products in the category admin and can loop thru the products, but I am not able to sort by position.

<?php foreach ($category as $categoryId): ?>
<?php 

$category = $categoryFactory->create()->load($categoryId);
$categoryProducts = $category->getProductCollection()
                        ->addAttributeToSort('position','ASC')
                        ->addAttributeToSelect('*');

?>

<?php foreach ($categoryProducts as $product): ?>

    // do something with the products

<?php endforeach ?>
  • I am also facing the same situation..could you share the code to sort the product collection by position. – aravind Apr 25 at 4:53
  • I ended up sorting outside of ES with Magento's built-in sorting. Magento Admin can't change this when ES is active. I set the sort position in the mysql table catalog_category_product. – XMQBbYmRDejbwKasTRhnNmXaUfxsnb Apr 25 at 14:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.