Skip to content

Commit

Permalink
Merge pull request Smile-SA#1842 from rbayet/fix-1804-store-scoped-pr…
Browse files Browse the repository at this point in the history
…oduct-attributes-2.9.x

Fix 1804 store scoped product attributes 2.9.x
  • Loading branch information
romainruaud authored Jun 11, 2020
2 parents 124f01d + d2afb7b commit c036227
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -226,8 +226,11 @@ private function addIndexedAttribute(&$productIndexData, $attribute)
$productIndexData['indexed_attributes'] = [];
}

// Data can be missing for this attribute (Eg : due to null value being escaped).
if (isset($productIndexData[$attribute->getAttributeCode()])) {
// Data can be missing for this attribute (Eg : due to null value being escaped,
// or this attribute is already included in the array).
if (isset($productIndexData[$attribute->getAttributeCode()])
&& !in_array($attribute->getAttributeCode(), $productIndexData['indexed_attributes'])
) {
$productIndexData['indexed_attributes'][] = $attribute->getAttributeCode();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,27 +112,38 @@ public function getAttributesRawData($storeId, array $entityIds, $tableName, arr
// The legacy entity_id field.
$entityIdField = $this->getEntityMetaData($this->getEntityTypeId())->getIdentifierField();

$joinStoreValuesConditionClauses = [
"t_default.$linkField = t_store.$linkField",
't_default.attribute_id = t_store.attribute_id',
't_store.store_id= ?',
$joinDefaultValuesCondition = [
new \Zend_Db_Expr("entity.$linkField = t_default.$linkField"),
't_default.attribute_id = attr.attribute_id',
$this->connection->quoteInto('t_default.store_id = ?', \Magento\Store\Model\Store::DEFAULT_STORE_ID),
];
$joinDefaultValuesCondition = implode(' AND ', $joinDefaultValuesCondition);

$joinStoreValuesCondition = $this->connection->quoteInto(
implode(' AND ', $joinStoreValuesConditionClauses),
$storeId
);
$joinStoreValuesConditionClauses = [
new \Zend_Db_Expr("entity.$linkField = t_store.$linkField"),
't_store.attribute_id = attr.attribute_id',
$this->connection->quoteInto('t_store.store_id = ?', $storeId),
];
$joinStoreValuesCondition = implode(' AND ', $joinStoreValuesConditionClauses);

$select->from(['entity' => $this->getEntityMetaData($this->getEntityTypeId())->getEntityTable()], [$entityIdField])
->joinInner(
['t_default' => $tableName],
new \Zend_Db_Expr("entity.{$linkField} = t_default.{$linkField}"),
['attr' => $this->getTable('eav_attribute')],
$this->connection->quoteInto('attr.attribute_id IN (?)', $attributeIds),
['attribute_id']
)
->joinLeft(['t_store' => $tableName], $joinStoreValuesCondition, [])
->where('t_default.store_id=?', 0)
->where('t_default.attribute_id IN (?)', $attributeIds)
->joinLeft(
['t_default' => $tableName],
$joinDefaultValuesCondition,
[]
)
->joinLeft(
['t_store' => $tableName],
$joinStoreValuesCondition,
[]
)
->where("entity.{$entityIdField} IN (?)", $entityIds)
->having('value IS NOT NULL')
->columns(['value' => new \Zend_Db_Expr('COALESCE(t_store.value, t_default.value)')]);

return $this->connection->fetchAll($select);
Expand Down

0 comments on commit c036227

Please sign in to comment.