考虑目的地的 Sylius 自定义运费计算器

Sylius custom shipping calculator which takes destination into account

我正在尝试创建一个自定义计算器,它根据送货地址计算运费。现在,我将根据邮政编码前缀对不同的费用进行硬编码...例如。

我对 sylius 和 php 还很陌生,所以非常感谢大家的帮助。我正在按照教程 here.

我的代码存根如下:

<?php
/**
 * Created by IntelliJ IDEA.
 * User: camerona
 * Date: 03/03/2017
 * Time: 08:09
 */

namespace AppBundle\Shipping;

use Sylius\Component\Shipping\Calculator\CalculatorInterface;
use Sylius\Component\Shipping\Model\ShippingSubjectInterface;

class PostCodeCalculator implements CalculatorInterface
{
    public function calculate(ShippingSubjectInterface $subject, array $configuration)
    {
        return $this->postCodeService->getShippingCostForPostCode($subject->getShippingAddress());
    }

    public function getType()
    {
        // TODO: Implement getType() method.
    }
}

在 sylius 中我可以通过某种方式获取订单的送货地址吗? ShippingSubjectInterface 仅允许访问体积、重量、项目和可发货项。

提前致谢。

/** @var $subject Shipment  */
$postCode = $subject->getOrder()->getShippingAddress()->getPostCode();

允许我从主题中获取地址。