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

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
Check Customer is logged in using knockout js Magento 2
Check Customer is logged in using knockout js 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
How to add a new page layout in Magento 2?
How to add a new page layout in 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 convert date according to specific locale in Magento 2?
How to convert date according to specific locale 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 set custom date format in Magento 2?
How to set custom date format 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 use Search Criteria for the custom collection in Magento 2?
How to use Search Criteria for the custom collection 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
Work with HTML and JS in Magento 2
Work with HTML and JS 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
Close Menu