alexedimensionz/royal-mail-price-calculator

一个用于计算通过皇家邮政发送包裹成本的库。

1.2.2 2023-04-28 10:25 UTC

This package is auto-updated.

Last update: 2024-09-28 14:07:01 UTC


README

此库是为了使其复活而进行的分支。由 WyldCode 构建,它是 e-dimensionz, Inc 的子公司。

它允许您计算通过皇家邮政发送包裹的成本,更新价格并扩展对所有包裹价格的支持。

用法

使用 composer require alexedimensionz/royal-mail-price-calculator 安装最新版本

Justin Hook's 仓库的主要变化

  • 删除 Doctrine 要求
  • 添加所有运输类型
  • 添加国际运输选项和价格
  • 持续更新价格列表

支持的服务

英国配送目标的示例

<?php

require 'vendor/autoload.php';

use \RoyalMailPriceCalculator\Calculator;
use \RoyalMailPriceCalculator\Package;
use \RoyalMailPriceCalculator\Services\GuaranteedByOnePmService;
use \RoyalMailPriceCalculator\Services\FirstClassService;

$calculator = new Calculator();

$package = new Package();
$package->setDimensions(15, 15, 0.4);
$package->setWeight(90);

$calculator->setServices(array(
							new FirstClassService(), 
							new GuaranteedByOnePmService()));

foreach ($calculator->calculatePrice($package) as $calculated)
{
    echo $calculated['service']->getName() . "\n";
    foreach ($calculated['prices'] as $price) {
        echo "  →  £{$price['price']} (Compensation: £{$price['compensation']})\n";
    }
    echo "\n";
}

将输出类似的内容

1st Class Service
  →  £0.62 (Compensation: £20)

Guaranteed by 1pm
  →  £6.40 (Compensation: £500)
  →  £7.40 (Compensation: £1000)
  →  £9.40 (Compensation: £2500)

国际配送目标的示例

<?php

require 'vendor/autoload.php';

use \RoyalMailPriceCalculator\Calculator;
use \RoyalMailPriceCalculator\Package;
use \RoyalMailPriceCalculator\Services\InternationalTracked;
use \RoyalMailPriceCalculator\Services\InternationalEconomy;

$calculator = new Calculator();

$package = new Package();
$package->setDimensions(15, 15, 0.4);
$package->setWeight(90);

// This part is mandatory for international shipments
$target_iso = 'US';
$calculator->setCountryCode($target_iso);
//


$calculator->setServices(array(
                         	new InternationalTracked(), 
                         	new InternationalEconomy()));


// Note: there is no compensation value for international
foreach ($calculator->calculatePrice($package) as $calculated)
{
    echo $calculated['service']->getName() . "\n";
    foreach ($calculated['prices'] as $price) {
        echo "  →  £{$price['price']}\n";
    }
    echo "\n";
}

将输出类似的内容

International Tracked
  →  £8.50

International Economy
  →  £13.30

有用的函数

皇家邮政有 5 个配送区域

  • 英国
  • 欧洲
  • 国际(区域 1)
  • 国际(区域 2)
  • 美国(区域 3)

您可以使用 2 位字母 ISO 代码找到您国家的区域代码。

<?php

require 'vendor/autoload.php';

use \RoyalMailPriceCalculator\Calculator;

?>
CA region is: <?php echo Calculator::get_region_code('CA'); ?><br/>
US region is: <?php echo Calculator::get_region_code('US'); ?><br/>
GB region is: <?php echo Calculator::get_region_code('GB'); ?><br/>
AU region is: <?php echo Calculator::get_region_code('AU'); ?><br/>
DE region is: <?php echo Calculator::get_region_code('DE'); ?>

将输出

CA region is: intl_1
US region is: intl_3
GB region is: uk
AU region is: intl_2 
DE region is: eu