Tag: Magento 2 Tutorials (page 8 of 10)

Magento 2 – How to Add Customer Attribute Programmatically

In this post I am going to explain how to add customer attribute programmatically in magento 2. First we need to create the setup file InstallData.php File path: app/code/Ht/Mymodule/Setup/InstallData.php <?php namespace Ht\Mymodule\Setup; use Magento\Eav\Model\Config; use Magento\Eav\Setup\EavSetup; use Magento\Eav\Setup\EavSetupFactory; use Magento\Framework\Setup\InstallDataInterface; use Magento\Framework\Setup\ModuleContextInterface; use Magento\Framework\Setup\ModuleDataSetupInterface; class InstallData implements InstallDataInterface { private $eavSetupFactory; public function __construct( EavSetupFactory…

Magento 2 – How to Get Product Collection by Category

In this post I am going to explain how to get product collection by category in magento 2. 1. Using Dependency Injection Add below code snippet in Block class. protected $_categoryFactory; protected $_productCollectionFactory; public function __construct( \Magento\Backend\Block\Template\Context $context, \Magento\Catalog\Model\CategoryFactory $categoryFactory, \Magento\Catalog\Model\ResourceModel\Product\CollectionFactory $productCollectionFactory, array $data = [] ) { $this->_categoryFactory = $categoryFactory; $this->_productCollectionFactory = $productCollectionFactory; parent::__construct($context,…

Magento 2 – How to Get Sub Categories of Specific Category

In this post I am going to explain how to get sub categories of specific category in magento 2. 1. Using Dependency Injection Add below code snippet in Block class. protected $_categoryFactory; public function __construct( \Magento\Backend\Block\Template\Context $context, \Magento\Catalog\Model\CategoryFactory $categoryFactory, array $data = [] ) { $this->_categoryFactory = $categoryFactory; parent::__construct($context, $data); } /* Get category object…

Magento 2 – How to Get Parent Category of Specific Category

In this post I am going to explain how to get parent category of specific category in magento 2. 1. Using Dependency Injection Add below code snippet in Block class. protected $_categoryFactory; public function __construct( \Magento\Backend\Block\Template\Context $context, \Magento\Catalog\Model\CategoryFactory $categoryFactory, array $data = [] ) { $this->_categoryFactory = $categoryFactory; parent::__construct($context, $data); } /* Get category object…

Magento 2 – How to Call CMS Static Block in phtml file

In this post I am going to explain how to to call CMS static block in phtml file. Use below code snippet to get CMS static block content in any template file. echo $this->getLayout() ->createBlock(‘Magento\Cms\Block\Block’) ->setBlockId(‘cms_static_block_identifier’) ->toHtml(); Thats it. Enjoy Magento 2!! Team HiddenTechiesWrite an article about ecommerce that help people to grow their ecommerce…

Magento 2 – How to Call Template Block in any CMS Page or CMS Static Block

In this post I am going to explain how to to call template block in any CMS page or CMS static block. If you want to call template block in CMS page or CMS static block, then you can do it by below code. Suppose that we have a phtml file called mytemplate.phtml of module…

How to install Magento 2 extensions using FTP

Extension helps you to make your business much easier and provide smooth shoppable experience to your customer. So here we will learn how to install Magento 2 extension to your store using FTP. Install Magento 2 extension using FTP First of all download your selected Magento 2 extensions and unzip it. Now connect your store…

Magento 2 – How to Call Template Block in phtml File

In this post I am going to explain how to to call template block in phtml file or how to use phtml file in another phtml file. Sometimes you want to get content from another phtml file without defining in layout. In this case, we can use a method called toHtml of a block. Suppose…

Magento 2 – How to get Current Store ID, Code, Name, URL and Website ID

In this post I am going to explain how to get current store information like store id, code, name, url and website id in Magento 2. 1. Using Dependency Injection protected $_storeManager; public function __construct( \Magento\Backend\Block\Template\Context $context, \Magento\Store\Model\StoreManagerInterface $storeManager, array $data = [] ) { $this->_storeManager = $storeManager; parent::__construct($context, $data); } public function getStore() {…

Magento 2 – How to Check Current URL is Homepage

In this post I am going to explain How to check IsHomePage in Magento 2. Add below code snippet in Block class. protected $_logo; public function __construct( \Magento\Backend\Block\Template\Context $context, \Magento\Theme\Block\Html\Header\Logo $logo, array $data = [] ) { $this->_logo = $logo; parent::__construct($context, $data); } public function isHomePage() { return $this->_logo->isHomePage(); }   Add below code snippet…

Older posts Newer posts