|
5 | 5 | */
|
6 | 6 | namespace Magento\Catalog\Model\ResourceModel\Collection;
|
7 | 7 |
|
| 8 | +use Magento\Eav\Model\Entity\Attribute\ScopedAttributeInterface; |
| 9 | +use Magento\Framework\Exception\LocalizedException; |
| 10 | + |
8 | 11 | /**
|
9 | 12 | * Catalog EAV collection resource abstract model
|
10 | 13 | *
|
@@ -227,6 +230,55 @@ protected function _addLoadAttributesSelectValues($select, $table, $type)
|
227 | 230 | return $select;
|
228 | 231 | }
|
229 | 232 |
|
| 233 | + /** |
| 234 | + * Initialize entity object property value |
| 235 | + * |
| 236 | + * Update attribute value if attribute scope is global |
| 237 | + * |
| 238 | + * Parameter $valueInfo is _getLoadAttributesSelect fetch result row |
| 239 | + * |
| 240 | + * @param array $valueInfo |
| 241 | + * @return \Magento\Eav\Model\Entity\Collection\AbstractCollection |
| 242 | + * @throws LocalizedException |
| 243 | + */ |
| 244 | + protected function _setItemAttributeValue($valueInfo) |
| 245 | + { |
| 246 | + $entityIdField = $this->getEntity()->getEntityIdField(); |
| 247 | + $entityId = $valueInfo[$entityIdField]; |
| 248 | + if (!isset($this->_itemsById[$entityId])) { |
| 249 | + throw new LocalizedException( |
| 250 | + __('A header row is missing for an attribute. Verify the header row and try again.') |
| 251 | + ); |
| 252 | + } |
| 253 | + |
| 254 | + $attribute = $this->_eavConfig->getAttribute( |
| 255 | + $this->getEntity()->getType(), |
| 256 | + $valueInfo['attribute_id'] |
| 257 | + ); |
| 258 | + $attributeCode = $attribute->getAttributeCode(); |
| 259 | + if ($attribute->getIsGlobal() === ScopedAttributeInterface::SCOPE_GLOBAL) { |
| 260 | + $attributeTable = $attribute->getBackend()->getTable(); |
| 261 | + $linkField = $attribute->getEntity()->getLinkField(); |
| 262 | + |
| 263 | + $select = $this->getConnection() |
| 264 | + ->select() |
| 265 | + ->from(['attr_table' => $attributeTable], "attr_table.value") |
| 266 | + ->where("attr_table.attribute_id = ?", $valueInfo['attribute_id']) |
| 267 | + ->where("attr_table.{$linkField} = ?", $entityId) |
| 268 | + ->where('attr_table.store_id = ?', $this->getDefaultStoreId(), \Zend_Db::INT_TYPE); |
| 269 | + $data = $this->getConnection()->fetchOne($select); |
| 270 | + if ($data) { |
| 271 | + $valueInfo['value'] = $data; |
| 272 | + } |
| 273 | + } |
| 274 | + |
| 275 | + foreach ($this->_itemsById[$entityId] as $object) { |
| 276 | + $object->setData($attributeCode, $valueInfo['value']); |
| 277 | + } |
| 278 | + |
| 279 | + return $this; |
| 280 | + } |
| 281 | + |
230 | 282 | /**
|
231 | 283 | * Adding join statement to collection select instance
|
232 | 284 | *
|
|
0 commit comments