Re: AJAX Add to Cart [Support Thread]
The jQuery selector used by this plugin to trigger the add_cart.php file's load is too general, as it applies to any submit action within the cart_quantity form. If you've got a plugin (like one of my premium offerings) that adds another submit-type action within the form, then the AJAX Add to Cart takes over all those actions.
The correction requires a minor change to the selector present in /includes/templates/YOUR_TEMPLATE/jscript/jscript_script_loader.php, changing from:
Code:
<?php
if (ZX_AJAX_CART_STATUS == 'true') {
if(ZX_AJAX_CART_JQUERY == 'true') echo '<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>';
?>
<script src="<?php echo DIR_WS_TEMPLATES.$template_dir ; ?>/jscript/jquery.form.min.js"></script>
<script language="javascript">
function showview(c){var b="#"+c;jQuery(b).show()}function hideview(c){var b="#"+c;jQuery(b).hide()}function closecart(){jQuery("#carttopcontainer").fadeOut(400)}function startHover(){jQuery("#carttopcontainer").fadeIn(600)}function endHover(){jQuery("#carttopcontainer").fadeOut(600)}function ajax_cart(){var a="shoppingcart.php";jQuery("#carttopcontainer").load(a),jQuery("html, body").animate({scrollTop:0},"slow"),jQuery("#carttopcontainer").fadeIn(400),jQuery("#carttopcontainer").delay(<?php echo ZX_AJAX_CART_FADE_DELAY; ?>).animate({height:"hide",opacity:"hide"},200).mouseover(function(){jQuery(this).stop(!0,!1).animate({opacity:1},200)}).mouseleave(function(){jQuery(this).animate({height:"hide",opacity:"hide"},200)})}function add_prod(a){jQuery.ajax({type:"POST",url:"add_prod.php",data:"products_id="+a,success:function(b){"success"==b.status?(jQuery("#cartBoxListWrapper2").html(b.cart),jQuery("#topcartinner").html(b.cart_top),jQuery("#bottomfinaltotal2").html(b.total)):"error"==b.status},dataType:"json"})}function showRequest(c,b,a){var d=jQuery.param(c);document.getElementById("loadBar").innerHTML='<?php echo zen_image(DIR_WS_TEMPLATE_IMAGES . 'bar-loading.gif', 'Loading...'); ?>';return true}function strpos(b,c,d){var a=(b+"").indexOf(c,(d||0));return a===-1?false:a}function showResponse(a,b){var c=strpos(a,"Warning",5);if(c>0){document.getElementById("loadBar").innerHTML="";document.getElementById("button_cart").innerHTML='<br /><?php echo TEXT_AJAX_CART_ERROR_NOT_ADDED; ?>'}else{document.getElementById("loadBar").innerHTML="";ajax_cart()}}$(document).ready(function(){var a={target:"#topcartinner",url:"add_to_cart.php",type:"POST",beforeSubmit:showRequest,success:showResponse};$("#cart_quantity").submit(function(){$(this).ajaxSubmit(a);return false})});
</script>
<?php } ?>
to
Code:
<?php
if (ZX_AJAX_CART_STATUS == 'true') {
if(ZX_AJAX_CART_JQUERY == 'true') echo '<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>';
?>
<script src="<?php echo DIR_WS_TEMPLATES.$template_dir ; ?>/jscript/jquery.form.min.js"></script>
<script language="javascript">
function showview(c){var b="#"+c;jQuery(b).show()}function hideview(c){var b="#"+c;jQuery(b).hide()}function closecart(){jQuery("#carttopcontainer").fadeOut(400)}function startHover(){jQuery("#carttopcontainer").fadeIn(600)}function endHover(){jQuery("#carttopcontainer").fadeOut(600)}function ajax_cart(){var a="shoppingcart.php";jQuery("#carttopcontainer").load(a),jQuery("html, body").animate({scrollTop:0},"slow"),jQuery("#carttopcontainer").fadeIn(400),jQuery("#carttopcontainer").delay(<?php echo ZX_AJAX_CART_FADE_DELAY; ?>).animate({height:"hide",opacity:"hide"},200).mouseover(function(){jQuery(this).stop(!0,!1).animate({opacity:1},200)}).mouseleave(function(){jQuery(this).animate({height:"hide",opacity:"hide"},200)})}function add_prod(a){jQuery.ajax({type:"POST",url:"add_prod.php",data:"products_id="+a,success:function(b){"success"==b.status?(jQuery("#cartBoxListWrapper2").html(b.cart),jQuery("#topcartinner").html(b.cart_top),jQuery("#bottomfinaltotal2").html(b.total)):"error"==b.status},dataType:"json"})}function showRequest(c,b,a){var d=jQuery.param(c);document.getElementById("loadBar").innerHTML='<?php echo zen_image(DIR_WS_TEMPLATE_IMAGES . 'bar-loading.gif', 'Loading...'); ?>';return true}function strpos(b,c,d){var a=(b+"").indexOf(c,(d||0));return a===-1?false:a}function showResponse(a,b){var c=strpos(a,"Warning",5);if(c>0){document.getElementById("loadBar").innerHTML="";document.getElementById("button_cart").innerHTML='<br /><?php echo TEXT_AJAX_CART_ERROR_NOT_ADDED; ?>'}else{document.getElementById("loadBar").innerHTML="";ajax_cart()}}$(document).ready(function(){var a={target:"#topcartinner",url:"add_to_cart.php",type:"POST",beforeSubmit:showRequest,success:showResponse};$('#cartAdd > input[type="submit"], #cartAdd > input[type="image"]').click(function(){$(this).ajaxSubmit(a);return false})});
</script>
<?php } ?>
Re: AJAX Add to Cart [Support Thread]
Darn it. There is one more change required, since the jQuery is now firing on the input rather than the form:
Code:
<?php
if (ZX_AJAX_CART_STATUS == 'true') {
if(ZX_AJAX_CART_JQUERY == 'true') echo '<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>';
?>
<script src="<?php echo DIR_WS_TEMPLATES.$template_dir ; ?>/jscript/jquery.form.min.js"></script>
<script language="javascript">
function showview(c){var b="#"+c;jQuery(b).show()}function hideview(c){var b="#"+c;jQuery(b).hide()}function closecart(){jQuery("#carttopcontainer").fadeOut(400)}function startHover(){jQuery("#carttopcontainer").fadeIn(600)}function endHover(){jQuery("#carttopcontainer").fadeOut(600)}function ajax_cart(){var a="shoppingcart.php";jQuery("#carttopcontainer").load(a),jQuery("html, body").animate({scrollTop:0},"slow"),jQuery("#carttopcontainer").fadeIn(400),jQuery("#carttopcontainer").delay(<?php echo ZX_AJAX_CART_FADE_DELAY; ?>).animate({height:"hide",opacity:"hide"},200).mouseover(function(){jQuery(this).stop(!0,!1).animate({opacity:1},200)}).mouseleave(function(){jQuery(this).animate({height:"hide",opacity:"hide"},200)})}function add_prod(a){jQuery.ajax({type:"POST",url:"add_prod.php",data:"products_id="+a,success:function(b){"success"==b.status?(jQuery("#cartBoxListWrapper2").html(b.cart),jQuery("#topcartinner").html(b.cart_top),jQuery("#bottomfinaltotal2").html(b.total)):"error"==b.status},dataType:"json"})}function showRequest(c,b,a){var d=jQuery.param(c);document.getElementById("loadBar").innerHTML='<?php echo zen_image(DIR_WS_TEMPLATE_IMAGES . 'bar-loading.gif', 'Loading...'); ?>';return true}function strpos(b,c,d){var a=(b+"").indexOf(c,(d||0));return a===-1?false:a}function showResponse(a,b){var c=strpos(a,"Warning",5);if(c>0){document.getElementById("loadBar").innerHTML="";document.getElementById("button_cart").innerHTML='<br /><?php echo TEXT_AJAX_CART_ERROR_NOT_ADDED; ?>'}else{document.getElementById("loadBar").innerHTML="";ajax_cart()}}$(document).ready(function(){var a={target:"#topcartinner",url:"add_to_cart.php",type:"POST",beforeSubmit:showRequest,success:showResponse};$('#cartAdd > input[type="submit"], #cartAdd > input[type="image"]').click(function(){$(this).closest( 'form' ).ajaxSubmit(a);return false})});
</script>
<?php } ?>
Re: AJAX Add to Cart [Support Thread]
It was brought to my attention that while investigating and validating that the current product_info form is missing $request_type
Code from 1.5.4
<!--bof Form start-->
<?php echo zen_draw_form('cart_quantity', zen_href_link(zen_get_info_page($_GET['products_id']), zen_get_all_get_params(array('action')) . 'action=add_product', $request_type), 'post', 'enctype="multipart/form-data"') . "\n"; ?>
<!--eof Form start-->
Code included in plugin
<!--bof Form start-->
<?php
// BOF ZX AJAX Add to Cart 1/2
echo zen_draw_form('cart_quantity', zen_href_link(zen_get_info_page($_GET['products_id']), zen_get_all_get_params(array('action')) . 'action=add_product'), 'post', 'enctype="multipart/form-data" id="cart_quantity"') . "\n";
// EOF ZX AJAX Add to Cart 1/2
?>
<!--eof Form start-->
Will this effect or cause any https mixed content errors?
Thanx
Re: AJAX Add to Cart [Support Thread]
Quote:
Originally Posted by
rbarbour
Will this effect or cause any https mixed content errors?
It shouldn't, but relying on "should" or "should not" was never the best idea... :smile:
If the entire store is set to https, then the zen_href_link function will generate an SSL link anyways. If the store is running normal, it should not be using https on product_info page, thus no mixed content errors should occur. But, I guess we always need to think ahead and allow for the possibility of product_info page running on https unexpectedly so, yes, this is a good catch and a good idea to add. It can't hurt, that's for sure. :wink:
Re: AJAX Add to Cart [Support Thread]
Hi. I'm the one that saw the issue. Google has been recommending full-time https for a few years now, but that's not the case with my site. The issue popped up when I started checkout @ PayPal, cancelled and returned to the cart. It landed on https and threw the errors. Whether that's a coding mistake with Zen, my mods, or PayPal I don't know at this point... but regardless, as you say, it hurts nothing to always send the request type to avoid mixed protocol issues.
Re: AJAX Add to Cart [Support Thread]
@s_mack - nice catch. But still, if you got to PayPal and cancelled, why would it take you back to the product_info page? If I'm not mistaken, it takes you back to the shopping cart page. From there, you would navigate away to product_info which would then be expected to use plain http regardless of http/https status on shopping_cart page. Kinda confusing...
But still, the change suggested is definitely good practice and I'll make sure I include it in the next release. Thanks for noticing this!
Re: AJAX Add to Cart [Support Thread]
Actually... it wasn't product info, it was the shopping cart. Is the cart using the product_info module to get the product data/photos/etc?
Keep in mind I have no experience with your mod on its own. rbarbour made me a custom template which includes your code so I'm not sure exactly what modifications are from what.
Re: AJAX Add to Cart [Support Thread]
OK, well, this doesn't make any sense. The solution suggested by rbarbour affects nothing else but the product_info page. It has nothing to do with shopping_cart page and can certainly NOT cause any mixed content issues on that page. Product data also has nothing to do with it.
So, in conclusion - rbarbour's suggestion IS valid and will definitely be included in the next release, but it didn't have anything to do with your mixed content errors.
Re: AJAX Add to Cart [Support Thread]
I didn't imagine it. The shopping cart contains product information, obviously (name, picture, etc) and my shopping cart that I was being returned to after cancelling was, in fact, showing mixed contents errors and it was, indeed, fixed with the change I suggested and he pasted above.
There may have been a mistake in the communication of the file. I'll double check when I get back tonight.
As I said, I'm not really familiar with your contrib directly. He has my site so that I have a fly-out Ajax cart. Clicking checkout on that cart goes as normal but cancelling the proceedure takes me back to the "standard" cart, not the fly-out one. I don't know if that's a source of confusion?
Re: AJAX Add to Cart [Support Thread]
I'm still having a hard time putting the two together because I can't see what might cause it. However, the exact same solution was known to cause that exact problem, but the source was search bar in the header. This was happening with an older version of Zen Cart, maybe even 1.5.0 - I'm not sure when exactly it was fixed... And, the error was popping up in Chrome only (I know it wasn't in Firefox). Nevermind, you got it resolved and that's all that matters.
But, the code posted above is found ONLY on product_info page, so I'm pretty sure it wasn't the source of your specific problem. Of course, the suggestion still IS valid and a good point for a future (non-critical) update.