Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
OptionSelectBuilder.php
Go to the documentation of this file.
1 <?php
7 
12 
17 {
23  private $attributeResource;
24 
30  private $attributeOptionProvider;
31 
36  public function __construct(Attribute $attributeResource, OptionProvider $attributeOptionProvider)
37  {
38  $this->attributeResource = $attributeResource;
39  $this->attributeOptionProvider = $attributeOptionProvider;
40  }
41 
45  public function getSelect(AbstractAttribute $superAttribute, int $productId, ScopeInterface $scope)
46  {
47  $select = $this->attributeResource->getConnection()->select()->from(
48  ['super_attribute' => $this->attributeResource->getTable('catalog_product_super_attribute')],
49  [
50  'sku' => 'entity.sku',
51  'product_id' => 'product_entity.entity_id',
52  'attribute_code' => 'attribute.attribute_code',
53  'value_index' => 'entity_value.value',
54  'super_attribute_label' => 'attribute_label.value',
55  ]
56  )->joinInner(
57  ['product_entity' => $this->attributeResource->getTable('catalog_product_entity')],
58  "product_entity.{$this->attributeOptionProvider->getProductEntityLinkField()} = super_attribute.product_id",
59  []
60  )->joinInner(
61  ['product_link' => $this->attributeResource->getTable('catalog_product_super_link')],
62  'product_link.parent_id = super_attribute.product_id',
63  []
64  )->joinInner(
65  ['attribute' => $this->attributeResource->getTable('eav_attribute')],
66  'attribute.attribute_id = super_attribute.attribute_id',
67  []
68  )->joinInner(
69  ['entity' => $this->attributeResource->getTable('catalog_product_entity')],
70  'entity.entity_id = product_link.product_id',
71  []
72  )->joinInner(
73  ['entity_value' => $superAttribute->getBackendTable()],
74  implode(
75  ' AND ',
76  [
77  'entity_value.attribute_id = super_attribute.attribute_id',
78  'entity_value.store_id = 0',
79  "entity_value.{$this->attributeOptionProvider->getProductEntityLinkField()} = "
80  . "entity.{$this->attributeOptionProvider->getProductEntityLinkField()}",
81  ]
82  ),
83  []
84  )->joinLeft(
85  ['attribute_label' => $this->attributeResource->getTable('catalog_product_super_attribute_label')],
86  implode(
87  ' AND ',
88  [
89  'super_attribute.product_super_attribute_id = attribute_label.product_super_attribute_id',
90  'attribute_label.store_id = ' . \Magento\Store\Model\Store::DEFAULT_STORE_ID,
91  ]
92  ),
93  []
94  )->joinLeft(
95  ['attribute_option' => $this->attributeResource->getTable('eav_attribute_option')],
96  'attribute_option.option_id = entity_value.value',
97  []
98  )->order(
99  'attribute_option.sort_order ASC'
100  )->where(
101  'super_attribute.product_id = ?',
102  $productId
103  )->where(
104  'attribute.attribute_id = ?',
105  $superAttribute->getAttributeId()
106  );
107 
108  if (!$superAttribute->getSourceModel()) {
109  $select->columns(
110  [
111  'option_title' => $this->attributeResource->getConnection()->getIfNullSql(
112  'option_value.value',
113  'default_option_value.value'
114  ),
115  'default_title' => 'default_option_value.value',
116  ]
117  )->joinLeft(
118  ['option_value' => $this->attributeResource->getTable('eav_attribute_option_value')],
119  implode(
120  ' AND ',
121  [
122  'option_value.option_id = entity_value.value',
123  'option_value.store_id = ' . $scope->getId(),
124  ]
125  ),
126  []
127  )->joinLeft(
128  ['default_option_value' => $this->attributeResource->getTable('eav_attribute_option_value')],
129  implode(
130  ' AND ',
131  [
132  'default_option_value.option_id = entity_value.value',
133  'default_option_value.store_id = ' . \Magento\Store\Model\Store::DEFAULT_STORE_ID,
134  ]
135  ),
136  []
137  );
138  }
139 
140  return $select;
141  }
142 }
getSelect(AbstractAttribute $superAttribute, int $productId, ScopeInterface $scope)
__construct(Attribute $attributeResource, OptionProvider $attributeOptionProvider)