Skip to content

Commit

Permalink
#1029956 by rszrama: add an API function and Views integration for li…
Browse files Browse the repository at this point in the history
…ne item titles and use the field in the default cart Views linked to the display path if it exists.
  • Loading branch information
rszrama committed Feb 19, 2011
1 parent e0a1d1a commit 9d9830d
Show file tree
Hide file tree
Showing 9 changed files with 370 additions and 228 deletions.
2 changes: 2 additions & 0 deletions modules/cart/commerce_cart.module
Expand Up @@ -315,6 +315,8 @@ function commerce_cart_block_view($delta) {
$content = theme('commerce_cart_empty_block');
}
else {
drupal_add_css(drupal_get_path('module', 'commerce_cart') . '/theme/commerce_cart.css');

// Build the variables array to send to the cart block template.
$variables = array(
'order' => $order,
Expand Down
4 changes: 4 additions & 0 deletions modules/cart/includes/commerce_cart.checkout_pane.inc
Expand Up @@ -44,6 +44,8 @@ function commerce_cart_contents_pane_settings_form($checkout_pane) {
function commerce_cart_contents_pane_checkout_form($form, &$form_state, $checkout_pane, $order) {
$pane_form = array();

drupal_add_css(drupal_get_path('module', 'commerce_cart') . '/theme/commerce_cart.css');

// Extract the View and display keys from the cart contents pane setting.
list($view_id, $display_id) = explode('|', variable_get('commerce_cart_contents_pane_view', 'commerce_cart_summary|default'));

Expand All @@ -59,6 +61,8 @@ function commerce_cart_contents_pane_checkout_form($form, &$form_state, $checkou
* Review checkout pane.
*/
function commerce_cart_contents_pane_review($form, $form_state, $checkout_pane, $order) {
drupal_add_css(drupal_get_path('module', 'commerce_cart') . '/theme/commerce_cart.css');

// Extract the View and display keys from the cart contents pane setting.
list($view_id, $display_id) = explode('|', variable_get('commerce_cart_contents_pane_view', 'commerce_cart_summary|default'));

Expand Down
2 changes: 2 additions & 0 deletions modules/cart/includes/commerce_cart.pages.inc
Expand Up @@ -43,6 +43,8 @@ function commerce_cart_view() {
$content = theme('commerce_cart_empty_page');
}
else {
drupal_add_css(drupal_get_path('module', 'commerce_cart') . '/theme/commerce_cart.css');

// Add the form for editing the cart contents.
$content = commerce_embed_view('commerce_cart_form', 'default', array($order->order_id));
}
Expand Down
507 changes: 286 additions & 221 deletions modules/cart/includes/views/commerce_cart.views_default.inc

Large diffs are not rendered by default.

20 changes: 20 additions & 0 deletions modules/cart/theme/commerce_cart.css
@@ -0,0 +1,20 @@
/* $Id$ */

.view-commerce-cart-block tr {
vertical-align: top;
}

.view-commerce-cart-block .views-field-quantity {
white-space: nowrap;
}

.view-commerce-cart-block td.price,
.view-commerce-cart-form td.price,
.view-commerce-cart-summary td.price {
white-space: nowrap;
}

.view-commerce-cart-form tr,
.view-commerce-cart-summary tr {
vertical-align: top;
}
1 change: 1 addition & 0 deletions modules/line_item/commerce_line_item.info
Expand Up @@ -13,6 +13,7 @@ files[] = includes/commerce_line_item.controller.inc
files[] = includes/views/handlers/commerce_line_item_handler_area_line_item_summary.inc
files[] = includes/views/handlers/commerce_line_item_handler_area_line_item_actions.inc
files[] = includes/views/handlers/commerce_line_item_handler_argument_line_item_line_item_id.inc
files[] = includes/views/handlers/commerce_line_item_handler_field_line_item_title.inc
files[] = includes/views/handlers/commerce_line_item_handler_field_line_item_type.inc
files[] = includes/views/handlers/commerce_line_item_handler_filter_line_item_type.inc
files[] = includes/views/handlers/commerce_line_item_handler_field_edit.inc
Expand Down
27 changes: 21 additions & 6 deletions modules/line_item/commerce_line_item.module
Expand Up @@ -619,6 +619,26 @@ function commerce_line_item_access($op, $line_item, $account = NULL) {
return FALSE;
}

/**
* Returns the title of a line item based on its type.
*
* Titles are returned sanitized and so do not need to be sanitized again prior
* to display.
*
* @param $line_item
* The line item object whose title should be returned.
*
* @return
* The type-dependent title of the line item.
*/
function commerce_line_item_title($line_item) {
// Find the line item type's title callback.
$line_item_type = commerce_line_item_type_load($line_item->type);
$title_callback = commerce_line_item_type_callback($line_item_type, 'title');

return $title_callback ? $title_callback($line_item) : '';
}

/**
* Implements hook_field_info().
*/
Expand Down Expand Up @@ -853,13 +873,8 @@ function commerce_line_item_field_widget_form(&$form, &$form_state, $field, $ins
'#default_value' => FALSE,
);

// The display title should come from the line item type.
$line_item_type = commerce_line_item_type_load($line_item->type);

$title_callback = commerce_line_item_type_callback($line_item_type, 'title');

$element['line_items'][$line_item_id]['title'] = array(
'#markup' => $title_callback ? $title_callback($line_item) : '',
'#markup' => commerce_line_item_title($line_item),
);

$element['line_items'][$line_item_id]['line_item_label'] = array(
Expand Down
11 changes: 10 additions & 1 deletion modules/line_item/includes/views/commerce_line_item.views.inc
Expand Up @@ -62,9 +62,18 @@ function commerce_line_item_views_data() {

// TODO: Expose the display view build mode.

// Expose the type-dependent line item title.
$data['commerce_line_item']['line_item_title'] = array(
'field' => array(
'title' => t('Title'),
'help' => t('The title of the line item determined by its type.'),
'handler' => 'commerce_line_item_handler_field_line_item_title',
),
);

// Expose the line item label.
$data['commerce_line_item']['line_item_label'] = array(
'title' => t('Line item label'),
'title' => t('Label'),
'help' => t('The label of the line item.'),
'field' => array(
'handler' => 'views_handler_field',
Expand Down
@@ -0,0 +1,24 @@
<?php
// $Id$

/**
* Field handler to return a line item's title.
*/
class commerce_line_item_handler_field_line_item_title extends views_handler_field {
function construct() {
parent::construct();

$this->additional_fields['line_item_id'] = 'line_item_id';
}

function query() {
$this->ensure_my_table();
$this->add_additional_fields();
}

function render($values) {
// Load the line item and return its title.
$line_item = commerce_line_item_load($values->{$this->aliases['line_item_id']});
return commerce_line_item_title($line_item);
}
}

0 comments on commit 9d9830d

Please sign in to comment.