Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function MYTHEME_commerce_price_formatted_components($variables) {
- global $user;
- $line_item_title = '';
- $order_number = '';
- $path_parts = explode('/', request_path() );
- if( sizeof($path_parts) == 4 && $path_parts[0] == 'user' && $path_parts[2] == 'orders') {
- $order = commerce_order_load($path_parts[3]);
- // dpm($order);
- }
- if( isset($order) && !$order )
- $order = commerce_cart_order_load($user->uid);
- if( isset($order) && $order) {
- foreach ($order->commerce_line_items['und'] as $line) {
- $line_item = commerce_line_item_load($line['line_item_id']);
- $line_item_wrapper = entity_metadata_wrapper('commerce_line_item', $line_item);
- // line item TYPE display title
- $line_item_type_title = commerce_line_item_type_get_name($line_item_wrapper->type->value());
- // for shipping line items
- if ($line_item_wrapper->type->value() == "shipping") {
- // shipping data
- $shipping_data = $line_item_wrapper->value()->data;
- // shipping method display title
- $line_item_title = $shipping_data['shipping_service']['title'];
- }
- }
- }
- // Add the CSS styling to the table.
- drupal_add_css(drupal_get_path('module', 'commerce_price') . '/theme/commerce_price.theme.css');
- // Build table rows out of the components.
- $rows = array();
- // dpm($variables['components']);
- foreach ($variables['components'] as $name => $component) {
- // dpm($component);
- if($component)
- $rows[] = array(
- 'data' => array(
- array(
- 'data' => ($component['title'] == 'Shipping' && $line_item_title ) ? $line_item_title : $component['title'],
- 'class' => array('component-title'),
- ),
- array(
- 'data' => $component['formatted_price'],
- 'class' => array('component-total'),
- ),
- ),
- 'class' => array(drupal_html_class('component-type-' . $name)),
- );
- }
- return theme('table', array('rows' => $rows, 'attributes' => array('class' => array('commerce-price-formatted-components'))));
- }
- function HOOK_commerce_price_formatted_components_alter(&$components, $item, $entity) {
- foreach ($entity->commerce_line_items['und'] as $line) {
- $line_item_wrapper = entity_metadata_wrapper('commerce_line_item', $line['line_item_id']);
- if ($line_item_wrapper->type->value() == "shipping") {
- $shipping_data = $line_item_wrapper->value()->data;
- $service_title = $shipping_data['shipping_service']['title'];
- break;
- }
- }
- if (isset($service_title)) {
- $components['shipping']['title'] = $service_title;
- }
- }
Add Comment
Please, Sign In to add comment