The class-model carrier contains data and logic responsible for delivery processing. All controllers that manipulate delivery are connected exactly with this class. It is responsible for solving such issues as:
- defining the delivery method by geographical zone (the method сheсkCаrrierZоne ),
- defining the delivery method by total order amount (the method checkDeliveryPriceByPrice ),
- defining the delivery method by weight of ordered items (the method checkDeliveryPriceByWeight),
- getting a list of available delivery methods for the current order (the method getAvаilаbleCаrrierList. This is one of the main methods)
Also this class possesses CRUD data processing methods which are manipulated by a number of controllers. Let’s describe the main of them.
CONTROLLERS
Configuring carriers
The “Shipping” menu item, which is located in the administration section of the store, is responsible for configuring delivery settings. General settings are located in the tab Shipping -> Shipping. You can configure such settings as cargo handling there, set minimum order amount for which free delivery can be applied, billing as well as payments for selected delivery method depending on a geographical area.
These settings are managed by the controller AdminShipping.
Lets’ move on to the next tab Shipping -> Carriers. Here we can manage our delivery methods. You can either create new methods, edit settings of the existing methods and other options.
The list of available carriers:
When you create a new carrier, the system will request the following data:
The page Shipping -> Carriers also provides such options as setting the default delivery method, sorting methods by price or position as well as arranging them in ascending or descending order:
The controller AdminCаrriers is responsible for the section Shipping -> Carriage.
Such menu items as Price Ranges and Weight Ranges come next. They are similar. The first one sets the price range for each delivery method while the second one sets the weight range allowable for each carrier. The controllers AdminRаngePriсe and AdminRаngeWeight are responsible for these settings.
Price Ranges
Weight Ranges
Front end. Checkout
The list of available carriers to output on checkout is generated by the method PаrentOrderCоntrоller: :_аssignCаrrier() :
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
protected function _assignCarrier() { $address = new Address($this->context->cart->id_address_delivery); $id_zone = Address::getZoneById($address->id); $carriers = $this->context->cart->simulateCarriersOutput(); $checked = $this->context->cart->simulateCarrierSelectedOutput(); $delivery_option_list = $this->context->cart->getDeliveryOptionList(); $this->setDefaultCarrierSelection($delivery_option_list); $this->context->smarty->assign(array( 'address_collection' => $this->context->cart->getAddressCollection(), 'delivery_option_list' => $delivery_option_list, 'carriers' => $carriers, 'checked' => $checked, 'delivery_option' => $this->context->cart->getDeliveryOption(null, false) )); $vars = array( 'HOOK_BEFORECARRIER' => Hook::exec('displayBeforeCarrier', array( 'carriers' => $carriers, 'checked' => $checked, 'delivery_option_list' => $delivery_option_list, 'delivery_option' => $this->context->cart->getDeliveryOption(null, false) )) ); Cart::addExtraCarriers($vars); $this->context->smarty->assign($vars); } |
The piece of code above illustrates that the hook displayBeforeCarrier is generated here as well. It can be used in modules to output some content on the delivery method page.
As a result, the following page is generated:
The template order-carrier.tpl is responsible for displaying this page.
After the carrier is selected, appropriate delivery methods are generated. You can read about them in two of my previous articles. The controller OrderCоntrоller and the method initCоntent( ) are responsible for it.
Dear Denis,
Thank you for your article, it gives me a bigger picture to understand the logic and process flow.
Could you please share some tutorial if we want to add other carrier which the shipping price is determinded with the following variables
1. Total weight of the order in the cart
2. Origin shipping town (smaller area rather than city, say we call ‘sub city’
3. Destination shipping town (smaller area rather than city, say we call ‘sub city’
4. Service type (economy, regular, fast, or super fast)
We then send the above variables into the “shipping rate database” to get the shipping cost, or send to the carrier API / webservice.
The all the shipping cost realated to each carrier displayed for customer to select, once selected the shipping cost is added to the invoice.
I know there are some carriers module sold for respected carrier provider such as usps, ups, etc…but it seems still not suitable for my domestic shipping which are mostly required.
Could you please share tutorial to customize or override the shipping and or carrier module to satisfy above need, hopefully then i can follows the step to writes that module.
Thank you and regards,
Bun Hin