@@ -1578,26 +1578,9 @@ public function addAttributeToFilter($attribute, $condition = null, $joinType =
1578
1578
$ this ->_allIdsCache = null ;
1579
1579
1580
1580
if (is_string ($ attribute ) && $ attribute == 'is_saleable ' ) {
1581
- $ columns = $ this ->getSelect ()->getPart (\Magento \Framework \DB \Select::COLUMNS );
1582
- foreach ($ columns as $ columnEntry ) {
1583
- list ($ correlationName , $ column , $ alias ) = $ columnEntry ;
1584
- if ($ alias == 'is_saleable ' ) {
1585
- if ($ column instanceof \Zend_Db_Expr) {
1586
- $ field = $ column ;
1587
- } else {
1588
- $ connection = $ this ->getSelect ()->getConnection ();
1589
- if (empty ($ correlationName )) {
1590
- $ field = $ connection ->quoteColumnAs ($ column , $ alias , true );
1591
- } else {
1592
- $ field = $ connection ->quoteColumnAs ([$ correlationName , $ column ], $ alias , true );
1593
- }
1594
- }
1595
- $ this ->getSelect ()->where ("{$ field } = ? " , $ condition );
1596
- break ;
1597
- }
1598
- }
1599
-
1600
- return $ this ;
1581
+ $ this ->addIsSaleableAttributeToFilter ($ condition );
1582
+ } elseif (is_string ($ attribute ) && $ attribute == 'tier_price ' ) {
1583
+ $ this ->addTierPriceAttributeToFilter ($ attribute , $ condition );
1601
1584
} else {
1602
1585
return parent ::addAttributeToFilter ($ attribute , $ condition , $ joinType );
1603
1586
}
@@ -2481,4 +2464,71 @@ public function getPricesCount()
2481
2464
2482
2465
return $ this ->_pricesCount ;
2483
2466
}
2467
+
2468
+ /**
2469
+ * Add is_saleable attribute to filter
2470
+ *
2471
+ * @param array|null $condition
2472
+ * @return $this
2473
+ */
2474
+ private function addIsSaleableAttributeToFilter (?array $ condition ): self
2475
+ {
2476
+ $ columns = $ this ->getSelect ()->getPart (Select::COLUMNS );
2477
+ foreach ($ columns as $ columnEntry ) {
2478
+ list ($ correlationName , $ column , $ alias ) = $ columnEntry ;
2479
+ if ($ alias == 'is_saleable ' ) {
2480
+ if ($ column instanceof \Zend_Db_Expr) {
2481
+ $ field = $ column ;
2482
+ } else {
2483
+ $ connection = $ this ->getSelect ()->getConnection ();
2484
+ if (empty ($ correlationName )) {
2485
+ $ field = $ connection ->quoteColumnAs ($ column , $ alias , true );
2486
+ } else {
2487
+ $ field = $ connection ->quoteColumnAs ([$ correlationName , $ column ], $ alias , true );
2488
+ }
2489
+ }
2490
+ $ this ->getSelect ()->where ("{$ field } = ? " , $ condition );
2491
+ break ;
2492
+ }
2493
+ }
2494
+
2495
+ return $ this ;
2496
+ }
2497
+
2498
+ /**
2499
+ * Add tier price attribute to filter
2500
+ *
2501
+ * @param string $attribute
2502
+ * @param array|null $condition
2503
+ * @return $this
2504
+ */
2505
+ private function addTierPriceAttributeToFilter (string $ attribute , ?array $ condition ): self
2506
+ {
2507
+ $ attrCode = $ attribute ;
2508
+ $ connection = $ this ->getConnection ();
2509
+ $ attrTable = $ this ->_getAttributeTableAlias ($ attrCode );
2510
+ $ entity = $ this ->getEntity ();
2511
+ $ fKey = 'e. ' . $ this ->getEntityPkName ($ entity );
2512
+ $ pKey = $ attrTable . '. ' . $ this ->getEntityPkName ($ entity );
2513
+ $ attribute = $ entity ->getAttribute ($ attrCode );
2514
+ $ attrFieldName = $ attrTable . '.value ' ;
2515
+ $ fKey = $ connection ->quoteColumnAs ($ fKey , null );
2516
+ $ pKey = $ connection ->quoteColumnAs ($ pKey , null );
2517
+
2518
+ $ condArr = ["{$ pKey } = {$ fKey }" ];
2519
+ $ this ->getSelect ()->join (
2520
+ [$ attrTable => $ this ->getTable ('catalog_product_entity_tier_price ' )],
2521
+ '( ' . implode (') AND ( ' , $ condArr ) . ') ' ,
2522
+ [$ attrCode => $ attrFieldName ]
2523
+ );
2524
+ $ this ->removeAttributeToSelect ($ attrCode );
2525
+ $ this ->_filterAttributes [$ attrCode ] = $ attribute ->getId ();
2526
+ $ this ->_joinFields [$ attrCode ] = ['table ' => '' , 'field ' => $ attrFieldName ];
2527
+ $ field = $ this ->_getAttributeTableAlias ($ attrCode ) . '.value ' ;
2528
+ $ conditionSql = $ this ->_getConditionSql ($ field , $ condition );
2529
+ $ this ->getSelect ()->where ($ conditionSql , null , Select::TYPE_CONDITION );
2530
+ $ this ->_totalRecords = null ;
2531
+
2532
+ return $ this ;
2533
+ }
2484
2534
}
0 commit comments