laratables/laravel-shipping 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

laratables/laravel-shipping

Composer 安装命令:

composer require laratables/laravel-shipping

包简介

A weight-based shipping cost calculator for Laravel with database-driven weight bands, free shipping thresholds, flat-rate fallback and a global on/off toggle.

README 文档

README

A weight-based shipping cost calculator for Laravel with database-driven weight bands, free shipping thresholds, flat-rate fallback, and a global on/off toggle.

Requirements

  • PHP 8.2+
  • Laravel 10, 11, 12 or 13

Note for Laravel 13 users: If you are developing on PHP 8.4 or 8.5 but deploying to a PHP 8.3 environment, add the following to your project's composer.json to prevent Composer pulling Symfony 8 components that require PHP 8.4:

"config": {
    "platform": {
        "php": "8.3.0"
    }
}

This pins dependency resolution to PHP 8.3 so Composer keeps pulling Symfony 7.4 components compatible with your server.

Installation

composer require laratables/laravel-shipping

Publish and run the migration:

php artisan vendor:publish --tag=shipping-migrations
php artisan migrate

Publish the config file:

php artisan vendor:publish --tag=shipping-config

Seed the default weight bands:

php artisan vendor:publish --tag=shipping-seeders
php artisan db:seed --class=ShippingWeightBandSeeder

Usage

Resolving shipping for a cart

use Laratables\Shipping\Services\ShippingResolver;

$result = app(ShippingResolver::class)->resolve(
    cart:          session('cart', []),
    orderSubtotal: 55.00,
);

$result['total_shipping'];     // float — final charge
$result['is_free_shipping'];   // bool
$result['free_shipping_info']; // progress bar data
$result['breakdown'];          // itemised lines

Cart item shape

[
    'product_id'    => 1,
    'name'          => 'T-Shirt',
    'weight_kg'     => 0.5,    // null to use flat rate
    'shipping_cost' => null,   // used when weight_kg is null
    'quantity'      => 2,
    'price'         => 19.99,
]

Per-product priority rule

weight_kg shipping_cost Result
set any Algorithm used, shipping_cost ignored
null set Flat rate used directly
null null Not shippable, skipped

Product estimate

$estimate = app(ShippingResolver::class)->estimateForProduct(
    productId:    $product->id,
    name:         $product->name,
    weightKg:     $product->weight_kg,
    shippingCost: $product->shipping_cost,
    quantity:     1,
);

Using the Facade

use Laratables\Shipping\Facades\Shipping;

$result = Shipping::resolve(session('cart', []), $subtotal);
$info   = Shipping::freeShippingInfo($subtotal);

Configuration

All settings are in config/shipping.php and driven by environment variables:

Key .env Default Description
enabled SHIPPING_ENABLED true Master on/off toggle
disabled_fallback.mode SHIPPING_DISABLED_MODE free free, flat_rate, or unavailable
disabled_fallback.flat_rate_amount SHIPPING_FLAT_RATE_AMOUNT 5.99 Fixed charge when mode is flat_rate
base_fee SHIPPING_BASE_FEE 2.50 Handling fee on every order
multi_product_surcharge SHIPPING_MULTI_PRODUCT_SURCHARGE 1.50 Added when cart has >1 product line
heavy_item_threshold_kg SHIPPING_HEAVY_ITEM_THRESHOLD_KG 10.0 Line weight that triggers heavy surcharge
heavy_item_surcharge SHIPPING_HEAVY_ITEM_SURCHARGE 3.00 Charge per heavy product line
max_weight_kg SHIPPING_MAX_WEIGHT_KG 100.0 Maximum shippable order weight
free_enabled SHIPPING_FREE_ENABLED true Enable free shipping threshold
free_threshold SHIPPING_FREE_THRESHOLD 75.00 Subtotal needed for free shipping
free_weight_limit_kg SHIPPING_FREE_WEIGHT_LIMIT_KG null Max weight still eligible for free shipping

Weight bands

Bands are stored in shipping_weight_bands and managed from your admin panel. After updating bands, clear the cache:

Cache::forget('shipping_weight_bands');

Disabled modes

SHIPPING_ENABLED=false
SHIPPING_DISABLED_MODE=flat_rate
SHIPPING_FLAT_RATE_AMOUNT=5.99
SHIPPING_DISABLED_MESSAGE="Flat rate shipping applied"
Mode Behaviour
free All orders ship free
flat_rate Fixed charge on every order
unavailable Throws RuntimeException, block checkout

Testing

composer test

License

MIT

laratables/laravel-shipping 适用场景与选型建议

laratables/laravel-shipping 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 2 次下载、GitHub Stars 达 0, 最近一次更新时间为 2026 年 04 月 04 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「ecommerce」 「laravel」 「shipping」 「calculator」 「weight」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 laratables/laravel-shipping 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 laratables/laravel-shipping 我们能提供哪些服务?
定制开发 / 二次开发

基于 laratables/laravel-shipping 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 2
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 42
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-04-04