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

Get available shipping methods
 
GoMediaLtd
Sr. Member
 
Avatar
Total Posts:  84
Joined:  2009-11-12
Wakefield, United Kingdom
 

I am trying to make a dropdown menu which will be included on every page in my Magento store, this dropdown will be populated with all available shipping methods.

I keep getting a 500 internal server error for some reason, anybody got any ideas? My code so far is:

Mage::helper("core"); 
Mage::app("default"); 
Mage::getSingleton("core/session", array("name" => "frontend")); 
$session Mage::getSingleton("customer/session"); 

$cartHelper Mage::helper('checkout/cart');
$quote Mage::getSingleton('checkout/cart')->getQuote();
if(
$cartHelper->getItemsCount()<1){
    
echo '<select name="delivery" style="font-size:9px; width:100%;">
     <option selected="selected" style="padding:3px;">'
."Please add at-least 1 product to see shipping methods".'</option></select>';
    return;
}
$shippingAddress 
$quote->getShippingAddress();
$groups $shippingAddress->getGroupedAllShippingRates();

if(!
$groups){
    $shippingCountry 
"GB";
    
$shippingRegionID "20";
    
$shippingRegion "";
    
$postcode "";
    
$shippingAddress->setCountryId($shippingCountry)
        ->
setCity("")
        ->
setPostcode($postcode)
        ->
setRegionId($shippingRegionID)
        ->
setRegion($shippingRegion)
        ->
setCollectShippingRates(true);

    
//echo $quote->getCode();

    
$code "matrixrate_matrixrate";
    
$shippingAddress->setShippingMethod($code)/*->collectTotals()*/->save();
    
$groups getGroupedAllShippingRates();
}

echo '<form id="di-co-shipping-method-form" action="<MY_URL>/index.php/checkout/cart/estimatePost/">';$countShip 1;
    foreach (
$groups as $code => $_rates):

        echo 
"<select name=\"estimate_method\" onchange=\"this.form.submit()\" style=\"font-size:9pxwidth:100%;\">";
        echo 
"<option style=\"padding:3px;\">"."Please Select"."</option>";

        foreach (
$_rates as $_rate):
            
//echo $_rate->getMethodTitle();
            //$selected = ($_rate->getCode() == Mage::helper('tax')->getAddressShippingMethod())?"selected":"";
            
$text $_rate->getMethodTitle()."&nbsp;";
            if(
$_rate->getPrice() != ""):

                
$_incl Mage::helper('tax')->getShippingPrice($_rate->getPrice(), true);
                
$text .= "£".$_incl;

            endif;

            echo 
"<option value=\"".$_rate->getCode()."\" ".$selected." style=\"padding:3px;\" >".$text."</opton>";

        endforeach;

        echo 
"</select>";   
    endforeach;

echo 
'</form>';
 
Magento Community Magento Community
Magento Community
Magento Community
 
GoMediaLtd
Sr. Member
 
Avatar
Total Posts:  84
Joined:  2009-11-12
Wakefield, United Kingdom
 

Bump for a fix! smile

 
Magento Community Magento Community
Magento Community
Magento Community
 
GoMediaLtd
Sr. Member
 
Avatar
Total Posts:  84
Joined:  2009-11-12
Wakefield, United Kingdom
 

Fixed it!

Anyone else who is having this problem all you need to do is change the form action from:

<MY_URL>/index.php/checkout/cart/estimatePost/

to

<MY_URL>/index.php/checkout/cart/estimateUpdatePost/

Simples smile

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