function commerce_product_attributes_field_attach_view_alter in Commerce Product Attributes 7
Implements hook_field_attach_view_alter().
We use this hook to replace the default line item.
File
- ./
commerce_product_attributes.module, line 160 - This module adds some improvements to the Drupal Commerce core.
Code
function commerce_product_attributes_field_attach_view_alter(&$output, $context) {
foreach ($output as $field_name => $element) {
if (!empty($element['#formatter']) && $element['#formatter'] == 'commerce_cart_add_to_cart_form') {
foreach (element_children($element) as $key) {
if (!isset($element[$key]['#arguments'])) {
continue;
}
$arguments = $element[$key]['#arguments'];
$line_item = $arguments['line_item'];
if (isset($_GET['line_item_id'])) {
$new_line_item = commerce_line_item_load($_GET['line_item_id']);
if (!empty($new_line_item) && commerce_product_attributes_access_to_line_item($new_line_item)) {
$new_line_item->data['context']['product_ids'] = $line_item->data['context']['product_ids'];
$new_line_item->data['context']['add_to_cart_combine'] = $line_item->data['context']['add_to_cart_combine'];
$output[$field_name][$key]['#arguments']['line_item'] = $new_line_item;
}
}
}
}
}
}