function _uc_product_get_variant in Ubercart 8.4
Same name and namespace in other branches
- 7.3 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.
array $data: Optional data to add to the product before invoking the alter hooks.
Return value
An variant of the product, altered based on the provided data.
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_product in uc_product/
uc_product.module - Renders product related content for product-type modules.
File
- uc_product/
uc_product.module, line 151 - 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::moduleHandler()
->alter('uc_product', $node);
$node->variant = TRUE;
if (!isset($node->data['module'])) {
$node->data['module'] = 'uc_product';
}
return $node;
}