Category: Magento 2 (page 24 of 33)

Magento 2 – How to Get Order Collection

In this post I am going to explain how to get list of all orders or you can say order collection in magento 2. 1. Using Dependency Injection Add below code snippet in Block class. protected $_orderCollectionFactory; public function __construct( \Magento\Backend\Block\Template\Context $context, \Magento\Sales\Model\ResourceModel\Order\CollectionFactory $orderCollectionFactory, array $data = [] ) { $this->_orderCollectionFactory = $orderCollectionFactory; parent::__construct($context, $data);…

Magento 2 – How to Get List of All Customers

In this post I am going to explain how to get list of all customers or you can say customer collection in magento 2. 1. Using Dependency Injection Add below code snippet in Block class. protected $_customerFactory; public function __construct( \Magento\Backend\Block\Template\Context $context, \Magento\Customer\Model\CustomerFactory $customerFactory, array $data = [] ) { $this->_customerFactory = $customerFactory; parent::__construct($context, $data);…

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…

Older posts Newer posts