Skip to content

Commit 2975ead

Browse files
committed
ACPT-677: Catalog product grid improvement
- Add records threshold as a configurable option;
1 parent a9af93d commit 2975ead

File tree

8 files changed

+27
-20
lines changed

8 files changed

+27
-20
lines changed

app/code/Magento/Backend/Block/Widget/Grid/Extended.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1327,4 +1327,14 @@ public function calculateApproximateProductsTotalNumber(): bool
13271327
{
13281328
return (bool)$this->_scopeConfig->getValue('admin/grid/calculate_approximate_total_number_of_products');
13291329
}
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+
}
13301340
}

app/code/Magento/Backend/etc/adminhtml/system.xml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -488,6 +488,14 @@
488488
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
489489
<comment>Calculate approximate total number of products in products grid.</comment>
490490
</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>
491499
</group>
492500
</section>
493501
<section id="web" translate="label" type="text" sortOrder="20" showInDefault="1" showInWebsite="1" showInStore="1">

app/code/Magento/Backend/etc/config.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
<admin>
3535
<grid>
3636
<calculate_approximate_total_number_of_products>1</calculate_approximate_total_number_of_products>
37+
<records_threshold>20000</records_threshold>
3738
</grid>
3839
</admin>
3940
<general>

app/code/Magento/Backend/view/adminhtml/templates/widget/grid/extended.phtml

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,7 @@ $numColumns = count($block->getColumns());
7373
<div class="admin__control-support-text">
7474
<?php if (!$block->calculateApproximateProductsTotalNumber()
7575
|| !$block->getCollection() instanceof ProductCollection
76-
|| ($block->calculateApproximateProductsTotalNumber()
77-
&& $block->getCollection() instanceof ProductCollection
78-
&& $countRecords < ProductCollection::RECORDS_LIMIT)): ?>
76+
|| $countRecords < $block->getRecordsThreshold()): ?>
7977
<span id="<?= $block->escapeHtml($block->getHtmlId()) ?>-total-count"
8078
<?= /* @noEscape */ $block->getUiId('total-count') ?>>
8179
<?= /* @noEscape */ $countRecords ?>
@@ -135,9 +133,7 @@ $numColumns = count($block->getColumns());
135133
<?php endif; ?>
136134
<?php if (!$block->calculateApproximateProductsTotalNumber()
137135
|| !$block->getCollection() instanceof ProductCollection
138-
|| ($block->calculateApproximateProductsTotalNumber()
139-
&& $block->getCollection() instanceof ProductCollection
140-
&& $countRecords < ProductCollection::RECORDS_LIMIT)): ?>
136+
|| $countRecords < $block->getRecordsThreshold()): ?>
141137
<input type="text"
142138
id="<?= $block->escapeHtml($block->getHtmlId()) ?>_page-current"
143139
name="<?= $block->escapeHtmlAttr($block->getVarNamePage()) ?>"

app/code/Magento/Catalog/Plugin/Ui/DataProvider/Product/ProductDataProvider.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88

99
namespace Magento\Catalog\Plugin\Ui\DataProvider\Product;
1010

11-
use Magento\Catalog\Ui\DataProvider\Product\ProductCollection;
1211
use Magento\Catalog\Ui\DataProvider\Product\ProductDataProvider as CatalogProductDataProvider;
1312
use Magento\Framework\App\Config\ScopeConfigInterface;
1413

@@ -53,7 +52,7 @@ private function addShowTotalRecords(array $data): array
5352
{
5453
if (key_exists('totalRecords', $data)) {
5554
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')) {
5756
$data['showTotalRecords'] = false;
5857
} else {
5958
$data['showTotalRecords'] = true;

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

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,6 @@
1414
*/
1515
class ProductCollection extends \Magento\Catalog\Model\ResourceModel\Product\Collection
1616
{
17-
/**
18-
* Limit to display/hide total number of products in grid
19-
*/
20-
public const RECORDS_LIMIT = 20000;
21-
2217
/**
2318
* Disables using of price index for grid rendering
2419
*
@@ -43,7 +38,7 @@ public function getSize()
4338
$sql = $this->getSelectCountSql();
4439
$estimatedCount = $this->analyzeCount($sql);
4540

46-
if ($estimatedCount > self::RECORDS_LIMIT) {
41+
if ($estimatedCount > $this->_scopeConfig->getValue('admin/grid/records_threshold')) {
4742
$columns = $sql->getPart(Select::COLUMNS);
4843
$sql->reset(Select::COLUMNS);
4944

@@ -53,10 +48,10 @@ public function getSize()
5348
}
5449
}
5550
$sql->setPart(Select::COLUMNS, $columns);
56-
$sql->limit(self::RECORDS_LIMIT);
51+
$sql->limit($this->_scopeConfig->getValue('admin/grid/records_threshold'));
5752
$query = new \Zend_Db_Expr('SELECT COUNT(*) FROM (' . $sql->assemble() . ') AS c');
5853
$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')) {
6055
$this->_totalRecords = $estimatedCount;
6156
}
6257
} else {

app/code/Magento/Catalog/etc/adminhtml/di.xml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@
9494
<argument name="collectionFactory" xsi:type="object">\Magento\Catalog\Ui\DataProvider\Product\ProductCollectionFactory</argument>
9595
<argument name="modifiersPool" xsi:type="object">Magento\Catalog\Ui\DataProvider\Product\Listing\Modifier\Pool</argument>
9696
</arguments>
97+
<plugin name="add_show_total_records_to_catalog_product_data" type="Magento\Catalog\Plugin\Ui\DataProvider\Product\ProductDataProvider"/>
9798
</type>
9899
<type name="Magento\Catalog\Model\Product\Action">
99100
<plugin name="invalidate_pagecache_after_update_product_attributes" type="Magento\Catalog\Plugin\Model\Product\Action\UpdateAttributesFlushCache"/>
@@ -290,7 +291,4 @@
290291
</argument>
291292
</arguments>
292293
</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>
296294
</config>

app/code/Magento/Ui/view/base/web/templates/grid/paging-total.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
<!-- ko if: showTotalRecords -->
99
<text args="totalRecords"></text> <!-- ko i18n: 'records found' --><!-- /ko -->
1010
<!-- /ko -->
11-
<!-- ko if: totalSelected -->
11+
<!-- ko if: totalSelected && showTotalRecords -->
1212
(<text args="totalSelected"></text> <!-- ko i18n: 'selected' --><!-- /ko -->)
1313
<!-- /ko -->
1414
</div>

0 commit comments

Comments
 (0)