You are here

function uc_attribute_cart_item in Ubercart 6.2

Same name and namespace in other branches
  1. 5 uc_attribute/uc_attribute.module \uc_attribute_cart_item()

Implements hook_cart_item().

File

uc_attribute/uc_attribute.module, line 554

Code

function uc_attribute_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;
      $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;
  }
}