I have added positions to the products in category in the backend.

enter image description here

This position is working in Category page in Frontend. But this position of product is not working in Product list widget inside a CMS page.

enter image description here

How can this value of position be used in Product list widget?

This is value is stored in this table in magento2 database. enter image description here

  • If you product list widget then from which category you will pull the positions because one product could be assigned to multiple categories? – Sukumar Gorai Feb 12 at 13:05
  • Conditions If ALL of these conditions are TRUE : Category is 17 – Sanaullah Ahmad Feb 12 at 13:35

When I var_dump() my grid Product object, I found some data related to "cat_index_position" in it. This is actually the piece of data i had to use to sort my product list with. enter image description here

enter image description here

So i run two foreach loop to sort again my product array and i get my products positioned according to to value given it to on Category settings in magento admin.

$items          = $block->getProductCollection()->getItems();

$CatIndexPosition= array();
$positioned_items= array();
foreach ($items as $_item): 
endforeach ;
$zeroadjust = max(array_keys($CatIndexPosition))+1;
//echo $zeroadjust;exit;
foreach ($CatIndexPosition as $key => $value): 
endforeach ;

Now in our loop i replaced $items variable with $positioned_items which i have created.

<?php foreach ($positioned_items as $_item): ?>
    <div class="col-sm-6 <?php if($iterator==0){?>p-l<?php }?>">
        <div class="img-box">
|improve this answer|||||

Your Answer

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

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