Page 51 of 68

Magento 2 – How to Create Custom Widget

In this post I am going to explain how to create custom widget in magento 2. First we will create the widget configuration file widget.xml, that contains all widget fields. So, create the widget.xml file with following content. File Path: etc/widget.xml <?xml version=”1.0″ encoding=”UTF-8″?> <widgets xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance” xsi:noNamespaceSchemaLocation=”urn:magento:module:Magento_Widget:etc/widget.xsd”> <widget id=”my_module_widget” class=”Ht\Mymodule\Block\Widget\Mymodule”> <label translate=”true”>Ht Mymodule Widget</label> <description>Ht…

Magento 2 – How to Change Customer Password from Database

In this post I am going to explain how to change customer password from database in magento 2. Go to phpmyadmin and copy the following sql query. UPDATE `customer_entity` SET `password_hash` = CONCAT(SHA2(‘xxxxxxxxYOURPASSWORD’, 256), ‘:xxxxxxxx:1’) WHERE `entity_id` = 1; Change the “entity_id” with your id and just change “YOURPASSWORD” (keep the xxxxxxxx) with your new…

Magento 2 – How to Add Product Attribute Programmatically

In this post I am going to explain how to add product attribute programmatically in magento 2. We are going to create three custom product attributes. Yes/No, Select Option and Text field. We need to create the data setup script(InstallData.php) with parameters of the new attribute. File path: app/code/Ht/Mymodule/Setup/InstallData.php <?php namespace Ht\Mymodule\Setup; use Magento\Eav\Setup\EavSetup; use…

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!!

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…

Create Urgency & Scarcity with Sales Countdown Timer Magento 2 Extension

What happens every day in your eCommerce  store? Customers are coming, visit product page and leave your product page. There is no purchase. Customers have natural tendency to delay buying as long as possible. It is necessary to boost conversion and sales. It can be achieved by only two thing  and that is FOMO and…

« Older posts Newer posts »