So I am working on an old site , the site has an AJAX cart. When I create a cookie that adds a product to the cart and then redirect to the view the cart. The cart updates before heading into a redirect loop and I have run out of ideas on how to figure it out.
I am also using window.location.href to redirect to the cart.
The site is http://www.omanionline.com/ if you want to see it in action.
Thanks for any insight!
This is where I redirect:
<script type="text/javascript"> $(function() { $("#cartform").validate({ rules: { "order_products::quantity[]": { required: true, min: 1 } }, errorPlacement: function($label, $element) { $("<tr />").append( $("<td />").attr({colspan: 2}).html($label.css({ margin: 0})) ).insertAfter($element.closest("tr")); }, submitHandler: function(form) { $form = $(form); var product_id = $form.find("input[name='order_products::product_id[]']").val(); if (product_id) { var values = $.map($form.find("select[name='order_product_values::value_id[]']"), >function(elem) { return elem.value; }); var quantity = $form.find("input[name='order_products::quantity[]']").val(); $.cart(product_id, values, quantity); $(".cart_count").html($.cart().length); //when the item was successfully added to the cart, the user is >redirected to their shopping cart summary window.location.href("order.php"); } return false; } }); }); </script>
This is where i create the cookie:
function writeCookie() { var crumbs = []; for (var i in cart) { crumbs.push( '{"product_id":' + cart[i].product_id + ',"quantity":' + cart[i].quantity + ',"values":[' + cart[i].values.toString() + ']}' ); } $.cookie('omani_cart', "[" + crumbs.join(",") + "]", { expires: 7, domain: location.hostname , path:'/'}); // setCookie('omani_cart',"[" + crumbs.join(",") + "]","/",location.hostname,false,true);*/ }
}