We are seeing this a lot as the customer places order with out logged in and later create and account and view their orders from the dashboard. We can solve this issue by directly running SQL queries or just creating a small script to do it. SQL Method Using PHP Script Source
Magento 2
How to get product collection based on custom attribute (drop down attribute value)
Magento 2 is well known for it’s capacity to extending the features. Today’s article we will be discussing how to get product collection based on custom attribute (drop down attribute value). For dropdown attribute, We can filter using dropdown option ID instead of Label. So your code is like below. The above 20 is the…Continue Reading
How Get Current URL from a PHTML – Magento 2
Today’s post we are discussing how to get the current URL in phtml file in Magento 2. As we know we have access to object in the phtml, we can utilize that for this purpose. Let’s print methods for the class It produces the output like this From this we can use the method get…Continue Reading
How to programmatically update name of category in specific store – Magento 2
Follow the below code to programatically update name of category in a specific store in Magento 2.
How to get category id by category name in Magento 2
In today’s blog, we are illustrating how to get a category id by category name in Magento 2. Call the collection factory in the constructor of the class and using addAttributeToFilter filter the collection by name. You should make sure your category names are unique, or you have to add the level field in the…Continue Reading
Magento 2: How to add option values to product attributes programmatically
In today’s blog, we are showing how to add option values to product attributes programmatically in Magento 2.
Magento 2: Get the product attribute’s select option value from option_id without loading the product
In today’s blog, we are showing how to get an option value based on the option id in Magento 2, without loading the product. First of all load the AttributeRepositoryInterface via constructor wherever you require this feature.
How to display images from theme folder in in phtml- Magento 2
You can use below two methods to display images from theme folder in phtml file in Magento 2. Often times it’s very convenient to keep the theme related images to theme images folders.
You need to configure Two-Factor Authorization in order to proceed to your store’s admin area – Magento 2
After installing Magento 2 you might encounter this screen, that says You need to configure Two-Factor Authorization in order to proceed to your store’s admin area.
How to Get Product Stock Quantity and Other Stock Information – Magento 2
In today’s tutorial, I am showing how to get the product stock quantity and information in Magento 2. In this article, I will illustrate mainly two methods to get product stock information in Magento 2, and both methods are tested and confirmed it’s working. #Method 1 This method will be using \Magento\CatalogInventory\Model\Stock\Item class to get…Continue Reading
How to add Index to table column using Magento 2?
It will be advisable to add an index to a database field for better performance and quick selection of records from the database table. Use the below snippet to add an index to database field in Magento 2.
How To Redirect To Previous Page in Magento 2?
Today’s tutorial we are showing how to redirect to previous page from a custom action in magento 2. This will be useful when you have an error message to show after a form submission. namespace Vendor\Module\Controller\Adminhtml\Index; class Fetch extends \Magento\Backend\App\Action { public function execute() { // TODO: Implement execute() method. $this->_redirect($this->_redirect->getRefererUrl()); } }
How to Apply the Magento 2 patch?
Change your Magento store to Developer mode php bin/magento deploy:mode:set developer Download the security patch git apply MAGENTO-9090-2020-010-1-10-04-03.patch After the above run below command to apply the patch php bin/magento setup:upgrade
How To Programatically Cancel The Order Using Order Id in Magento 2 ?
It’s very common that we need a feature to cancel an order Programatically in Magento 2. Instead of factory method, we use Magento/Sales/Api/OrderManagementInterface as it’s advisable to use service contracts in Magento 2. Below snippet will help you cancel an order programatically in Magento 2. protected $orderManagement; public function __construct( … \Magento\Sales\Api\OrderManagementInterface $orderManagement, …. )…Continue Reading
How To Load Stock Item Using product_id In Magento 2?
In some cases you have to load stock item using product_id in Magento2. Today’s snippet we are showing how to do that. For illustration purpose we use a model example. namespace Vendor\Module\Model; use Magento\CatalogInventory\Model\Stock\StockItemRepository; class HelloWorld extends extends \Magento\Framework\Model\AbstractModel { protected $stockItemRepository; public function __construct( StockItemRepository $stockItemRepository ) { $this->stockItemRepository = $stockItemRepository; } public function…Continue Reading
How to get GMT date time in Magento 2?
Magento 2 usually saves the time in GMT in database, but display on admin or frontend will be based on the selected timezone. Use the below code to get the time with GMT timezone from Magento 2 code. Magento comes with DateTime php class, Magento\Framework\Stdlib\DateTime\DateTime is used for Forms GMT date. <?php public function __construct(…Continue Reading
How To Get The Collection Of Records From A Custom Module In Magento 2?
If you are working on a custom Magento 2 module, and wondering how to get the collection of records from your custom database table, this article is for you. This is very common that your Magento 2 website needs more database tables than what Magento shipped with. So in a listing page such as blog…Continue Reading
Disable versions in Magento 2
By default Magento 2 static urls have a version string attached to it. For example, if you take the view source of the page, you will see urls contains the following string -version1490119662.
How to disable or allow guest checkout in Magento 2?
Default Magento 2 setup allows users to checkout as guest in your storefront. But one must say gathering max customer information will be advantageous for both customer and shop owner. Today’s tutorial we are showing how to disable or allow guest checkout in Magento 2. Step 1. Log in to Magento 2 admin panel. Step…Continue Reading
“Your session has expired” On Clicking Add To Cart – Magento 2.3.x Localhost
In your Magento 2 journey, you might have greeted with this error message – “Your session has expired”, when clicking on the add to cart button.
How to Use Magento 2 code in external File/Script
This script allows you to call Magento 2 functions run outside Magento 2 setup. You can create any PHP file in Magento 2 root folder and run Magento 2 from there.
How to Add Store Codes to the URLs in Magento 2?
If you have a multi-language store and want to add Store Codes to this is the tutorial for you. So your example urls will look like this yourdomain.com/en, yourdomain.com/us, yourdomain.com/uk. Follow the below steps. Login to the Magento 2 admin panel Navigate to Stores > Configuration > General > Web and find the Url Options…Continue Reading
Product Sort By Price: Low to High and High to Low Magento 2.3
Today’s tutorial we are showing, how to add a new filter option in the product listing area of Magento 2.3. Here we are adding price sorting options such as Low to High and High to Low.
Reset “Use Secure in Front End or Admin” in Database – Magento 2
If you ran into a problem like you have changed the secure admin URL back to non secure URL and you forgot to change the or Admin to zero -means disable. It’s total mess that you cannot access the admin side again as all the JavaScript and CSS urls will have https prefix and all…Continue Reading
How To Change The Magento 2 Admin Session Timeout
It’s quite annoying that every time page goes to login page when we try to refresh a page or saving a product in Magento 2 admin side. So this can be achieved by changing the admin session timeout in Magento 2.
How to Install Magento 2.3 & Create a Web Server-LAMP
This tutorial demonstrates how to install Magento 2.3 and build a web server on operating system Ubuntu 16.04 LTS. In this tutorial I have used Digital Ocean droplet (2GB instance), you may please create the same or you can install one in your PC. First we create a user apart from root user, as it…Continue Reading