Posts

Showing posts with the label magento2

Magento 2: Delete sample data and test data from your store

Here is a script to delete all the test data from your magento store. This can come in handy especially at the time of launching your website from beta to production mode. Don't forget to bookmark it for your next launch. NOTE: It is advisable to take full database backup before performing any operations below: SCRIPT: SET FOREIGN_KEY_CHECKS=0; # Clean order history TRUNCATE TABLE `sales_bestsellers_aggregated_daily`; TRUNCATE TABLE `sales_bestsellers_aggregated_monthly`; TRUNCATE TABLE `sales_bestsellers_aggregated_yearly`; # Clean order infos TRUNCATE TABLE `sales_creditmemo`; TRUNCATE TABLE `sales_creditmemo_comment`; TRUNCATE TABLE `sales_creditmemo_grid`; TRUNCATE TABLE `sales_creditmemo_item`; TRUNCATE TABLE `sales_invoice`; TRUNCATE TABLE `sales_invoiced_aggregated`; TRUNCATE TABLE `sales_invoiced_aggregated_order`; TRUNCATE TABLE `sales_invoice_comment`; TRUNCATE TABLE `sales_invoice_grid`; TRUNCATE TABLE `sales_invoice_item`; TRUNCATE TABLE `sales_order`; TRUNCATE...

Magento 2 - How to generate translation strings for your magento project

If you have want to create a multi-language store then you may require to translate all English strings into the language of your choice. For this you will need accumulate all of the eligible strings for translation into a CSV file. In this article we will discuss how to generate this list of strings from your Magento project which are eligible for translations. Magento allows the list generation with following command: For Whole Project: php bin/magento i18n:collect-phrases --magento -o translations.csv cat translations.csv For A Particular Module: php bin/magento i18n:collect-phrases path/to/my/module -o translations.csv cat translations.csv Thenafter, this CSV file (translations.csv in above example) can be translated either manually or using third party translator extensions like Qordoba.

Magento 2: How to fix Temando Error logs

If you are not using Temando Shipping module which comes packaged with Out of the Box Magento in your E-commerce site then most likely you will see your var/log/system.log file being spammed with numerous errors that look like below: [2020-09-02 11:13:03] temando.CRITICAL: "accountId" is required. Enter and try again. { "exception":"[object] (Magento\\Framework\\Exception InputException(code: 0): \"accountId\" is required. Enter and try again at /vendor/magento/framework/Exception/InputException.php:91)" } This error is a Core magento bug. It may seem minor, but over a period of time if ignored, it can result in a humungous system log file size and as a result your actual logs and important messages can get lost between these errors. In order to fix this error there are 2 ways: 1) Disable the Temando_Shipping module in your magento site using this command: php bin/magento module:disable Temando_Shipping OR 2) Create a d...

Magento 2: How to place order as a guest customer using Magento 2 REST API

In order to place a new order as a guest customer using REST APIs in Magento 2, please follow below steps: MAGENTO 2 REST APIs: CREATE GUEST CART: NOTE: Quote/Cart ID here is received from Step 1 of creating guest cart. ADD ITEMS TO GUEST CART: GET TOTALS OF GUEST CART: ESTIMATE SHIPPING OF GUEST CART: SET BILLING AND SHIPPING DETAILS OF GUEST CART: PLACE ORDER FROM GUEST CART:

Magento 2: How to login as Customer and place new order via REST APIs

In order to place a new order as a logged in customer using REST APIs in Magento 2, please follow below steps: You can Download the Postman Tool from here: www.postman.com Now, Open Post man and create below Requests: MAGENTO 2 REST APIs: CUSTOMER LOGIN: CREATING CUSTOMER QUOTE: ADD ITEMS TO CART COLLECT CART TOTALS GET AVAILABLE SHIPPING METHODS & ESTIMATING SHIPPING CHARGES SET BILLING AND SHIPPING ADDRESS OF ORDER PLACE ORDER Now check your admin panel and there will be a new COD order placed.

Magento 2: How to create new indexer for your custom module

For this tutorial we will consider an example of a custom module called Vendor_ModuleName. Create below files to generate a new VSBridge indexer and Elastic Index for your own module: Vendor_ModuleName\etc\indexer.xml Vendor_ModuleName\etc\mview.xml Vendor\ModuleName\Model\Indexer\CustomIndexer.php Now, open console and run below command: You will now see following: A new indexer job for your module in Magento admin panel > System > Tools > Index Management A new index in elastic You can refresh your indexer with php bin/magento indexer:reindex my_custom_indexer

Magento 2 - Vue Storefront PWA Integration: How to create a new VSBridge indexer job and Elastic Index for your custom module

For this tutorial we will consider an example of a custom module called Vendor_ModuleName . You need to have the module divante/magento2-vsbridge-indexer installed and configured in your project, in order for it to work with your Vue StoreFront PWA website. You can do this with below command: Once you have the module installed and configured correctly, create below files to generate a new VSBridge indexer and Elastic Index for your own module: Vendor_ModuleName\etc\indexer.xml Vendor_ModuleName\etc\mview.xml Vendor_ModuleName\etc\vsbridge_indices.xml Vendor\ModuleName\Model\Indexer\CustomIndexer.php Vendor\ModuleName\Model\Indexer\Mapping\CustomIndexer.php Vendor\ModuleName\etc\di.xml Now, open console and run below command: You will now see following: A new indexer job for your module in Magento admin panel > System > Tools > Index Management A new index in elastic You can refresh your indexer with php bin/magento indexer:reindex vsbr...

Magento2: How to stop a product from getting added to cart programmatically?

If youn want to stop a product from getting addded to cart programmatically, add below files to your module: Vendor_Module\etc\di.xml Vendor_Module\Model\Checkout\Cart\AddProduct.php

Magento 2: How to create your own Patch File and apply it through composer

Magento releases new patches for it's framework from time to time. Here is a tutorial of how to create your own patch file in Magento. Although I personally am not a huge fan of patches, due to various drawbacks, there are desperate times when you need to apply a patch. I would suggest to use this approach as less as possible and instead opt going the standard magento way of versioned modules that store your changes. But, In case there are times when you are forced to create a patch, or just for self-knowledge on how it's done, you can follow below tutorial. STEP 1: In your magento root directory create a folder called "patches". STEP 2: Create a sub-directory with the name Namespace_Module for the module which you want to create a patch for. So the path will look like this: < >\patches\Namespace_Module STEP 3: Add your patch file in the directory you created in Step 2 of this tutorial. HOW TO CREATE A PATCH FILE: Create a backup of the ori...

Magento 2: Add new button on Category Edit Page in Admin Panel

For this example we will assume you have a custom module. Let's call it Namespace_Module. Now, create files as below: Namespace_Module\view\adminhtml\ui_component\category_form.xml Namespace_Module\Block\Adminhtml\Category\Edit\Button\AssignButton.php Namespace_Module\Controller\Adminhtml\Category\Assign.php Voila !! That's it. Now, clear all caches and check the category page in admin panel. There will be a new button called "Assign".

Magento 2: How to add custom discount in cart programmatically?

Refer to how Magento2 applies sales-rule discounts. I applied similar approach to apply custom discount, by creating following files in my module: Namespace_Module\etc\sales.xml Namespace_Module\Model\Quote\Discount.php Namespace_Module\view\frontend\layout\checkout_cart_index.xml Namespace_Module\view\frontend\layout\checkout_index_index.xml If Fetch is not showing the custom discount description, it was a core magento bug, see this ticket for patch details: https://github.com/magento/magento2/issues/3594

MAGENTO 2: Get REST API Request Params

MAGENTO: How to add a button in store configuration

For this illustration, we will add a button in store configuration called "Assign Button". When this button is clicked it will call a controller and perform the necessary function. We will first need to have a custom module where we can manage all this code. For this example we will use Namespace_Module . This will add button in store configuration.

MAGENTO 2-PWA KUBERNETES: How to put your elastic search behind username and password

For this illustration I am using Magernto, Vue Store Front PWA, Elastic Search and Kubernetes. First goto console and type This will ask you to enter the password. Enter the password which you wish to set for elastic authentication. After this is done run below command: Copy the contents of the file. Now, In your nginx.yaml file add the following: