Attribute Price Multiplier

Contrib type: 
Initial upload
Not ready for moderation


Ubercart 1.x

This is a patch to the uc_attribute module that allows price adjustment using multiplication and division along with the current addition and subtraction. For example, you can specify an option that, when selected, will double (or half) the item's price.

There are two main issues with this initial version:
1. Some of the form layouts aren't very nice
2. This will not work well if multiple attributes are added to a product.

To use this, just use your favorite patch tool to apply the patch to the uc_attribute module, run the update script, and you're ready to go!

When using this, I recommend configuring attributes to display the total price rather than the price adjustments. To make this change, navigate on your site to admin/store/settings/attributes.

This was developed for Ubercart 1.x.

Updates/comments are welcome. I'm sure there are ways this can be improved.

uc_attribute_price_multiplier.patch17.12 KB's picture
Joined: 03/19/2009
Juice: 10
Re: Attribute Price Multiplier

Brilliant! I'll test this on my site - I'm using ubercart 2.x so hopefully it's compatible. I'll let you know how I go's picture
Joined: 03/19/2009
Juice: 10
Re: Re: Attribute Price Multiplier

hmm not so compatible after all..'s picture
Joined: 03/19/2009
Juice: 10

An alternative method I used instead that was pretty painless

and in the custom price window for that product add the following code

$licenses = $item->data['attributes'][3];
if (intval($licenses)){
   $item->price = $item->price*intval($licenses);
   #drupal_set_message("Number of licenses is incorrect, must be anumber ($licenses)","status");
   drupal_set_message("Number of licenses is incorrect, must be a number ($licenses)","error");

you may need to put a print_r($item) in the code to see what your $item object looks like

Hope this helps someone

orthodoxkohen's picture
Joined: 08/10/2009
Juice: 8
Custom Price Modifications

Could you give a general explanation of how this works?


mizerydearia's picture
Joined: 09/01/2009
Juice: 12
Re: Attribute Price Multiplier

I want to modify the function of ubercart attributes so that the price inputted does not add/subtract to the cost of the base product, but instead entirely changes the cost, setting it to the value specified. I found in ubercart/uc_attribute/uc_attribute.module function _uc_attribute_alter_form() has a line "'price' => $product->sell_price + $option->price," that I changed to "'price' => $option->price," which only visually makes products appear to be less, but when adding to cart it does not take effect. I, of course, want to write my own module to permanently make this change, but I'm not sure where to start to create a module to accomplish that. Any pointers?

Also in ubercart/uc_attribute/uc_attribute.module function uc_attribute_cart_item has
$item->price += $op_prices;
which I changed to
$item->price = $op_prices;

How can I write a module to make these changes permanent so that when upgrading ubercart, they aren't lost?

rendog's picture
Joined: 10/21/2009
Juice: 7
Anyone have a solution for Ubercart 2.0

Urgently need the ability to add subtract multiply and divide to an attribute does anyone have any works in progress..

Any help would be greatly appreciated.


Unarmed's picture
Joined: 08/07/2009
Juice: 139
Re: Attribute Price Multiplier

Any plans on doing something similare for Ubercart 2.x?

galundin's picture
Joined: 09/13/2011
Juice: 7
Custom pricing

For anyone else looking for more flexibility in the way attributes affect the price, read up on these two modules: