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.
So I run two for each loop to sort again my product array and I get my products positioned according to the value given to on Category settings in Magento admin.
$items = $block->getProductCollection()->getItems();
var_dump($items);exit;
$CatIndexPosition= array();
$positioned_items= array();
foreach ($items as $_item):
$CatIndexPosition[$_item->getId()]=$_item->getCatIndexPosition();
endforeach ;
//print_r($CatIndexPosition);echo'<br>';//exit;
$zeroadjust = max(array_keys($CatIndexPosition))+1;
//echo $zeroadjust;exit;
foreach ($CatIndexPosition as $key => $value):
if($value=='0'){
$positioned_items[$zeroadjust]=$items[$key];
$zeroadjust++;
}
else{
$positioned_items[$value]=$items[$key];
}
endforeach ;
ksort($positioned_items);
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">