Skip to content

Commit b30a08e

Browse files
committed
ACP2E-1754: Store level URL rewrites are removed after product import
1 parent df6e3ae commit b30a08e

File tree

1 file changed

+69
-55
lines changed

1 file changed

+69
-55
lines changed

app/code/Magento/Eav/Model/ResourceModel/AttributeValue.php

Lines changed: 69 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -61,36 +61,51 @@ public function getValues(
6161
array $attributeCodes = [],
6262
array $storeIds = []
6363
): array {
64-
return $this->getValuesImplementation($entityType, $entityId, $attributeCodes, $storeIds);
64+
$metadata = $this->metadataPool->getMetadata($entityType);
65+
$connection = $metadata->getEntityConnection();
66+
$selects = [];
67+
$attributeTables = $this->prepareAttributeTables($entityType, $attributeCodes);
68+
foreach ($attributeTables as $attributeTable => $attributeIds) {
69+
$select = $connection->select()
70+
->from(
71+
['t' => $attributeTable],
72+
['*']
73+
)
74+
->where('attribute_id IN (?)', $attributeIds);
75+
76+
$select->where($metadata->getLinkField() . ' = ?', $entityId);
77+
78+
if (!empty($storeIds)) {
79+
$select->where(
80+
'store_id IN (?)',
81+
$storeIds
82+
);
83+
}
84+
$selects[] = $select;
85+
}
86+
87+
if (count($selects) > 1) {
88+
$select = $connection->select();
89+
$select->from(['u' => new UnionExpression($selects, Select::SQL_UNION_ALL, '( %s )')]);
90+
} else {
91+
$select = reset($selects);
92+
}
93+
94+
return $connection->fetchAll($select);
6595
}
6696

6797
/**
68-
* Implementation for the getValues methods
98+
* Fill the attribute tables array
6999
*
70100
* @param string $entityType
71-
* @param int $entityId
72-
* @param string[] $attributeCodes
73-
* @param int[] $storeIds
74-
* @param int[] $entityIds
75-
* @param bool $isMultiple
101+
* @param array $attributeCodes
76102
* @return array
77-
* @throws \Exception
78103
*/
79-
private function getValuesImplementation(
80-
string $entityType,
81-
int $entityId = 0,
82-
array $attributeCodes = [],
83-
array $storeIds = [],
84-
array $entityIds = [],
85-
bool $isMultiple = false
86-
): array {
87-
$metadata = $this->metadataPool->getMetadata($entityType);
88-
$connection = $metadata->getEntityConnection();
89-
$selects = [];
104+
private function prepareAttributeTables(string $entityType, array $attributeCodes) : array
105+
{
90106
$attributeTables = [];
91107
$attributes = [];
92108
$allAttributes = $this->getEntityAttributes($entityType);
93-
$result = [];
94109
if ($attributeCodes) {
95110
foreach ($attributeCodes as $attributeCode) {
96111
$attributes[$attributeCode] = $allAttributes[$attributeCode];
@@ -104,6 +119,29 @@ private function getValuesImplementation(
104119
$attributeTables[$attribute->getBackend()->getTable()][] = $attribute->getAttributeId();
105120
}
106121
}
122+
return $attributeTables;
123+
}
124+
125+
/**
126+
* Bulk version of the getValues() for several entities
127+
*
128+
* @param string $entityType
129+
* @param int[] $entityIds
130+
* @param string[] $attributeCodes
131+
* @param int[] $storeIds
132+
* @return array
133+
*/
134+
public function getValuesMultiple(
135+
string $entityType,
136+
array $entityIds,
137+
array $attributeCodes = [],
138+
array $storeIds = []
139+
) : array {
140+
$metadata = $this->metadataPool->getMetadata($entityType);
141+
$connection = $metadata->getEntityConnection();
142+
$selects = [];
143+
$result = [];
144+
$attributeTables = $this->prepareAttributeTables($entityType, $attributeCodes);
107145

108146
if ($attributeTables) {
109147
foreach ($attributeTables as $attributeTable => $attributeIds) {
@@ -113,17 +151,15 @@ private function getValuesImplementation(
113151
['*']
114152
)
115153
->where('attribute_id IN (?)', $attributeIds);
116-
if (!$isMultiple) {
117-
$select->where($metadata->getLinkField() . ' = ?', $entityId);
118-
} else {
119-
$linkField = $metadata->getLinkField();
120-
$select->joinInner(
121-
['e_t' => $metadata->getEntityTable()],
122-
't.' . $linkField . ' = e_t.' . $linkField,
123-
[]
124-
);
125-
$select->where('e_t.' . $metadata->getIdentifierField() . ' IN(?)', $entityIds, \Zend_Db::INT_TYPE);
126-
}
154+
155+
$linkField = $metadata->getLinkField();
156+
$select->joinInner(
157+
['e_t' => $metadata->getEntityTable()],
158+
't.' . $linkField . ' = e_t.' . $linkField,
159+
[]
160+
);
161+
$select->where('e_t.' . $metadata->getIdentifierField() . ' IN(?)', $entityIds, \Zend_Db::INT_TYPE);
162+
127163
if (!empty($storeIds)) {
128164
$select->where(
129165
'store_id IN (?)',
@@ -140,36 +176,14 @@ private function getValuesImplementation(
140176
$select = reset($selects);
141177
}
142178

143-
if (!$isMultiple) {
144-
$result = $connection->fetchAll($select);
145-
} else {
146-
foreach ($connection->fetchAll($select) as $row) {
147-
$result[$row[$metadata->getLinkField()]][$row['store_id']] = $row['value'];
148-
}
179+
foreach ($connection->fetchAll($select) as $row) {
180+
$result[$row[$metadata->getLinkField()]][$row['store_id']] = $row['value'];
149181
}
150182
}
151183

152184
return $result;
153185
}
154186

155-
/**
156-
* Bulk version of the getValues() for several entities
157-
*
158-
* @param string $entityType
159-
* @param int[] $entityIds
160-
* @param string[] $attributeCodes
161-
* @param int[] $storeIds
162-
* @return array
163-
*/
164-
public function getValuesMultiple(
165-
string $entityType,
166-
array $entityIds,
167-
array $attributeCodes = [],
168-
array $storeIds = []
169-
) : array {
170-
return $this->getValuesImplementation($entityType, 0, $attributeCodes, $storeIds, $entityIds, true);
171-
}
172-
173187
/**
174188
* Delete attribute values
175189
*

0 commit comments

Comments
 (0)