This module will add Ubercart product attributes as 'attribute' tokens for use elsewhere. As of initial upload the only code to use these tokens is the contributed Custom Price Calculation module. The combo of these two modules allows an admin to enter custom code to set item properties such as price based on attributes.

One use could be setting up an attribute with no options on a product called donation which would in turn generate a token called [donation] and would add a text box for a customer to enter a donation amount to add to the product price. This could then be used by the Custom Price module with the following code inserted...

$item->price += [donation];

You'd want to do validation (e.g. check_plain()) and formatting here as well since [donation] is going to be any text that a user could enter and this expects a 2 decimal place number with no leading dollar sign.

Another use might be for implementing complex logic beyond just +1.00 or -2.00 for attribute price adjustments. Within the custom code block you can reference all of the attribute values and make adjustments based on the exact combo of attributes selected. For instance, if you only want to charge $1.00 extra for a (large, black) t-shirt but a (large, red) and a (medium, black) will sell for regular price you can set all of the product attributes to 0 price adjustment and then add the following custom code...

if('[size]' == 'large' && '[color]' == 'black') {
  $item->price += 1;
}

*I believe this could cause problems if you happen to name your attributes the same as existing tokens generated elsewhere, but it's unlikely the tokens would be applied in the same contexts. Perhaps tokens generated here should be prefixed attr_

Thanks to cYu for the original code

Module ported to Drupal 6 / Ubercart 2, enhanced, and now maintained by TR

Project Information

Downloads