I'm on windows and don't know how to make a patch, but I figured out how to get cart links to work with the wish list module
the link is exactly the same as the cart link but a w is added and the destination can be changed to wishlist.
Assuming the cart link code for a product is
/cart/add/p200_q1_a5o10_a4o5?destination=cart
Add a w and change the destination so the new cart link is
/cart/add/p200_w_q1_a5o10_a4o5?destination=wishlist
The file uc_cart_links.pages.inc has to be patched
I put in some comments with my initials IMR
Around line 34 a statement
$wishlist = false; // IMR
The main change is in
// Add a product to the cart.
case 'p':
Around line 75 but im reproducing the whole case 'P' here:
// Add a product to the cart.
case 'p':
// Set the default product variables.
$p = array('nid' => 0, 'qty' => 1, 'data' => array());
$msg = TRUE;
// Parse the product action to adjust the product variables.
$parts = explode('_', $action);
foreach ($parts as $part) {
switch (drupal_substr($part, 0, 1)) {
// Set the product node ID: p23
case 'p':
$p['nid'] = intval(drupal_substr($part, 1));
break;
// Set the quantity to add to cart: q2
case 'q':
$p['qty'] = intval(drupal_substr($part, 1));
break;
// Set an attribute/option for the product: a3o6
case 'a':
$attribute = intval(drupal_substr($part, 1, strpos($part, 'o') - 1));
$option = intval(drupal_substr($part, strpos($part, 'o') + 1));
$p['attributes'][$attribute] = (string) $option;
break;
// Suppress the add to cart message: m0
case 'm':
$msg = intval(drupal_substr($part, 1)) == 1 ? TRUE : FALSE;
break;
// IMR - add support for wishlist
case 'w':
$wishlist = true;
break;
}
}
// Add the item to the cart, suppressing the default redirect.
if ($p['nid'] > 0 && $p['qty'] > 0) {
if (! $wishlist) { // IMR - add to wishlist?
uc_cart_add_item($p['nid'], $p['qty'], $p['data'] + module_invoke_all('add_to_cart_data', $p), NULL, $msg, FALSE);
}
else { // IMR - yes so add to wishlist if it exists
if (module_exists('wishlist')) {
uc_wishlist_add_item($p['nid'], $p['qty'], $p['data'] + module_invoke_all('add_to_cart_data', $p));
}
}
}
break;
That's all that's involved in getting cart links to work with the wish list module
I am attaching a copy of the patched uc_cart_links.pages.inc
Comments
Comment #1
tr commentedYou can read http://drupal.org/patch/create to find out about how to create patches.
I think in general this is a good idea, BUT it doesn't belong as part of the uc_cart_links module. It can and should be implemented as part of the uc_wishlist contributed module. The reason it doesn't belong as part of cart links is because that introduces an unneeded dependency on a non-core module. Wish list isn't part of core and isn't going to become part of core. There are also a number of problems with your patch: You need to provide the help text for wish links similar to what is available for cart links, make sure the admin functions and reports support wish links, etc. Semantically, /cart/add is probably not the right path - it should be /wishlist/add, and then you won't even have to define or use the 'w' case.
How I would go about doing this is, in uc_wishlist, define $items['wishlist/add/%'] in hook_menu(). Then patch uc_cart_links_process() to accept an optional argument, which would be the name of the function that does the adding to cart or wishlist. The default value of the argument would be 'uc_cart_add_item' so that no other changes are needed anywhere else in Ubercart. But that will enable you to pass in 'uc_wishlist_add_item' in the page arguments for the wishlist/add/% path. In fact, that make this a pretty extensible mechanism for taking action, any action, based on a product link as defined by the cart links module.
Comment #2
Ira Rabinowitz commentedThank you for your reply. I will have to look at doing this when I get a chance. I am new to Drupal and trying to learn and understand all of this.
Ira
Comment #3
naveenvalechaClosing because Drupal 6 is no longer supported. If the issue verifiably applies to later versions, please reopen with details and update the version.