function uc_attribute_uc_product_alter in Ubercart 8.4
Same name and namespace in other branches
- 7.3 uc_attribute/uc_attribute.module \uc_attribute_uc_product_alter()
Implements hook_uc_product_alter().
File
- uc_attribute/
uc_attribute.module, line 355 - Ubercart Attribute module.
Code
function uc_attribute_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->value += $option['cost'];
$node->price->value += $option['price'];
$node->display_price += $option['price'];
$node->weight->value += $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);
$connection = \Drupal::database();
$model = $connection
->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;
}
}
}