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

Echo a Shipping Table Rate value
 
Spez86
Jr. Member
 
Total Posts:  22
Joined:  2010-02-14
 

Hi all.

I’m attempting to create a shipping weight ‘allowance’ bar that fills as the customer adds products to their cart so they can see how full their box is on the current shipping tariff. I.e. total cart weight = 15kg, tariff 0-30kg which obviously equals 50% full. For this, I’ll basically do some php maths with the variables and spit out a percentage and make a div width based on that.

My question is though, I can retrieve the cart weight value no problem but I also need to call or retrieve the ‘max weight’ or ‘weight up to’ value from the table rates, in this case it would be 30, which I can’t seem to do!! I’m not new to Magento but new to php and have played around for hours but can’t get this value.

Does anybody know how I would do this?

Many thanks.

 
Magento Community Magento Community
Magento Community
Magento Community
 
Sunovisio
Sr. Member
 
Avatar
Total Posts:  94
Joined:  2012-04-12
Ho Chi Minh
 

Hi Spez86,

Table Rate values are stored in table shipping_tablerate.

Hope my answer will help you.

 
Magento Community Magento Community
Magento Community
Magento Community
 
Spez86
Jr. Member
 
Total Posts:  22
Joined:  2010-02-14
 

Hi sunovisio. Thanks for your reply. Please could you expand on that? How would I go about calling a value from that table? And where is the table referenced?

Many thanks.

 
Magento Community Magento Community
Magento Community
Magento Community
 
Sunovisio
Sr. Member
 
Avatar
Total Posts:  94
Joined:  2012-04-12
Ho Chi Minh
 

Hi Spez86,

You can use this function to get the table rates collection:

$collection Mage::getResourceModel('shipping/carrier_tablerate_collection');

I just wrote an article about that following your question: you can find it here.

Hope my answer will help you.

 
Magento Community Magento Community
Magento Community
Magento Community
 
Spez86
Jr. Member
 
Total Posts:  22
Joined:  2010-02-14
 

EDIT: I managed to call the data I was looking for but it seems it’s just reading the first line in the table.

I’m using the Premium Matrixrate extension and on the collection.php file, setWeightRange() function obviously sets the weight range for the rate result, and it’s this I’m trying to call on the Estimate Shipping page: template/checkout/cart/shipping.phtml.
This is what I’ve written:

<?php $collection Mage::getResourceModel('premiumrate_shipping/carrier_premiumrate_collection');
                                        foreach(
$collection as $rate)
                                        
{
                                            $weighttomax 
$rate->getData();
                                            
                                        
}
                                        
echo "{$weighttomax["weight_to_value"]}";
                                    
?>

This echoes ‘30’ which is right but when I increase the cart weight to over 30, this figure should increase to the next ‘weight_to_value’ in the table rates which is ‘60’ - it doesn’t, it just echoes 30.

Any ideas?
Sunovisio THANK YOU!!!

You are awesome! I grabbed the data from the array that I needed and now I can use that value to in a variable that I can call my ‘Maximum weight’ value. Your article is super! You should re-post it here for all to see. A* my friend!

Thanks again!

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