Magento 2.x Preference

Preference is used to override or rewrite existing / custom classes (Controller, Block & Helper). Preference using Dependency Injection to override or rewrite classes.

How To Define Preference : Preference is defined inside di.xml

Path : app/code/VendorName/ModuleName/etc/di.xml

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
           xsi:noNamespaceSchemaLocation="urn:magento:framework:Acl/etc/acl.xsd">

<preference for="Class Which Override" type="Custom Class By Which Override" />

    </config>

Overriding (By Preference in di.xml) a method is not recommended because it can cause conflicts in the system and increase the complexity to upgrade.

Always try to user other extensibility options, such as event observers and plugins, when possible.

Magento 2.x Plugins

“A plugin or interceptor is a class that modifies or expand or edit the behavior of public class functions by intercepting a function call or set of code before, after or around that function call”

“Inserting code dynamically without changing original class behavior is called Plugin”

Plugins using design pattern “Interception”

Plugins Limitation : There are following below criteria where plugins can not used.

  • final classes
  • non public methods
  • static methods
  • constructor
  • virtual types
  • objects that are initialized before plugins loading

Plugins Types : There are three types plugins

  • Before listener Plugin (Before Plugin)
  • After listener Plugin (After Plugin)
  • Around listener Plugin (Around Plugin)

Difference between plugin and preference in Magento 2.x

Both Plugins and Preferences are used to override the classes. However, Plugins are preferable than Preferences since plugins do not override the class logically instead it hooks our logic into the available classes. Finally, to modify or extend any existing business logic, it is better to use the plugins.

Preference is used for overriding class & Plugin is used for adding functionality before, after and around methods by using function call or set of code.

“Always prefer Plugin over Preference , while overriding or modify class”

Magento 2.x module.xml

module.xml file is a module’s naming configuration file, that is used to define module name, It is required to place this file into the below file path of module or custom module directory

magento/app/code/namespace/modulename/etc/module.xml

  • Declaration of module.xml
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
<module name="Namespace_Modulename" setup_version="3.0.1"/> 
</config>

The schema_version is no longer required since releasing Magento 2.3.3

There are following steps defined as follows:

  • module name declaration (moduleName) format : name=”Namespace_Modulename”
  • module’s version (setupVersion) format:

setup_version=”3.4.1″

There are three things in setup_module database table having three column

module : store module name as Namespace_Modulename

schema_version & data_version : The setup_version which is module version, this identify both things schema version data version as schema_version=3.4.1 & data_version=3.4.1

Module Naming convention format as follows:

  • Module Name: attribute can contain only [A-Za-z0-9_]
  • Setup Version: attribute can contain only [0-9.]

The xmlns attribute provides a location to the XMLSchema instance and the xsi:noNamespaceSchemaLocation attribute provides a path to an XSD (XML Schema Definition) file of a Magento 2 framework.

Magento 2.x Component & Registration.php File

Magento 2 component is set of (module, language, library, theme, setup etc), each component has unique identity.

  • Component module defines module Registration

//For Component Module Registration 

ComponentRegistrar::register(ComponentRegistrar::MODULE, '<VendorName_ModuleName>', __DIR__);
  • The Module component of registration.php looks as follows:
<?php

\Magento\Framework\Component\ComponentRegistrar::register(
    \Magento\Framework\Component\ComponentRegistrar::MODULE,
    'VendorName_ModuleName',
    __DIR__
);
  • Component theme defines theme Registration
// For Component Theme Registration

ComponentRegistrar::register(ComponentRegistrar::THEME, '<area>/<vendor>/<theme name>', __DIR__);
  • The Theme component of registration.php looks as follows:


\Magento\Framework\Component\ComponentRegistrar::register(
    \Magento\Framework\Component\ComponentRegistrar::THEME,
    'frontend/vendor/custom-theme',
    __DIR__
);


  • Component Language defines Language Registration

// For Component Libraries Registration
ComponentRegistrar::register(ComponentRegistrar::LANGUAGE, '<VendorName>_<Language packageName>', __DIR__);
  • The Language component of registration.php looks as follows:


\Magento\Framework\Component\ComponentRegistrar::register(
    \Magento\Framework\Component\ComponentRegistrar::LANGUAGE,
    'vendor_sp_sp',
    __DIR__
);

  • Component library defines library Registration

// For Component Theme Registration 
ComponentRegistrar::register(ComponentRegistrar::THEME, '//', __DIR__);

Magento 2.x Remove Unused Core Modules

There are following below steps need to follow to remove Magento 2 core module, add following below code in composer.json & write name of modules you want to remove inside replace

"replace": {
"magento/module-marketplace": "*",
"magento/module-authorizenet": "*",
"magento/module-braintree": "*",
"magento/module-multishipping": "*",
}

Magento 2 Database Tables

There are following below link need to click to know Magento 2 All 500 & more Tables, where each Magento 2 Table Briefly Explanation has been explained

Magento 2 All Database Tables [500 & more Tables]

Which Magento 2.x database table store customer’s Email Data


Which Magento 2.x Database Table Store Customer Newsletter Data


Which Magento 2.x database table store customer’s shipping and billing address


How To Remove Sales Order Data & Customer Data in Magento 2


How To Remove / Delete Catalog Data or Categories / Products in Magento 2.x


Which Magento 2.x Database Tables Store Customer Rating


Which Magento 2.x Database Tables Store Customer Review


Which Magento 2.x Database Tables Store Customer Wishlist Products


Which Magento 2.x Database Table Store Patches


Which Magento 2.x Database Table Store Static Blocks & Its Details


Which Magento 2.x Database Table Store CMS Pages & Its Details


Which Magento 2.x Database Tables Having All URLs Storage


Which Magento 2.x Database Tables Store Sales Order Data


Which Magento 2.x Database Tables Store Sales Invoice Order Data


Which Magento 2.x Database Tables Store Sales Tax and Its related Data


Which Magento 2.x Database Tables Store Catalog Price Rules


Which Magento 2.x Database Tables Store Cart Price Rules

How To Configure Checkout Total Sort Order in Magento 2.x

During Order Review of Order Summary Page before Place An Order,
There are following below things are being displayed as Sequence below

  • Subtotal
  • Discount
  • Shipping rate
  • Tax
  • Fixed product tax
  • Grand total

The detailed view Order Summary helps customers understand how the store is charged. This provides transparency of the store, increasing the trust of the customers.

This image has an empty alt attribute; its file name is image-9.png

Need to adjustments & Position of above fields, each field having own position, to do this Store Owner(Admin) required Sort Order settings
There are following below steps need to follow.

[1]- Go To STORES > Configuration, redirects on configuration.

[2]- In left panel, expand the Sales section and choose Sales underneath.

[3]- Once redirection on [Right Panel] Checkout Totals Sort Order section.

[4]- Once clicked / expanded Checkout Totals Sort Order section [Right Panel]

[5]- Change the number assigned to each item to determine its Order Position, in Order Summary Page.

[6]- Finally click on Save Config Button

Which Magento 2.x database table establish connection between Categories and products

There are following below table establish connection between Categories and products.

catalog_category_product

Magento 2 All Database Tables [500 & more Tables]

Which Magento 2 database table store customer’s Email Data


Which Magento 2 Database Table Store Customer Newsletter Data


Which Magento 2 database table store customer’s shipping and billing address


How To Remove Sales Order Data & Customer Data in Magento 2


Which Magento 2 Database Tables Store Customer Rating


Which Magento 2 Database Tables Store Customer Review


Which Magento 2 Database Tables Store Customer Wishlist Products


Which Magento 2 Database Table Store Patches


Which Magento 2 Database Table Store Patches


Which Magento 2 Database Table Store Static Blocks & Its Details


Which Magento 2 Database Table Store CMS Pages & Its Details


Which Magento 2 Database Tables Having All URLs Storage