Has anyone ever attempted to notify an admin that a completed order contains an item from a wishlist?

It seems it may be fairly easy to add an entry to the order comments or add some text to the admin order notification email, but I'm not sure what is available to pull from.

Anyone have thoughts or experience?

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

naveenvalecha’s picture

Use hook_uc_checkout_complete($order, $account) in your custom module to send email to admin.
Code of the custom module foobar is like :

function foobar_uc_checkout_complete($order, $account) {
    foreach ($order->products as $key => $item) {
      if (isset($item->data['wid']) && isset($item->data['wpid']) && !isset($item->data['wset'])) {
        $wid = $item->data['wid'];
        $wpid = $item->data['wpid'];
        $w = uc_wishlist_load($wid);
        $witem = uc_wishlist_get_product($wpid);
        //@todo send email code 
}

We will soon add this functionality in module.
For more information about hook_uc_checkout_complete see here http://drupalcontrib.org/api/drupal/contributions%21ubercart%21uc_cart%2...

Poieo’s picture

Rather than adding this to the module, would it be easier to add a rule to check if a product is from a registry?

Poieo’s picture

What I'd really like to do is add the wishlist name to the admin notification. I know the below is wrong, but I can't seem to figure out how to pull the wishlist into the uc-order--admin.tpl template.

<?php print t('Products:'); ?><br />
<?php foreach ($products as $product): ?>
- <?php print $product->qty; ?> x <?php print $product->title; ?> - <?php print $product->total_price; ?><br />
    <?php $title = $item->data['title']; ?>
    <?php uc_wishlist_load($title); ?>
    <?php uc_wishlist_get_product($wpid); ?>
    <?php print t('Wishlist:'); ?> <?php print $item->data['title']; ?>
<br />
&nbsp;&nbsp;<?php print t('SKU'); ?>: <?php print $product->model; ?><br />
    <?php if (!empty($product->data['attributes'])): ?>
    <?php foreach ($product->data['attributes'] as $attribute => $option): ?>
    &nbsp;&nbsp;<?php print t('@attribute: @options', array('@attribute' => $attribute, '@options' => implode(', ', (array)$option))); ?><br />
    <?php endforeach; ?>
    <?php endif; ?>
<br />
<?php endforeach; ?>
jaykainthola’s picture

Hi,

I have updated latest Dev version to add rules to check if order contain wishlist product. You need to create rules for the order and there will be condition for the wishlist product in rules.

Thanks

naveenvalecha’s picture

Component: Miscellaneous » Code
Status: Active » Fixed

Use the latest dev release.

Poieo’s picture

Thank you! Would it be possible to make a wishlist title token available? Something like [order:wishlist:title]?

Poieo’s picture

Status: Fixed » Needs work

I've been trying this out and I think the condition that an order contains a wishlist product triggers if the ordered product is in any wishlist. Not, which I think should be the correct method, if the order contains a product that was added to the cart from a wishlist.

In other words, the rule gets triggered when an order contains a product that is listed in any wishlist whether the buyer purchased it from an actual wishlist or not.

berenddeboer’s picture

Issue summary: View changes
Status: Needs work » Needs review
FileSize
17.34 KB

This is a patch which properly checks if an order has products ordered from a wish list. Works both for the new views and the existing wish list display.

Does not implement [order:wishlist:title]. Please create a new feature request for this.

naveenvalecha’s picture

Status: Needs review » Needs work
Issue tags: +Needs reroll
Poieo’s picture

Here is a patch against the latest dev. However, I wasn't sure how to handle this:

diff --git a/uc_wishlist.module b/uc_wishlist.module
index 564ee39..b046088 100644
--- a/uc_wishlist.module
+++ b/uc_wishlist.module
@@ -337,23 +337,24 @@ function uc_wishlist_form_alter(&$form, &$form_state, $form_id) {
     if (!user_access('create wish lists'))
       return;
 
-        /**
-        * If only in stock products can be added to the wishlist, check if we have
-        * stock, and if not, bail out.
-        */
-        if (!variable_get('uc_wishlist_out_of_stock', FALSE)) {
+    /**
+     * If only in stock products can be added to the wishlist, check if we have
+     * stock, and if not, bail out.
+     */
+    $product = $form_state['build_info']['args'][0];
+    if (!variable_get('uc_wishlist_out_of_stock', FALSE)) {
       /**
-      * If stock module not enabled, or stock not active for this product, we
-      * don't care about stock.
-      */
+       * If stock module not enabled, or stock not active for this product, we
+       * don't care about stock.
+       */
       if (module_exists('uc_stock')) {
-        $product = $form['node']['#value'];
         $stock_level = uc_stock_level ($product->model);
         if ($stock_level !== FALSE && $stock_level <= 0) {
           return;
-		}
+		    }
       }
     }
+
     // Add the wish list button to the add to cart form.
     $form['actions']['wishlist'] = array(
       '#type' => 'submit',

That section has changed in the latest dev to this:

  if (user_access('create wish lists') && variable_get('uc_wishlist_out_of_stock', FALSE)) {
    if ((strpos($form_id, 'uc_product_add_to_cart_form_') === 0) || (strpos($form_id, 'uc_product_kit_add_to_cart_form_') === 0)) {

However, this checks for uc_wishlist_out_of_stock as FALSE. This doesn't validate if stock is not enabled and prevents the add to wishlist button from being added. We probably need to run a check to see if stock is enabled first.

Aside from that, the purpose of sending the notification email via rules is working great.

Poieo’s picture

Added a new issue for the wishlist title token: #2375519: Make Wishlist Tokens Available to Rules

berenddeboer’s picture

Poieo, the proper stock check fix is attached to issue #728550: Disable products on wishlist that are out of stock.

berenddeboer’s picture

Status: Needs work » Needs review
Issue tags: -Needs reroll
FileSize
14.95 KB

This patch needs #728550: Disable products on wishlist that are out of stock applied first. Then reroll should apply fine I hope. Juggling a lot of patches, so hope I got the order right.

  • jaykainthola committed f1669e8 on
    Issue #2091331: Created rules for wishlist to check wishlish product in...
  • jaykainthola committed 7f4dcdd on
    Issue #2091331: Fixed securrity issues which is shown by coder module.
    
naveenvalecha’s picture

Added parent issue.

berenddeboer’s picture

This is a reroll of the previous patch. Does two things:

  1. Keep track of what products came from a wish list.
  2. Adds a views handler to create a simple add to cart button.

The latter is unrelated to number one in some sense but have put it in this patch, as it allows people to create simple wish lists views, and those doing that are probably also interested to keep track of what products where from the wish list.

But happy to split patch if needed.

naveenvalecha’s picture

Regarding point 2.
I think we should not provide a views handler for the same.Because we are adding the wishlist button to the add to cart form so it seems not right to me.

jaykainthola’s picture

@naveen, yes you are right.. We are not using views handler to create a simple add wishlist button.

berenddeboer’s picture

Note that the views handler is optional: it's NOT used. It's an extra feature to allow people who use views to show their wish list. So orthogonal to this issue, and I'm happy to split the patch into two if it's confusing.

berenddeboer’s picture

Reroll of patch against latest dev.

Poieo’s picture

Thanks berenddeboer. The latest patch seems to be missing the following from the original and doesn't seem to work without it:

diff --git a/uc_wishlist.rules.inc b/uc_wishlist.rules.inc
index a145535..8c838b7 100644
--- a/uc_wishlist.rules.inc
+++ b/uc_wishlist.rules.inc
@@ -20,6 +20,9 @@ function uc_wishlist_rules_condition_info() {
         'label' => t('Order'),
       ),
     ),
+    'provides' => array(
+      'wishlist_name' => array('type' => 'text', 'label' => t('Wishlist name')),
+    ),
   );
 
   return $conditions;