Getting product collection in Magento 2 Step 1: Declare in Vendor_ModuleName Block Step 2: Display product collection in phtml file .. Step 1: Declare in Vendor_ModuleName Block You will use a block class of the module Vendor_ModuleName, then possibly inject the object of `\Magento\Catalog\Model\ResourceModel\Product\CollectionFactory` in the constructor of the module’s block class. app/code/Vendor/ModuleName/Block/ProductCollection.php add code this code <?php namespace Vendor\ModuleName\Block; class ProductCollection extends \Magento\Framework\View\Element\Template { protected $_productCollectionFactory; public function __construct( \Magento\Backend\Block\Template\Context $context, \Magento\Catalog\Model\ResourceModel\Product\CollectionFactory $productCollectionFactory, array $data = [] ) { $this->_productCollectionFact...
Magento 2 is an open-source E-commerce platform, that help to support any medium or large scale business as online store. it is easy to say that Magento is best option that one can growth of their business. I have done 40+ magento projects till now, develop 10-12 extension, and custom online shipping method, payment method using API.
Comments
Post a Comment