5 replies [Last post]
freeyland's picture
Offline
Joined: 02/21/2008
Juice: 14
Was this information Helpful?

Hi,

I am developping a module where you can choose that an attribute is multiplied by the quantity or not. I need this because I want to sell ski-holidays. If a family wants insurrance, the attribte price needs to be multiplied by the quantity (= number of persons). If a family selects a reduction for children (1, 2 or 3 children), they only get this reduction once and should not be multiplied by the quantity.

To do this I used the hook cart_item but the problem is that the original attribute module is called after my own created atrribute module (uc_aattrb). SO the changes I've made are overwritten again. I tried to change the weight in the system table, but without success.

/**
* Implementation of hook_cart_item().
*/
function uc_aattrb_cart_item($op, &$item) {
  switch ($op) {
    case 'load':   
      $item->options = _uc_aattrb_cart_product_get_options($item);
        
      $op_costs = 0;
      $op_prices = 0;
      $op_weight = 0;
      foreach ($item->options as $option){
      if ($option['multiply_qty']=="yes"){
        $op_costs += $option['cost'];
        $op_prices1 += $option['price'];
        $op_cost1 += $option['cost'];
        $op_weight += $option['weight'];
    }else{
$op_prices2 += $option['price'];
$op_cost2 += $option['cost'];
    }
      }
      $item->cost += $op_costs;
      $item->weight += $op_weight;
      $op_costs += $option['cost'];
     
      $item->cost_multiply += $op_costs1;
      $item->cost_nomultiply += $op_costs2;
     
      $item->price_attributes_multiply += $op_prices1;
      $item->price_attributes_nomultiply += $op_prices2;
      $item->price_product += $item->price;
     
      if (!empty($item->data['model'])) {
        $item->model = $item->data['model'];
      }
      //echo '<pre>'. print_r($item, TRUE) .'</pre>';
      //echo "uc_aattrb_cart_item:". $item->price;
      //echo '<pre>'. print_r($item, TRUE) .'</pre>';
      //echo '<pre>3==>'. print_r($item, TRUE) .'</pre>';
      break;
  }
}
freeyland's picture
Offline
Joined: 02/21/2008
Juice: 14
Re: Attribute multiply by quantity / order of hooks

Sorry my mistake. It worked after changing the weight in drupal system table.

birdy1980's picture
Offline
Joined: 07/18/2008
Juice: 4
Module

Hello,

Where can I find this module. This is exactly the functionality I'm looking for.

Thanks

activelyOUT's picture
Offline
Joined: 04/20/2009
Juice: 70
Trying to use this for advertising system

I am trying to use this for an advertising system

((size of ad + type of ad)x number of pages they want it displayed on ) x number of weeks.

I think your code will help me get partially there.

Chris

Francois's picture
Offline
Joined: 08/19/2008
Juice: 387
Any luck

Has anyone gotten this to work?

--------
'Twas the end of the world, and you didn't even know it.

luketarplin's picture
Offline
Joined: 04/26/2010
Juice: 187
Re: Any luck

I have written an attribute quantity module, uc_attribute_quantity