5
5
*/
6
6
namespace Magento \Catalog \Ui \DataProvider \Product ;
7
7
8
- use Magento \Catalog \Model \ResourceModel \Eav \Attribute ;
9
- use Magento \Framework \Exception \LocalizedException ;
10
- use Magento \Eav \Model \Entity \Attribute \AttributeInterface ;
11
-
12
8
/**
13
9
* Collection which is used for rendering product list in the backend.
14
10
*
15
11
* Used for product grid and customizes behavior of the default Product collection for grid needs.
16
- *
17
- * @SuppressWarnings(PHPMD.CookieAndSessionMisuse)
18
12
*/
19
13
class ProductCollection extends \Magento \Catalog \Model \ResourceModel \Product \Collection
20
14
{
@@ -31,66 +25,4 @@ protected function _productLimitationJoinPrice()
31
25
$ this ->_productLimitationFilters ->setUsePriceIndex (false );
32
26
return $ this ->_productLimitationPrice (true );
33
27
}
34
-
35
- /**
36
- * Add attribute filter to collection
37
- *
38
- * @param AttributeInterface|integer|string|array $attribute
39
- * @param null|string|array $condition
40
- * @param string $joinType
41
- * @return $this
42
- * @throws LocalizedException
43
- */
44
- public function addAttributeToFilter ($ attribute , $ condition = null , $ joinType = 'inner ' )
45
- {
46
- $ storeId = (int )$ this ->getStoreId ();
47
- if ($ attribute === 'is_saleable '
48
- || is_array ($ attribute )
49
- || $ storeId !== $ this ->getDefaultStoreId ()
50
- ) {
51
- return parent ::addAttributeToFilter ($ attribute , $ condition , $ joinType );
52
- }
53
-
54
- if ($ attribute instanceof AttributeInterface) {
55
- $ attributeModel = $ attribute ;
56
- } else {
57
- $ attributeModel = $ this ->getEntity ()->getAttribute ($ attribute );
58
- if ($ attributeModel === false ) {
59
- throw new LocalizedException (
60
- __ ('Invalid attribute identifier for filter (%1) ' , get_class ($ attribute ))
61
- );
62
- }
63
- }
64
-
65
- if ($ attributeModel ->isScopeGlobal () || $ attributeModel ->getBackend ()->isStatic ()) {
66
- return parent ::addAttributeToFilter ($ attribute , $ condition , $ joinType );
67
- }
68
-
69
- $ this ->addAttributeToFilterAllStores ($ attributeModel , $ condition );
70
-
71
- return $ this ;
72
- }
73
-
74
- /**
75
- * Add attribute to filter by all stores
76
- *
77
- * @param Attribute $attributeModel
78
- * @param array $condition
79
- * @return void
80
- */
81
- private function addAttributeToFilterAllStores (Attribute $ attributeModel , array $ condition ): void
82
- {
83
- $ tableName = $ this ->getTable ($ attributeModel ->getBackendTable ());
84
- $ entity = $ this ->getEntity ();
85
- $ fKey = 'e. ' . $ this ->getEntityPkName ($ entity );
86
- $ pKey = $ tableName . '. ' . $ this ->getEntityPkName ($ entity );
87
- $ attributeId = $ attributeModel ->getAttributeId ();
88
- $ condition = "( {$ pKey } = {$ fKey }) AND ( "
89
- . $ this ->_getConditionSql ("{$ tableName }.value " , $ condition )
90
- . ') AND ( '
91
- . $ this ->_getConditionSql ("{$ tableName }.attribute_id " , $ attributeId )
92
- . ') ' ;
93
- $ selectExistsInAllStores = $ this ->getConnection ()->select ()->from ($ tableName );
94
- $ this ->getSelect ()->exists ($ selectExistsInAllStores , $ condition );
95
- }
96
28
}
0 commit comments