Download & Extend

Product tokens not available for stock threshold mail

Project:Ubercart
Version:6.x-2.x-dev
Component:Stock
Category:feature request
Priority:normal
Assigned:Unassigned
Status:closed (fixed)

Issue Summary

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!

Comments

#1

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

#2

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

This issue obtains on dev-version, too.

#3

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

reply at the same time ;)

#4

Status:active» needs review

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.

AttachmentSizeStatusTest resultOperations
uc_stock.module.patch1.55 KBIdleFAILED: [[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 details

#5

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

AttachmentSizeStatusTest resultOperations
uc_stock.module.02.patch1.44 KBIdleFAILED: [[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 details

#6

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?

#7

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

#8

Status:needs work» needs review

#9

Status:needs review» needs work

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

#10

Status:needs work» needs review

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)

AttachmentSizeStatusTest resultOperations
ubercart-enable_product_tokens_for_stock_threshold_mail-791028-10.patch2.62 KBIdlePASSED: [[SimpleTest]]: [MySQL] 1,544 pass(es).View details

#11

Version:6.x-2.x-dev» 7.x-3.x-dev
Component:Code» Stock
Category:bug report» feature request
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.

#12

Status:patch (to be ported)» needs review

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.

AttachmentSizeStatusTest resultOperations
791028-uc_stock-product-token-test.patch2.36 KBTest request sentNoneView details

#13

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

Committed to 7.x-3.x.

#14

Status:patch (to be ported)» fixed

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

#15

Status:fixed» closed (fixed)

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