Stock.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\CatalogInventory\Model\Indexer;
  7. use Magento\Framework\Indexer\CacheContext;
  8. class Stock implements \Magento\Framework\Indexer\ActionInterface, \Magento\Framework\Mview\ActionInterface
  9. {
  10. /**
  11. * @var \Magento\CatalogInventory\Model\Indexer\Stock\Action\Row
  12. */
  13. protected $_productStockIndexerRow;
  14. /**
  15. * @var \Magento\CatalogInventory\Model\Indexer\Stock\Action\Rows
  16. */
  17. protected $_productStockIndexerRows;
  18. /**
  19. * @var \Magento\CatalogInventory\Model\Indexer\Stock\Action\Full
  20. */
  21. protected $_productStockIndexerFull;
  22. /**
  23. * @var \Magento\Framework\Indexer\CacheContext
  24. */
  25. private $cacheContext;
  26. /**
  27. * @param Stock\Action\Row $productStockIndexerRow
  28. * @param Stock\Action\Rows $productStockIndexerRows
  29. * @param Stock\Action\Full $productStockIndexerFull
  30. */
  31. public function __construct(
  32. \Magento\CatalogInventory\Model\Indexer\Stock\Action\Row $productStockIndexerRow,
  33. \Magento\CatalogInventory\Model\Indexer\Stock\Action\Rows $productStockIndexerRows,
  34. \Magento\CatalogInventory\Model\Indexer\Stock\Action\Full $productStockIndexerFull
  35. ) {
  36. $this->_productStockIndexerRow = $productStockIndexerRow;
  37. $this->_productStockIndexerRows = $productStockIndexerRows;
  38. $this->_productStockIndexerFull = $productStockIndexerFull;
  39. }
  40. /**
  41. * Execute materialization on ids entities
  42. *
  43. * @param int[] $ids
  44. *
  45. * @return void
  46. */
  47. public function execute($ids)
  48. {
  49. $this->_productStockIndexerRows->execute($ids);
  50. $this->getCacheContext()->registerEntities(\Magento\Catalog\Model\Product::CACHE_TAG, $ids);
  51. }
  52. /**
  53. * Execute full indexation
  54. *
  55. * @return void
  56. */
  57. public function executeFull()
  58. {
  59. $this->_productStockIndexerFull->execute();
  60. $this->getCacheContext()->registerTags(
  61. [
  62. \Magento\Catalog\Model\Category::CACHE_TAG,
  63. \Magento\Catalog\Model\Product::CACHE_TAG
  64. ]
  65. );
  66. }
  67. /**
  68. * Execute partial indexation by ID list
  69. *
  70. * @param int[] $ids
  71. *
  72. * @return void
  73. */
  74. public function executeList(array $ids)
  75. {
  76. $this->_productStockIndexerRows->execute($ids);
  77. }
  78. /**
  79. * Execute partial indexation by ID
  80. *
  81. * @param int $id
  82. *
  83. * @return void
  84. */
  85. public function executeRow($id)
  86. {
  87. $this->_productStockIndexerRow->execute($id);
  88. }
  89. /**
  90. * Get cache context
  91. *
  92. * @return \Magento\Framework\Indexer\CacheContext
  93. * @deprecated 100.0.7
  94. */
  95. protected function getCacheContext()
  96. {
  97. if (!($this->cacheContext instanceof CacheContext)) {
  98. return \Magento\Framework\App\ObjectManager::getInstance()->get(CacheContext::class);
  99. } else {
  100. return $this->cacheContext;
  101. }
  102. }
  103. }