Set country from custom cart controller
-
13-12-2019 - |
Question
I try to set the country from my custom cart controller with the following function:
public function setCountryAction()
{
$country = (string) $this->getRequest()->getParam('country');
$quote = Mage::getSingleton('checkout/session')->getQuote();
$quote->getBillingAddress()->setCountryId($country);
$quote->getShippingAddress()->setCountryId($country);
$quote->save();
// print $quote->getBillingAddress()->getCountryId();
}
The print at the end of the function contains the expected result but unfortunately the country is not actually saved to the quote.
When I change the country from the checkout, go back to the cart and do the action again, strangely enough it works perfectly.
So the problem only exists with a new, empty session.
Solution 2
Finally found! This issue has to do with the 'Default country' option in the OneStepCheckout extension.
OTHER TIPS
Instead of $quote->save();
or before it try
$quote->getBillingAddress()->save();
$quote->getShippingAddress()->save();
Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange