Allow customer to choose Ship to Country at any time
-
12-12-2019 - |
Question
How would I allow my customers to choose their ship to country at any time in the site.
I thought I could do so with this example code but the checkout still defaults to the stores default values (If not logged in, still as guest)
$shippingAddress = Mage::getModel('checkout/cart')->getQuote()->getShippingAddress();
$shippingAddress->setCountryId('GB')->save();
// Great Britain as an example!
The goal is to not have to create a store for every country and to show the customers that we can ship to any country.
The customer will choose from a country select page and then the site would remember the ship to at checkout.
Any guidance would be appreciated.
Solution
You can try to set it in session:
Mage::getSingleton('checkout/session')->setCountryId('GB');
and then to change in app/code/core/Mage/Checkout/Block/Onepage/Abstract.php
-> public function getCountryHtmlSelect($type)
this code:
if (is_null($countryId)) {
$countryId = Mage::helper('core')->getDefaultCountry();
}
with this:
if (is_null($countryId)) {
if (Mage::getSingleton('checkout/session')->hasCountryId()) {
$countryId = Mage::getSingleton('checkout/session')->getCountryId();
} else {
$countryId = Mage::helper('core')->getDefaultCountry();
}
}
Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange