Stock.php 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\CatalogInventory\Model\Source;
  7. use Magento\Eav\Model\Entity\Attribute\Source\AbstractSource;
  8. /**
  9. * CatalogInventory Stock source model
  10. * @api
  11. * @since 100.0.2
  12. *
  13. * @deprecated 100.3.0 Replaced with Multi Source Inventory
  14. * @link https://devdocs.magento.com/guides/v2.3/inventory/index.html
  15. * @link https://devdocs.magento.com/guides/v2.3/inventory/catalog-inventory-replacements.html
  16. */
  17. class Stock extends AbstractSource
  18. {
  19. /**
  20. * Retrieve option array
  21. *
  22. * @return array
  23. */
  24. public function getAllOptions()
  25. {
  26. return [
  27. ['value' => \Magento\CatalogInventory\Model\Stock::STOCK_IN_STOCK, 'label' => __('In Stock')],
  28. ['value' => \Magento\CatalogInventory\Model\Stock::STOCK_OUT_OF_STOCK, 'label' => __('Out of Stock')]
  29. ];
  30. }
  31. /**
  32. * Add Value Sort To Collection Select.
  33. *
  34. * @param \Magento\Eav\Model\Entity\Collection\AbstractCollection $collection
  35. * @param string $dir
  36. *
  37. * @return $this
  38. * @since 100.2.4
  39. */
  40. public function addValueSortToCollection($collection, $dir = \Magento\Framework\Data\Collection::SORT_ORDER_DESC)
  41. {
  42. $collection->getSelect()->joinLeft(
  43. ['stock_item_table' => 'cataloginventory_stock_item'],
  44. "e.entity_id=stock_item_table.product_id",
  45. []
  46. );
  47. $collection->getSelect()->order("stock_item_table.qty $dir");
  48. return $this;
  49. }
  50. }