2

shipping collectRates method RateRequest class method of $request->getDestRegionId() is returning an empty value on estimate-shipping-methods-by-address-id, but same working well on estimate-shipping-methods

/V1/carts/mine/estimate-shipping-methods-by-address-id

from above API call in checkout $request->getDestRegionId() or $request->getDestRegionCode() is not working as expected.

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($this->_code);
    $method->setCarrierTitle($this->getConfigData('title'));

    $method->setMethod($this->_code);
    $method->setMethodTitle($this->getConfigData('name'));

    $amount = $this->getShippingPrice();

    $method->setPrice($amount);
    $method->setCost($amount);
    
    $region     = ($request->getDestRegionId() !== null) ? $this->getStateNameByRegionID($request->getDestRegionId()) : $request->getDestRegionCode();
    
    $result->append($method);

    return $result;
}

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.