If this is your first visit, check our documentation. To post, register or login.
Forums / Community Contributed Add-Ons / All Other Contributions/Addons / AJAX Add to Cart [Support Thread]

AJAX Add to Cart [Support Thread]

Started by balihr on 6 Jun 2014, 1:13 PM · Views: 29,036

Results 101 to 120 of 134
16 Sep 2015, 6:10 PM
#101
lat9 avatar

lat9

Administrator

Join Date:
Sep 2009
Location:
Stuart, FL
Posts:
14,146
Plugin Contributions:
56

Post #101 by lat9

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:

<?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

<?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};$([B]'#cartAdd > input[type="submit"], #cartAdd > input[type="image"]').click[/B](function(){$(this).ajaxSubmit(a);return false})});
</script>
<?php } ?>
16 Sep 2015, 7:05 PM
#102
lat9 avatar

lat9

Administrator

Join Date:
Sep 2009
Location:
Stuart, FL
Posts:
14,146
Plugin Contributions:
56

Post #102 by lat9

Darn it. There is one more change required, since the jQuery is now firing on the input rather than the form:

<?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};$([B]'#cartAdd > input[type="submit"], #cartAdd > input[type="image"]').click(function(){$(this).closest( 'form' ).[/B]ajaxSubmit(a);return false})});
</script>
<?php } ?>
14 Oct 2015, 3:59 PM
#103
rbarbour avatar

rbarbour

Totally Zenned

Join Date:
Feb 2010
Posts:
2,159
Plugin Contributions:
10

Post #103 by rbarbour

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

14 Oct 2015, 4:18 PM
#104
balihr avatar

balihr

Totally Zenned

Join Date:
Oct 2008
Location:
Croatia
Posts:
1,819
Plugin Contributions:
24

Post #104 by balihr

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:

My site - Pro ZC Help
My portfolio | My plugins

14 Oct 2015, 5:37 PM
#105
s_mack avatar

s_mack

Totally Zenned

Join Date:
Jun 2005
Location:
Kelowna, BC Canada
Posts:
1,033
Plugin Contributions:
4

Post #105 by s_mack

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.

14 Oct 2015, 6:56 PM
#106
balihr avatar

balihr

Totally Zenned

Join Date:
Oct 2008
Location:
Croatia
Posts:
1,819
Plugin Contributions:
24

Post #106 by balihr

@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!

My site - Pro ZC Help
My portfolio | My plugins

14 Oct 2015, 9:49 PM
#107
s_mack avatar

s_mack

Totally Zenned

Join Date:
Jun 2005
Location:
Kelowna, BC Canada
Posts:
1,033
Plugin Contributions:
4

Post #107 by s_mack

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.

14 Oct 2015, 10:17 PM
#108
balihr avatar

balihr

Totally Zenned

Join Date:
Oct 2008
Location:
Croatia
Posts:
1,819
Plugin Contributions:
24

Post #108 by balihr

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.

My site - Pro ZC Help
My portfolio | My plugins

14 Oct 2015, 10:47 PM
#109
s_mack avatar

s_mack

Totally Zenned

Join Date:
Jun 2005
Location:
Kelowna, BC Canada
Posts:
1,033
Plugin Contributions:
4

Post #109 by s_mack

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?

14 Oct 2015, 10:55 PM
#110
balihr avatar

balihr

Totally Zenned

Join Date:
Oct 2008
Location:
Croatia
Posts:
1,819
Plugin Contributions:
24

Post #110 by balihr

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.

My site - Pro ZC Help
My portfolio | My plugins

22 Nov 2015, 5:44 PM
#111
s_mack avatar

s_mack

Totally Zenned

Join Date:
Jun 2005
Location:
Kelowna, BC Canada
Posts:
1,033
Plugin Contributions:
4

Post #111 by s_mack

I'm having another issue that I believe is related to the ajax add-to-cart mod. The "who's online" is effectively broken by it. Is this something you've dealt with before and perhaps there's a fix?

Basically, every visit is being recorded as "/shop/cart.php" rather than the page they're "really" on.

I imagine its a matter of timing... having the the who's online init triggered after the page call but before the cart inclusion... but I wouldn't know where to begin. Thoughts?

22 Nov 2015, 6:11 PM
#112
s_mack avatar

s_mack

Totally Zenned

Join Date:
Jun 2005
Location:
Kelowna, BC Canada
Posts:
1,033
Plugin Contributions:
4

Post #112 by s_mack

So, I think I realized the root cause... /shop/cart.php is requiring includes/application_top.php. That means we're doubling up on EVERYTHING every time any page is called... but whatever, it doesn't seem like there's a practical performance issue. My "solution' for this problem (more of a dirty fix) involves a core edit (yuk). in the file /includes/init_special_funcs.php I found this code:

require(DIR_WS_FUNCTIONS . 'whos_online.php');
zen_update_whos_online();

and wrapped it in a condition, like so:

if ($_SERVER['REQUEST_URI'] != DIR_WS_CATALOG . 'cart.php') {
require(DIR_WS_FUNCTIONS . 'whos_online.php');
zen_update_whos_online();
}

It works. I think a better solution would be for cart.php (and all files lying outside the normal file structure) to define a custom config.core that only loads what those files actually need. There's probably a way to exclude itself from affecting things like who's online... but it would require quite a rewrite for a relatively small "bug".

18 May 2016, 7:14 PM
#113
andy_c27 avatar

andy_c27

Zen Follower

Join Date:
Oct 2010
Location:
United Kingdom
Posts:
477
Plugin Contributions:
0

Post #113 by andy_c27

Can I ask is this mod OK to use on 1.5.5 ,and does it cause issues at all
thanks

18 May 2016, 7:36 PM
#114
balihr avatar

balihr

Totally Zenned

Join Date:
Oct 2008
Location:
Croatia
Posts:
1,819
Plugin Contributions:
24

Post #114 by balihr

It's quite early to tell since 1.5.5 hasn't been around that long, but I have it running on several sites using 1.5.5a and so far haven't heard of any problems. If you encounter any problems or weird behavior, please make sure you report it here. :smile:

My site - Pro ZC Help
My portfolio | My plugins

4 Jun 2016, 9:37 PM
#115
andy_c27 avatar

andy_c27

Zen Follower

Join Date:
Oct 2010
Location:
United Kingdom
Posts:
477
Plugin Contributions:
0

Post #115 by andy_c27

Thanks , I may just give it a run as this seems a really good idea as my basket does get a bit lost it is so small

25 Jul 2016, 10:25 AM
#116
strelitzia avatar

strelitzia

Totally Zenned

Join Date:
Nov 2005
Location:
France
Posts:
588
Plugin Contributions:
1

Post #116 by strelitzia

Has this module been tested and confirmed working with regards to displaying the message stack if a user tries to add to cart without selecting a required attribute?
I can't get it to work correctly at all. It just briefly show the popup saying that the cart is empty and the message stack warning is never displayed so the user doesn't know why it wasn't added.
Message stack for the required attributes works fine if I disable the ajax add to cart, so the core system is working just fine.

Zen Cart developer since 2009 — Zen Cart Solutions
Ecommerce development, integrations & automation — Junction Solutions

23 Sep 2016, 1:11 AM
#117
jagall avatar

jagall

Zen Follower

Join Date:
Mar 2011
Location:
Ireland
Posts:
286
Plugin Contributions:
0

Post #117 by jagall

Hi I am using zc1.5.4, just installed this mod and nothing happening, sidebox not even appearing. I did download the numinix Ajax Add to Cart paid version earlier but wanted to have the shopping cart pop up. my site is https://www.sweetco.ie thank you very much if you can help

23 Jan 2019, 5:00 AM
#118
jimmie avatar

jimmie

Totally Zenned

Join Date:
Jan 2013
Location:
New Port Richey, Florida
Posts:
971
Plugin Contributions:
0

Post #118 by jimmie

zen v 1.51 with responsive sheffield blue 2.0
i added this module and it works on main site, but does not allow me to add to cart, just spins, but if i click checkout it adds the product.
http://jnsflooringandsupplies.com/WorkSite
if i turn module off it works as it should, just no ajax add to cart

23 Jan 2019, 4:44 PM
#119
lankeeyankee avatar

lankeeyankee

Totally Zenned

Join Date:
Jan 2007
Posts:
1,514
Plugin Contributions:
1

Post #119 by lankeeyankee

Sounds like a javascript conflict or something not loading correctly. If you check it in the developer console of your browser you should see some errors generated that can point to the problem.


Zen Cart and it's community are the best!!

23 Jan 2019, 6:28 PM
#120
jimmie avatar

jimmie

Totally Zenned

Join Date:
Jan 2013
Location:
New Port Richey, Florida
Posts:
971
Plugin Contributions:
0

Post #120 by jimmie

fixed had to put this```

<!-- BOF ZX AJAX Add to Cart --> <?php // BOF AJAX Cart if (ZX_AJAX_CART_STATUS == 'true') {?>
    <?php echo '<div id="carttopcontainer"></div>';?>
    <?php require(DIR_WS_MODULES. 'sideboxes/'.$template_dir. '/zx_ajax_shopping_cart.php');?>
<?php } else { ?>
<li><a href="<?php echo zen_href_link(FILENAME_SHOPPING_CART, '', 'NONSSL'); ?>"><?php echo HEADER_TITLE_CART_CONTENTS; ?></a></li>
<li><a href="<?php echo zen_href_link(FILENAME_CHECKOUT_SHIPPING, '', 'SSL'); ?>"><?php echo HEADER_TITLE_CHECKOUT; ?></a></li>
<?php } // EOF AJAX Cart ?> <div class="clearBoth"></div> <div id="header-promo"><?php echo HEADER_TITLE_PROMO1; ?></div> <!-- EOF ZX AJAX Add to Cart -->