Attribute Tokens

Contrib type: 
Module
Status: 
Initial upload
Moderation: 
Not ready for moderation

Downloads


Compatibility: 
Ubercart 1.x

This module will add product attributes as uc_cart_item tokens to be used 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 set up 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 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. Perhaps tokens generated here should be prefixed attr_


PreviewAttachmentSize
uc_attribute_tokens.zip1.11 KB
crooke's picture
Offline
Joined: 03/15/2008
Juice: 77
Hi! If i get it right, this

Hi!

If i get it right, this module generates tokens from product attributes. What I'm after is including tokens in product attributes, let's say the product is called "Test Product", I want the options to be:

- Addon 1 to "Test Product"
- Addon 2 to "Test Product"

So basically on the option edit form I would submit something like:

Addon 1 to [node:title]

Is that possible somehow?

Thanks!

glennnz's picture
Offline
Joined: 01/20/2009
Juice: 458
Hi I can't get this to

Hi

I can't get this to work...

Below is what I'm using to test.

The module works fine if I use just:

$item->price = $item->price*3;

But when I use

global $user;
if (in_array('member', $user->roles))
{
$item->price = $item->price*3;
}

the price doesn't change for a user with that role...

Also see this node.

Thanks

cYu
cYu's picture
Offline
Bug FinderGetting busy with the Ubercode.
Joined: 11/19/2007
Juice: 852
Re: Hi I can't get this to

This doesn't really have anything to do with this module, but $user->roles is going to give you an array of role ids, not of strings.

glennnz's picture
Offline
Joined: 01/20/2009
Juice: 458
Re: Re: Hi I can't get this to

Is there any easy way to return role strings???

glennnz's picture
Offline
Joined: 01/20/2009
Juice: 458
Re: Re: Hi I can't get this to

Also, is my syntax correct, especially '[attribute]'???

if (in_array('3', $user->roles) && '[Course Modules]' == 'Professional Practice module')
{
$item->price = '253';
}

I desperately need help with this...

Thanks heaps

Glenn

glennnz's picture
Offline
Joined: 01/20/2009
Juice: 458
Not working..... :-(

OK, more info.

With this code:

if ('[Course Modules]' == 'All modules')
{
$item->price = '1';
}

if ('[Course Modules]' == 'Software module')
{
$item->price = '2';
}

if ('[Course Modules]' == 'Theory module')
{
$item->price = '3';
}

if ('[Course Modules]' == 'Professional Practice module')
{
$item->price = '4';
}

it works perfectly for the administrator, but not for anyone else....

HELP!!!!!!!

Thanks

Glenn

TSE
TSE's picture
Offline
Joined: 11/18/2008
Juice: 16
use attributes to calculate shipping ?

Hi,

is it possible to calculate shipping costs using attributes ?

It should work like this:

Products have an attribute called "Length". Users could enter a Length which is allready used to calculate the product price. Now i want to use workflowNG rules to fetch a shipping quote using a numeric comparision rule.

for example if uc_cart_item_[Length] is greater 2000 then fetch the (expensive) shipping quote.

Is this possible ??

TSE

Lyle's picture
Offline
AdministratoreLiTe!
Joined: 08/07/2007
Juice: 6855
Re: use attributes to calculate shipping ?

In Ubercart 2, there is a condition to check an ordered product's attributes. This could probably be backported to use Workflow-ng in Ubercart 1.

johnross.c's picture
Offline
Joined: 06/22/2009
Juice: 5
In relation to other products.

Is it possible to set the products price for free if it is bought together with other products. And not for free if a certain product is bought alone (or with no other products)?

Thanks!

jazzdrive3's picture
Offline
Joined: 03/29/2009
Juice: 221
cYu, Do these attribute

cYu,

Do these attribute tokens contain the price change they include? So if one attribute is supposed to add $5 to the price, there is something like a data array that contains it?

Thanks!

jazzdrive3's picture
Offline
Joined: 03/29/2009
Juice: 221
Re: cYu, Do these attribute

Well, just tried it out, and I can't enable it, because it says it's incompatible with drupal 6.13.

cYu
cYu's picture
Offline
Bug FinderGetting busy with the Ubercode.
Joined: 11/19/2007
Juice: 852
Re: cYu, Do these attribute

No, the attribute token simply contains the option value and not the price. Someone else had mentioned adding an info file and having it work straight away in d6, but I have not yet tried that and as you've discovered the original module was only written for d5.

juanlacueva's picture
Offline
Joined: 06/03/2009
Juice: 17
Ported to 6.13

Can this be ported to 6.13
We really need this tokens to combine the Automatic SKU generation Pattern by tokens....

Any ideas?

BoromirOfGondor's picture
Offline
Joined: 10/01/2009
Juice: 8
Hey juanlacueva, I've ported

Hey juanlacueva,

I've ported it to 6.14 by simply modifying the .info file.

It works great with custom price module.

Cheers,
Chris

Olaf Karsten's picture
Offline
Joined: 10/08/2009
Juice: 8
Ported to Ubercart 2 RC 7 and Drupal 6.14

I have "ported" it to 6.14 / Ubercart2RC7 too, by modifying the .info file.

I'm not an developer, so I don't now how to contribute that. The changes only takes a minute or so.

It works like expected with custom price module, so maybe the maintainer can spend 5 minutes to make this available for all. The code works.

mk123's picture
Offline
Joined: 12/13/2009
Juice: 41
Re: Ported to Ubercart 2 RC 7 and Drupal 6.14

could you upload your modified module somewhere and provide a simple example how you aquired the attributes data (your attribute name/options and the code you inserted in the custom prize php field ?

thanks,
m.

grfths's picture
Offline
Joined: 01/05/2010
Juice: 2
6.15

According to my admin/build/modules page:

"This version is incompatible with the 6.15 version of Drupal core."

I've tried changing the .info file - nothing works.

Also, a link in the description to some help on validation would be very helpful.
I've used this contrib before and it's great. Thankyou.

markagray's picture
Offline
Joined: 09/09/2009
Juice: 192
Using with D6.15 and U2.2

I'd like to use this uc_attribute_tokens module and the uc_custom_price module with Drupal 6.15 and Ubercart 2.2. Has anyone tried this? If so, what were your results? If it worked, what versions (or modifications) of uc_attribute_tokens and uc_custom_price did you use?

mk123's picture
Offline
Joined: 12/13/2009
Juice: 41
welcome, see my last post

welcome,

see my last post in
http://www.ubercart.org/forum/support/14756/using_form_set_value_change_...

I didn´t get the uc_attribute_tokens to work either - lucky you don´t need it (using drupal 6.x, ubercart 2.x)

install the uc_custom_price module - you can add php code to every product after that - include a php file (mine is within a module folder named uc_displaychange - there you can access $item and $product - and that´s all you need (see the print statement to have a look at your actual data)
it will take some trying to get the values you´ll need and do your calculations but you´ll get there.
in your $item are your (or better the customers) selections and the apropriate values are in $product.

two things are important
1. the code seems to be invoked whenever a product is displayed (meaning ubercart reloads it´s values and afterwards your custom code changed this values)
2. i noticed that if I used selection fields (dropdown) for the attribute selection and i chose something like '0 timers' it would still be displayed in (for example) the cart overview - meaning that when there would be like 20 attributes to choose from and usually the customer would only choose 2-4 attributes for a product there still would be like 16-18 times a line under the product where something would be like '[attribute-name]: 0 times'.
one way is to manually unset (php: unset) the entries wich have been choosen 0-times - that however made it impossible for me to change the amount of times a product has been choosen in the cart overview - I had to look for those values which have been choosen 0-times in my theme functions and remove them from the display structure there.

regards,
m.

TR
TR's picture
Offline
Bug FinderFAQ ModeratorGetting busy with the Ubercode.
Joined: 11/05/2007
Juice: 3277
Drupal 6 / Ubercart 2 version now available on drupal.org

I have ported this module to work in Drupal 6 / Ubercart 2, with the new attribute data structure, and with support for Textfield, Radio button, Checkbox, and Select attributes. With cYu's permission I have published this on drupal.org at http://drupal.org/project/uc_attribute_tokens. I will be supporting the module only through the issue queue on that project page, so I'm locking this thread to prevent further posts

I don't intend to maintain a Drupal 5 / Ubercart 1 version of the module - if you need that you can download it from the link at the top of this thread.

<tr>.