17 replies [Last post]
sphoenixee's picture
Offline
Joined: 06/29/2008
Juice: 16
Was this information Helpful?

Hello,

Just got started using UC today Smiling

I was wondering if I could somehow configure attributes so that price change would be by percent, and not by an absolute amount. Basically, I have two attributes and I need (or would prefer) each to change by a percentage, e.g. attribute 1 offers price changes 10%, 20%, 30%, and attribute 2 has same price changes of 10%, 20%, 30%. If it were only 1 attribute, then I could just compute out the 10%, 20%, 30%, and do it that way. However, there being two attributes, there is no possible way I can simulate the percent changing with just +/- figures. I was wondering if anyone knew of a hack, had a code snippet, etc. that would implement this (price changing by percent with attributes).

Alternatively, I would not mind computing out all the values and applying them to each possibility, but that does not seem possible either. (i.e. all the combinations of values for both attributes)

It is quite possibly I am just missing an obvious feature as this is my first day using this. Apologies if this is the case.

Thank you for your help,

sphoenixee

Daniorama's picture
Offline
Joined: 09/15/2008
Juice: 46
Re: Attributes - Change Price by Percent

Hey, I'm looking for the same, did you find anything regarding that? Thanks!

cha0s's picture
Offline
Getting busy with the Ubercode.
Joined: 08/22/2008
Juice: 416
Re: Re: Attributes - Change Price by Percent

It can be done by adding an operator to the attributes, so instead of assuming that the value would be added, we could have a select list of operators like +, -, *, / that would do the specified operation between the price/weight and the modifier.

Try FreeBASIC!
My game Lynn's Legacy

Daniorama's picture
Offline
Joined: 09/15/2008
Juice: 46
Re: Re: Re: Attributes - Change Price by Percent

Do you mean that is already implemented or that could be easily implemented? I tried your suggestion but it doesn't work (also in the information of ubercart it's said just + or -) Thanks!

sejal's picture
Offline
Joined: 01/09/2009
Juice: 31
Adding % to the options of attributes

Did anybody get the solution for how to implement the % function for price?

NecroHill's picture
Offline
Joined: 08/12/2008
Juice: 107
Re: Re: Re: Attributes - Change Price by Percent

how to add this operator?

icymetal's picture
Offline
Joined: 06/19/2009
Juice: 24
Re: Re: Re: Attributes - Change Price by Percent

It definitely makes sense to add an operator.

Leetamus's picture
Offline
Joined: 01/21/2009
Juice: 97
Re: Attributes - Change Price by Percent

subscribed

Anand yrh's picture
Offline
Joined: 03/06/2009
Juice: 271
Re: Attributes - Change Price by Percent

How to implement the % function for price?

jazzdrive3's picture
Offline
Joined: 03/29/2009
Juice: 221
Re: Re: Attributes - Change Price by Percent

Yes, has anyone figured this out? I have one attribute that changes the price by percent.

thechanceg's picture
Offline
Joined: 09/04/2009
Juice: 8
Re: Re: Re: Attributes - Change Price by Percent

I would really like this feature as well. Has anyone had any luck?

PompeyDrupal's picture
Offline
Joined: 06/09/2009
Juice: 70
Re: Re: Re: Re: Attributes - Change Price by Percent

I don't suppose anyone has cracked this yet have they?

tars16's picture
Offline
Joined: 01/18/2010
Juice: 23
Re: Attributes - Change Price by Percent

Any development here? I'd like to get this going again. Do you have any suggestions on where to start?

finex's picture
Offline
Joined: 03/01/2010
Juice: 17
Re: Attributes - Change Price by Percent

A workaround could be using the "Custom Price" module and re-calculate the price from the attribute value, but you've to write a custom php code for each product... :-|

goose2000's picture
Offline
Joined: 06/03/2010
Juice: 19
Re: Attributes - Change Price by Percent

Ubercart attributes really need:

- 100%

Example - so student discount checked off, they get in free for school functions, - 100%

PaniX's picture
Offline
Joined: 01/27/2010
Juice: 95
Re: Attributes - Change Price by Percent

So was a solution found for this ?

the-sandman's picture
Offline
Joined: 02/10/2009
Juice: 5
Solution

Hallo,

I have a quick and dirty solution for your problem, because I have had the same problem.
You just to have to implement the following two functions in your existing or a new module:

function hook_cart_item($op, &$item)
{
  switch ($op)
  {
    case 'load':
      $options = _uc_cart_product_get_options($item);

      $op_costs = 0;
      $op_prices = 0;
      $op_weight = 0;

      foreach ($options as $option)
      {
        $op_costs += $option['cost'];
        $op_prices += $option['price'];
        $op_weight += $option['weight'];
      }
     
      $item->cost -= $op_costs;
      $item->price -= $op_prices;
      $item->weight -= $op_weight;
     
      $item->cost *= (!empty($op_costs) ? ($op_costs / 100) : 1); //If no percent-value is set, take the default value by multiply the value with 1.
      $item->price *= (!empty($op_prices) ? ($op_prices / 100) : 1); //If no percent-value is set, take the default value by multiply the value with 1.
      $item->weight *= (!empty($op_weight) ? ($op_weight / 100) : 1); //If no percent-value is set, take the default value by multiply the value with 1.

      $combination = array();
      foreach ((array)$item->data['attributes'] as $aid => $value)
      {
        if (is_numeric($value))
        {
          $attribute = uc_attribute_load($aid, $item->nid, 'product');
          if ($attribute && ($attribute->display == 1 || $attribute->display == 2))
          {
            $combination[$aid] = $value;
          }
        }
      }
     
      ksort($combination);

      $result = db_query("SELECT
          model
        FROM {uc_product_adjustments}
        WHERE nid = %d
        AND combination LIKE '%s'",
      $item->nid, serialize($combination));
     
      $model = db_result($result);

      if (!empty($model))
      {
        $item->model = $model;
      }
    break;
  }
}

This functions substract the static options-values wich was added before and transform the static option-values in percent-values.

function hook_form_uc_attribute_options_form_alter(&$form, &$form_state)
{
  if (is_array($form['options']))
  {
    foreach ($form['options'] as $key => $option)
    {
      if (is_numeric($key))
      {
        $form['options'][$key]['cost']['#value'] = str_replace(variable_get('uc_currency_sign', '$'), '%', $form['options'][$key]['cost']['#value']);
        $form['options'][$key]['price']['#value'] = str_replace(variable_get('uc_currency_sign', '$'), '%', $form['options'][$key]['price']['#value']);
      }
    }
  }
}

This function rewrite text of the currency to a text with "%"

I think this is all to get percent-support on option-values. When you now enter a value (e.g. 150) to an option of a product, the new price of the product should be [price]*1,5 (because of 150%).

I would be nice to notify me, if something is wrong.

Best regards from Germany
the-sandman

lauraatamysragbag's picture
Offline
Joined: 02/24/2010
Juice: 68
Re: Attributes - Change Price by Percent

Someone made a patch called multipliers. You can find it here: http://www.ubercart.org/forum/ideas_and_suggestions/4582/price_adjustmen...