Category: Magento Tutorials (page 4 of 12)

Magento 2 – How to Add Dependant Field in Admin System Configuration

In this post I am going to explain how to add dependant field in admin system configuration in magento 2. In order to create a field dependant on single value, use the below code: <depends> <field id=”parent_field_id”>1</field> </depends> And to create a field dependant on two or more values, use the below code: <depends> <field…

Magento 2 – How to Add Customer Address Programmatically

In this post I am going to explain how to add customer address programmatically in magento 2. 1. Using Dependency Injection Add below code snippet in Block class. protected $addressFactory; public function __construct( \Magento\Catalog\Block\Product\Context $context, \Magento\Customer\Model\AddressFactory $addressFactory, array $data = [] ) { $this->addressFactory = $addressFactory; parent::__construct($context, $data); } public function addAddress($customerId) { $firstName =…

Magento 2 – How to Add Date Picker in Custom Form

In this post I am going to explain how to add date picker in custom form. Date Field HTML: <div class=”field start_date”> <label class=”label” for=”start_date”> <span><?php echo __(‘Start Date’); ?></span> </label> <div class=”control”> <input id=”start_date” name=”start_date” title=”<?php echo __(‘Start Date’); ?>” class=”datepicker input-text” type=”text” value=””/> </div> </div> Add the below script to apply the date…

Magento 2 – How to Create Customer Programmatically

In this post I am going to explain how to create customer programmatically in magento 2. 1. Using Dependency Injection Add below code snippet in Block class. protected $storeManager; protected $customerFactory; public function __construct( \Magento\Catalog\Block\Product\Context $context, \Magento\Store\Model\StoreManagerInterface $storeManager, \Magento\Customer\Model\CustomerFactory $customerFactory, array $data = [] ) { $this->storeManager = $storeManager; $this->customerFactory = $customerFactory; parent::__construct($context, $data); }…

Magento 2 – How to Add Form Key in phtml File

In this post I am going to explain how to add form key in phtml file. Add below code snippet in Block class. public function __construct( \Magento\Catalog\Block\Product\Context $context, \Magento\Framework\Data\Form\FormKey $formKey, array $data = [] ) { parent::__construct($context, $data); $this->formKey = $formKey; } public function getFormKey() { return $this->formKey->getFormKey(); } Add below code snippet in template…

Magento 2 – How to Unlock Reindex Process | HiddenTechies

In Magento 2, Sometimes an issue comes like the indexing process gets locked at the time of reindexing. When the process or the index type is locked then you cannot reindex that specific locked index type. The reindex will always skip that index type and you will get an error as below. “Index is locked…

Magento 2 – How to Get Region Id and Region Name By Region Code

In this post I am going to explain how to get region id and region name by region code in Magento 2. Use this below code snippet. $regionCode = ‘CA’; $countryCode = ‘US’; $objectManager = \Magento\Framework\App\ObjectManager::getInstance(); $region = $objectManager->create(‘Magento\Directory\Model\Region’); $regionId = $region->loadByCode($regionCode, $countryCode)->getId(); echo $regionId; $regionName = $region->loadByCode($regionCode, $countryCode)->getName(); echo $regionName;   Thats it. Enjoy…

Magento 2 – How to Remove Customer Account Navigation Links

In this post I am going to explain how to remove customer account navigation links in Magento 2. First you need to create one layout file “customer_account.xml” in your custom extension or theme. Syntax to remove link: <referenceBlock name=”link-block-name” remove=”true” /> Here are list of links. <page xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance” xsi:noNamespaceSchemaLocation=”urn:magento:framework:View/Layout/etc/page_configuration.xsd”> <body> <!– Store credit –> <referenceBlock…

Magento 2 – How to Resize Product Image

In this post I am going to explain how to resize product image in Magento 2. Using the below code snippet you can resize the product image in the template (.phtml) file. <?php $productId = ’12’; $_product = $block->getProductById($productId); $imageHelper = $this->helper(‘Magento\Catalog\Helper\Image’); $imgWidth = 350; $imgHeight = 400; $imageId = ‘category_page_grid’; $productImage = $imageHelper->init($_product, $imageId)…

How to Get Invoice Details by Invoice Id in Magento 2?

In this post I am going to explain how to get invoice details by invoice id in Magento 2. Using below code snippet you can get invoice details by passing invoice id. 1. Using Dependency Injection Add below code snippet in Block class. protected $_invoiceRepositoryInterface; protected $_logger; public function __construct( \Magento\Framework\View\Element\Template\Context $context, \Magento\Sales\Api\InvoiceRepositoryInterface $invoiceRepositoryInterface, \Psr\Log\LoggerInterface…

Older posts Newer posts