How To Update/change Shipping Cost Before Placing Order?

Is there a way to update/change shipping cost before the customer placing order at checkout? Which function should I use?

[quote name='ooaykac' timestamp='1438032610' post='224503']

Is there a way to update/change shipping cost before the customer placing order at checkout? Which function should I use?

[/quote]



It should be recalculated automatically on the last step of the checkout. If you need additional action, please use the fn_calculate_cart_content function

[quote name=‘eComLabs’ timestamp=‘1438074193’ post=‘224545’]

It should be recalculated automatically on the last step of the checkout. If you need additional action, please use the fn_calculate_cart_content function

[/quote]

I did this:


<br />
foreach ($cart['product_groups'] as $group_key => $group) {<br />
if (!empty($group['shippings'])) {<br />
				foreach ($group['shippings'] as $shipping_key => $shipping) {<br />
					  <br />
                               $cart['product_groups'][$group_key]['shippings'][$shipping_key]['rate']= 20; //my price<br />
	<br />
				 foreach ($shipping['rate_info']['rate_value']['C'] as $rate_key => $rate) {<br />
									<br />
                                $cart['product_groups'][$group_key]['shippings'][$shipping_key]['rate_info']['rate_value']['C'][$rate_key]['value'] = 20; //my price<br />
				  }<br />
	<br />
				}<br />
  }<br />
}<br />
  fn_calculate_cart_content($cart, $auth, 'E', true, 'F', true);<br />

```<br />
<br />
but it doesn't work <img src="upload://n4syhXZrRhsStKvmS4jT3Mp2S3k.png" class="bbc_emoticon" alt=":(">

hi ooaykac,



actually, you should check fn_calculate_cart_content function which makes global recalculation of cart content

in this function there are many php hooks and you should find the appropriate one to implement your code.



if you have difficulties with it, our specialists can assist you so please don't hesitate to contact us.



best regards,

WSA team

fn_calculate_cart_content function has $calculate_shipping value which has 3 parameters



// A - calculate all available methods

// E - calculate selected methods only (from cart[shipping])

// S - skip calculation





Should I use “E”?

And should I use this function at the end of the all cart processes?



I added this:


if (!empty($cart['shipping'])) {

foreach ($cart['shipping'] as $shipping_key => $shipping) {

$cart['shipping'][$shipping_key]['rate']= 1;

foreach ($shipping['rate_info']['rate_value']['C'] as $rate_key => $rate) {

$cart['shipping'][$shipping_key]['rate_info']['rate_value']['C'][$rate_key]['value'] = 1;
}

}
}




before
fn_calculate_cart_content($cart, $auth, 'E', true, 'F', true);


in my addon.



But after using fn_calculate_cart_content these values I changed turn to previosly values again. So the function calculates according to values which is saved in cs cart shipping.

Make sure that the following lines exists in your custom controller:



$cart = & $_SESSION['cart'];

YOUR CODE

Registry::get('view')->assign('cart', $cart);

[quote name='eComLabs' timestamp='1438159012' post='224707']

Make sure that the following lines exists in your custom controller:



$cart = & $_SESSION['cart'];

YOUR CODE

Registry::get('view')->assign('cart', $cart);


[/quote]

thanks ecom. I could add the custom shipping cost to the order and save it. but when I try to edit the order that I saved, the shipping cost turns to value that registeredin shipping.



I realized that the custom shipping cost is not being saved order data table while saving the order. That's why the shipping cost value turns to default when editting the order.



How to save shipping cost at the same time to the order data table?





or should I use change rate value of the existing shipping method in cart?