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:

<?php
$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!

Files: 
CommentFileSizeAuthor
#12 791028-uc_stock-product-token-test.patch2.36 KBlongwave
Test request sent.
[ View ]
#10 ubercart-enable_product_tokens_for_stock_threshold_mail-791028-10.patch2.62 KBmitrpaka
PASSED: [[SimpleTest]]: [MySQL] 1,544 pass(es).
[ View ]
#5 uc_stock.module.02.patch1.44 KBhaggins
FAILED: [[SimpleTest]]: [MySQL] Unable to apply patch uc_stock.module.02.patch. This may be a -p0 (old style) patch, which is no longer supported by the testbots.
[ View ]
#4 uc_stock.module.patch1.55 KBhaggins
FAILED: [[SimpleTest]]: [MySQL] Unable to apply patch uc_stock.module.patch. This may be a -p0 (old style) patch, which is no longer supported by the testbots.
[ View ]

Comments

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

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

This issue obtains on dev-version, too.

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

reply at the same time ;)

Status:Active» Needs review
StatusFileSize
new1.55 KB
FAILED: [[SimpleTest]]: [MySQL] Unable to apply patch uc_stock.module.patch. This may be a -p0 (old style) patch, which is no longer supported by the testbots.
[ View ]

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.

StatusFileSize
new1.44 KB
FAILED: [[SimpleTest]]: [MySQL] Unable to apply patch uc_stock.module.02.patch. This may be a -p0 (old style) patch, which is no longer supported by the testbots.
[ View ]

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).

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:
    <?php
    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:
    <?php
    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?

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 ...

Status:Needs work» Needs review

Status:Needs review» Needs work

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

Status:Needs work» Needs review
StatusFileSize
new2.62 KB
PASSED: [[SimpleTest]]: [MySQL] 1,544 pass(es).
[ View ]

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)

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.

Status:Patch (to be ported)» Needs review
StatusFileSize
new2.36 KB
Test request sent.
[ View ]

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.

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

Committed to 7.x-3.x.

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.