Posted by haggins on May 5, 2010 at 11:26pm
5 followers
| 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
#2
This issue obtains on dev-version, too.
#3
reply at the same time ;)
#4
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.
#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).
#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:
<?phpfunction _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()
<?phpfunction 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
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
#9
The last submitted patch, uc_stock.module.02.patch, failed testing.
#10
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)
#11
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
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.
#13
Committed to 7.x-3.x.
#14
Ported and committed to 6.x-2.x.
#15
Automatically closed -- issue fixed for 2 weeks with no activity.