Magento 2: Create Widget Programmatically & Assign Static Block to it

This article shows how you can add/create Widget using Upgrade Script of a module in Magento 2. This code is useful when you need to auto add/create widget while upgrading your custom module. Here, we will also create a CMS Static Block and assign that newly created static block to the Widget. Add Widget and … Read more

Magento 2: Add/Update CMS Static Block via Install/Upgrade Script Programmatically

This article shows how you can add or update CMS Static Block using Install or Upgrade Script of a module in Magento 2. This code is useful when you need to auto add/edit cms static block while installing or upgrading your custom module. Add CMS Static Block from InstallData Setup Script This will add cms … Read more

Magento 2: Add/Update CMS Page via Install/Upgrade Script Programmatically

This article shows how you can add or update CMS Page using Install or Upgrade Script of a module in Magento 2. This code is useful when you need to auto add/edit cms page while installing or upgrading your custom module. Add CMS Page from InstallData Setup Script This will add cms page when you … Read more

Magento 2: Change Increment ID Prefix, Suffix, Start value, Step, Pad length of Order, Invoice, Creditmemo & Shipment

This article shows how you can change/update the Order Increment ID, Invoice Increment ID, Creditmemo Increment ID, Shipment Increment ID of your Magento 2 store. In Magento 1, you could simply change the increment prefix and last increment id from the database table entity_store_id. In Magento 2, it’s different. You have the option to change … Read more

Magento 2: Create/Alter Database Table & Insert Data while Installing/Upgrading Module

This article shows how you can create a new database table and install data into the table while installing a custom module or upgrading the module in Magento 2. The install and upgrade setup script file should be inside the Setup folder of your module. The install script should be named InstallSchema.php & InstallData.php and … Read more

Magento 2: Create/Add Product from module’s InstallData or UpgradeData Script

This article shows how you can add a product from your custom module’s InstallData or UpgradeData Setup script file. This code is useful when you need to auto add product while installing or upgrading your custom module. Add product from InstallData Setup Script This will add product when you install your custom module for the … Read more

Magento 2: Insert Multiple Rows into Database Table

This article shows how you can insert multiple rows or records into your database table. Generally, we add a single row of data into the database table. However, we have situations where we need to insert multiple rows of data into the table at once. We can do so by running the insert query multiple … Read more

Magento 2: Create/Add Configurable Product Programmatically

This article shows how you can add Configurable Product programmatically in Magento 2. I am using a standalone script for this purpose using Object Manager. You can use this code in your custom module as well by using Dependency Injection (DI) instead of Object Manager. Initialize Object Manager and Set the Area code The following … Read more