Access to shipping costs in the Magento trolley and / or checkout

Please note that this question is about shipping cost, not price. There is an important difference, that is, $$ charges the shipping method for the store owner, as opposed to what kind of $$ payment the customer pays.

The database table shipping_tablerateincludes a field costthat is populated by the object Mage_Shipping_Model_Carrier_Tablerateduring the method collectRates. However, this field is not available anywhere on the stack, for example. from the quotation address.

I need to access this value on the cart page, and I cannot find it to achieve the goal, except creating an instance of the object Mage_Shipping_Model_Rate_Requestto go to collectRates(). This seems unnecessarily inefficient, given that the data has already been loaded from the table and should be accessible.

I tried to Watch the event <shipping_carrier_tablerate_load/>, but it seems that the event is _loadnot selected for this model.

I also tried to access the course from a quote:

$quote = Mage::getSingleton('checkout/cart')->getQuote();
$address = $quote->getShippingAddress();
$rate = $address->getShippingRateByCode($code ='tablerate_bestway');

I can see the calculated price, but costmissing from this model.

At this point, my ideas run out. Any suggestions gratefully received!

Thanks Jonathan

+5
source share
1 answer

-, , - . . , Magento SQL-, , , , .

-, . shipping/rate_request, -, . ,

Mage_Shipping_Model_Shipping::collectRatesByAddress
Mage_Sales_Model_Quote_Address::requestShippingRates

, shipping/rate_request , . , , Mage_Shipping_Model_Carrier_Tablerate::collectRates, , .

, - , , , OO-, -. , , , ( ) ( , - - )

-, -, , , . -

class Package_Module_Model_Carriertablerate extends
Mage_Shipping_Model_Carrier_Tablerate
{
    public function getRate(Mage_Shipping_Model_Rate_Request $request)
    {
        $rate = parent::getRate($request);  
        Mage::register('package_module_carriertablerates', $rate);
        return $rate;
    }

}

...
//later, retrieve the rate
$rates = Mage::registry('package_module_carriertablerates');

, , - . , .

+6

All Articles