I am trying to create a custom calculator which calculates shipping costs based of a deleivery address. For now, I will be hardcoding different fees according to a postcode prefix... e.g.
I am following the tutorial here.
The code stub I have is as follows:
<?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.
}
}
Is there a way in sylius where I can get access to the shipping address of an order? The ShippingSubjectInterface only allows access to volume, weight, items, and shippables.
/** @var $subject Shipment */
$postCode = $subject->getOrder()->getShippingAddress()->getPostCode();
Allowed me get address from subject.