I need to integrate a courier API to get the dynamic price based on the customer's pin code. So I can't use the Table rate Method
Here is my code for Carrier Model:
namespace Custom\Shipping\Model\Carrier; use Magento\Quote\Model\Quote\Address\RateRequest; use Magento\Shipping\Model\Rate\Result; class Example extends \Magento\Shipping\Model\Carrier\AbstractCarrier implements \Magento\Shipping\Model\Carrier\CarrierInterface { /** * @var string */ protected $_code = 'example'; /** * @param \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig * @param \Magento\Quote\Model\Quote\Address\RateResult\ErrorFactory $rateErrorFactory * @param \Psr\Log\LoggerInterface $logger * @param \Magento\Shipping\Model\Rate\ResultFactory $rateResultFactory * @param \Magento\Quote\Model\Quote\Address\RateResult\MethodFactory $rateMethodFactory * @param array $data */ public function __construct( \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig, \Magento\Quote\Model\Quote\Address\RateResult\ErrorFactory $rateErrorFactory, \Psr\Log\LoggerInterface $logger, \Magento\Shipping\Model\Rate\ResultFactory $rateResultFactory, \Magento\Quote\Model\Quote\Address\RateResult\MethodFactory $rateMethodFactory, array $data = [] ) { $this->_rateResultFactory = $rateResultFactory; $this->_rateMethodFactory = $rateMethodFactory; parent::__construct($scopeConfig, $rateErrorFactory, $logger, $data); } /** * @return array */ public function getAllowedMethods() { return [$this->_code => $this->getConfigData('name')]; } /** * @param RateRequest $request * @return bool|Result */ public function collectRates(RateRequest $request) { if (!$this->getConfigFlag('active')) { return false; } /** @var \Magento\Shipping\Model\Rate\Result $result */ $result = $this->_rateResultFactory->create(); /** @var \Magento\Quote\Model\Quote\Address\RateResult\Method $method */ $method = $this->_rateMethodFactory->create(); $method->setCarrier('example'); $method->setCarrierTitle($this->getConfigData('title')); $method->setMethod('example'); $method->setMethodTitle($this->getConfigData('name')); /*you can fetch shipping price from different sources over some APIs, we used price from config.xml - xml node price*/ $amount = $this->getConfigData('price'); $method->setPrice($amount); $method->setCost($amount); $result->append($method); return $result; } }
$amount should be dynamic based on the customer's pin code. How can I get the customer's pin code here to run a courier API or any one have some other method to do this.