1
votes

Is there a way to add a custom shipping rate for to basket (order) in magento not from admin but in programing.

What I need is, I will have a field with each product "shipping_cost" , now suppose customer added 3 products to basket, now the shipping cost of the order will be the highest of shipping_costs of the products. For example, the 3 products have shipping_costs like $10, $20 and $30 , so the shipping_cost for basket will be $30.

Please help me out.

1

1 Answers

0
votes

Yes,In your conditon you need to get maximum shipping rate and assign that value to $shippingprice. You can add your custom shipping price for an order in magento using given code:-

    $order = Mage::getModel('sales/order')->load($increamentId, 'increment_id');

    $shippingprice = 30;

    $order->setShippingAmount($shippingprice);

    $order->setBaseShippingAmount($shippingprice); 
$order->setGrandTotal($order->getGrandTotal() + $shippingprice); //adding shipping price to grand total

    $order->save();

It will update your shipping price and grand total.I guess it will helpful to you.