File tree Expand file tree Collapse file tree 8 files changed +27
-20
lines changed
view/adminhtml/templates/widget/grid
Plugin/Ui/DataProvider/Product
Ui/view/base/web/templates/grid Expand file tree Collapse file tree 8 files changed +27
-20
lines changed Original file line number Diff line number Diff line change @@ -1327,4 +1327,14 @@ public function calculateApproximateProductsTotalNumber(): bool
1327
1327
{
1328
1328
return (bool )$ this ->_scopeConfig ->getValue ('admin/grid/calculate_approximate_total_number_of_products ' );
1329
1329
}
1330
+
1331
+ /**
1332
+ * Get records threshold for approximate total number of products calculation.
1333
+ *
1334
+ * @return int
1335
+ */
1336
+ public function getRecordsThreshold (): int
1337
+ {
1338
+ return $ this ->_scopeConfig ->getValue ('admin/grid/records_threshold ' );
1339
+ }
1330
1340
}
Original file line number Diff line number Diff line change 488
488
<source_model >Magento\Config\Model\Config\Source\Yesno</source_model >
489
489
<comment >Calculate approximate total number of products in products grid.</comment >
490
490
</field >
491
+ <field id =" records_threshold" translate =" label comment" type =" text" sortOrder =" 2" showInDefault =" 1" canRestore =" 1" >
492
+ <label >Records Threshold</label >
493
+ <validate >validate-greater-than-zero validate-number</validate >
494
+ <comment >Calculate approximate total number of products if their number is greater than this threshold.</comment >
495
+ <depends >
496
+ <field id =" calculate_approximate_total_number_of_products" >1</field >
497
+ </depends >
498
+ </field >
491
499
</group >
492
500
</section >
493
501
<section id =" web" translate =" label" type =" text" sortOrder =" 20" showInDefault =" 1" showInWebsite =" 1" showInStore =" 1" >
Original file line number Diff line number Diff line change 34
34
<admin >
35
35
<grid >
36
36
<calculate_approximate_total_number_of_products >1</calculate_approximate_total_number_of_products >
37
+ <records_threshold >20000</records_threshold >
37
38
</grid >
38
39
</admin >
39
40
<general >
Original file line number Diff line number Diff line change @@ -73,9 +73,7 @@ $numColumns = count($block->getColumns());
73
73
<div class="admin__control-support-text">
74
74
<?php if (!$ block ->calculateApproximateProductsTotalNumber ()
75
75
|| !$ block ->getCollection () instanceof ProductCollection
76
- || ($ block ->calculateApproximateProductsTotalNumber ()
77
- && $ block ->getCollection () instanceof ProductCollection
78
- && $ countRecords < ProductCollection::RECORDS_LIMIT )): ?>
76
+ || $ countRecords < $ block ->getRecordsThreshold ()): ?>
79
77
<span id="<?= $ block ->escapeHtml ($ block ->getHtmlId ()) ?> -total-count"
80
78
<?= /* @noEscape */ $ block ->getUiId ('total-count ' ) ?> >
81
79
<?= /* @noEscape */ $ countRecords ?>
@@ -135,9 +133,7 @@ $numColumns = count($block->getColumns());
135
133
<?php endif ; ?>
136
134
<?php if (!$ block ->calculateApproximateProductsTotalNumber ()
137
135
|| !$ block ->getCollection () instanceof ProductCollection
138
- || ($ block ->calculateApproximateProductsTotalNumber ()
139
- && $ block ->getCollection () instanceof ProductCollection
140
- && $ countRecords < ProductCollection::RECORDS_LIMIT )): ?>
136
+ || $ countRecords < $ block ->getRecordsThreshold ()): ?>
141
137
<input type="text"
142
138
id="<?= $ block ->escapeHtml ($ block ->getHtmlId ()) ?> _page-current"
143
139
name="<?= $ block ->escapeHtmlAttr ($ block ->getVarNamePage ()) ?> "
Original file line number Diff line number Diff line change 8
8
9
9
namespace Magento \Catalog \Plugin \Ui \DataProvider \Product ;
10
10
11
- use Magento \Catalog \Ui \DataProvider \Product \ProductCollection ;
12
11
use Magento \Catalog \Ui \DataProvider \Product \ProductDataProvider as CatalogProductDataProvider ;
13
12
use Magento \Framework \App \Config \ScopeConfigInterface ;
14
13
@@ -53,7 +52,7 @@ private function addShowTotalRecords(array $data): array
53
52
{
54
53
if (key_exists ('totalRecords ' , $ data )) {
55
54
if ($ this ->scopeConfig ->getValue ('admin/grid/calculate_approximate_total_number_of_products ' )
56
- && $ data ['totalRecords ' ] >= ProductCollection:: RECORDS_LIMIT ) {
55
+ && $ data ['totalRecords ' ] >= $ this -> scopeConfig -> getValue ( ' admin/grid/records_threshold ' ) ) {
57
56
$ data ['showTotalRecords ' ] = false ;
58
57
} else {
59
58
$ data ['showTotalRecords ' ] = true ;
Original file line number Diff line number Diff line change 14
14
*/
15
15
class ProductCollection extends \Magento \Catalog \Model \ResourceModel \Product \Collection
16
16
{
17
- /**
18
- * Limit to display/hide total number of products in grid
19
- */
20
- public const RECORDS_LIMIT = 20000 ;
21
-
22
17
/**
23
18
* Disables using of price index for grid rendering
24
19
*
@@ -43,7 +38,7 @@ public function getSize()
43
38
$ sql = $ this ->getSelectCountSql ();
44
39
$ estimatedCount = $ this ->analyzeCount ($ sql );
45
40
46
- if ($ estimatedCount > self :: RECORDS_LIMIT ) {
41
+ if ($ estimatedCount > $ this -> _scopeConfig -> getValue ( ' admin/grid/records_threshold ' ) ) {
47
42
$ columns = $ sql ->getPart (Select::COLUMNS );
48
43
$ sql ->reset (Select::COLUMNS );
49
44
@@ -53,10 +48,10 @@ public function getSize()
53
48
}
54
49
}
55
50
$ sql ->setPart (Select::COLUMNS , $ columns );
56
- $ sql ->limit (self :: RECORDS_LIMIT );
51
+ $ sql ->limit ($ this -> _scopeConfig -> getValue ( ' admin/grid/records_threshold ' ) );
57
52
$ query = new \Zend_Db_Expr ('SELECT COUNT(*) FROM ( ' . $ sql ->assemble () . ') AS c ' );
58
53
$ this ->_totalRecords = (int )$ this ->getConnection ()->query ($ query )->fetchColumn ();
59
- if ($ this ->_totalRecords === self :: RECORDS_LIMIT ) {
54
+ if ($ this ->_totalRecords === ( int ) $ this -> _scopeConfig -> getValue ( ' admin/grid/records_threshold ' ) ) {
60
55
$ this ->_totalRecords = $ estimatedCount ;
61
56
}
62
57
} else {
Original file line number Diff line number Diff line change 94
94
<argument name =" collectionFactory" xsi : type =" object" >\Magento\Catalog\Ui\DataProvider\Product\ProductCollectionFactory</argument >
95
95
<argument name =" modifiersPool" xsi : type =" object" >Magento\Catalog\Ui\DataProvider\Product\Listing\Modifier\Pool</argument >
96
96
</arguments >
97
+ <plugin name =" add_show_total_records_to_catalog_product_data" type =" Magento\Catalog\Plugin\Ui\DataProvider\Product\ProductDataProvider" />
97
98
</type >
98
99
<type name =" Magento\Catalog\Model\Product\Action" >
99
100
<plugin name =" invalidate_pagecache_after_update_product_attributes" type =" Magento\Catalog\Plugin\Model\Product\Action\UpdateAttributesFlushCache" />
290
291
</argument >
291
292
</arguments >
292
293
</type >
293
- <type name =" Magento\Catalog\Ui\DataProvider\Product\ProductDataProvider" >
294
- <plugin name =" add_show_total_records_to_catalog_product_data" type =" Magento\Catalog\Plugin\Ui\DataProvider\Product\ProductDataProvider" />
295
- </type >
296
294
</config >
Original file line number Diff line number Diff line change 8
8
<!-- ko if: showTotalRecords -->
9
9
< text args ="totalRecords "> </ text > <!-- ko i18n: 'records found' --> <!-- /ko -->
10
10
<!-- /ko -->
11
- <!-- ko if: totalSelected -->
11
+ <!-- ko if: totalSelected && showTotalRecords -->
12
12
(< text args ="totalSelected "> </ text > <!-- ko i18n: 'selected' --> <!-- /ko --> )
13
13
<!-- /ko -->
14
14
</ div >
You can’t perform that action at this time.
0 commit comments