It seems that there are no product tokens available for use in the threshold mail. I.e. I tried [model] which doesn't get replaced. I think it's because of line 245 at uc_stock.module:

$token_filters = array('global' => NULL, 'order' => $order, 'stock' => $stock);

Function _uc_stock_send_mail() is documented with three parameters "$order, $product and $stock". But it's implemented with $product missing.

Please add this parameter, thanks!

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

TR’s picture

Title: Product tokens not available for threshold mail » Product tokens not available for stock threshold mail
haggins’s picture

Title: Product tokens not available for stock threshold mail » Product tokens not available for threshold mail

This issue obtains on dev-version, too.

haggins’s picture

Title: Product tokens not available for threshold mail » Product tokens not available for stock threshold mail

reply at the same time ;)

haggins’s picture

Status: Active » Needs review
FileSize
1.55 KB

Here's a patch.

Since uc_product_token_values() needs a full node-object you have to load the products node at uc_stock_decrement_product_stock().
uc_product will then replace [model] and all other product-tokens with their values.

Mostly [model] will be replaced with the expected value. If not you can use [stock-model] if you want to get the sold products model.

Sometime there may be situations where both is not the value you want to mail in the threshold mail or save at the order comments.
Just imagine you sell tickets for a concert with two price categorys "adults" and "children". They will share the same stock of course (maybe even on n days => n stocks). This could be managed of a custom module which should have the chance to hook into and rename the model or change other properties. This would imho be the most abstract solution at this point.

haggins’s picture

FileSize
1.44 KB

I'm sorry, here's a new one. With patch of #4 token [model] did not have the behavior as expected. With this one you get the nodes model by default (until you hook into).

haggins’s picture

Hmm, I've got another suggestion:

Don't introduce a new hook but don't let the information in $product get lost. So there are two alternatives:

  • Create an additional token type. It would look like this:
    function _uc_stock_send_mail($order, $product, $stock, $node) {
      $token_filters = array('global' => NULL, 'order' => $order, 'product' => $product, 'stock' => $stock, 'node' => $node);
      // ...
    }
    

    "node" type contains a full node which is needed by uc_product to replace all product-tokens.
    "product" could be used to give modules a chance to introduce additional token.

    Advantage: more information available
    Disadvantage: each type fires a new hook_token_values()

  • The $product information could be merged with $node information which get passed to 'node' token-type. Maybe something like this:
    function uc_stock_decrement_product_stock($product, $key, $order) {
      // ...
      // Should we notify?
      if (variable_get('uc_stock_threshold_notification', FALSE) && $stock->stock <= $stock->threshold) {
        $node = node_load($product->nid);
        $node->product = $product;
        _uc_stock_send_mail($order, $node, $stock);
      }
      // ...
    }
    

    So other modules can implement hook_token_values(), too. Since $product data is available in node-type it's possible to introduce new tokens without an extra hook invocation.

I think we should not loose any data at this point to offer more flexibility.
What do you think?

TR’s picture

Version: 6.x-2.2 » 6.x-2.x-dev
Status: Needs review » Needs work

Let's sic the testbot on this one. It's going to fail due to the age of the patch, but it's a start ...

TR’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, uc_stock.module.02.patch, failed testing.

mitrpaka’s picture

Status: Needs work » Needs review
FileSize
2.62 KB

Here is updated patch based on #5 and #6. No additional features introduced/provided, just plain fix to enable product tokens in stock threshold mail. (Same could be applied to 7.x-3.x as well)

longwave’s picture

Version: 6.x-2.x-dev » 7.x-3.x-dev
Component: Code » Stock
Category: bug » feature
Status: Needs review » Patch (to be ported)

Thanks for the patch - I finally committed #10 with minor changes for coding standards. Also committed a followup to show node and product tokens in the token help page.

Needs porting to 7.x-3.x.

longwave’s picture

Status: Patch (to be ported) » Needs review
FileSize
2.36 KB

Ported and committed to 7.x in http://drupalcode.org/project/ubercart.git/commitdiff/85c1f7d

The attached patch changes the default stock notification mail to include the product title, along with a set of tests.

longwave’s picture

Version: 7.x-3.x-dev » 6.x-2.x-dev
Status: Needs review » Patch (to be ported)

Committed to 7.x-3.x.

longwave’s picture

Status: Patch (to be ported) » Fixed

Ported and committed to 6.x-2.x.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.