News:

You may pay someone to create your store, or you visit our seminar and become a professional yourself with the silver certification

Main Menu

Change continue shopping action

Started by _kuro, July 17, 2012, 23:53:39 PM

Previous topic - Next topic

_kuro

/**
* Add the product to the cart, with JS
*
* @author Max Milbers
* @access public
*/
public function addJS() {

//maybe we should use $mainframe->close(); or jexit();instead of die;
/* Load the cart helper */
//require_once(JPATH_VM_SITE.DS.'helpers'.DS.'cart.php');
$this->json = null;
$cart = VirtueMartCart::getCart(false);
if ($cart) {
// Get a continue link */
$virtuemart_category_id = shopFunctionsF::getLastVisitedCategoryId();
if ($virtuemart_category_id) {
$categoryLink = '&view=category&virtuemart_category_id=' . $virtuemart_category_id;
} else
$categoryLink = '';
$continue_link = JRoute::_('index.php?option=com_virtuemart' . $categoryLink);
$virtuemart_product_ids = JRequest::getVar('virtuemart_product_id', array(), 'default', 'array');
$errorMsg = JText::_('');
if ($cart->add($virtuemart_product_ids, $errorMsg )) {

$this->json->msg = '<a class="continue" href="' . $continue_link . '" >' . JText::_('COM_VIRTUEMART_CONTINUE_SHOPPING') . '</a>';
$this->json->msg .= '<a class="showcart floatright" href="' . JRoute::_("index.php?option=com_virtuemart&view=cart") . '">' . JText::_('COM_VIRTUEMART_CART_SHOW_MODAL') . '</a>';
if ($errorMsg) $this->json->msg .= '<div>'.$errorMsg.'</div>';
$this->json->stat = '1';
} else {
// $this->json->msg = '<p>' . $cart->getError() . '</p>';
$this->json->msg = '<a class="continue" href="' . $continue_link . '" >' . JText::_('COM_VIRTUEMART_CONTINUE_SHOPPING') . '</a>';
$this->json->msg .= '<div>'.$errorMsg.'</div>';
$this->json->stat = '2';
}
} else {
$this->json->msg = '<a href="' . JRoute::_('index.php?option=com_virtuemart') . '" >' . JText::_('COM_VIRTUEMART_CONTINUE_SHOPPING') . '</a>';
$this->json->msg .= '<p>' . JText::_('COM_VIRTUEMART_MINICART_ERROR') . '</p>';
$this->json->stat = '0';
}
echo json_encode($this->json);
jExit();
}



This piece of code, can control the action over the button "Continue Shopping"  (with javascript active [facebox])

And the only thing I want to do is:
When the user press continue shopping, I want them to stay in the same page.

Why?
Because if you're navigating in page 12 of category X  (just an example) and you click add to cart . .  pop up comes, you click "Continue shopping" and voilĂ ! The button sends you at the first categories page . . (and yes, that's sucks) and you'll have to  search for page 12 all over again.

VM 2.0.6
Joomla 2.5.4

_kuro

/**
    * Add the product to the cart, with JS
    *
    * @author Max Milbers
    * @access public
    */
   public function addJS() {

      //maybe we should use $mainframe->close(); or jexit();instead of die;
      /* Load the cart helper */
      //require_once(JPATH_VM_SITE.DS.'helpers'.DS.'cart.php');
      $this->json = null;
      $cart = VirtueMartCart::getCart(false);
      if ($cart) {
         // Get a continue link */
         $virtuemart_category_id = shopFunctionsF::getLastVisitedCategoryId();
         if ($virtuemart_category_id) {
            $categoryLink = '&view=category&virtuemart_category_id=' . $virtuemart_category_id;
         } else
         $categoryLink = '';
         $continue_link = JRoute::_('index.php?option=com_virtuemart' . $categoryLink)<--- Change this line

         $continue_link = JRoute::_('' . $_SERVER['HTTP_REFERER']); <-- And subtitute for this !





This action is capable to left you at the same page where you click  add to cart (and send you the pop up with the options : continue shopping  and go to cart).
As you can imagine, when you apply this modification, if you click the link "Continue shopping", this refresh the page and left you in the same place (if you have a long category [12 pages] and you are at page 6, this modification left you in page six and don't send you at the first category page)...

Maybe, in a while, i can do the modification inside a product..

Th.Pilegaard

Hi

I wanted the same behavior, but found another solution.

If you replace this line:
$this->json->msg = '<a class="continue" href="' . $continue_link . '" >' . JText::_('COM_VIRTUEMART_CONTINUE_SHOPPING') . '</a>';

with this:
$this->json->msg = '<a class="continue" href="javascript:void(0);" onclick="jQuery(document).trigger(\'close.facebox\');" >' . JText::_('COM_VIRTUEMART_CONTINUE_SHOPPING') . '</a>';

then the popup simply closes without wasting time to reload the page

(The code that generated the continue_link can simply be outcommented or deleted)

kind regards
Thomas

oldbarn

What file do you put this code in? I have the same issue. Not sure why VM core takes you away from the product your on when you "continue shopping"..kinda dumb. I agree if I am on a product I want to stay on that product (or at least have the option to)

Thanks for the help

Th.Pilegaard

from joomlaroot: components/com_virtuemart/controllers/cart.php

PRO

the uses fancybox for the add to cart pop up, and is customizable.

I would wait on the newest because hacking the core

zainabubu

you road map doesn't show this fix coming up soon. either way, until it gets fixed, thanks Th.Pilegaard!!! Works well.

zainabubu

Updated to 2.0.22, and the changes have not been made yet. When you click on continue shopping, it refreshes the page, but when you click on X, it does exactly as I want it to...it does not refresh the page.

PRO

Quote from: zainabubu on July 10, 2013, 19:07:58 PM
Updated to 2.0.22, and the changes have not been made yet. When you click on continue shopping, it refreshes the page, but when you click on X, it does exactly as I want it to...it does not refresh the page.

mine goes back to the "category" when I click continue shopping


WebStuff

#9
For the new version you need to edit the file [JOOMLA ROOT]/components/com_virtuemart/views/cart/tmpl/padded.php.
And just afterdefined('_JEXEC') or die('Restricted access');add:
$continue_link = $_SERVER['HTTP_REFERER'];
$this->continue_link = $continue_link;

Hope this helps.

EDIT:
You should be able to do this as a template override too but I haven't tried that.

zainabubu

Quote from: PRO on July 10, 2013, 23:10:46 PM
Quote from: zainabubu on July 10, 2013, 19:07:58 PM
Updated to 2.0.22, and the changes have not been made yet. When you click on continue shopping, it refreshes the page, but when you click on X, it does exactly as I want it to...it does not refresh the page.

mine goes back to the "category" when I click continue shopping



Exactly, I want to continue where I left off, not back to category listings.

Pejo

Quote from: Th.Pilegaard on April 01, 2013, 10:16:37 AM
Hi

I wanted the same behavior, but found another solution.

If you replace this line:
$this->json->msg = '<a class="continue" href="' . $continue_link . '" >' . JText::_('COM_VIRTUEMART_CONTINUE_SHOPPING') . '</a>';

with this:
$this->json->msg = '<a class="continue" href="javascript:void(0);" onclick="jQuery(document).trigger(\'close.facebox\');" >' . JText::_('COM_VIRTUEMART_CONTINUE_SHOPPING') . '</a>';

then the popup simply closes without wasting time to reload the page

(The code that generated the continue_link can simply be outcommented or deleted)

kind regards
Thomas

This one works great. Leave you on the same product you have inserted in cart.
Thanks. ;)

chris916

Hi

Does anyone knows this code for VM 3.0.12  meaning when the user press continue shopping to stay in the same page.

Thanks

royaloak

I'm also looking for the same solution for VM 3.0... would like the user to stay on the same page when clicking "Continue Shopping" rather than being redirected to another page.


GJC Web Design

over ride components\com_virtuemart\views\cart\tmpl\padded.php



change
echo '<a class="continue_link" href="' . $this->continue_link . '" >' . vmText::_('COM_VIRTUEMART_CONTINUE_SHOPPING') . '</a>';

to

echo '<a class="continue_link" href="javascript:void(0);" onclick="jQuery.fancybox.close();" >' . vmText::_('COM_VIRTUEMART_CONTINUE_SHOPPING') . '</a>';
GJC Web Design
VirtueMart and Joomla Developers - php developers https://www.gjcwebdesign.com
VM4 AusPost Shipping Plugin - e-go Shipping Plugin - VM4 Postcode Shipping Plugin - Radius Shipping Plugin - VM4 NZ Post Shipping Plugin - AusPost Estimator
Samport Payment Plugin - EcomMerchant Payment Plugin - ccBill payment Plugin
VM2 Product Lock Extension - VM2 Preconfig Adresses Extension - TaxCloud USA Taxes Plugin - Virtuemart  Product Review Component
https://extensions.joomla.org/profile/profile/details/67210
Contact for any VirtueMart or Joomla development & customisation