Drupal 7 'Add to Cart' Rule for Ubercart

On a current site in development I am using Ubercart to provide a renewable subscription service. To make the user experience clean, I wanted to protect the user from going 'shopping' to add their subscription. To do this I decided to use a rule to add the product to the user cart when the user is created by an administrator or when the subscription is cancelled or fails payment. I tried the Ubercart Rules module, but this is mainly for dealing with orders and not carts, and did not contain the needed add to cart rule.

Lucky it is easy to make one for yourself using the php action in rules. The following is the needed code for adding a nid to a specified users cart:

<?php
// uc_cart_add_item($nid, $qty = 1, $data = NULL, $cid = NULL, $msg = TRUE, $check_redirect = TRUE, $rebuild = TRUE)
uc_cart_add_item($product_nid, 1, NULL, $user_uid, FALSE);
?>

Please note the commented out add to cart call with all the bells and whistles. I have included an export of the component for ease of import.

Peace!

AttachmentSize
addtocartrule.txt615 bytes

Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

Hi i am trying to find a

Hi i am trying to find a similar functionality for this issue https://drupal.org/node/2206137 . Can you help me out

I haven't worked with

I haven't worked with ubercart product attributes in awhile. I would think that you could examine the user carts on product submission and using a php rule, do what you are looking for.

Post new comment

  • Allowed HTML tags: <em> <strong>
  • Lines and paragraphs break automatically.

More information about formatting options

Image CAPTCHA
Enter the characters shown in the image.