I have cart links which empty the cart and direct users immediately to the checkout page, skipping the "cart" altogether (I'm selling only two products: monthly subscription or annual). To make things simple for the user, there are only these two cart links available to access the checkout page.

The problem: when a user returns to the site after thinking about their purchase, and they click on the "annual subscription" link again, as they've done before, they're presented with the "The current contents of your shopping cart will be lost. Are you sure you want to continue?" page. This will suprise the user since it's the same thing they chose before

The requested solution: Is it possible to check whether, after emtying the cart, the contents will actually change as a result of the cart link? In this case perhaps we can skip the "empty confirmation" page?

Comments

shaundychko’s picture

Title: skip Cart Links emtpy cart confirmation when cart unchanged » skip Cart Links empty cart confirmation when cart unchanged
gennadiy’s picture

I also would like to use e action, but it doesn't work.

This works well:
/cart/add/p35_q1_a1o1_m0?destination=cart/checkout

And this sends user to the empty cart after "The current contents of your shopping cart will be lost. Are you sure you want to continue?" page if cart wasn't empty:
/cart/add/e_p35_q1_a1o1_m0?destination=cart/checkout
If cart was empty, then it sends user to the empty cart without any messages.
So my guess that code for e action changed and that is why it doesn't work anymore. Normally it should empty cart with whatever is in it and then add product to it and then redirect user to cart/checkout (in my case).

e action is not even among available actions in the help:
/admin/store/help/cart_links

If it could be fixed, please. Thank you!

tr’s picture

New features should go into 7.x-3.x first at this point.

tr’s picture

Version: 6.x-2.x-dev » 7.x-3.x-dev

I thought I changed the version ...

mkmk’s picture

Version: 7.x-3.x-dev » 6.x-2.x-dev

I need the ability to bypass that message, too.

mkmk’s picture

Well, for now, it's just as easy to hardcode this change in the source:

uc_cart_links.pages.inc

if ($action == 'e' || $action == 'E') {

into

if ($action == 'E') {

mkmk’s picture

Version: 6.x-2.x-dev » 7.x-3.x-dev
tr’s picture

@mkmk: First, this thread is about skipping the confirmation message when the cart is unchanged. It's NOT about skipping the confirmation link altogether. Second, skipping the confirmation link altogether poses a security issue. Read all the other related threads if you're interested in the details, but your suggestion is simply a bad idea. Besides hacking core, it opens up a security vulnerability. Please don't suggest doing something like this.

I'm leaving this open as a feature request to remove the confirmation message if the cart link action results in an unchanged cart. If you'd like to offer a PATCH that does that, we'd all be grateful.

baby.hack’s picture

Status: Needs work » Active

I wanted this functionality, too.
I've no inclination to write a patch, but here are the changes I made. Might not be pretty, but seems to work for my site. (uc_cart_links.pages.inc):

Change this:

      foreach ($actions as $action) {
      	$action = drupal_substr($action, 0, 1);
      	if ($action == 'e' || $action == 'E') {
        	return confirm_form(array(), t('The current contents of your shopping cart will be lost. Are you sure you want to continue?'), variable_get('uc_cart_links_invalid_page', ''));
      	}
      }

To this:

    // Getting list of product numbers to be added:
    $added = array();
    foreach ($actions as $action_group) {
      $action = drupal_substr($action_group, 0, 1);
      if ($action == 'p' || $action == 'P') {
		  $nid = intval(drupal_substr($action_group, 1));
		  $added[]=$nid;
      }
    }
    // Getting list of product numbers in cart:
    $in_cart = array();
    foreach ($items as $item_info) {
		if($item_info->nid){
			$in_cart[]=$item_info->nid;
		}
    }
    // Sort lists:
    asort($added);
    asort($in_cart);
    // If the lists are different (if cart will change)...
    if($added != $in_cart){
	  // Show confirmation
         foreach ($actions as $action) {
      	   $action = drupal_substr($action, 0, 1);
      	   if ($action == 'e' || $action == 'E') {
        	return confirm_form(array(), t('The current contents of your shopping cart will be lost. Are you sure you want to continue?'), variable_get('uc_cart_links_invalid_page', ''));
      	  }
        }
    }
tr’s picture

Status: Active » Needs work
thehideki’s picture

Status: Active » Needs work

I needed this also, decided on forking the cart_links module to use a hash created from the user & product data, and a check that the hash matches. If the hash value matches, the confirmation is skipped.

Maybe some kind of optional hash parameter could be added to the url check on 7.x? It could be done using an admin settings field with token support. Then one could create a link (with views or your preferred method), and the cart_links function could check the parameter, and bypass the validation if it matches.

Just my 2 cents.

longwave’s picture

If you could post your forked code that handles hashes in this way, that would be helpful; it sounds like a reasonable approach to this issue.

thehideki’s picture

Edit: Sorry guys, was reading two threads, and posted on the wrong page (also the comment before)

I posted a comment here with custom code with a optional hash check to skip confirmation. The functionality i meant removes the confirmation ALWAYS if the hash matches, regardless of the current cart content.

Moved my comment here: http://drupal.org/node/1091166#comment-5619530