Skip navigation
Help

hook_uc_product_alter

7 uc_product.api.php hook_uc_product_alter(&$node)

Make alterations to a specific variant of a product node.

Parameters

$node: The product node to be altered.

Related topics

3 functions implement hook_uc_product_alter()

1 invocation of hook_uc_product_alter()

File

ubercart/uc_product/uc_product.api.php, line 19
Hooks provided by the Product module.

Code

function hook_uc_product_alter(&$node) {
  if (isset($node->data['attributes']) && is_array($node->data['attributes'])) {
    $options = _uc_cart_product_get_options($node);
    foreach ($options as $option) {
      $node->cost += $option['cost'];
      $node->price += $option['price'];
      $node->weight += $option['weight'];
    }

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

    $model = db_query("SELECT model FROM {uc_product_adjustments} WHERE nid = :nid AND combination LIKE :combo", array(':nid' => $node->nid, ':combo' => serialize($combination)))->fetchField();

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