1

I want to display a custom notice on cart page "if customer's order total above $299, then he is qualified for free shipping". For that I have imported following table rates:

Country | Region/State | Zip/Postal Code | Order Subtotal (and above) | Shipping Price

US | * | * | 0 | 15

US | * | * | 299 | 0

I can get single table rate using collectRatesByAddress() function of \Magento\Shipping\Model\Shipping class, but I can't get multiple table rates. Please see sample code as follows:

$quote = $this->_checkoutSession->getQuote(); $shippingAddress = $quote->getShippingAddress(); $shippingAddress->setCountryId("US") ->setCity("New York") ->setPostcode("11209") ->setRegionId("") ->setRegion("") ->setCollectShippingRates(true)->collectShippingRates(); $shippingCarrier = 'tablerate'; $carriers[$shippingCarrier] = ''; $result = $this->_shippingModel->collectRatesByAddress($shippingAddress, array_keys($carriers))->getResult(); foreach ($result->getAllRates() as $rate) { echo $rate->getPrice(); } 

Please give me any solution/suggestion/hint to resolve this problem.

Thanks in appreciation.

1 Answer 1

2

Have you tried using the method \Magento\Shipping\Model\Shipping::collectRates ?

Or, Alternatively you may query the database table shipping_tablerate which has the table rates stored in it.

1
  • After investigation, I found that collectRatesByAddress() returns applicable table rate data based on subtotal. So finally I used suggested alternate solution. @nikin Thank you for the guide lines. Commented Dec 7, 2018 at 6:11

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.