Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
BundleOptionStockDataSelectBuilder.php
Go to the documentation of this file.
1 <?php
8 
11 
19 {
24  public function __construct(
26  \Magento\Framework\EntityManager\MetadataPool $metadataPool
27  ) {
28  $this->resourceConnection = $resourceConnection;
29  $this->metadataPool = $metadataPool;
30  }
31 
36  public function buildSelect($idxTable)
37  {
38  $select = $this->resourceConnection->getConnection()->select();
39  $linkField = $this->metadataPool->getMetadata(ProductInterface::class)->getLinkField();
40 
41  $select->from(
42  ['product' => $this->resourceConnection->getTableName('catalog_product_entity')],
43  ['entity_id']
44  )->join(
45  ['bo' => $this->resourceConnection->getTableName('catalog_product_bundle_option')],
46  "bo.parent_id = product.$linkField",
47  []
48  )->join(
49  ['cis' => $this->resourceConnection->getTableName('cataloginventory_stock')],
50  '',
51  ['website_id', 'stock_id']
52  )->joinLeft(
53  ['bs' => $this->resourceConnection->getTableName('catalog_product_bundle_selection')],
54  'bs.option_id = bo.option_id',
55  []
56  )->joinLeft(
57  ['i' => $idxTable],
58  'i.product_id = bs.product_id AND i.website_id = cis.website_id AND i.stock_id = cis.stock_id',
59  []
60  )->joinLeft(
61  ['e' => $this->resourceConnection->getTableName('catalog_product_entity')],
62  'e.entity_id = bs.product_id',
63  []
64  )->group(
65  ['product.entity_id', 'cis.website_id', 'cis.stock_id', 'bo.option_id']
66  )->columns(['option_id' => 'bo.option_id']);
67 
68  return $select;
69  }
70 }
__construct(\Magento\Framework\App\ResourceConnection $resourceConnection, \Magento\Framework\EntityManager\MetadataPool $metadataPool)