[2] sales_order_item :: Store [Product Details, Order ID(order_id)]
[3] sales_order_grid :: Store [Billing/Shipping Address Grand Item Price,Customer ID(customer_id), Order ID as increment_id]
[4] sales_order_address :: Store [Shipping & Billing Address, , Customer ID(customer_id)], each time store two row one for Billing address and another For shipping address while ordering any product
[5] sales_order_payment :: Store [payment details on the bases of Order ID]
[6] sales_order_status :: Store [Sales Order Status like canceled, closed, complete, fraud, holded, payment_review, Paypal Canceled Reversal, Paypal Reversed, Pending, Pending Payment, Pending Paypal, Processing]
sales_order_grid :: Store [Billing/Shipping Address Grand Item Price,Customer ID(customer_id), Order ID as increment_id]
order_id of sales_order_item Become increment_id of sales_order_grid increment_id display in
Magento 2 virtual type allows user to change the arguments of a specific injectable dependency and change the behavior of a particular class. This allows user to use a customized class without affecting other classes that have a dependency on the original.
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.
“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
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”