@@ -1013,9 +1013,9 @@ public function getMaxAttributeValue($attribute)
1013
1013
$ tableAlias = $ attributeCode . '_max_value ' ;
1014
1014
$ fieldAlias = 'max_ ' . $ attributeCode ;
1015
1015
$ condition = 'e.entity_id = ' . $ tableAlias . '.entity_id AND ' . $ this ->_getConditionSql (
1016
- $ tableAlias . '.attribute_id ' ,
1017
- $ attribute ->getId ()
1018
- );
1016
+ $ tableAlias . '.attribute_id ' ,
1017
+ $ attribute ->getId ()
1018
+ );
1019
1019
1020
1020
$ select ->join (
1021
1021
[$ tableAlias => $ attribute ->getBackend ()->getTable ()],
@@ -1048,9 +1048,9 @@ public function getAttributeValueCountByRange($attribute, $range)
1048
1048
$ tableAlias = $ attributeCode . '_range_count_value ' ;
1049
1049
1050
1050
$ condition = 'e.entity_id = ' . $ tableAlias . '.entity_id AND ' . $ this ->_getConditionSql (
1051
- $ tableAlias . '.attribute_id ' ,
1052
- $ attribute ->getId ()
1053
- );
1051
+ $ tableAlias . '.attribute_id ' ,
1052
+ $ attribute ->getId ()
1053
+ );
1054
1054
1055
1055
$ select ->reset (\Magento \Framework \DB \Select::GROUP );
1056
1056
$ select ->join (
@@ -1088,9 +1088,9 @@ public function getAttributeValueCount($attribute)
1088
1088
1089
1089
$ select ->reset (\Magento \Framework \DB \Select::GROUP );
1090
1090
$ condition = 'e.entity_id= ' . $ tableAlias . '.entity_id AND ' . $ this ->_getConditionSql (
1091
- $ tableAlias . '.attribute_id ' ,
1092
- $ attribute ->getId ()
1093
- );
1091
+ $ tableAlias . '.attribute_id ' ,
1092
+ $ attribute ->getId ()
1093
+ );
1094
1094
1095
1095
$ select ->join (
1096
1096
[$ tableAlias => $ attribute ->getBackend ()->getTable ()],
@@ -1180,9 +1180,27 @@ protected function _getSelectCountSql(?Select $select = null, $resetLeftJoins =
1180
1180
if ($ resetLeftJoins ) {
1181
1181
$ countSelect ->resetJoinLeft ();
1182
1182
}
1183
+
1184
+ $ this ->removeEntityIdentifierFromGroupBy ($ countSelect );
1185
+
1183
1186
return $ countSelect ;
1184
1187
}
1185
1188
1189
+ /**
1190
+ * Using `entity_id` for `GROUP BY` causes COUNT() return {n} rows of value = 1 instead of 1 row of value {n}
1191
+ *
1192
+ * @param Select $select
1193
+ * @throws \Zend_Db_Select_Exception
1194
+ */
1195
+ private function removeEntityIdentifierFromGroupBy (Select $ select ): void
1196
+ {
1197
+ $ groupBy = array_filter ($ select ->getPart (Select::GROUP ), function ($ field ) {
1198
+ return false === strpos ($ field , $ this ->getIdFieldName ());
1199
+ });
1200
+
1201
+ $ select ->setPart (Select::GROUP , $ groupBy );
1202
+ }
1203
+
1186
1204
/**
1187
1205
* Prepare statistics data
1188
1206
*
@@ -1766,28 +1784,28 @@ public function addAttributeToSort($attribute, $dir = self::SORT_ORDER_ASC)
1766
1784
protected function _prepareProductLimitationFilters ()
1767
1785
{
1768
1786
if (isset (
1769
- $ this ->_productLimitationFilters ['visibility ' ]
1770
- ) && !isset (
1771
- $ this ->_productLimitationFilters ['store_id ' ]
1772
- )
1787
+ $ this ->_productLimitationFilters ['visibility ' ]
1788
+ ) && !isset (
1789
+ $ this ->_productLimitationFilters ['store_id ' ]
1790
+ )
1773
1791
) {
1774
1792
$ this ->_productLimitationFilters ['store_id ' ] = $ this ->getStoreId ();
1775
1793
}
1776
1794
if (isset (
1777
- $ this ->_productLimitationFilters ['category_id ' ]
1778
- ) && !isset (
1779
- $ this ->_productLimitationFilters ['store_id ' ]
1780
- )
1795
+ $ this ->_productLimitationFilters ['category_id ' ]
1796
+ ) && !isset (
1797
+ $ this ->_productLimitationFilters ['store_id ' ]
1798
+ )
1781
1799
) {
1782
1800
$ this ->_productLimitationFilters ['store_id ' ] = $ this ->getStoreId ();
1783
1801
}
1784
1802
if (isset (
1785
- $ this ->_productLimitationFilters ['store_id ' ]
1786
- ) && isset (
1787
- $ this ->_productLimitationFilters ['visibility ' ]
1788
- ) && !isset (
1789
- $ this ->_productLimitationFilters ['category_id ' ]
1790
- )
1803
+ $ this ->_productLimitationFilters ['store_id ' ]
1804
+ ) && isset (
1805
+ $ this ->_productLimitationFilters ['visibility ' ]
1806
+ ) && !isset (
1807
+ $ this ->_productLimitationFilters ['category_id ' ]
1808
+ )
1791
1809
) {
1792
1810
$ this ->_productLimitationFilters ['category_id ' ] = $ this ->_storeManager ->getStore (
1793
1811
$ this ->_productLimitationFilters ['store_id ' ]
@@ -1820,12 +1838,12 @@ protected function _productLimitationJoinWebsite()
1820
1838
'int '
1821
1839
);
1822
1840
} elseif (isset (
1823
- $ filters ['store_id ' ]
1824
- ) && (!isset (
1825
- $ filters ['visibility ' ]
1826
- ) && !isset (
1827
- $ filters ['category_id ' ]
1828
- )) && !$ this ->isEnabledFlat ()
1841
+ $ filters ['store_id ' ]
1842
+ ) && (!isset (
1843
+ $ filters ['visibility ' ]
1844
+ ) && !isset (
1845
+ $ filters ['category_id ' ]
1846
+ )) && !$ this ->isEnabledFlat ()
1829
1847
) {
1830
1848
$ joinWebsite = true ;
1831
1849
$ websiteId = $ this ->_storeManager ->getStore ($ filters ['store_id ' ])->getWebsiteId ();
@@ -1901,9 +1919,9 @@ protected function _productLimitationJoinPrice()
1901
1919
/**
1902
1920
* Join Product Price Table with left-join possibility
1903
1921
*
1904
- * @see \Magento\Catalog\Model\ResourceModel\Product\Collection::_productLimitationJoinPrice()
1905
1922
* @param bool $joinLeft
1906
1923
* @return $this
1924
+ * @see \Magento\Catalog\Model\ResourceModel\Product\Collection::_productLimitationJoinPrice()
1907
1925
*/
1908
1926
protected function _productLimitationPrice ($ joinLeft = false )
1909
1927
{
@@ -2334,8 +2352,8 @@ public function addPriceDataFieldFilter($comparisonFormat, $fields)
2334
2352
* @return $this
2335
2353
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
2336
2354
* @SuppressWarnings(PHPMD.NPathComplexity)
2337
- * @since 101.0.1
2338
2355
* @throws \Magento\Framework\Exception\LocalizedException
2356
+ * @since 101.0.1
2339
2357
*/
2340
2358
public function addMediaGalleryData ()
2341
2359
{
@@ -2360,7 +2378,7 @@ public function addMediaGalleryData()
2360
2378
'entity. ' . $ linkField . ' IN (?) ' ,
2361
2379
array_map (
2362
2380
function ($ item ) use ($ linkField ) {
2363
- return (int ) $ item ->getOrigData ($ linkField );
2381
+ return (int )$ item ->getOrigData ($ linkField );
2364
2382
},
2365
2383
$ items
2366
2384
)
@@ -2411,9 +2429,9 @@ private function getGalleryReadHandler()
2411
2429
/**
2412
2430
* Retrieve Media gallery resource.
2413
2431
*
2432
+ * @return \Magento\Catalog\Model\ResourceModel\Product\Gallery
2414
2433
* @deprecated 101.0.1
2415
2434
*
2416
- * @return \Magento\Catalog\Model\ResourceModel\Product\Gallery
2417
2435
*/
2418
2436
private function getMediaGalleryResource ()
2419
2437
{
0 commit comments