Get order id by increment id Magento 2

In this article, I will show you how you can load order by increment id in Magento 2 We can use the order interface Magento\Sales\Api\Data\OrderInterface to load order by increment id. By Object Manager: $objectManager = \Magento\Framework\App\ObjectManager::getInstance(); $incrementId = "100009633"; $orderInterface = $objectManager->create('Magento\Sales\Api\Data\OrderInterface'); $order = $orderInterface->loadByIncrementId($incrementId); // Print Order Object print_r($order->debug()); // Get Order Id…

Continue Reading Get order id by increment id Magento 2

Create dynamically link in customer account navigation in Magento 2

We can create custom customer account link with reference block customer_account_navigation with a custom block class 1) Add block class in customer_account.xml File: app/code/Vendor/Module/view/frontend/layout/customer_account.xml <?xml version="1.0"?> <page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd"> <body> <referenceBlock name="customer_account_navigation"> <block class="{vendor}\{Module}\Block\Customer\Link" name="customer-account-navigation-new-product-link" after="-"> <arguments> <argument name="label" xsi:type="string">Some link</argument> <argument name="path" xsi:type="string">customer/somelink/index</argument> </arguments> </block> </referenceBlock> </body> </page> 2) Now create Link.php namespace Vendor\Module\Block\Customer;…

Continue Reading Create dynamically link in customer account navigation in Magento 2

Check Customer is logged in using knockout js Magento 2

We can use Magento_Customer/js/model/customercomponent to check if the customer is logged in or not in knockout js. Check full component here customer.js We can use isLoggedIn() method. It will return true if customer is loggedIn and return false if customer is not loggedIn Check below code snippet of JS: define([ 'uiComponent', 'Magento_Customer/js/model/customer' ], function (Component,…

Continue Reading Check Customer is logged in using knockout js Magento 2

How to add a new page layout in Magento 2?

In this article, I am going to learn that How we can create a new layout in Magento 2. There are 5 default layouts available in Magento Empty1 column2 columns with left bar2 columns with right bar3 columns During frontend development, Sometimes we need to create our own layout page for customization. So follow the…

Continue Reading How to add a new page layout in Magento 2?

How to convert date according to specific locale in Magento 2?

Sometimes we need to convert date formate to locale. We can use \Magento\Framework\Stdlib\DateTime\TimezoneInterface class to convert dare according to locale. Using Object Manager: $date = new \DateTime('2019-11-21'); $objectManager = \Magento\Framework\App\ObjectManager::getInstance(); $formatDate = $objectManager->create('Magento\Framework\Stdlib\DateTime\TimezoneInterface') ->formatDate( $date, \IntlDateFormatter::FULL, false ); Using Dependency Injection: namespace MagePrince\Testing\Model; class FormatDatLocale { private $timezoneInterface; public function __construct( \Magento\Framework\Stdlib\DateTime\TimezoneInterface $timezoneInterface ) {…

Continue Reading How to convert date according to specific locale in Magento 2?

How to set custom date format in Magento 2?

We can use Magento\Framework\Stdlib\DateTime\DateTimeFactory class to set custom date format. During development, we need to set a custom date format to display in the frontend or need to pass the custom data to APIs. So here is the code to set custom date format. namespace MagePrince\Testing\Model; class FormatDate { private $dateTimeFactory; public function __construct( \Magento\Framework\Stdlib\DateTime\DateTimeFactory…

Continue Reading How to set custom date format in Magento 2?

How to use multiple AND and OR conditions in searchCriteria filter in Magento 2?

In this article, I will show you how you can use multiple OR and AND operation in searchCriteria filter. When we are working with API and working with getList collection using searchCriteria, we sometimes need to build a custom query to get the collection. There are two main part of searchCrieria FilterFilter Group 1. Filter…

Continue Reading How to use multiple AND and OR conditions in searchCriteria filter in Magento 2?

How to use Search Criteria for the custom collection in Magento 2?

In this article, I will show you, how you can use Search Criteria in the custom collection. Search Criteria is an implementation of the SearchCriteriaInterface class that allows you to build custom requests with different conditions. You can read more at devdoc for Search Criteria Searching with Repositories 1. Here we use getList() method to get custom…

Continue Reading How to use Search Criteria for the custom collection in Magento 2?

Work with HTML and JS in Magento 2

During development in Magento 2, we face many issues related to HTML or JS. Sometimes js and HTML changes are not reflected. I often see that many developer run all the commands after doing changes in HTML or JS files. To reflect Html or js changes you don't need to run any command. You even…

Continue Reading Work with HTML and JS in Magento 2

How to add form key in Magento 2?

In this article, I will show you how you can use form key in your form in phtml file. In Magento, form key is used for preventing Cross-Site Request Forgery. Learn more about cross-site forgery You can use directly getBlockHtml('formkey') to get form key with a hidden field in phtml files like echo $block->getBlockHtml('formkey'); OutPut:…

Continue Reading How to add form key in Magento 2?