Posting in the Magento forums has been disabled pending the implementation of a new and improved forum solution which should better serve the community.

For new questions please post at magento.stackexchange.com, the community-run support site for the Magento community. We will be providing updates on the new forum solution soon. For questions or concerns please email community@magento.com.

Magento Forum

Default shipping estimation
 
crius
Guru
 
Avatar
Total Posts:  623
Joined:  2007-10-16
Denmark
 

I am trying to modify the shopping cart page to display the shipping price in the totals already when the page is loaded for the first time, with default values for shipping address and shipping method. So basically, the server should “fill out” the estimate shipping box automatically.

I have created an observer function for the controller_action_predispatch_checkout_cart_index event. The function is like this:

public function setDefaultShipping($observer)
    
{
        $shippingaddress 
Mage::getSingleton('checkout/cart')->getQuote()->getShippingAddress();
        if (!
$shippingaddress->getShippingMethod()) {
            $shippingaddress
->setShippingMethod('flatrate_flatrate')->setCollectShippingRates(true);
        
}
        
if (!$shippingaddress->getCountryId()) {
            $defaultcountry 
Mage::getStoreConfig('general/country/default');
            
$shippingaddress->setCountryId($defaultcountry);
        
}
        Mage
::getSingleton('checkout/cart')->getQuote()->save();
    
}

Unfortunately, the shipping country and method is not set when viewing the cart for the first time. The strange thing is it works if you reload the cart page. When viewing the cart for the second time, the country and method is set, and the shipping price shows up in the totals.

Does anyone have an idea why the changes do not affect the page immediately?

 
Magento Community Magento Community
Magento Community
Magento Community
 
hexagram
Jr. Member
 
Total Posts:  23
Joined:  2009-01-08
 

Anders,

Did you figure this out?

 
Magento Community Magento Community
Magento Community
Magento Community
 
crius
Guru
 
Avatar
Total Posts:  623
Joined:  2007-10-16
Denmark
 

Nope.

 
Magento Community Magento Community
Magento Community
Magento Community
 
Tomas iTokas
Member
 
Total Posts:  44
Joined:  2010-06-07
 

I am interested to this modification too, any new about it ?

 
Magento Community Magento Community
Magento Community
Magento Community
 
Lexn
Jr. Member
 
Avatar
Total Posts:  5
Joined:  2010-06-10
 

Any news about this yet?

 
Magento Community Magento Community
Magento Community
Magento Community
 
Lexn
Jr. Member
 
Avatar
Total Posts:  5
Joined:  2010-06-10
 

I’ve solved this with ajax.

So no problem anymore.

 
Magento Community Magento Community
Magento Community
Magento Community
 
jonathanmd
Jr. Member
 
Total Posts:  22
Joined:  2011-02-14
 

this seems to work but the very first time you add a product it remains blank. thereafter (if you reload the page) it appears.

http://www.arscommunity.com/wiki/magento/default-address-for-shipping-estimation

 
Magento Community Magento Community
Magento Community
Magento Community
 
jonathanmd
Jr. Member
 
Total Posts:  22
Joined:  2011-02-14
 

Hi guys,

Finally found a solution to this problem. Add this code before

$this->_quote = $quote;

in Mage_Checkout_Model_Session (or inherit properly).

$sha $quote->getShippingAddress();
            
            if (!
$sha->getCountry()) {

              $country 
Mage::getStoreConfig('shipping/origin/country_id');
              
$state Mage::getStoreConfig('shipping/origin/region_id');
              
$postcode Mage::getStoreConfig('shipping/origin/postcode');
              
                
$quote ->getShippingAddress()
                    ->
setShippingMethod('flatrate_flatrate')
                    ->
setCountryId($country)
                    ->
setRegionId($state)
                    ->
setPostcode($postcode)
                    ->
setCollectShippingRates(true);
                    
                
$this->resetCheckout();
                
                
$quote->save();

Then just comment out the form in template\checkout\cart\shipping.phtml.

Hope this helps someone.

Jonno.

 
Magento Community Magento Community
Magento Community
Magento Community
 
haltabush
Jr. Member
 
Total Posts:  13
Joined:  2009-09-14
 

Hi,
I’ve the exact same problem : I can’t collect shipping rates on the 1st call to the cart page, 2nd is fine.
I’ve tried the ->resetCheckout(), unfortunately I don’t have this method in Mage_Checkout_Model_Session so it doesn’t have any chance to work…
I’m working on Magento ENtreprise 1.9, any idea is welcome smile

edit : oops, I have it, but it still doesn’t work…

 
Magento Community Magento Community
Magento Community
Magento Community
 
brendanb
Mentor
 
Total Posts:  1093
Joined:  2008-07-16
London, United Kingdom
 

hi,

thanks for the example, however as per above. This only works on 2nd page refresh. Any ideas on why this is occuring

brendan

 
Magento Community Magento Community
Magento Community
Magento Community
 
Tim MST
Jr. Member
 
Avatar
Total Posts:  9
Joined:  2011-10-26
 

You can use my module. It apply a shipping method before go to cart page. So don’t need to reload page anymore. You can set default shipping method code in Observer.php file. I’m test in magento 1.7.0.2.

Hope it help someone.

File Attachments
Switchshipping.zip  (File Size: 2KB - Downloads: 146)
 
Magento Community Magento Community
Magento Community
Magento Community
 
jaysismyson
Jr. Member
 
Total Posts:  3
Joined:  2013-08-16
 

Landlord good man, appreciate you sharing Fifa 13 Forums this articles quality article, I learned a lot, thank you very much.

 
Magento Community Magento Community
Magento Community
Magento Community
 
wowgold5
Jr. Member
 
Total Posts:  2
Joined:  2013-08-17
 

I am very much agree with your point of view ,I think it’s doors very well this is our game sites recommended to you.
-------------------------------------------------------------------
http://www.d3joy.com/
http://www.sellgw2.com/

 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
Back to top