“Get Quotes” returns no Error if there are no rates avaliable
-
12-12-2019 - |
Question
It's always a good approach to show any result (negative or positive) to the user.
In my case, when I click on the 'Get quotes' button on My Cart page and rates are available — it's OK.
But when there is NO rates available for that address, I need to show to customer something like 'Hey, no rates dude'.
As far as I understand, I need to dig in the estimatePostAction
method and check the rates manually and set some flash-message.
But I'm just wondering about is there another Magento-way to have this approach?
Thanks for any suggestion or vision.
Solution
Well, finally I resolved this problem.
But I used not the CartController due to this issue, but the observer sales_quote_collect_totals_after
.
OTHER TIPS
I just use something similar to:
<?php $_shippingRateGroups = $this->getShippingRates(); ?>
<?php if (!$_shippingRateGroups): ?>
<p><?php echo $this->__('Sorry, no shipping quotes are available to this address. Please contact us at ' . Mage::getStoreConfig('general/store_information/phone') . ' for a shipping quote') ?></p>
<?php else: ?>
...success message...
and our getshippingrates function looks something like this:
public function getShippingRates()
{
if (empty($this->_rates)) {
$this->getAddress()->collectShippingRates()->save();
$groups = $this->getAddress()->getGroupedAllShippingRates();
/**
* If no shipping rate is found an error report will be logged containing product and customer information.
*/
if (empty($groups)) {
$this->noShipRateError();
}
return $this->_rates = $groups;
}
return $this->_rates;
}