Skip to content

Commit 76222ea

Browse files
author
Serhii Balko
committed
Merge remote-tracking branch 'origin/MC-41138' into 2.4-develop-pr54
2 parents 940480a + 0e92df5 commit 76222ea

File tree

3 files changed

+70
-17
lines changed

3 files changed

+70
-17
lines changed

app/code/Magento/Catalog/view/frontend/templates/product/list.phtml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ $_helper = $block->getData('outputHelper');
153153
<?php endforeach; ?>
154154
</ol>
155155
</div>
156-
<?= $block->getToolbarHtml() ?>
156+
<?= $block->getChildBlock('toolbar')->setIsBottom(true)->toHtml() ?>
157157
<script type="text/x-magento-init">
158158
{
159159
"[data-role=tocart-form], .form.map.checkout": {

app/code/Magento/Catalog/view/frontend/templates/product/list/toolbar.phtml

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -10,27 +10,23 @@
1010
*
1111
* @var $block \Magento\Catalog\Block\Product\ProductList\Toolbar
1212
*/
13-
14-
// phpcs:disable Magento2.Security.IncludeFile.FoundIncludeFile
15-
// phpcs:disable PSR2.Methods.FunctionCallSignature.SpaceBeforeOpenBracket
1613
?>
1714
<?php if ($block->getCollection()->getSize()) :?>
1815
<?php $widget = $this->helper(\Magento\Framework\Json\Helper\Data::class)->jsonDecode($block->getWidgetOptionsJson());
1916
$widgetOptions = $this->helper(\Magento\Framework\Json\Helper\Data::class)->jsonEncode($widget['productListToolbarForm']);
2017
?>
2118
<div class="toolbar toolbar-products" data-mage-init='{"productListToolbarForm":<?= /* @noEscape */ $widgetOptions ?>}'>
22-
<?php if ($block->isExpanded()) :?>
23-
<?php include ($block->getTemplateFile('Magento_Catalog::product/list/toolbar/viewmode.phtml')) ?>
24-
<?php endif; ?>
25-
26-
<?php include ($block->getTemplateFile('Magento_Catalog::product/list/toolbar/amount.phtml')) ?>
27-
28-
<?= $block->getPagerHtml() ?>
29-
30-
<?php include ($block->getTemplateFile('Magento_Catalog::product/list/toolbar/limiter.phtml')) ?>
31-
32-
<?php if ($block->isExpanded()) :?>
33-
<?php include ($block->getTemplateFile('Magento_Catalog::product/list/toolbar/sorter.phtml')) ?>
34-
<?php endif; ?>
19+
<?php if ($block->getIsBottom()): ?>
20+
<?= $block->getPagerHtml() ?>
21+
<?= $block->fetchView($block->getTemplateFile('Magento_Catalog::product/list/toolbar/limiter.phtml')) ?>
22+
<?php else: ?>
23+
<?php if ($block->isExpanded()): ?>
24+
<?= $block->fetchView($block->getTemplateFile('Magento_Catalog::product/list/toolbar/viewmode.phtml')) ?>
25+
<?php endif ?>
26+
<?= $block->fetchView($block->getTemplateFile('Magento_Catalog::product/list/toolbar/amount.phtml')) ?>
27+
<?php if ($block->isExpanded()): ?>
28+
<?= $block->fetchView($block->getTemplateFile('Magento_Catalog::product/list/toolbar/sorter.phtml')) ?>
29+
<?php endif ?>
30+
<?php endif ?>
3531
</div>
3632
<?php endif ?>

dev/tests/integration/testsuite/Magento/Catalog/Controller/CategoryTest.php

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,18 @@
88
namespace Magento\Catalog\Controller;
99

1010
use Magento\Catalog\Api\CategoryRepositoryInterface;
11+
use Magento\Catalog\Api\Data\CategoryInterface;
1112
use Magento\Catalog\Model\Category;
1213
use Magento\Catalog\Model\Category\Attribute\LayoutUpdateManager;
1314
use Magento\Catalog\Model\Product\ProductList\Toolbar as ToolbarModel;
15+
use Magento\Catalog\Model\ResourceModel\Category\Collection;
16+
use Magento\Catalog\Model\ResourceModel\Category\CollectionFactory;
1417
use Magento\Catalog\Model\Session;
1518
use Magento\Framework\App\Http\Context;
1619
use Magento\Framework\ObjectManagerInterface;
1720
use Magento\Framework\Registry;
1821
use Magento\Framework\View\LayoutInterface;
22+
use Magento\Store\Model\Store;
1923
use Magento\TestFramework\Catalog\Model\CategoryLayoutUpdateManager;
2024
use Magento\TestFramework\Helper\Bootstrap;
2125
use Magento\TestFramework\TestCase\AbstractController;
@@ -53,6 +57,11 @@ class CategoryTest extends AbstractController
5357
*/
5458
private $httpContext;
5559

60+
/**
61+
* @var CollectionFactory
62+
*/
63+
private $categoryCollectionFactory;
64+
5665
/**
5766
* @inheritdoc
5867
*/
@@ -64,6 +73,8 @@ protected function setUp(): void
6473
$this->objectManager->configure([
6574
'preferences' => [LayoutUpdateManager::class => CategoryLayoutUpdateManager::class]
6675
]);
76+
77+
$this->categoryCollectionFactory = $this->objectManager->create(CollectionFactory::class);
6778
$this->registry = $this->objectManager->get(Registry::class);
6879
$this->layout = $this->objectManager->get(LayoutInterface::class);
6980
$this->session = $this->objectManager->get(Session::class);
@@ -233,4 +244,50 @@ public function testViewWithRememberPaginationAndPreviousValue(): void
233244
$this->assertEquals($newPaginationValue, $this->session->getData(ToolbarModel::LIMIT_PARAM_NAME));
234245
$this->assertEquals($newPaginationValue, $this->httpContext->getValue(ToolbarModel::LIMIT_PARAM_NAME));
235246
}
247+
248+
/**
249+
* Test to generate category page without duplicate html element ids
250+
*
251+
* @magentoDataFixture Magento/Catalog/_files/category_with_three_products.php
252+
* @magentoDataFixture Magento/Catalog/_files/catalog_category_product_reindex_all.php
253+
* @magentoDataFixture Magento/Catalog/_files/catalog_product_category_reindex_all.php
254+
* @magentoDbIsolation disabled
255+
*/
256+
public function testViewWithoutDuplicateHmlElementIds(): void
257+
{
258+
$category = $this->loadCategory('Category 999', Store::DEFAULT_STORE_ID);
259+
$this->dispatch('catalog/category/view/id/' . $category->getId());
260+
261+
$responseHtml = $this->getResponse()->getBody();
262+
$htmlElementIds = ['modes-label', 'mode-list', 'toolbar-amount', 'sorter', 'limiter'];
263+
foreach ($htmlElementIds as $elementId) {
264+
$matches = [];
265+
$idAttribute = "id=\"$elementId\"";
266+
preg_match_all("/$idAttribute/mx", $responseHtml, $matches);
267+
$this->assertCount(1, $matches[0]);
268+
$this->assertEquals($idAttribute, $matches[0][0]);
269+
}
270+
}
271+
272+
/**
273+
* Loads category by id
274+
*
275+
* @param string $categoryName
276+
* @param int $storeId
277+
* @return CategoryInterface
278+
*/
279+
private function loadCategory(string $categoryName, int $storeId): CategoryInterface
280+
{
281+
/** @var Collection $categoryCollection */
282+
$categoryCollection = $this->categoryCollectionFactory->create();
283+
/** @var CategoryInterface $category */
284+
$category = $categoryCollection->setStoreId($storeId)
285+
->addAttributeToSelect('display_mode', 'left')
286+
->addAttributeToFilter(CategoryInterface::KEY_NAME, $categoryName)
287+
->setPageSize(1)
288+
->getFirstItem();
289+
$category->setStoreId($storeId);
290+
291+
return $category;
292+
}
236293
}

0 commit comments

Comments
 (0)