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.

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();
  • Just giving it a try think you may be right – Barry Connolly Nov 24 '16 at 22:01
-2

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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