Author Topic: Stay on same page when add-to-cart clicked  (Read 15855 times)

steveorg

  • Beginner
  • *
  • Posts: 49
Stay on same page when add-to-cart clicked
« on: April 12, 2010, 19:49:48 pm »
I'd like to change the add function in ps_cart.php so that the user remains on the same page after they click add-to-cart.

When the cart is not empty, the mini-cart is displayed at the bottom of the page, so at the same time I'd like to refresh the page so that the mini-cart is updated.

If that can't be done, how would I automatically return to the previous page instead of show the "The product quantity has been updated." message?

Forrest

  • Full Member
  • ***
  • Posts: 1972
  • Me and my baby
    • Web Developer
Re: Stay on same page when add-to-cart clicked
« Reply #1 on: April 13, 2010, 00:06:24 am »
Use ajax cart in VM admin config -> site -> theme settings.

steveorg

  • Beginner
  • *
  • Posts: 49
Re: Stay on same page when add-to-cart clicked
« Reply #2 on: April 13, 2010, 19:43:56 pm »
Thanks Forrest. I already have ajax cart enabled, but it isn't automatically selected for my usage. I'm using the mod_virtuemart_cart  module inside an article, which defaults to the minicart. I figured out how to add code to automatically return to the previous page, so to an extent I've solved my problem. However, the ajax cart would be much cleaner. Is there a way to use it as a module?

Forrest

  • Full Member
  • ***
  • Posts: 1972
  • Me and my baby
    • Web Developer
Re: Stay on same page when add-to-cart clicked
« Reply #3 on: April 13, 2010, 19:47:33 pm »
I guess I am not fully understanding you. How about a link to a page and an explanation of what you want to have happen on that page.

steveorg

  • Beginner
  • *
  • Posts: 49
Re: Stay on same page when add-to-cart clicked
« Reply #4 on: April 13, 2010, 20:56:05 pm »
I really appreciate your help Forrest.

I created this demo page: http://www.qoolery.com/shop.html (edited to change link to actual working page)

It's an article page with a few items added by the Product Snapshot plugin and the mod_virtuemart_cart added by the Modules Anywhere plugin.

I've modified the code for the cart to return to this page after an item is added to the cart and to add a checkout button on the bottom. I still have quite a bit of VM configuration and styling left, so please don't judge the page to harshly. ::)

I'm also working on modifying the Product Snapshot plugin to use quantity boxes with add to cart buttons instead of links. I've hit a wall on that, so you'll shortly be able to see a post on that issue in the programming forum.

Ultimately, my goal is to create something that looks like this: http://forum.virtuemart.net/index.php?topic=69336. Since that's difficult to do with Virtuemart, I plan on using an article with a combination of text and plugins to achieve the goal.

Forrest

  • Full Member
  • ***
  • Posts: 1972
  • Me and my baby
    • Web Developer
Re: Stay on same page when add-to-cart clicked
« Reply #5 on: April 13, 2010, 21:08:22 pm »
I understand now. And so you want to leverage the ajax cart functions so the page doesn't need a refresh when adding to cart... correct?

steveorg

  • Beginner
  • *
  • Posts: 49
Re: Stay on same page when add-to-cart clicked
« Reply #6 on: April 13, 2010, 21:29:18 pm »
Correct!

Forrest

  • Full Member
  • ***
  • Posts: 1972
  • Me and my baby
    • Web Developer
Re: Stay on same page when add-to-cart clicked
« Reply #7 on: April 13, 2010, 22:52:01 pm »
I added ajax cart with a wishlist system.

This is what I used:

Code: [Select]
<form action="<?php echo $mm_action_url ?>index.php" method="post" name="addtocart" id="<?php echo uniqid('addtocart_'?>" class="addtocart_form" onsubmit="handleAddToCart( this.id );return false;">

<span style="float: right;padding-right:5px;">
<input type="text" class="inputboxquantity" size="4" id="quantity<?php echo $prod_id ?>" name="quantity[]" value="0" />
<input type="button" class="quantity_box_button quantity_box_button_up" onclick="var qty_el = document.getElementById('quantity<?php echo $prod_id ?>'); var qty = qty_el.value; if( !isNaN( qty )) qty_el.value++;return false;" />
<input type="button" class="quantity_box_button quantity_box_button_down" onclick="var qty_el = document.getElementById('quantity<?php echo $prod_id ?>'); var qty = qty_el.value; if( !isNaN( qty ) &amp;&amp; qty > 0 ) qty_el.value--;return false;" />
</span>

<input type="hidden" name="flypage" value="shop.<?php echo $flypage ?>" />
<input type="hidden" name="page" value="shop.cart" />
<input type="hidden" name="manufacturer_id" value="<?php echo $manufacturer_id ?>" />
<input type="hidden" name="category_id" value="<?php echo $category_id ?>" />
<input type="hidden" name="func" value="cartAdd" />
<input type="hidden" name="option" value="com_virtuemart" />
<input type="hidden" name="Itemid" value="<?php echo $Itemid ?>" />
</form>

You'd need to define itemid, category_id, prod_id, manufacturer_id (if desired), flypage.

Wouldn't take much to adjust accordingly for your needs.

steveorg

  • Beginner
  • *
  • Posts: 49
Re: Stay on same page when add-to-cart clicked
« Reply #8 on: April 14, 2010, 16:43:10 pm »
Thanks Forrest. That works for building the form, but unfortunately it doesn't help embed an ajax cart in an article. Is that a pipe dream?

Without the ajax cart, the individual add-to-cart buttons make the flow less satisfying, so my current implementation splits the difference. It uses the revised plug-in to add the quantity fields (and a bit of overkill for the hidden fields), but only has a single add to cart button. The button is added by form code in the article.

(edited to delete inactive URL)

Forrest

  • Full Member
  • ***
  • Posts: 1972
  • Me and my baby
    • Web Developer
Re: Stay on same page when add-to-cart clicked
« Reply #9 on: April 16, 2010, 11:19:14 am »
Have you tried using the VM Mainframe plugin. That should initialize all css and js (which I think would enable the js/ajax for slimbox/cart) on non-vm pages. Worth a shot.

steveorg

  • Beginner
  • *
  • Posts: 49
Re: Stay on same page when add-to-cart clicked
« Reply #10 on: April 16, 2010, 13:30:29 pm »
Definitely worth a shot. Now only if I could find the plugin. I've searched the VMED and JED without any luck.

There is also another issue that we probably should have discussed sooner. The form action on submit opens the cart on a different page. Does this part of the code have to change, and if so, how?

Forrest

  • Full Member
  • ***
  • Posts: 1972
  • Me and my baby
    • Web Developer
Re: Stay on same page when add-to-cart clicked
« Reply #11 on: April 16, 2010, 22:33:11 pm »
No, I think it's doing that because the js scripts aren't loading. The onclicks aren't executing.

I know it's in the 1.5 version of VM. I have also seen posts regarding this, and I'm not sure if it's been included in a 1.1.x version.

Here is an older 1.5 version you can try. I have no idea if it will work, so give it a shot.

[attachment cleanup by admin]

steveorg

  • Beginner
  • *
  • Posts: 49
Re: Stay on same page when add-to-cart clicked
« Reply #12 on: April 21, 2010, 20:56:58 pm »
Wow, I can't believe it's been 5 days since I've had a chance to work on this.

The plugin isn't doing anything, that is if I'm using it correctly. I've embedded this in the code: {vmmainframe}. The text appears on the page instead of the expected plugin action.

As an alternative, I put the VM css and js code in the Joomla theme's index page header. Unfortunately that did not help. This is what the code looks like. Is it possible that the gzip or fetchscript is getting in the way? If so, what should it look like?
Code: [Select]
<script src="http://www.qoolery.com/components/com_virtuemart/fetchscript.php?gzip=0&amp;subdir[0]=/themes/default&amp;file[0]=theme.js&amp;subdir[1]=/js&amp;file[1]=sleight.js&amp;subdir[2]=/js/mootools&amp;file[2]=mootools-release-1.11.js&amp;subdir[3]=/js/mootools&amp;file[3]=mooPrompt.js&amp;subdir[4]=/js/slimbox/js&amp;file[4]=slimbox.js" type="text/javascript"></script>
<script type="text/javascript">var cart_title = "Cart";var ok_lbl="Continue";var cancel_lbl="Cancel";var notice_lbl="Notice";var live_site="http://www.qoolery.com";</script>
<script type="text/javascript">var slimboxurl = 'http://www.qoolery.com/components/com_virtuemart/js/slimbox/';</script>
<link href="http://www.qoolery.com/components/com_virtuemart/fetchscript.php?gzip=0&amp;subdir[0]=/themes/default&amp;file[0]=theme.css&amp;subdir[1]=/themes/default&amp;file[1]=pages.css&amp;subdir[2]=/js/mootools&amp;file[2]=mooPrompt.css&amp;subdir[3]=/js/slimbox/css&amp;file[3]=slimbox.css" type="text/css" rel="stylesheet" />



Just in case, I also confirmed that I have enabled Ajax in the configuration.

Forrest

  • Full Member
  • ***
  • Posts: 1972
  • Me and my baby
    • Web Developer
Re: Stay on same page when add-to-cart clicked
« Reply #13 on: April 22, 2010, 05:48:18 am »
Um, I don't think you do that with this plugin... tho I could be wrong. The thing to check is if your VM scripts are getting loaded (view source) when the plugin is enabled. Again, this simply may not work.

If not, then I would have done what you did.

steveorg

  • Beginner
  • *
  • Posts: 49
Re: Stay on same page when add-to-cart clicked
« Reply #14 on: May 05, 2010, 21:45:45 pm »
Okay - I'm back for the final push! It's formatted and mostly working the way I want.

I have no idea why, but one day ajax was not working and the next day it was without any intervention. Sounds like a cache issue, except I believe that all caches were disabled. That will probably have to remain a mystery of the universe. The mainframe plugin also started working, so I removed the code from the template's index page.

The problem that is left is that the lightbox doesn't work for the images. I copied working code from the products' page. As best I can make out, the javascript is from slimbox.js, which is loaded by the mainframe plugin. I also added it back to the index header. Any guidance on getting that working would be appreciated.

Here's the page: http://www.qoolery.com/shop.html