I'm kind of stuck on getting AJAX shipping cost update for Expresso Store.
Shipping part in the checkout page looks like:
<tr>
<td>Shipping</td>
<td colspan="2">
{field:shipping_method}
{if error:shipping_method}<p class="help-block">{error:shipping_method}</p>{/if}
</td>
<td style="text-align:right"><div id="order_shipping">{embed="cart/shipping"}</div></td>
</tr>
then "cart/shipping" include looks like:
{exp:store:checkout}
{order_shipping}
{/exp:store:checkout}
All works fine when I use "Update Total", but my goal is to update shipping cost on shipping method select using AJAX below
<script type="text/javascript">
$(document).ready(function() {
$("#shipping_method").change(function() {
var url = $(this.form).attr('action');
var data = $("#shipping_method").val();
$.post(url, data, function() {
$("#order_shipping").load("/cart/shipping");
});
return false;
});
});
</script>
In that case I'm not able to retrieve updated shipping cost.
Any clue where I have made an error?
UPDATE
"cart/shipping" updated to:
{exp:store:checkout}
<div id="oso">{order_shipping}</div>
{/exp:store:checkout}
And AJAX part looks now like:
$(document).ready(function() {
$("#shipping_method").change(function() {
var url = $(this.form).attr('action');
var data = $(this.form).serialize();
$.post(url, data, function() {
$("#order_shipping").load("/cart/shipping #oso);
});
return false;
});
});
It can retrieve shipping cost, but initial cost for the shipping, when checkout process is started, it becomes selected first from the shipping method list but with real value of 0. I have try to .prepend
empty option field, but no matter what is selecting first shipping method for new carts (I'm using UPS shipping module). Default shipping method for new carts from the Store settings is not working either.