AddStockStatusToCollection.php 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\CatalogInventory\Model;
  7. use Magento\Catalog\Model\ResourceModel\Product\Collection;
  8. /**
  9. * Catalog inventory module plugin
  10. */
  11. class AddStockStatusToCollection
  12. {
  13. /**
  14. * @var \Magento\CatalogInventory\Helper\Stock
  15. */
  16. protected $stockHelper;
  17. /**
  18. * @param \Magento\CatalogInventory\Model\Configuration $configuration
  19. * @param \Magento\CatalogInventory\Helper\Stock $stockHelper
  20. */
  21. public function __construct(
  22. \Magento\CatalogInventory\Helper\Stock $stockHelper
  23. ) {
  24. $this->stockHelper = $stockHelper;
  25. }
  26. /**
  27. * @param Collection $productCollection
  28. * @param bool $printQuery
  29. * @param bool $logQuery
  30. * @return array
  31. */
  32. public function beforeLoad(Collection $productCollection, $printQuery = false, $logQuery = false)
  33. {
  34. $this->stockHelper->addIsInStockFilterToCollection($productCollection);
  35. return [$printQuery, $logQuery];
  36. }
  37. }