Skip to the content
Documentation
Help Start
Reading in:
  • German: 9,059 of 9,059 pages
About the help in other languages
All help pages

Custom shipping handler

Writing a shipping handler for an Exponential store - the three methods eZShippingManager calls, the array getShippingInfo returns with several shipping items and their VAT, how the basket info handler adds shipping to…

Download as PDF

Address: https://doc.exponential.earth/exphelp/viewer/help/e-commerce/extending/custom-shipping-handler.md

On this page

Custom shipping handler

This page is for developers who need shipping rules beyond the flat amount of the Simple shipping event. No shipping handler is shipped in the kernel; the contract is documented in kernel/classes/ezshippingmanager.php, and this page turns it into a recipe.

Contents

  1. The contract
  2. What getShippingInfo returns
  3. Registering the handler
  4. How shipping reaches the totals
  5. Common models
  6. Testing

The contract

eZShippingManager loads the handler named in shop.ini [ShippingSettings] Handler and calls three methods, each with the basket's product collection id:

MethodCalledReturns
getShippingInfo( $productCollectionID )Whenever the basket, the confirmation or totals need shippingAn array (below), or nothing for no shipping
updateShippingInfo( $productCollectionID )When an item is added (the update-shipping-info step of addtobasket)Anything your handler needs; use it to recalculate or store choices
purgeShippingInfo( $productCollectionID )When shipping information should be removedNothing

The class name is <name>ShippingHandler in <name>shippinghandler.php.

What getShippingInfo returns

One shipping line:

return array( 'description' => 'Standard delivery',
              'cost'        => 6.50,
              'vat_value'   => 20,
              'is_vat_inc'  => 1 );

Several lines, for example when parcels carry different VAT rates:

return array( 'shipping_items' => array(
                  array( 'description' => 'Parcel, standard VAT', 'cost' => 5.00, 'vat_value' => 20, 'is_vat_inc' => 1 ),
                  array( 'description' => 'Parcel, reduced VAT', 'cost' => 3.00, 'vat_value' => 5, 'is_vat_inc' => 1 ) ),
              'description' => 'Total shipping',
              'cost'        => 8.00,
              'vat_value'   => false,
              'is_vat_inc'  => 1 );
KeyMeaning
descriptionText shown to the customer
costAmount as a float
vat_valueVAT percentage as a number, or false when the total combines several rates
is_vat_inc1 if cost includes VAT, 0 if not
any other keyPassed to templates, for example management_link to a page where the customer picks a method

Registering the handler

In your extension's settings/shop.ini.append.php:

[ShippingSettings]
Handler=mystore
ExtensionDirectories[]=mystore_shop

and the class in extension/mystore_shop/shippinghandlers/mystoreshippinghandler.php. If the file is not found, the debug log says "Shipping handler 'mystore' not found" with the directories searched. Remove the simple shipping workflow from the confirmorder trigger when the handler goes live.

How shipping reaches the totals

eZShippingManager::vatPriceInfo() turns your array into amounts per VAT rate, and the shipped basket info handler (ezdefault) adds them to the basket's price information per VAT rate and to the total (Basket info and confirm order handlers). The handle-shipping step of the confirmorder operation applies shipping when the order is confirmed (Checkout operations step by step).

Common models

ModelWhat the handler reads
Free shipping above an amountThe product collection's items and their prices
Rates by country or zoneThe customer's country (eZVATManager::getUserCountry()) or the account data
Rates by weightA weight field on product classes, times item counts
Customer chooses a methodA choice stored by your own view (linked with management_link), read back by getShippingInfo()
Carrier rate serviceA call to the carrier with the address and parcel data; cache the answer per basket

Whether shipping carries VAT, and at which rate, is a question for your tax adviser.

Testing

  • To do: Unit tests for the calculation with fixed baskets (DB-less PHPUnit tests).
  • To do: Basket, confirmation, order view and mail show the same shipping.
  • To do: Changing quantities changes shipping when it should.
  • To do: Each country or zone you support, and one you do not.
  • To do: No second shipping line from an old simple shipping workflow.

Become an Exponential Partner

Partners share their information, provide funding, contribute back and develop the products with us, and that is how Exponential grows. A partner website and dashboard are planned for mid-2027: please become a partner today to speed up our growth rate and land new features faster.

Something wrong on this page? Report an error

Documentation license

This documentation is free documentation, licensed under the GNU Free Documentation License 1.3 or later.

Exponential Copyright © 1998-2026 Exponential Foundation and 7x