How to remove extra column from database table using Magento 2?

In Magento 2 Sometimes we have added an extra column in the table for extended functionality in module and in future, we have removed that functionality so we need to remove extra column field from a database table.

I have added one field name gst in sales_order table and I want to remove extra field from table in future. You can remove field using dropColumn() in UpgradeSchema.php file.
Using below code snippet you can remove already existed column field from table.

Upgrade the setup_version number of module from module.xml file. An older version number is 1.0.1 so I have added new version 1.0.2 in module.xml file

Path: Magento22/app/code/Rbj/Training/etc/module.xml

Create UpgradeSchema.php file under Setup folder in your module.
Path: Magento22/app/code/Rbj/Training/Setup/UpgradeSchema.php

Run command from root directory of your project,
php bin/magento setup:upgrade

If you want to add the field in table  Add New Field in Database Table Magento 2
If you want to rename/change column field name, Refer link Rename Column name in Table Magento 2

List of all events in Magento 2.

Magento 2 Comes with many events by default in the core module. You can use any required events from Core module to accomplish your requirement. You can also create your own custom event to accomplish your task.

There are many core events comes with Magento 2 native. You can use events in events.xml and create observer.php file to do specific action for an event. Continue reading “List of all events in Magento 2.”

How to create a custom theme in magento 2?

Why do you need to create a custom theme in Magento 2?
We need to create a custom theme for Magento 2 because of To customize the design of your Magento store. Natively Magento comes with preinstalled blank and luma theme.
Keeping Maintainability and Upgradability in mind, We need to create a custom theme.
If we modify directly to our changes to core module, Changes will be wiped out in future if we upgrade the Magento version. Do not modify the out of the box Magento core phtml files when we need to customize changes on phtml file.

You need to refer below steps for creating a custom theme in Magento 2.
Go to Magento root folder where you have installed your Magento,

1. Create a directory under app/design/frontend/Magento2/demotheme.
2. Create a theme declaration file theme.xml.
3. Create registration.php file to register our theme.
4. Create a composer.json file.
5. Create a web directories for CSS, JavaScript, images, and fonts of our custom theme.

Your theme structure looks like below, For Demo, We have kept Vendorname as Magento2 and themename as demotheme. You can change based on your themename.
— You should Keep Vendorname as Camelcase letter and themename in lowercase as per Magento theme standard.

Create theme.xml  file to your theme directory. app/design/frontend/Magento2/demotheme.

In above title is your theme title and parent node is for parent theme name.
You can keep your parent theme we have declared luma as a parent now.

Create registration.php file,

app/design/frontend/Magento2/demotheme/registration.php

Create composer.json file,

Above file,  “name” key will be your theme name.
“description” key will be your theme description.
“require” key will be your theme dependency modules.
“type” must be magento2-theme (for any custom theme)
“version” is your theme version.

You can keep your static files in web folder.
— images folder for images of store front
— js folder for js files
— css folder for less/CSS files
— fonts folder for font files

Now run command to our theme activation in site.

Our theme will be activated and check it from the admin panel.
Go To Content Menu from left sidebar, Click Design -> Themes
Your new theme will be shown in the grid.

If you want to apply your custom theme to store,
Go To Content Menu from left sidebar,
Click Design -> Configuration
Click on Edit link and set Your theme from Applied Theme drop-down section.
Save theme.

Clear cache and you can check your storefront with your custom theme.