function uc_product_kit_node_view in Ubercart 8.4
Implements hook_node_view().
File
- uc_product_kit/
uc_product_kit.module, line 668 - The product kit module for Ubercart.
Code
function uc_product_kit_node_view(array &$build, NodeInterface $node, EntityViewDisplayInterface $display, $view_mode) {
if ($node
->getType() != 'product_kit') {
return;
}
uc_product_view_product($build, $node, $display, $view_mode);
$variant = $build['#node'];
// Calculate the display price.
$display_price = 0;
$suffixes = [];
if ($node->mutable != UC_PRODUCT_KIT_MUTABLE) {
// If this is a non-mutable kit, then sum the display price of each of the
// component products.
foreach ($variant->products as $product) {
$component = uc_product_load_variant($product
->id(), $product->data);
$display_price += $component->display_price * $product->qty;
$suffixes += $component->display_price_suffixes;
}
}
else {
// For mutable, just use the price.
$display_price = $variant->price->value;
$suffixes = [];
}
$build['display_price']['#value'] = $display_price;
$build['display_price']['#suffixes'] = $suffixes;
if ($node->mutable != UC_PRODUCT_KIT_UNMUTABLE_NO_LIST) {
$build['products'] = [
'#weight' => 6,
];
$i = 0;
foreach ($node->products as $product) {
$build['products'][$product
->id()]['qty'] = [
'#theme' => 'uc_product_kit_list_item',
'#product' => $product,
'#prefix' => '<div class="product-qty">',
'#suffix' => '</div>',
];
$build['products'][$product
->id()]['#weight'] = $i++;
}
}
}