Skip to content

Commit fe48fd2

Browse files
AC-1214 Fixed WebAPI tests failures and updated attribute value in product collection if scope is global
1 parent 0251589 commit fe48fd2

File tree

2 files changed

+53
-1
lines changed

2 files changed

+53
-1
lines changed

app/code/Magento/Catalog/Model/ResourceModel/Collection/AbstractCollection.php

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
*/
66
namespace Magento\Catalog\Model\ResourceModel\Collection;
77

8+
use Magento\Eav\Model\Entity\Attribute\ScopedAttributeInterface;
9+
use Magento\Framework\Exception\LocalizedException;
10+
811
/**
912
* Catalog EAV collection resource abstract model
1013
*
@@ -227,6 +230,55 @@ protected function _addLoadAttributesSelectValues($select, $table, $type)
227230
return $select;
228231
}
229232

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+
230282
/**
231283
* Adding join statement to collection select instance
232284
*

app/code/Magento/Quote/Model/ResourceModel/Quote/Item/Collection.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@ protected function _assignProducts(): self
250250
$this->_productIds
251251
)->addAttributeToSelect(
252252
$this->_quoteConfig->getProductAttributes()
253-
)->addPriceData();
253+
);
254254
$this->skipStockStatusFilter($productCollection);
255255
$productCollection->addOptionsToResult()->addStoreFilter()->addUrlRewrite();
256256

0 commit comments

Comments
 (0)