ZenCart library -shipping.php interpretation of the principle of realization

Reading this article realization includes / classes / shipping.php shipping class

关于MODULE_SHIPPING_INSTALLED

It indicates the system has been installed in the module, as described in the background arrangement

Installed Modules
List of shipping module filenames separated by a semi-colon. This is automatically updated. No need to edit. (Example: ups.php;flat.php;item.php)

Please make the necessary changes

Module Installed
list of file names shipping modules, separated by semicolons.
This automatically updated. Without editing. (Example: ups.php; flat.php; item.php)

The role of the constructor

1. Load module you have installed

Loading principle is above MODULE_SHIPPING_INSTALLED, this database configuration, this configuration in the configuration group id = 6 hidden inside, in fact the background is not displayed, but can http:? //Localhost/ZenCart156cDev/sprAy-Dsk-birtH/configuration.php gID = 6  access to this configuration group

This field is additional configuration loaded into the system at the time includes / init_includes / init_db_config_read.php initialization.

Dividing the value of this field, the array element

Loop through the array - to get the class name and file name

Then load in DIR_WS_MODULES. 'Shipping /' directory

First load module corresponding language file, and then load the module itself

Sign up to $ GLOBALS variable last to go, class name as an index value as an instance of the class

2. The load module corresponding language

The module attributes, determining whether to turn on or off the module

The principle is to use check_enabled check function, function of the parameter types - using class instance as an input parameter. Internal inspection method which method_exists whether a class instance object specified method, then the method invocation, or instance check_enabled_for_zone check_enabled.

So far shipping has actually achieved, characteristics similar .net reflection, but also the realization of the principle of plug-in mechanism.

You can call on a specific implementation class shipping, such as flat class function, achieve easy expansion characteristics.

Return plug-in is enabled in accordance with the following order of priority

First: Default $ enabled = $ class-> enabled; default, in fact, is initialized when the class constructor executes flat properties, internal calls zen_get_shipping_enabled function, and the area was examined

第二:$enabled = $class->check_enabled_for_zone();

第三:$enabled = $class->check_enabled();

 

4. instantiation module configured instance of the object, and to register the global variable which is the ultimate purpose of []


$modules

Constructor defined in this attribute

This property only after the results of the simple installation module "MODULE_SHIPPING_INSTALLED" division, with no further


MODULE_SHIPPING_INSTALLED

During initialization, just read the Configuration Groups 2 and 3, MODULE_SHIPPING_INSTALLED in the configuration group inside the 6, then it is how to read it?

This problem has been answered, seen from above


Properties of the module - based on flat

code-- module identification code, usually the class name, and class files with the same name, and refer to it in the $ GLOBALS variable

title-- module title, defined in the language file

description-- module itself is described, defined in the language file

sort_order--, the sort field is defined determines whether the module is enabled, it is also very important

icon icon ---

Use taxes tax_class--

What tax_basis-- is a tax based on the math

On what basis is Shipping Tax calculated. Options are
Shipping - Based on customers Shipping Address
Billing Based on customers Billing address
Store - Based on Store address if Billing/Shipping Zone equals Store zone

Whether the module is enabled enabled--

_check-- widget attributes used to read the status value MODULE_SHIPPING_FLAT_STATUS

The role of zen_get_shipping_enabled

disable only when entire cart is free shipping
disabled only when the entire cart free shipping

This function is listed first internal comments

for admin always true if installed
for administrators, if installed, it is always true


Free Shipping when 0 weight - enable freeshipper - ORDER_WEIGHT_ZERO_STATUS must be on
free shipping zero weight - weight must be enabled freeshipper- orders 0 state


Free Shipping when 0 weight - disable everyone - ORDER_WEIGHT_ZERO_STATUS must be on
free shipping when the weight of 0 - disables all of us - the weight of the order must be 0


Always free shipping only true - enable freeshipper
always free shipping - enabled freeshipper


Always free shipping only true - disable everyone
always free shipping - disabled owner


Always free shipping only is false - disable freeshipper
always free shipping is wrong - Disabled Free Shipping

At the same time it involved a function

$_SESSION['cart']->in_cart_check('product_is_always_free_shipping','1');

Check the number of products specified field

$_SESSION['cart']->count_contents();

Statistics shopping total item

$_SESSION['cart']->show_weight();

The total weight of the Statistical cart

 

About quote method

Returns a reference to the method, this method returns a reference to all the modules, a module may return a reference to a separate

Internal implementation mechanisms are:

First of all references to $ shipping_weight, $ uninsurable_value; $ uninsurable_value represents the shipping insurance to see if there is a specific class method get_uninsurable_value

Defined $ quotes_array, which is our ultimate array of objects to be returned, only this array object contains a module has been enabled

Through two cycles, the analysis module you want from a $ this-> modules properties

Foreach loop implements a first check from $ GLOBALS, enabled determination module adds only enabled to deposit $ quotes_array module

Second cycle, the update status; quote calling a specific method of shipping, and re-calculated weight of the global variable assignment


The next question is: flat shipping How is it calculated?

 

$ Shipping_weight When was the definition?

 

Session $ _SESSION [ 'shipping'] is what is written?

 

shipping module instantiation, have been identified and check the good which modules can be used


About envisaged demand environment

Free International Shipping on all orders

All orders fixed a postage

All orders fixed a postage, but enable the individual to a particular area

How many full amount of the order, on Free International Shipping

Order amount set interval range, not in the scope of the freight is not the same

Order number of installations Free International Shipping


About flat class

This is a flat-rate shipping modules, all orders shipping costs are the same, but can also be set to open in an area

 

Quote on flat class method

quote Chinese meaning is a reference, this method is to return relevant information for such a reference

Stored in quotes within an array, the following structure

Id-- unique identifier module, do not repeat globally

The title module-- module is defined in the language pack

methods-- This is an array that contains calculated on freight

tax-- tax rate

icon-- freight icon

Flat.php binding assay modules and freeshipper.php module, both the write mode at the same height

flat.php ---- means that all orders unified freight, tax rate

freeshipper.php ---- represents Free International Shipping


flat configuration module is in the area where the set? Temporarily unknown

zen_cfg_pull_down_zone_classes


 

Published 110 original articles · won praise 3 · views 30000 +

Guess you like

Origin blog.csdn.net/yueyekonglong/article/details/104257824