Guest User

Untitled

a guest
Mar 18th, 2018
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.55 KB | None | 0 0
  1. function MYTHEME_commerce_price_formatted_components($variables) {
  2. global $user;
  3. $line_item_title = '';
  4. $order_number = '';
  5. $path_parts = explode('/', request_path() );
  6. if( sizeof($path_parts) == 4 && $path_parts[0] == 'user' && $path_parts[2] == 'orders') {
  7. $order = commerce_order_load($path_parts[3]);
  8. // dpm($order);
  9. }
  10. if( isset($order) && !$order )
  11. $order = commerce_cart_order_load($user->uid);
  12. if( isset($order) && $order) {
  13. foreach ($order->commerce_line_items['und'] as $line) {
  14. $line_item = commerce_line_item_load($line['line_item_id']);
  15. $line_item_wrapper = entity_metadata_wrapper('commerce_line_item', $line_item);
  16. // line item TYPE display title
  17. $line_item_type_title = commerce_line_item_type_get_name($line_item_wrapper->type->value());
  18. // for shipping line items
  19. if ($line_item_wrapper->type->value() == "shipping") {
  20. // shipping data
  21. $shipping_data = $line_item_wrapper->value()->data;
  22. // shipping method display title
  23. $line_item_title = $shipping_data['shipping_service']['title'];
  24. }
  25. }
  26. }
  27. // Add the CSS styling to the table.
  28. drupal_add_css(drupal_get_path('module', 'commerce_price') . '/theme/commerce_price.theme.css');
  29. // Build table rows out of the components.
  30. $rows = array();
  31. // dpm($variables['components']);
  32. foreach ($variables['components'] as $name => $component) {
  33. // dpm($component);
  34. if($component)
  35. $rows[] = array(
  36. 'data' => array(
  37. array(
  38. 'data' => ($component['title'] == 'Shipping' && $line_item_title ) ? $line_item_title : $component['title'],
  39. 'class' => array('component-title'),
  40. ),
  41. array(
  42. 'data' => $component['formatted_price'],
  43. 'class' => array('component-total'),
  44. ),
  45. ),
  46. 'class' => array(drupal_html_class('component-type-' . $name)),
  47. );
  48. }
  49. return theme('table', array('rows' => $rows, 'attributes' => array('class' => array('commerce-price-formatted-components'))));
  50. }
  51.  
  52. function HOOK_commerce_price_formatted_components_alter(&$components, $item, $entity) {
  53. foreach ($entity->commerce_line_items['und'] as $line) {
  54. $line_item_wrapper = entity_metadata_wrapper('commerce_line_item', $line['line_item_id']);
  55.  
  56. if ($line_item_wrapper->type->value() == "shipping") {
  57. $shipping_data = $line_item_wrapper->value()->data;
  58. $service_title = $shipping_data['shipping_service']['title'];
  59. break;
  60. }
  61. }
  62.  
  63. if (isset($service_title)) {
  64. $components['shipping']['title'] = $service_title;
  65. }
  66. }
Add Comment
Please, Sign In to add comment