考虑目的地的 Sylius 自定义运费计算器
Sylius custom shipping calculator which takes destination into account
我正在尝试创建一个自定义计算器,它根据送货地址计算运费。现在,我将根据邮政编码前缀对不同的费用进行硬编码...例如。
- SK1 = 4
- SK2 = 4
- SK3 = 4
- SK4 = 4
- M1 = 6
- M2=6
- M3=6
- M4=6
- 其他所有 = 10
我对 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();
允许我从主题中获取地址。
我正在尝试创建一个自定义计算器,它根据送货地址计算运费。现在,我将根据邮政编码前缀对不同的费用进行硬编码...例如。
- SK1 = 4
- SK2 = 4
- SK3 = 4
- SK4 = 4
- M1 = 6
- M2=6
- M3=6
- M4=6
- 其他所有 = 10
我对 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();
允许我从主题中获取地址。