You are here

function _uc_product_get_variant in Ubercart 7.3

Same name and namespace in other branches
  1. 8.4 uc_product/uc_product.module \_uc_product_get_variant()

Gets a specific, cloned, altered variant of a product node.

Generally, you should always use uc_product_load_variant() instead, except when node_load() cannot be invoked, e.g. when implementing hook_node_load().

Parameters

$node: The product node to alter. Throws an exception if this is already a product variant.

$data: Optional data to add to the product before invoking the alter hooks.

Return value

object An variant of the product, altered based on the provided data.

Throws

\Exception If the caller tries to create a variant of a variant.

2 calls to _uc_product_get_variant()
uc_product_load_variant in uc_product/uc_product.module
Loads a specific altered variant of a product node.
uc_product_view in uc_product/uc_product.module
Implements hook_view().

File

uc_product/uc_product.module, line 606
The product module for Ubercart.

Code

function _uc_product_get_variant($node, $data = FALSE) {
  if (!empty($node->variant)) {
    throw new Exception(t('Cannot create a variant of a variant.'));
  }
  $node = clone $node;
  if (!empty($data)) {
    $node->data = $data;
  }

  // Ensure that $node->data is an array (user module leaves it serialized).
  if (isset($node->data) && !is_array($node->data)) {
    $node->data = unserialize($node->data);
  }
  drupal_alter('uc_product', $node);
  $node->variant = TRUE;
  if (!isset($node->data['module'])) {
    $node->data['module'] = 'uc_product';
  }
  return $node;
}