跳转到内容

Shipping System

此内容尚不支持你的语言。

Checkout Service
↓
Shipping Provider Factory
├── Weight-Based Provider
├── Manual Provider
├── DHL Provider
├── FedEx Provider
└── UPS Provider
↓
Shipping Rates → Client selects → Order finalized
#[async_trait]
pub trait ShippingProvider: Send + Sync {
fn id(&self) -> &str;
fn name(&self) -> &str;
fn is_available(&self) -> bool;
async fn get_rates(&self, from: &Address, to: &Address, package: &Package, options: &RateOptions) -> Result<Vec<ShippingRate>>;
// ...
}

Default provider. Calculates rates based on:

  • Total cart weight (from product weights)
  • Destination country
  • Zone-based rates per 0.5kg

Weight rounds up to nearest 0.5kg.

Zone rates are per 0.5kg and configured in the weight-based provider, with a default fallback zone for unmatched destinations. Example:

ZoneRate/0.5kg
Domestic$5.00 flat
Europe$10.00
Rest of world$15.00

Full mechanics in the Shipping guide.

For EU destinations, VAT is applied to items at the configured rate; shipping charges themselves are not taxed:

  • A $10.00 item with a 20% VAT class → $2.00 VAT
  • A $2.00 item with a 20% VAT class → $0.40 VAT

Product weights are fetched from the database. Products without weight default to 0.5kg.

let weights = cart_service.get_product_weights(&product_ids).await?;
let total_weight: Decimal = items.iter()
.map(|item| {
let w = weights.get(&item.product_id).copied().unwrap_or(dec!(0.5));
Decimal::from(item.quantity) * w
})
.sum();

The ShippingProviderFactory must be cloned for the rate aggregator. Each provider is re-created in the clone (providers are stateless).