Skip to content

Commit c30c408

Browse files
committed
Fixed broken category listing pagination
1 parent 4e0d982 commit c30c408

File tree

3 files changed

+18
-5
lines changed

3 files changed

+18
-5
lines changed

ViewModel/Category.php

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use Magento\Framework\Pricing\PriceCurrencyInterface;
88
use Magento\Framework\Serialize\Serializer\Json;
99
use Magento\Framework\View\Element\Block\ArgumentInterface;
10+
use Magento\Framework\View\Layout;
1011
use Magento\Store\Model\StoreManagerInterface;
1112

1213
class Category implements ArgumentInterface
@@ -29,24 +30,30 @@ class Category implements ArgumentInterface
2930
/** @var PriceCurrencyInterface $priceCurrency */
3031
private $priceCurrency;
3132

33+
/** @var Layout $layout */
34+
private $layout;
35+
3236
/**
3337
* Define class dependencies
3438
*
3539
* @param Json $json
3640
* @param StoreManagerInterface $storeManager
3741
* @param Resolver $layerResolver
3842
* @param PriceCurrencyInterface $priceCurrency
43+
* @param Layout $layout
3944
*/
4045
public function __construct(
4146
Json $json,
4247
StoreManagerInterface $storeManager,
4348
Resolver $layerResolver,
44-
PriceCurrencyInterface $priceCurrency
49+
PriceCurrencyInterface $priceCurrency,
50+
Layout $layout
4551
) {
4652
$this->json = $json;
4753
$this->storeManager = $storeManager;
4854
$this->layer = $layerResolver->get();
4955
$this->priceCurrency = $priceCurrency;
56+
$this->layout = $layout;
5057
}
5158

5259
/**
@@ -70,11 +77,16 @@ private function getCategoryName()
7077
*/
7178
private function prepareItems()
7279
{
80+
81+
/** @var \Magento\Catalog\Block\Product\ListProduct $productList */
82+
$productList = $this->layout->createBlock(\Magento\Catalog\Block\Product\ListProduct::class);
83+
$collection = $productList->getLoadedProductCollection();
84+
$productList->getToolbarBlock()->setCollection($productList->getLoadedProductCollection());
85+
7386
$items = [];
7487
$index = 0;
75-
7688
/** @var \Magento\Catalog\Model\Product $product */
77-
foreach ($this->layer->getProductCollection() as $product) {
89+
foreach ($collection as $product) {
7890
$items[] = [
7991
'item_name' => $product->getName(),
8092
'item_id' => $product->getId(),

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"license": [
66
"GPL-3.0-only"
77
],
8-
"version": "1.0.6",
8+
"version": "1.0.7",
99
"require": {
1010
"php": ">=7.4.0"
1111
},

etc/module.xml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
<?xml version="1.0"?>
22

33
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../lib/internal/Magento/Framework/Module/etc/module.xsd">
4-
<module name="Stape_Gtm" schema_version="1.0.6" setup_version="1.0.6">
4+
<module name="Stape_Gtm" schema_version="1.0.7" setup_version="1.0.7">
55
<sequence>
66
<module name="Magento_Backend" />
7+
<module name="Magento_Catalog" />
78
</sequence>
89
</module>
910
</config>

0 commit comments

Comments
 (0)