Category: Magento (page 3 of 24)

How to get CMS Page Collection in Magento 2

In this post I am going to explain how to get cms page collection in Magento 2. 1. Using Dependency Injection Add below code snippet in Block class. protected $_pageRepository; protected $_searchCriteriaBuilder; public function __construct( \Magento\Framework\View\Element\Template\Context $context, \Magento\Cms\Api\PageRepositoryInterface $pageRepository, \Magento\Framework\Api\SearchCriteriaBuilder $searchCriteriaBuilder, array $data = [] ) { $this->_pageRepository = $pageRepository; $this->_searchCriteriaBuilder = $searchCriteriaBuilder; parent::__construct($context, $data);…

Magento 2 – How to Add Validation in System Configuration

In this post I am going to explain how to add validation in system configuration in Magento 2. In order to do validatetion in system configuration field, you just need to add “validate” tag for field in system.xml file and pass validation class in it. See the below example of required field validation and email…

How to Get All Regions of Country by Country Code in Magento 2

In this post I am going to explain how to get all regions of country by country code Magento 2. Add below code snippet in Block class. protected $_country; public function __construct( \Magento\Framework\View\Element\Template\Context $context, \Magento\Directory\Model\Country $country, array $data = [] ) { $this->_country = $country; parent::__construct($context, $data); } // Get All Regions of Country public…

How to get CMS Block Collection in Magento 2

In this post I am going to explain how to get cms block collection in Magento 2. 1. Using Dependency Injection Add below code snippet in Block class. protected $_blockRepository; protected $_searchCriteriaBuilder; public function __construct( \Magento\Framework\View\Element\Template\Context $context, \Magento\Cms\Api\BlockRepositoryInterface $blockRepository, \Magento\Framework\Api\SearchCriteriaBuilder $searchCriteriaBuilder, array $data = [] ) { $this->_blockRepository = $blockRepository; $this->_searchCriteriaBuilder = $searchCriteriaBuilder; parent::__construct($context, $data);…

How to Remove Block From Layout on Specific Condition in Magento 2

In this post I am going to explain how to remove block from layout on specific condition Magento 2. If you have a specific condition to add/remove block then you can achieve it by observer. Here I have given the example to remove search block. First you need to create event.xml file on below path….

Magento 1 to Magento 2 Migration without Breaking Anything

With forecasts indicating an 18% increase in e-commerce spending in the United States alone, your company should put more attention on its user interface and optimize the overall shopping experience for your customers. Increasingly, people are buying things online, which has pushed companies to develop eCommerce Websites and apps for small businesses. Platforms like Magneto…

How to Get Customer Data By Customer Email in Magento 2

In this post I am going to explain how to get customer data by customer email Magento 2. Using below code snippet you can get customer data by passing customer email and website id. Add below code snippet in Block class. protected $_customerRepository; public function __construct( \Magento\Framework\View\Element\Template\Context $context, \Magento\Customer\Api\CustomerRepositoryInterface $customerRepository, array $data = [] )…

Magento 2 – How to get Magento 2 Edition and Version

In this post I am going to explain how to get Magento 2 edition and version. 1. Using Dependency Injection Add below code snippet in Block class. protected $_productMetadataInterface; public function __construct( \Magento\Framework\View\Element\Template\Context $context, \Magento\Framework\App\ProductMetadataInterface $productMetadataInterface, array $data = [] ) { $this->_productMetadataInterface = $productMetadataInterface; parent::__construct($context, $data); } /* Get Magento 2 Edition */ public…

Magento 2 – How To Get System Configuration Value in phtml File

In this post I am going to explain how to get system configuration value in phtml file in Magento 2. You can get system configuration field value programatically as below. Add below code snippet in Block class. protected $scopeConfig; public function __construct( \Magento\Framework\View\Element\Template\Context $context, \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig, array $data = [] ) { $this->scopeConfig = $scopeConfig;…

Magento 2 – How to Unlock Admin User via Command Line

In this post I am going to explain how to unlock admin user via command line in Magento 2. First login to SSH panel and navigate to Magento 2 setup root. Run the following command. It will show usage of the command. php bin/magento admin:user:unlock –help Output: Description: Unlock Admin Account Usage: admin:user:unlock <username> Arguments:…

Older posts Newer posts