Skip to content

Commit 28ea476

Browse files
committed
ACP2E-1307: improve loading time for store / website level attributes
1 parent cd6b255 commit 28ea476

File tree

2 files changed

+13
-32
lines changed

2 files changed

+13
-32
lines changed

app/code/Magento/CatalogWidget/Model/Rule/Condition/Product.php

Lines changed: 12 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@
1212
use Magento\Catalog\Model\ProductCategoryList;
1313
use Magento\Catalog\Model\ResourceModel\Product\Collection;
1414
use Magento\Framework\DB\Select;
15+
use Magento\Framework\Exception\LocalizedException;
1516
use Magento\Store\Model\Store;
17+
use Zend_Db_Select_Exception;
1618

1719
/**
1820
* Rule product condition data model
@@ -201,34 +203,6 @@ protected function addNotGlobalAttribute(
201203
\Magento\Catalog\Model\ResourceModel\Eav\Attribute $attribute,
202204
Collection $collection
203205
) {
204-
/*$storeId = $this->storeManager->getStore()->getId();
205-
$values = $collection->getAllAttributeValues($attribute);
206-
$validEntities = [];
207-
if ($values) {
208-
foreach ($values as $entityId => $storeValues) {
209-
if (isset($storeValues[$storeId])) {
210-
if ($this->validateAttribute($storeValues[$storeId])) {
211-
$validEntities[] = $entityId;
212-
}
213-
} else {
214-
if (isset($storeValues[Store::DEFAULT_STORE_ID]) &&
215-
$this->validateAttribute($storeValues[Store::DEFAULT_STORE_ID])
216-
) {
217-
$validEntities[] = $entityId;
218-
}
219-
}
220-
}
221-
}
222-
$this->setOperator('()');
223-
$this->unsetData('value_parsed');
224-
if ($validEntities) {
225-
$this->setData('value', implode(',', $validEntities));
226-
} else {
227-
$this->unsetData('value');
228-
}
229-
230-
return $this;*/
231-
232206
$connection = $this->_productResource->getConnection();
233207
switch ($attribute->getBackendType()) {
234208
case 'decimal':
@@ -244,8 +218,14 @@ protected function addNotGlobalAttribute(
244218
$aliasDefault = 'at_' . sha1($this->getId()) . $attribute->getAttributeCode() . '_default';
245219
$aliasStore = 'at_' . sha1($this->getId()) . $attribute->getAttributeCode();
246220

247-
$storeDefaultId = $connection->getIfNullSql($aliasDefault . '.store_id', Store::DEFAULT_STORE_ID);
248-
$storeId = $connection->getIfNullSql($aliasStore . '.store_id', $this->storeManager->getStore()->getId());
221+
$storeDefaultId = $connection->getIfNullSql(
222+
$aliasDefault . '.store_id',
223+
Store::DEFAULT_STORE_ID
224+
);
225+
$storeId = $connection->getIfNullSql(
226+
$aliasStore . '.store_id',
227+
$this->storeManager->getStore()->getId()
228+
);
249229
$linkField = $attribute->getEntity()->getLinkField();
250230

251231
$collection->getSelect()->joinLeft(
@@ -263,8 +243,8 @@ protected function addNotGlobalAttribute(
263243
}
264244

265245
$fromPart = $collection->getSelect()->getPart(Select::FROM);
266-
if (isset($fromPart['search_result']['joinType'])
267-
&& $fromPart['search_result']['joinType'] == Select::LEFT_JOIN
246+
if (isset($fromPart[$aliasStore]['joinType'])
247+
&& isset($fromPart[$aliasDefault]['joinType'])
268248
) {
269249
$conditionCheck = $connection->quoteIdentifier($aliasStore . '.value_id') . " > 0";
270250
$conditionTrue = $connection->quoteIdentifier($aliasStore . '.value');

app/code/Magento/Rule/Model/Condition/Sql/Builder.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@ protected function _joinTablesToCollection(
144144
* @return string
145145
* @throws \Magento\Framework\Exception\LocalizedException
146146
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
147+
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
147148
*/
148149
protected function _getMappedSqlCondition(
149150
AbstractCondition $condition,

0 commit comments

Comments
 (0)