Skip to content

Commit a937dbe

Browse files
committed
Merge remote-tracking branch 'origin/MAGETWO-98335' into 2.3-develop-pr19
2 parents 2fa6bae + 8ff613e commit a937dbe

File tree

2 files changed

+108
-0
lines changed

2 files changed

+108
-0
lines changed
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
/**
4+
* Copyright © Magento, Inc. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
-->
8+
9+
<tests xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
10+
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/testSchema.xsd">
11+
<test name="AdminFilterByNameByStoreViewOnProductGridTest">
12+
<annotations>
13+
<features value="Catalog"/>
14+
<stories value="Filter products"/>
15+
<title value="Product grid filtering by store view level attribute"/>
16+
<description value="Verify that products grid can be filtered on all store view level by attribute"/>
17+
<severity value="MAJOR"/>
18+
<testCaseId value="MAGETWO-98755"/>
19+
<useCaseId value="MAGETWO-98335"/>
20+
<group value="catalog"/>
21+
</annotations>
22+
<before>
23+
<createData entity="SimpleProduct2" stepKey="createSimpleProduct"/>
24+
<actionGroup ref="LoginAsAdmin" stepKey="loginAsAdmin"/>
25+
</before>
26+
<after>
27+
<deleteData createDataKey="createSimpleProduct" stepKey="deleteSimpleProduct"/>
28+
<actionGroup ref="ClearProductsFilterActionGroup" stepKey="clearProductsFilter"/>
29+
<actionGroup ref="logout" stepKey="logout"/>
30+
</after>
31+
<amOnPage url="{{AdminProductEditPage.url($$createSimpleProduct.id$$)}}" stepKey="goToEditPage"/>
32+
<actionGroup ref="AdminSwitchStoreViewActionGroup" stepKey="switchToDefaultStoreView">
33+
<argument name="storeView" value="_defaultStore.name"/>
34+
</actionGroup>
35+
<scrollToTopOfPage stepKey="scrollToTopOfAdminProductFormSection"/>
36+
<click selector="{{AdminProductFormSection.productNameUseDefault}}" stepKey="uncheckUseDefault"/>
37+
<fillField selector="{{AdminProductFormSection.productName}}" userInput="{{SimpleProduct.name}}" stepKey="fillNewName"/>
38+
<actionGroup ref="saveProductForm" stepKey="saveSimpleProduct"/>
39+
<amOnPage url="{{AdminProductIndexPage.url}}" stepKey="navigateToProductIndex"/>
40+
<actionGroup ref="filterProductGridByName" stepKey="filterGridByName">
41+
<argument name="product" value="SimpleProduct"/>
42+
</actionGroup>
43+
<see selector="{{AdminProductGridSection.firstProductRow}}" userInput="{{SimpleProduct2.name}}" stepKey="seeProductNameInGrid"/>
44+
</test>
45+
</tests>

app/code/Magento/Catalog/Ui/DataProvider/Product/ProductCollection.php

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@
55
*/
66
namespace Magento\Catalog\Ui\DataProvider\Product;
77

8+
use Magento\Catalog\Model\ResourceModel\Eav\Attribute;
9+
use Magento\Framework\Exception\LocalizedException;
10+
use Magento\Eav\Model\Entity\Attribute\AttributeInterface;
11+
812
/**
913
* Collection which is used for rendering product list in the backend.
1014
*
@@ -25,4 +29,63 @@ protected function _productLimitationJoinPrice()
2529
$this->_productLimitationFilters->setUsePriceIndex(false);
2630
return $this->_productLimitationPrice(true);
2731
}
32+
33+
/**
34+
* Add attribute filter to collection
35+
*
36+
* @param AttributeInterface|integer|string|array $attribute
37+
* @param null|string|array $condition
38+
* @param string $joinType
39+
* @return $this
40+
* @throws LocalizedException
41+
*/
42+
public function addAttributeToFilter($attribute, $condition = null, $joinType = 'inner')
43+
{
44+
$storeId = (int)$this->getStoreId();
45+
if ($attribute === 'is_saleable'
46+
|| is_array($attribute)
47+
|| $storeId !== $this->getDefaultStoreId()
48+
) {
49+
return parent::addAttributeToFilter($attribute, $condition, $joinType);
50+
}
51+
52+
if ($attribute instanceof AttributeInterface) {
53+
$attributeModel = $attribute;
54+
} else {
55+
$attributeModel = $this->getEntity()->getAttribute($attribute);
56+
if ($attributeModel === false) {
57+
throw new LocalizedException(
58+
__('Invalid attribute identifier for filter (%1)', get_class($attribute))
59+
);
60+
}
61+
}
62+
63+
if ($attributeModel->isScopeGlobal() || $attributeModel->getBackend()->isStatic()) {
64+
return parent::addAttributeToFilter($attribute, $condition, $joinType);
65+
}
66+
67+
$this->addAttributeToFilterAllStores($attributeModel, $condition);
68+
69+
return $this;
70+
}
71+
72+
/**
73+
* Add attribute to filter by all stores
74+
*
75+
* @param Attribute $attributeModel
76+
* @param array $condition
77+
* @return void
78+
*/
79+
private function addAttributeToFilterAllStores(Attribute $attributeModel, array $condition): void
80+
{
81+
$tableName = $this->getTable($attributeModel->getBackendTable());
82+
$entity = $this->getEntity();
83+
$fKey = 'e.' . $this->getEntityPkName($entity);
84+
$pKey = $tableName . '.' . $this->getEntityPkName($entity);
85+
$condition = "({$pKey} = {$fKey}) AND ("
86+
. $this->_getConditionSql("{$tableName}.value", $condition)
87+
. ')';
88+
$selectExistsInAllStores = $this->getConnection()->select()->from($tableName);
89+
$this->getSelect()->exists($selectExistsInAllStores, $condition);
90+
}
2891
}

0 commit comments

Comments
 (0)