Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
StatusBaseSelectProcessor.php
Go to the documentation of this file.
1 <?php
7 
17 
22 {
26  private $eavConfig;
27 
31  private $metadataPool;
32 
36  private $storeManager;
37 
46  public function __construct(
47  Config $eavConfig,
48  MetadataPool $metadataPool,
49  StoreResolverInterface $storeResolver,
50  StoreManagerInterface $storeManager = null
51  ) {
52  $this->eavConfig = $eavConfig;
53  $this->metadataPool = $metadataPool;
54  $this->storeManager = $storeManager ?: \Magento\Framework\App\ObjectManager::getInstance()
55  ->get(StoreManagerInterface::class);
56  }
57 
61  public function process(Select $select)
62  {
63  $linkField = $this->metadataPool->getMetadata(ProductInterface::class)->getLinkField();
64  $statusAttribute = $this->eavConfig->getAttribute(Product::ENTITY, ProductInterface::STATUS);
65 
66  $select->joinLeft(
67  ['status_global_attr' => $statusAttribute->getBackendTable()],
68  "status_global_attr.{$linkField} = " . self::PRODUCT_TABLE_ALIAS . ".{$linkField}"
69  . ' AND status_global_attr.attribute_id = ' . (int)$statusAttribute->getAttributeId()
70  . ' AND status_global_attr.store_id = ' . Store::DEFAULT_STORE_ID,
71  []
72  );
73 
74  $select->joinLeft(
75  ['status_attr' => $statusAttribute->getBackendTable()],
76  "status_attr.{$linkField} = " . self::PRODUCT_TABLE_ALIAS . ".{$linkField}"
77  . ' AND status_attr.attribute_id = ' . (int)$statusAttribute->getAttributeId()
78  . ' AND status_attr.store_id = ' . $this->storeManager->getStore()->getId(),
79  []
80  );
81 
82  $select->where('IFNULL(status_attr.value, status_global_attr.value) = ?', Status::STATUS_ENABLED);
83 
84  return $select;
85  }
86 }
__construct(Config $eavConfig, MetadataPool $metadataPool, StoreResolverInterface $storeResolver, StoreManagerInterface $storeManager=null)