1
Answers
updating the shipping line item after rules have run
I have a shop where the shipping price calculation is so complicated i need to basically add an extra amount after rules calculation is done. I added an extra rule that should allow me to do this, but any time I try to alter the line item, it gets overwritten right after i call any sort of save function.
Is there any way of making this work?
<?php
function custom_add_extra_shipping($order,$amount){
dsm('rule: add an extra shipping amount');
$amount = 5000; //this is hardcoded, but in my code it's part of a huge calculation
foreach ($order->commerce_line_items['und'] as $id) {
$line_item = commerce_line_item_load($id['line_item_id']);
if($line_item->type == 'shipping'){
dsm($line_item);
$line_item->commerce_total['und'][0]['amount'] = $amount;
$line_item->commerce_total['und'][0]['data']['components'][0]['price']['amount'] = $amount;
commerce_line_item_save($line_item);
}
}
}
?>
Comments
Is there any reason you don't just do this calculation in a rate calculation rule weighted to run at the end of the process?
Ryan -- that's what I'm trying to do but I can't get the action to work. Trying to use 'Set a data value'.