Getting Started
A shipping method in Bagisto is a carrier: a class that quotes a rate for the cart, added from a package through merged configuration. This section builds one carrier, then explains each of its parts, without editing a core package.
What You'll Build
Webkul\CustomExpressShipping, a package that adds the carrier custom_express_shipping:
- an Express Delivery (1-2 Days) option on the checkout's shipping step
- a rate charged once per order, or once per item that ships
- a Custom Express Shipping section in the admin's shipping method configuration, with its status, title, description, rate and pricing type per channel
How It Works
Paths are relative to packages/Webkul/CustomExpressShipping/src.
| Part | File | Plugs into |
|---|---|---|
| Carrier configuration | Config/carriers.php | Merged into config('carriers'); its class key names the carrier class |
| Carrier class | Carriers/CustomExpressShipping.php | Extends Webkul\Shipping\Carriers\AbstractShipping; calculate() returns the rate |
| System configuration | Config/system.php | Merged into config('core') as the section sales.carriers.custom_express_shipping, which the carrier's getConfigData() reads |
| Service provider | Providers/CustomExpressShippingServiceProvider.php | Merges both files; listed in bootstrap/providers.php |
At checkout, Webkul\Shipping\Shipping::collectRates() creates every carrier in config('carriers'), calls its calculate() and groups the rates for the shipping step. The checkout does this only for a cart with stockable items, and saves the customer's choice only if a collected rate carries the same method code.
Prerequisites
- Bagisto 2.5, installed and running: see Installation.
- How a package is autoloaded and its provider registered: see Package Development.
The Path
- Creating Your First Shipping Method: build the package by hand and see its rate at checkout. To scaffold it instead, see Package Generator.
- Understanding Carrier Configuration: the
carriers.phpkeys, the admin section insystem.php, and carriers with several services. - Understanding the Carrier Class: what
AbstractShippingprovides, whencalculate()runs, and common pricing patterns.
Next Step
Start by building the package.
Continue to: Creating Your First Shipping Method
