Magento 2: Exclude group products in list page using a plugin
If you want to exclude group products in category page then follow below steps:
1. Put below code in your module di.xml file.
123 <type name="Magento\Catalog\Model\Layer"><plugin name="LayerPlugin" type="Vendername\Modulename\Plugin\Layer"/></type>
2. The next step is to create Layer.php file in your module and paste below code in Vendername\Modulename\Plugin folder
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 |
<?php namespace Vendername\Modulename\Plugin; use Magento\Catalog\Api\CategoryRepositoryInterface; use Magento\Framework\Exception\NoSuchEntityException; use Magento\Catalog\Model\ResourceModel\Product\Attribute\CollectionFactory as AttributeCollectionFactory; class Layer { /** * Product collections array * * @var array */ protected $_productCollections = []; /** * Key which can be used for load/save aggregation data * * @var string */ protected $_stateKey = null; /** * Core registry * * @var \Magento\Framework\Registry */ protected $registry = null; /** * Store manager * * @var \Magento\Store\Model\StoreManagerInterface */ protected $_storeManager; /** * Catalog product * * @var \Magento\Catalog\Model\ResourceModel\Product */ protected $_catalogProduct; /** * Attribute collection factory * * @var AttributeCollectionFactory */ protected $_attributeCollectionFactory; /** * Layer state factory * * @var \Magento\Catalog\Model\Layer\StateFactory */ protected $_layerStateFactory; /** * @var \Magento\Catalog\Model\Layer\ItemCollectionProviderInterface */ protected $collectionProvider; /** * @var \Magento\Catalog\Model\Layer\Category\StateKey */ protected $stateKeyGenerator; /** * @var \Magento\Catalog\Model\Layer\Category\CollectionFilter */ protected $collectionFilter; /** * @var CategoryRepositoryInterface */ protected $categoryRepository; /** * @param Layer\ContextInterface $context * @param Layer\StateFactory $layerStateFactory * @param AttributeCollectionFactory $attributeCollectionFactory * @param \Magento\Catalog\Model\ResourceModel\Product $catalogProduct * @param \Magento\Store\Model\StoreManagerInterface $storeManager * @param \Magento\Framework\Registry $registry * @param CategoryRepositoryInterface $categoryRepository * @param array $data */ public function __construct( \Magento\Catalog\Model\Layer\StateFactory $layerStateFactory, AttributeCollectionFactory $attributeCollectionFactory, \Magento\Catalog\Model\ResourceModel\Product $catalogProduct, \Magento\Store\Model\StoreManagerInterface $storeManager, \Magento\Framework\Registry $registry, CategoryRepositoryInterface $categoryRepository, array $data = [] ) { $this->_layerStateFactory = $layerStateFactory; $this->_attributeCollectionFactory = $attributeCollectionFactory; $this->_catalogProduct = $catalogProduct; $this->_storeManager = $storeManager; $this->registry = $registry; $this->categoryRepository = $categoryRepository; } public function afterGetProductCollection(\Magento\Catalog\Model\Layer $subject, $collection) { $collection->addAttributeToFilter('type_id', array('eq' => 'grouped')); return $collection; } } |
[crayon-63d3d61ad1700462250332/] Using above fucntion Images can be imported directly from...
Override view block using di.xml and add the below code...
You can check a list of called layout XML for...
Follow the below steps to install and set up PWA...
If you want to remove all leading zero's from order,...
Let our Magento expert connect to discuss your requirement.
We offer Magento
certified developers.
Our Magento clientele
is 500+.
We sign NDA for the
security of your projects.
We’ve performed 100+
Magento migration projects.
Free quotation
on your project.
Three months warranty on
code developed by us.