You are here

function uc_attribute_uc_order_product_alter in Ubercart 8.4

Same name and namespace in other branches
  1. 7.3 uc_attribute/uc_attribute.module \uc_attribute_uc_order_product_alter()

Implements hook_uc_order_product_alter().

File

uc_attribute/uc_attribute.module, line 321
Ubercart Attribute module.

Code

function uc_attribute_uc_order_product_alter(OrderProductInterface &$product, OrderInterface $order) {

  // Convert the attribute and option ids to their current names. This
  // preserves the important data in case the attributes or options are
  // changed later.
  if (!empty($product->data->attributes)) {
    $attributes_keys = array_keys($product->data->attributes);
    if (is_numeric(array_shift($attributes_keys))) {
      $attributes = [];
      $options = _uc_cart_product_get_options($product);
      foreach ($options as $option) {
        $attributes[$option['attribute']][$option['oid']] = $option['name'];
      }
      $product->data->attributes = $attributes;
    }
  }
}