Tag: Magento (page 13 of 16)

Magento 2 – How to Get Product by SKU

In this post I am going to explain how to load product by SKU in magento 2. 1. Using Dependency Injection Add below code snippet in Block class. protected $_productRepository; public function __construct( \Magento\Backend\Block\Template\Context $context, \Magento\Catalog\Model\ProductRepository $productRepository, array $data = [] ) { $this->_productRepository = $productRepository; parent::__construct($context, $data); } public function getProductBySku($productSku) { return $this->_productRepository->get($productSku);…

Magento 2 – How to Get Product by ID

In this post I am going to explain how to load product by ID in magento 2. 1. Using Dependency Injection Add below code snippet in Block class. protected $_productRepository; public function __construct( \Magento\Backend\Block\Template\Context $context, \Magento\Catalog\Model\ProductRepository $productRepository, array $data = [] ) { $this->_productRepository = $productRepository; parent::__construct($context, $data); } public function getProductById($productId) { return $this->_productRepository->getById($productId);…

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 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.3.0 Released! What’s New in Magento 2.3.0?

Great News for Magento Community! The new version of Magento 2.3.0 is Release. Magento Open Source 2.3.0 includes a wealth of new features as well as hundreds of enhancements and fixes to the core product. What’s New in Magento 2.3? Let see the new Features & Improvements in Magento 2.3.0 Progressive Web Apps (PWA) GraphQL…

3 Must have Magento 2 WhatsApp Extensions to Boost Sales

WhatsApp has proven to be a tool so valuable with all of the noise across social media — if you haven’t started building a WhatsApp marketing campaign, now is the time. That’s why we’re introducing Magento 2 WhatsApp Extensions: a new way to run your business on the go by bringing customer conversations, marketing workflows,…

How to enable CAPTCHA in Magento 2?

This tutorial will explain you how to enable CAPTCHA protection in Magento 2 store. CAPTCHAs help protect your site from spamming by bots and other malicious actors. To enable CAPTCHA protection for the administration side on Magento 2, follow below steps: 1) Log in to Magento 2 using your admin account. 2) From left sidebar,…

Older posts Newer posts