But I need help, I believe the problem is in the data I'm posting back, not containing the checkout attributes because after the post, the checkout attributes are cleared.
Please help!
Here is my code
@Shopping Cart controller
Added the following to the UpdateCart Action:
//Save checkout attributes when the cart is updated.
ParseAndSaveCheckoutAttributes(cart, form);
Added the following Action:
//testing AJAX postback
[ValidateInput(false)]
public virtual ActionResult SaveCheckoutAttributes (FormCollection form)
{
var cart = _workContext.CurrentCustomer.ShoppingCartItems
.Where(sci => sci.ShoppingCartType == ShoppingCartType.ShoppingCart)
.LimitPerStore(_storeContext.CurrentStore.Id)
.ToList();
//parse and save checkout attributes
ParseAndSaveCheckoutAttributes(cart, form);
return Json(new
{
html = "<p>Success</p>"
}
);
}
@OrderSummary Partial View
<script type="text/javascript">
$(document).ready(function () {
var formsubmited = false;
$('#SaveCheckoutAttributes').click(function () {
if (!formsubmited) {
formsubmited = true;
var form = $('#form_formattributes :input, #form_formattributes textarea, #form_formattributes select').serialize();
//addAntiForgeryToken(form);
$.ajax({
cache: false,
url: '@(Url.Action("SaveCheckoutAttributes", "ShoppingCart"))',
data: form,
type: "POST",
success: function (data) {
alert("Your shopping cart has been saved!");
if (data.Result == "OK") {
$(this).click();
}
}
});
}
});
})
</script>
<button type="submit" name="SaveCheckoutAttributes" id="SaveCheckoutAttributes" class="btn bg-blue">
<i class="fa fa-floppy-o"></i>
@T("Save")
</button>