77use Magento \Framework \Pricing \PriceCurrencyInterface ;
88use Magento \Framework \Serialize \Serializer \Json ;
99use Magento \Framework \View \Element \Block \ArgumentInterface ;
10+ use Magento \Framework \View \Layout ;
1011use Magento \Store \Model \StoreManagerInterface ;
1112
1213class 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 (),
0 commit comments