Magento 2: Create/Add Product Programmatically [Simple & Virtual Product with Image, Category & Custom Option]

This article shows how you can add Simple & Virtual products programmatically in Magento 2. This article also shows how you can: – add images to the product – assign the product to different categories – add custom options to the product I am using a standalone script for this purpose using Object Manager. You … Read more

Magento 2: Setup Multiple Stores and Websites

This article shows how you can setup multiple stores and multiple websites in your Magento 2 shop. I have assumed that we are having a separate domain or sub-domain for the stores and websites. After adding the necessary stores and websites in the Magento admin, you then need to add some code in either index.php … Read more

Magento 2: Add / Delete / View Custom Options of Product Programmatically

Custom options on Magento products are designed to make simple products function like a configurable product with different choosing options like color, size, etc. before purchasing the product. In this tutorial, I present the code to create/add, view and delete custom options of a simple product in Magento 2. I am using a standalone script … Read more

Magento 2: Delete Duplicate Product Attributes Options Programmatically

This article shows how you can delete duplicate product attribute options in Magento 2. I am using a standalone script for this purpose. You can use this code in your custom module as well. Initialize Object Manager and Set the Area Code The following things are done in the below code: – Initialize the object … Read more

Magento 2: Invalid Form Key. Please refresh the page. Error on Product Save

Problem: The following error occurred while saving a product from Magento 2 admin: Invalid Form Key. Please refresh the page. Cause: The cause of this error is related to the max_input_vars (Maximum Input Variables) directive in the PHP settings. The max_input_vars directive value is the maximum number of variables that can be used for a … Read more

Magento 1 & 2: Join Collection to get Customer Fullname

This article shows how you can use the join query on any custom collection to get the customer firstname, lastname and contact firstname & lastname to get the customer full name. I will be showing example code for both Magento version 1.x and Magento version 2.x. Magento 1: Join Collection to get Customer Fullname I … Read more

Magento 2: Show Calendar/DatePicker & Date-Range Field in Custom Form

This article shows how you can add a calendar or date-picker field in any custom form in Magento 2. I will be showing three different ways of adding date picker in the template file (.phtml) in Magento 2. 1) using calendar widget 2) using datepicker widget 3) using datetimepicker widget I will also show how … Read more