5

I have the following code and I have searched and searched and can not find the answer. Everything I find on these forums tell me to do what I have already done but the shipping cost will just not save on the quote.

Here is how I call the quote,

$quote = Mage::getModel('sales/quote')->load($QID);

I then add all my items and customer details etc and then I add the shipping details like so,

$delCost = 10 //// I set this as a variable 
$delTitle = 'MY CUSTOM TITLE' //// I set this as a variable 



    $quote->getShippingAddress()->setShippingDescription($delTitle); /// THIS IS WORKING
    $quote->getShippingAddress()->setShippingAmount($delCost);
    $quote->getShippingAddress()->setBaseShippingAmount($delCost);
    $quote->getShippingAddress()->setData('price',$delCost);
    $quote->getShippingAddress()->setRate($delCost);
    $quote->getShippingAddress()->setCost($delCost);
    $quote->getShippingAddress()->setCountry('GB');
    $quote->save();

When I retrieve the quote I can see it has saved the shipping description but it doesn't save the cost .

This is stand alone code that I am using where I create a quote programmatically for a point of sale system I am creating. Any help would be most appreciated as I have followed every tutorial I can find and I know its probably something simple I am missing.

2 Answers 2

0

It may be that you have to add the shipping method as well. I've used the following code for free shipping before which works. You may need to add in your extra bits.

$quote->getShippingAddress()->setCollectShippingRates(true)->collectShippingRates()->setShippingMethod('freeshipping_freeshipping');
$quote->collectTotals();
$quote->save();
2
  • Just giving it a try think you may be right Nov 24, 2016 at 22:01
  • if i want to set custom shipping price how? using the same syntax Jul 16, 2020 at 8:53
-3

You can add shipping cost to the quote programmatically by creating a new module for shipping follow below reference link.

https://inchoo.net/magento/custom-shipping-method-in-magento/

edit a function mentioned in the above link:

_getStandardRate()

$delCost = 10
$rate = Mage::getModel('shipping/rate_result_method'); 
$rate->setCarrier($this->_code);
$rate->setCarrierTitle($this->getConfigData('title'));
$rate->setMethod('large');
$rate->setMethodTitle('Standard delivery');
$rate->setPrice($delCost);
$rate->setCost($delCost);

return $rate;

And set your price in the setPrice(your price ) and setCost functions

Also set this new shipping method on the quote.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.