0

I have extended ListProduct class into my custom module like this:

di.xml

<preference type="Ktpl\QuickShop\Block\Product\ListProduct" 
   for="Magento\Catalog\Block\Product\ListProduct"/>

After that I have created my own custom function and fetched that product collection into my own custom function and removed unwanted products from product collection. The Products is displaying properly it is just the count is not showing proper.

can anyone help me to do this?

ListProduct.php

<?php
/**
 * Copyright © Magento, Inc. All rights reserved.
 * See COPYING.txt for license details.
 */

namespace Ktpl\QuickShop\Block\Product;

use Magento\Catalog\Model\Product;

/**
 * Product list
 * @api
 * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
 * @since 100.0.2
 */
class ListProduct extends \Magento\Catalog\Block\Product\ListProduct
{
    protected $_customerSession;
    protected $categoryFactory;

    /**
     * ListProduct constructor.
     * @param \Magento\Catalog\Block\Product\Context $context
     * @param \Magento\Framework\Data\Helper\PostHelper $postDataHelper
     * @param \Magento\Catalog\Model\Layer\Resolver $layerResolver
     * @param \Magento\Catalog\Api\CategoryRepositoryInterface $categoryRepository
     * @param \Magento\Framework\Url\Helper\Data $urlHelper
     * @param Helper $helper
     * @param array $data
     * @param \Magento\Customer\Model\Session $customerSession
     * @param \Magento\Catalog\Model\CategoryFactory $categoryFactory
     */
    public function __construct(
        \Magento\Catalog\Block\Product\Context $context,
        \Magento\Framework\Data\Helper\PostHelper $postDataHelper,
        \Magento\Catalog\Model\Layer\Resolver $layerResolver,
        \Magento\Catalog\Api\CategoryRepositoryInterface $categoryRepository,
        \Magento\Framework\Url\Helper\Data $urlHelper,
        array $data = [],
        \Magento\Customer\Model\Session $customerSession,
        \Magento\Catalog\Model\CategoryFactory $categoryFactory
    ) {
        $this->_customerSession = $customerSession;
        $this->categoryFactory = $categoryFactory;
        // $this->_helper = $helper;
        parent::__construct(
            $context,
            $postDataHelper,
            $layerResolver,
            $categoryRepository,
            $urlHelper,
            $data
        );

    }

    public function customProductCollection($baseProductGroupPrice)
    {
        $collection = $this->getLoadedProductCollection();

        foreach ($collection as $key => $value) 
        {
            if($value->getMappingPrice() != $baseProductGroupPrice)
            {
                $collection->removeItemByKey($key);
            }
        }

        return $collection;
    }


}

The Count is showing wrong here.

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.