Skip to content

Commit 24d1e79

Browse files
author
Pavel
committed
Issue-13556 Modified source model "app/code/Magento/CatalogInventory/Model/Source/Stock.php" - overridden parent method "addValueSortToCollection" for adding sorting by stock items qty.
1 parent 6d5cf58 commit 24d1e79

File tree

1 file changed

+19
-0
lines changed
  • app/code/Magento/CatalogInventory/Model/Source

1 file changed

+19
-0
lines changed

app/code/Magento/CatalogInventory/Model/Source/Stock.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,23 @@ public function getAllOptions()
2626
['value' => \Magento\CatalogInventory\Model\Stock::STOCK_OUT_OF_STOCK, 'label' => __('Out of Stock')]
2727
];
2828
}
29+
30+
/**
31+
* Add Value Sort To Collection Select
32+
*
33+
* @param \Magento\Eav\Model\Entity\Collection\AbstractCollection $collection
34+
* @param string $dir
35+
*
36+
* @return $this
37+
*/
38+
public function addValueSortToCollection($collection, $dir = \Magento\Framework\Data\Collection::SORT_ORDER_DESC)
39+
{
40+
$collection->getSelect()->joinLeft(
41+
['stock_item_table' => 'cataloginventory_stock_item'],
42+
"e.entity_id=stock_item_table.product_id",
43+
[]
44+
);
45+
$collection->getSelect()->order("stock_item_table.qty $dir");
46+
return $this
47+
}
2948
}

0 commit comments

Comments
 (0)