I think a very helpful feature would be to integrate this module with the Cart Links [http://www.ubercart.org/contrib/1427] module such that we could add a parameter to a link which would not only add a product to the cart, but apply a coupon as well. All this would require is adding a hook in cart links to accept a parameter like "c=COUPONCODE", and would have added value of not forcing users to manually enter coupon code. This doesn't seem to be covered in existing documentation for either module.

Comments

longwave’s picture

Yeah, as you found uc_cart_links_process() just ignores extra parameters, it would be useful if it invoked a hook when an unknown parameter was found to give other modules a chance to act on the link. This will require a patch to Ubercart core before any work can be done in uc_coupon.

longwave’s picture

Status: Active » Postponed

Postponed as this is not achievable unless Ubercart itself is patched.

longwave’s picture

Status: Postponed » Closed (won't fix)

Unlikely to happen in 6.x-1.x as cart links is not extensible.

wodenx’s picture

This is something you could do fairly easily via an intermediary link - i've done something similar to restore the missing 'e' (empty cart) functionality in the latest cart links release (see #881752: Cart Links - Missing code for "Empty cart" function). Basically, you would create a new path (e.g. /cart/add-c/%) which would parse the cart link specification for a coupon code (eg c12345), and if one were found, set the session coupon variable to that code. Then it would reconstitute the link (without the "c12345") and invoke cart links via drupal_goto.

eg:


// menu callback for, e.g., /cart/add-c/% or /coupon/cart-link/% or whatever
function uc_coupon_cart_link($cl=NULL) { 

  // look for a coupon code
  $ops = explode('-',$cl);
  $nops = array();
  foreach ($ops as $op) {
    if ($op[0]==='c'||$op[0]==='C') {
      if (strlen($op)>1 ) {
        $_SESSION['uc_coupon'] = substr($op,1);
      }
    }
    else {
      $nops[]=$op;
    }
  }
  $cl = implode('-',$nops);
  // create a cart link
  $path = "cart/add/$cl";
  drupal_goto($path);
}

Note - code avove is *UNTESTED*. Would probably have to be altered to handle the destination query string properly - but that shouldn't be too difficult. You also might want to encrypt the coupon code a la the better cart links module.

@longwave- if this is something you think would be useful as a part of uc_coupon let me know and I'll write a patch when I get some time.

longwave’s picture

As there is no real flexibility needed here, unlike with cart links, it's probably easier to just accept a querystring parameter - so on any page, you can use a URL like http://example.com/node/123?coupon=COUPONCODE to attempt to apply a specific coupon. http://drupal.org/project/uc_eco apparently already implements this, so it should be fairly easy to merge into uc_coupon itself...

longwave’s picture

I added this feature; the parameter is configurable at /admin/store/settings/coupon