VirtueMart Forum

VirtueMart 2 + 3 => Virtuemart Development and bug reports => Topic started by: ghardin on June 09, 2017, 01:13:01 am

Title: Empty cart stay when user removes all items
Post by: ghardin on June 09, 2017, 01:13:01 am
Joomla 3.7.2
VM 3.2.2
When a user removes all items from the cart, the cart pages remains on top and there are a number of error messages that confuse the user, like for shipping or payment plugins etc.  How can it be configured so that when a user removes all items, they are taken back to the storefront page, or some other location?  I have looked all over the net and these forums and there does not seem to be anyone that finds this a problem?
Title: Re: Empty cart stay when user removes all items
Post by: jenkinhill on June 09, 2017, 12:56:05 pm
Using default VM templates when I empty the cart the only message I see is "Product quantity successfully updated"  Are you using a commercial template or OPC plugin?
Title: Re: Empty cart stay when user removes all items
Post by: ghardin on June 11, 2017, 12:37:29 pm
stock Joomla Protostar
Title: Re: Empty cart stay when user removes all items
Post by: GJC Web Design on June 11, 2017, 16:56:25 pm
I assume u have no filters on your shipping etc

try adding a Minimum number of products to your methods
If u want to go somewhere else on an empty cart perhaps in components\com_virtuemart\controllers\cart.php  updatecart() test the quantity and if 0 redirect

or might work in the cart default template  -- test quantity and if 0 redirect

Title: Re: Empty cart stay when user removes all items
Post by: ghardin on June 11, 2017, 22:25:56 pm
Thanks.  I will give that a try and see what I can make happen.
Title: Re: Empty cart stay when user removes all items
Post by: ghardin on June 12, 2017, 00:45:21 am
Looked int that file and I do not know where I can find where the quantity in the cart is totaled.  Where can I find where updatecart() checks this?
Title: Re: Empty cart stay when user removes all items
Post by: AH on June 12, 2017, 09:37:14 am
"joomla 3.7.2
VM 3.2.2
When a user removes all items from the cart, the cart pages remains on top and there are a number of error messages that confuse the user, like for shipping or payment plugins etc.  How can it be configured so that when a user removes all items, they are taken back to the storefront page, or some other location?  I have looked all over the net and these forums and there does not seem to be anyone that finds this a problem?"

You might want to consider a cart page override - when the cart is empty it "tells" you so and does not display much else, rather than showing you a whole load of configuration options that are irrelevant (at that moment in time).

\templates\YOURTEMPLATE\html\com_virtuemart\cart\default.php

Code: [Select]
<?php
// dont show anything if cart is empty
if (!$this->cart->cartProductsData){ ?>


<h3><?php echo vmText::('COM_VIRTUEMART_EMPTY_CART'); ?></h3>
<?php
//show login
echo shopFunctionsF::getLoginForm ($this->cartFALSE,$uri);

if (!empty(
$this->continue_link_html)) {
echo $this->continue_link_html;
}

//dont process anything else
return;
}

Title: Re: Empty cart stay when user removes all items
Post by: ghardin on June 12, 2017, 16:02:26 pm
Thanks.  I will play around with this.
Title: Re: Empty cart stay when user removes all items
Post by: ghardin on June 13, 2017, 15:24:28 pm
Can't figure out where to insert this piece of code.  I tried it in a couple of cart related files but it mostly just caused "page Not Found" errors.  Also I think the snipet is missing a closing tag for php somewhere.  Anyway, it might work but I cannot find where to implement it without creating errors.
Title: Re: Empty cart stay when user removes all items
Post by: AH on June 13, 2017, 18:12:06 pm
I have adjusted to make it simpler and fixed errors

This is the top of the code for that file to help you see where it goes:-

Quote
\templates\YOURTEMPLATE\html\com_virtuemart\cart\default.php

Code: [Select]

<?php
/**
 *
 * Layout for the shopping cart
 *
 * @package    VirtueMart
 * @subpackage Cart
 * @author Max Milbers
 *
 * @link https://virtuemart.net
 * @copyright Copyright (c) 2004 - 2016 VirtueMart Team. All rights reserved.
 * @license http://www.gnu.org/copyleft/gpl.html GNU/GPL, see LICENSE.php
 * VirtueMart is free software. This version may have been modified pursuant
 * to the GNU General Public License, and as distributed it includes or
 * is derivative of works licensed under the GNU General Public License or
 * other free or open source software licenses.
 * @version $Id: cart.php 2551 2010-09-30 18:52:40Z milbo $
 */

// Check to ensure this file is included in Joomla!
defined ('_JEXEC') or die('Restricted access');

vmJsApi::vmValidator();


// dont show anything if cart is empty
if (!$this->cart->cartProductsData){ ?>


    <h3><?php echo vmText::('COM_VIRTUEMART_EMPTY_CART'); ?></h3>
<?php
    
if (!empty($this->continue_link_html)) {
    echo 
$this->continue_link_html;
    }

    
//dont process anything else
    
return;
    }



?>



Title: Re: Empty cart stay when user removes all items
Post by: ghardin on June 13, 2017, 20:05:19 pm
Thanks.  That makes it clearer.  I assume "continue_link_html" is where I put the page I want to go to on an empty cart?  Is there a joomla format for that so I get it right?
Title: Re: Empty cart stay when user removes all items
Post by: AH on June 14, 2017, 09:35:40 am
That is the code you can use with no further edits

The continue link is created by VM and you do not touch it!

$this->continue_link_html
Title: Re: Empty cart stay when user removes all items
Post by: ghardin on June 14, 2017, 15:59:36 pm
Nothing changes.  When a user removes item from the cart and it is empty, the cart screen remains with the various error message about no weight etc.
What I need to happen is that when the cart is emptied by the user, that there is a redirect to some other page.  Store front page or site home page would be fine.  Just something I can use to get the user out of the cart page and taken somewhere else.
Title: Re: Empty cart stay when user removes all items
Post by: Jörgen on June 14, 2017, 16:20:31 pm
Hello
You don't give much info. Where have you put the code? Is it actually beeing called? Are you using a custom template?
Usually when nothing happens nothing has been changed where it should have been.
Regards
Jörgen @ Kreativ Fotografi
Title: Re: Empty cart stay when user removes all items
Post by: ghardin on June 14, 2017, 16:46:26 pm
Pretty much all of the details are in the thread of the post.  You would need to read all of the discussion to understand what has been happening.
I appreciate you wanting to assist, but I do not want to tell the story all over again.
Title: Re: Empty cart stay when user removes all items
Post by: GJC Web Design on June 14, 2017, 17:45:24 pm
Jörgens point is if u are in the right file and the code is as above it WILL work
Title: Re: Empty cart stay when user removes all items
Post by: ghardin on June 14, 2017, 18:10:53 pm
I am in the right file, in fact I tried it in the default files in the virtuemart components folder AND in the virtuemart HTML folder in my template overrides.  In the code, I see nothing that tells me WHERE the user will be directed to when the cart is empty.  What if I want them to go to some specific page?
I thought I was being pretty specific in what I wanted to happen.  Maybe I am not understanding what it is this section of code is supposed to do.
All that happens is that the user now sees:
Cart Empty
Continue shopping (the link)
and then the breadcrumbs for the navigation, which indicates "Home>Our Store>Shopping Cart"
Because they are still actually "in the Cart", the error messages from the shipping or other plugins STILL are displayed.  If the user is redirected to another page, those do not appear.  They are only active for the cart.

What I want is for the user to actually be redirect to ANOTHER page automatically.  This just tells them the cart is empty, which they already know because they emptied it and then has them click the "Continue Shopping" link.  I just want them to go directly back to the storefront or the category they were in before the cart (or some other page if it is appropriate)
Title: Re: Empty cart stay when user removes all items
Post by: AH on June 14, 2017, 18:33:41 pm
The code works

If you are using default templates you should not see error messages when you empty the cart.  You will probably see the Notice product quantity successfully updated.

It will not direct you to a specific page - other than that show in the VM continue shopping link (which is set by VM when you enter the cart)

Quote
What if I want them to go to some specific page?
I thought I was being pretty specific in what I wanted to happen.  Maybe I am not understanding what it is this section of code is supposed to do.

If you have a more specific request - then maybe you need to have someone code this on your behalf.
Title: Re: Empty cart stay when user removes all items
Post by: ghardin on June 14, 2017, 18:41:11 pm
I thought I was pretty specific that I want to redirect to someplace other than the cart.  Thanks for the attempts to help, but I will have to figure it out myself.
Title: Re: Empty cart stay when user removes all items
Post by: Jörgen on June 14, 2017, 19:21:45 pm
I have read the whole thread and you don't give any details whatsoever what you have put and where. Filepath, linenumber e.t.c
It is hard to give any more than this without doing your job fir you. But if you think you have given all the info that you would need to have yourself to fix this. Then ok i will not ask you for more.

Regards

Jörgen @ Kreativ Fotografi
Title: Re: Empty cart stay when user removes all items
Post by: ghardin on June 14, 2017, 19:31:51 pm
Ok.  one more time - when the user empties the cart I want them to be automatically redirected to the site home page.  The code snippet does part of what I want, in that it clears the cart page and does Display the words "EMPTY CART" via COM_VIRTUEMART_EMPTY_CART.
Then it displays the "Continue Shopping" link via echo $this->continue_link_html;

I do not want the user to have to click that link at all.  I do not want them to even be in the cart anymore.  I want to redirect them to some other page and for the purposes of this post, let take them to the sites home page (index.php).  If we can get that far then I think I can figure out how to get them to the storefront on the site if that is where I want them to go.  Does all of that make sense?
Title: Re: Empty cart stay when user removes all items
Post by: AH on June 15, 2017, 09:27:39 am
Ghardin

I am unsure as to how you think the forums work.  You are not doing anyone here a favour by providing information.

The comment  "Ok.  one more time"  is uncalled for.

I suggest you might need to go to the jobs forum for such a thing, someone there may wish to pick this up for you.

http://forum.virtuemart.net/index.php?board=18.0 (http://forum.virtuemart.net/index.php?board=18.0)



Title: Re: Empty cart stay when user removes all items
Post by: ghardin on June 15, 2017, 16:32:03 pm
Not meaning to be rude.  I am just frustrated because I believe I clearly explained what I wanted to accomplish in the very first post and in much of the thread of discussions between yourself and I.  Then other people joined in and while I appreciated the willingness to help, it seems as though I was asked to explain what I was try to do a second or third time, even while you and I had been working on a solution that was pretty clearly defined.  I frequent the forums quite a bit looking answers to problems and I read the threads and the reference links pretty thoroughly to see if they might be of use.  So I know when I read something that I understand the problem and explanations through the entire threads.  I find the assistance here to be very helpful and while I may have come across as ungrateful, I am not.  But it would behoove others here to not to jump to those conclusions so quickly.  I appreciate all of the efforts to help, but some are more useful than others.

On a separate but related issue, in your snippet of code was this:
 if (!empty($this->continue_link_html)) {
    echo $this->continue_link_html;
    }

That was the part I had a problem with as it still left the user in the cart, even though it cleared the screen and made it clear the cart was empty, it did not take the user to another page and that is the heart of what I am trying to accomplish.  More searching on the net found this bit of code that does do that:
// REDIRECT WITHIN A JOOMLA SCRIPT:
$allDone =& JFactory::getApplication();
$allDone->redirect('[link URL]');

But it still does not solve the other part of the problem, in that it does not clear or remove the various error messages from shipping plugins.  It appears that I need to find a way to refresh the page I redirect to, probably the shopfront, so it clears the messages.
If you have a suggestion, I would be pleased to see it.  But if you are done with this effort I also understand that.
Title: Re: Empty cart stay when user removes all items
Post by: jenkinhill on June 15, 2017, 16:43:04 pm
You are asking for bespoke coding help, which really is not what this forum is for.  As AH suggested you may be wise to commission a developer, as you want to do something that nobody has ever requested before in the forum. I wonder how many people actually clear a cart. 

Title: Re: Empty cart stay when user removes all items
Post by: ghardin on June 15, 2017, 17:14:42 pm
The client is a US veterans support group with limited funds and resources.  I am doing the work for them pro-bono so paying someone to produce a small snippet of code is just not feasible.  All of the work on the site, including marketing and SEO has been done pro-bono or by volunteers.  Potentially we might find the right person, but for now I will make do with what I can glean from this and other resources.
To answer your question about who empties a cart, well we do not know that.  But when it does happen, and we have done some testing on the site, the user has to navigate back to somewhere else on the site and that is what we want to make happen automatically.  The error message/warning from the other plugins are also a confusing factor and I am working with those developers for a solution as well.  It improves the overall user experience and because the site relies on the store for a major source of funds, we do not want to turn off any potential customers.  While it is not a huge issue that is a cause for concern, thinking outside of the box and looking to what future needs might be is what I do.  I have been working with computers and systems since the late 1970's and find that much of the software and coding done today only addresses short term needs and relies on frequent updates to fix problems that should have been considered early on.  Mostly it is because of the rush to market most applications seem to have that precludes that.

But I digress into a philosophy that is unlikely to change any time soon. I am confident I will find the solution to the problem with enough research.  Being retired, I have the luxury of time on my side.
Title: Re: Empty cart stay when user removes all items
Post by: GJC Web Design on June 16, 2017, 13:14:42 pm
you already have the code to detect if the cart is empty or not

now google for any standard code snippet to redirect any where you want to go.. 
by php header or  javascript redirect.. what ever.. 
u could even have a js snippet to programatically "click" the continue button

this is really basic stuff that google will show u