You are here

function hook_uc_product_alter in Ubercart 7.3

Same name and namespace in other branches
  1. 8.4 uc_product/uc_product.api.php \hook_uc_product_alter()

Make alterations to a specific variant of a product node.

Parameters

$node: The product node to be altered.

3 functions implement hook_uc_product_alter()

Note: this list is generated by pattern matching, so it may include some functions that are not actually implementations of this hook.

uc_attribute_uc_product_alter in uc_attribute/uc_attribute.module
Implements hook_uc_product_alter().
uc_product_kit_uc_product_alter in uc_product_kit/uc_product_kit.module
Implements hook_uc_product_alter().
uc_product_uc_product_alter in uc_product/uc_product.module
Implements hook_uc_product_alter().
1 invocation of hook_uc_product_alter()
_uc_product_get_variant in uc_product/uc_product.module
Gets a specific, cloned, altered variant of a product node.

File

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;
    }
  }
}