Skip to content

Commit d5dbe99

Browse files
committed
ACPT-677: Catalog product grid improvement
- Use view model to eliminate BIC in block;
1 parent 2975ead commit d5dbe99

File tree

7 files changed

+80
-27
lines changed

7 files changed

+80
-27
lines changed

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

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1317,24 +1317,4 @@ public function getMainButtonsHtml()
13171317
}
13181318
return $html;
13191319
}
1320-
1321-
/**
1322-
* Check if configuration setting to calculate approximate total number of products in grid is enabled.
1323-
*
1324-
* @return bool
1325-
*/
1326-
public function calculateApproximateProductsTotalNumber(): bool
1327-
{
1328-
return (bool)$this->_scopeConfig->getValue('admin/grid/calculate_approximate_total_number_of_products');
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-
}
13401320
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\Backend\ViewModel;
9+
10+
use Magento\Framework\App\Config\ScopeConfigInterface;
11+
use Magento\Framework\View\Element\Block\ArgumentInterface;
12+
13+
/**
14+
* Get configuration values related to approximate number of products calculation for grid.
15+
*/
16+
class CalculateApproximateProductsNumber implements ArgumentInterface
17+
{
18+
/**
19+
* @var ScopeConfigInterface
20+
*/
21+
private ScopeConfigInterface $scopeConfig;
22+
23+
/**
24+
* @param ScopeConfigInterface $scopeConfig
25+
*/
26+
public function __construct(
27+
ScopeConfigInterface $scopeConfig
28+
) {
29+
$this->scopeConfig = $scopeConfig;
30+
}
31+
32+
/**
33+
* Check if configuration setting to calculate approximate total number of products in grid is enabled.
34+
*
35+
* @return bool
36+
*/
37+
public function calculateApproximateProductsTotalNumber(): bool
38+
{
39+
return (bool)$this->scopeConfig->getValue('admin/grid/calculate_approximate_total_number_of_products');
40+
}
41+
42+
/**
43+
* Get records threshold for approximate total number of products calculation.
44+
*
45+
* @return int
46+
*/
47+
public function getRecordsThreshold(): int
48+
{
49+
return (int)$this->scopeConfig->getValue('admin/grid/records_threshold');
50+
}
51+
}

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

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,10 @@ use Magento\Catalog\Ui\DataProvider\Product\ProductCollection;
2121
/**
2222
* @var \Magento\Backend\Block\Widget\Grid\Extended $block
2323
* @var \Magento\Framework\View\Helper\SecureHtmlRenderer $secureRenderer
24+
* @var \Magento\Backend\ViewModel\CalculateApproximateProductsNumber $viewModel
2425
*/
2526
$numColumns = count($block->getColumns());
27+
$viewModel = $block->getViewModel();
2628

2729
?>
2830
<?php if ($block->getCollection()): ?>
@@ -71,9 +73,9 @@ $numColumns = count($block->getColumns());
7173
<?php endif; ?>
7274
<?php $countRecords = $block->getCollection()->getSize(); ?>
7375
<div class="admin__control-support-text">
74-
<?php if (!$block->calculateApproximateProductsTotalNumber()
75-
|| !$block->getCollection() instanceof ProductCollection
76-
|| $countRecords < $block->getRecordsThreshold()): ?>
76+
<?php if (!$block->getCollection() instanceof ProductCollection
77+
|| !$viewModel->calculateApproximateProductsTotalNumber()
78+
|| $countRecords < $viewModel->getRecordsThreshold()): ?>
7779
<span id="<?= $block->escapeHtml($block->getHtmlId()) ?>-total-count"
7880
<?= /* @noEscape */ $block->getUiId('total-count') ?>>
7981
<?= /* @noEscape */ $countRecords ?>
@@ -131,9 +133,9 @@ $numColumns = count($block->getColumns());
131133
<span><?= $block->escapeHtml(__('Previous page')) ?></span>
132134
</button>
133135
<?php endif; ?>
134-
<?php if (!$block->calculateApproximateProductsTotalNumber()
135-
|| !$block->getCollection() instanceof ProductCollection
136-
|| $countRecords < $block->getRecordsThreshold()): ?>
136+
<?php if (!$block->getCollection() instanceof ProductCollection
137+
|| !$viewModel->calculateApproximateProductsTotalNumber()
138+
|| $countRecords < $viewModel->getRecordsThreshold()): ?>
137139
<input type="text"
138140
id="<?= $block->escapeHtml($block->getHtmlId()) ?>_page-current"
139141
name="<?= $block->escapeHtmlAttr($block->getVarNamePage()) ?>"

app/code/Magento/Sales/view/adminhtml/layout/sales_order_create_index.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,11 @@
7171
<block class="Magento\Sales\Block\Adminhtml\Order\Create\Search" template="Magento_Sales::order/create/abstract.phtml" name="search">
7272
<block class="Magento\Sales\Block\Adminhtml\Order\Create\Search\Grid" name="search_grid" as="grid"/>
7373
</block>
74+
<referenceBlock name="search_grid">
75+
<arguments>
76+
<argument name="view_model" xsi:type="object">Magento\Backend\ViewModel\CalculateApproximateProductsNumber</argument>
77+
</arguments>
78+
</referenceBlock>
7479
<block class="Magento\Sales\Block\Adminhtml\Order\Create\Items" template="Magento_Sales::order/create/items.phtml" name="items">
7580
<block class="Magento\Sales\Block\Adminhtml\Order\Create\Items\Grid" template="Magento_Sales::order/create/items/grid.phtml" name="items_grid">
7681
<block class="Magento\Sales\Block\Adminhtml\Order\Create\Coupons" template="Magento_Sales::order/create/coupons/form.phtml" name="coupons">

app/code/Magento/Sales/view/adminhtml/layout/sales_order_create_load_block_data.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,11 @@
4646
<block class="Magento\Sales\Block\Adminhtml\Order\Create\Search" template="Magento_Sales::order/create/abstract.phtml" name="search">
4747
<block class="Magento\Sales\Block\Adminhtml\Order\Create\Search\Grid" name="search.grid" as="grid"/>
4848
</block>
49+
<referenceBlock name="search.grid">
50+
<arguments>
51+
<argument name="view_model" xsi:type="object">Magento\Backend\ViewModel\CalculateApproximateProductsNumber</argument>
52+
</arguments>
53+
</referenceBlock>
4954
<block class="Magento\Sales\Block\Adminhtml\Order\Create\Items" template="Magento_Sales::order/create/items.phtml" name="items">
5055
<block class="Magento\Sales\Block\Adminhtml\Order\Create\Items\Grid" template="Magento_Sales::order/create/items/grid.phtml" name="items_grid">
5156
<block class="Magento\Sales\Block\Adminhtml\Order\Create\Coupons" template="Magento_Sales::order/create/coupons/form.phtml" name="coupons">

app/code/Magento/Sales/view/adminhtml/layout/sales_order_create_load_block_search.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,11 @@
1111
<block class="Magento\Sales\Block\Adminhtml\Order\Create\Search" template="Magento_Sales::order/create/abstract.phtml" name="search">
1212
<block class="Magento\Sales\Block\Adminhtml\Order\Create\Search\Grid" name="search.grid" as="grid"/>
1313
</block>
14+
<referenceBlock name="search.grid">
15+
<arguments>
16+
<argument name="view_model" xsi:type="object">Magento\Backend\ViewModel\CalculateApproximateProductsNumber</argument>
17+
</arguments>
18+
</referenceBlock>
1419
</referenceContainer>
1520
</body>
1621
</page>

app/code/Magento/Sales/view/adminhtml/layout/sales_order_create_load_block_search_grid.xml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,12 @@
88
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
99
<body>
1010
<referenceContainer name="content">
11-
<block class="Magento\Sales\Block\Adminhtml\Order\Create\Search\Grid" name="serach.grid" as="grid"/>
11+
<block class="Magento\Sales\Block\Adminhtml\Order\Create\Search\Grid" name="search.grid" as="grid"/>
1212
</referenceContainer>
13+
<referenceBlock name="search.grid">
14+
<arguments>
15+
<argument name="view_model" xsi:type="object">Magento\Backend\ViewModel\CalculateApproximateProductsNumber</argument>
16+
</arguments>
17+
</referenceBlock>
1318
</body>
1419
</page>

0 commit comments

Comments
 (0)