You are here

function commerce_product_attributes_attribute_field in Commerce Product Attributes 7

Implements hook_attribute_field()

File

./commerce_product_attributes.module, line 53
This module adds some improvements to the Drupal Commerce core.

Code

function commerce_product_attributes_attribute_field(&$element, &$line_item) {
  if ($line_item->type != 'product') {
    return;
  }

  // Add displayed attributes on product page also in shopping cart:
  $line_item_wrapper = entity_metadata_wrapper('commerce_line_item', $line_item);
  $product = $line_item_wrapper->commerce_product
    ->value();
  $product->bundle = 'product';
  field_attach_prepare_view('commerce_product', array(
    $product->product_id => $product,
  ), 'attribute_view');
  $output = field_attach_view('commerce_product', $product, 'attribute_view');
  $element['attributes'][] = array(
    '#markup' => '<div class="commerce-product-attributes-wrapper">' . drupal_render($output) . '</div>',
  );
}