You are here

function hook_uc_product_alter in Ubercart 8.4

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

Make alterations to a specific variant of a product node.

Parameters

\Drupal\node\NodeInterface $node: The product node to be altered.

4 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().
uc_tax_uc_product_alter in uc_tax/uc_tax.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 21
Hooks provided by the Product module.

Code

function hook_uc_product_alter(NodeInterface $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 = [];
    foreach ($node->data['attributes'] as $aid => $value) {
      if (is_numeric($value)) {
        $attribute = uc_attribute_load($aid, $node
          ->id(), '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", [
      ':nid' => $node
        ->id(),
      ':combo' => serialize($combination),
    ])
      ->fetchField();
    if (!empty($model)) {
      $node->model = $model;
    }
  }
}