I think that we'd need to provide a delete link for line item types, but probably restrict it only to those provided by this module as it won't make any sense to delete code-provided line item types. They would just reappear as if nothing happened.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

rfay’s picture

Definitely. Thought I'd already opened this issue :-) - There's even commented-out code for this.

The complexity is that line item types that have content shouldn't be deleted. So it needs that code.

ryan.gibson’s picture

yep.

Subscribe.

pcambra’s picture

Status: Active » Needs review
FileSize
7.51 KB

Here's an initial patch that includes the basic functionality for the delete.

I'd appreciate some testing prior to commit this.

I think we'd probably need to adapt the code to be in different files (types.inc and forms.inc) for edit and delete the same way that product ui does before putting this into commerce itself.
Also we probably need some breadcrumb magic :) but this is good to go after some review.

I'm also including some basic fixes as labels and so.

rfay’s picture

I haven't tested this, but a read-through of the patch looks like it does what needs to be done. Thanks for the cleanup too.

+++ b/commerce_custom_line_items.module
@@ -355,8 +363,78 @@ function commerce_custom_line_items_line_item_type_form_wrapper($type) {
+  // Don't allow deletion of product types that have products already.

Line items in the comment, of course.

rfay’s picture

Just gave it a test drive and it looks good to me.

Note that dangling references to the old line type in the display settings of a content type will cause ugly entity exceptions. But I think this is true everywhere.

pcambra’s picture

Status: Needs review » Fixed

Ooops thanks :)

Reviewed and commited!

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

sibiru’s picture

Category: task » support
Status: Closed (fixed) » Active

Hi, sorry to open this issue again.

I need help how to delete custom line item type
I got this message

There are 39 line items of this type. It cannot be deleted.

How to find the product that has this line item type?
I've tried using Views but cannot delete it but it wont works

Exported Views

$view = new view();
$view->name = 'commerce_line_item_table';
$view->description = 'Display a set of line items in a table.';
$view->tag = 'commerce';
$view->base_table = 'commerce_line_item';
$view->human_name = 'Line items';
$view->core = 0;
$view->api_version = '3.0';
$view->disabled = FALSE; /* Edit this to true to make a default view disabled initially */

/* Display: Defaults */
$handler = $view->new_display('default', 'Defaults', 'default');
$handler->display->display_options['use_more_always'] = FALSE;
$handler->display->display_options['access']['type'] = 'none';
$handler->display->display_options['cache']['type'] = 'none';
$handler->display->display_options['query']['type'] = 'views_query';
$handler->display->display_options['query']['options']['query_comment'] = FALSE;
$handler->display->display_options['exposed_form']['type'] = 'basic';
$handler->display->display_options['pager']['type'] = 'none';
$handler->display->display_options['style_plugin'] = 'table';
$handler->display->display_options['style_options']['columns'] = array(
  'line_item_id' => 'line_item_id',
  'type' => 'type',
  'line_item_title' => 'line_item_title',
  'line_item_label' => 'line_item_title',
  'commerce_unit_price' => 'commerce_unit_price',
  'quantity' => 'quantity',
  'commerce_total' => 'commerce_total',
);
$handler->display->display_options['style_options']['default'] = '-1';
$handler->display->display_options['style_options']['info'] = array(
  'line_item_id' => array(
    'sortable' => 0,
    'default_sort_order' => 'asc',
    'align' => '',
    'separator' => '',
  ),
  'type' => array(
    'sortable' => 0,
    'default_sort_order' => 'asc',
    'align' => '',
    'separator' => '',
  ),
  'line_item_title' => array(
    'align' => '',
    'separator' => ' ',
  ),
  'line_item_label' => array(
    'sortable' => 0,
    'default_sort_order' => 'asc',
    'align' => '',
    'separator' => '',
  ),
  'commerce_unit_price' => array(
    'sortable' => 0,
    'default_sort_order' => 'asc',
    'align' => '',
    'separator' => '',
  ),
  'quantity' => array(
    'sortable' => 0,
    'default_sort_order' => 'asc',
    'align' => '',
    'separator' => '',
  ),
  'commerce_total' => array(
    'sortable' => 0,
    'default_sort_order' => 'asc',
    'align' => 'views-align-right',
    'separator' => '',
  ),
);
/* No results behavior: Global: Text area */
$handler->display->display_options['empty']['area']['id'] = 'area';
$handler->display->display_options['empty']['area']['table'] = 'views';
$handler->display->display_options['empty']['area']['field'] = 'area';
$handler->display->display_options['empty']['area']['label'] = 'Empty line item text.';
$handler->display->display_options['empty']['area']['content'] = 'No line items found.';
$handler->display->display_options['empty']['area']['format'] = 'plain_text';
/* Field: Commerce Line Item: Line item ID */
$handler->display->display_options['fields']['line_item_id']['id'] = 'line_item_id';
$handler->display->display_options['fields']['line_item_id']['table'] = 'commerce_line_item';
$handler->display->display_options['fields']['line_item_id']['field'] = 'line_item_id';
$handler->display->display_options['fields']['line_item_id']['label'] = 'ID';
$handler->display->display_options['fields']['line_item_id']['exclude'] = TRUE;
/* Field: Commerce Line Item: Type */
$handler->display->display_options['fields']['type']['id'] = 'type';
$handler->display->display_options['fields']['type']['table'] = 'commerce_line_item';
$handler->display->display_options['fields']['type']['field'] = 'type';
$handler->display->display_options['fields']['type']['exclude'] = TRUE;
/* Field: Commerce Line Item: Title */
$handler->display->display_options['fields']['line_item_title']['id'] = 'line_item_title';
$handler->display->display_options['fields']['line_item_title']['table'] = 'commerce_line_item';
$handler->display->display_options['fields']['line_item_title']['field'] = 'line_item_title';
/* Field: Commerce Line Item: Label */
$handler->display->display_options['fields']['line_item_label']['id'] = 'line_item_label';
$handler->display->display_options['fields']['line_item_label']['table'] = 'commerce_line_item';
$handler->display->display_options['fields']['line_item_label']['field'] = 'line_item_label';
$handler->display->display_options['fields']['line_item_label']['alter']['alter_text'] = TRUE;
$handler->display->display_options['fields']['line_item_label']['alter']['text'] = '([line_item_label])';
/* Field: Commerce Line item: Unit price */
$handler->display->display_options['fields']['commerce_unit_price']['id'] = 'commerce_unit_price';
$handler->display->display_options['fields']['commerce_unit_price']['table'] = 'field_data_commerce_unit_price';
$handler->display->display_options['fields']['commerce_unit_price']['field'] = 'commerce_unit_price';
$handler->display->display_options['fields']['commerce_unit_price']['click_sort_column'] = 'amount';
$handler->display->display_options['fields']['commerce_unit_price']['type'] = 'commerce_price_formatted_amount';
/* Field: Commerce Line Item: Quantity */
$handler->display->display_options['fields']['quantity']['id'] = 'quantity';
$handler->display->display_options['fields']['quantity']['table'] = 'commerce_line_item';
$handler->display->display_options['fields']['quantity']['field'] = 'quantity';
$handler->display->display_options['fields']['quantity']['precision'] = '0';
/* Field: Commerce Line item: Total */
$handler->display->display_options['fields']['commerce_total']['id'] = 'commerce_total';
$handler->display->display_options['fields']['commerce_total']['table'] = 'field_data_commerce_total';
$handler->display->display_options['fields']['commerce_total']['field'] = 'commerce_total';
$handler->display->display_options['fields']['commerce_total']['click_sort_column'] = 'amount';
$handler->display->display_options['fields']['commerce_total']['type'] = 'commerce_price_formatted_amount';
/* Sort criterion: Commerce Line Item: Line item ID */
$handler->display->display_options['sorts']['line_item_id']['id'] = 'line_item_id';
$handler->display->display_options['sorts']['line_item_id']['table'] = 'commerce_line_item';
$handler->display->display_options['sorts']['line_item_id']['field'] = 'line_item_id';
/* Contextual filter: Commerce Line Item: Line item ID */
$handler->display->display_options['arguments']['line_item_id']['id'] = 'line_item_id';
$handler->display->display_options['arguments']['line_item_id']['table'] = 'commerce_line_item';
$handler->display->display_options['arguments']['line_item_id']['field'] = 'line_item_id';
$handler->display->display_options['arguments']['line_item_id']['default_action'] = 'empty';
$handler->display->display_options['arguments']['line_item_id']['default_argument_type'] = 'fixed';
$handler->display->display_options['arguments']['line_item_id']['summary']['number_of_records'] = '0';
$handler->display->display_options['arguments']['line_item_id']['summary']['format'] = 'default_summary';
$handler->display->display_options['arguments']['line_item_id']['summary_options']['items_per_page'] = '25';
$handler->display->display_options['arguments']['line_item_id']['break_phrase'] = TRUE;
/* Filter criterion: Commerce Line Item: Line item is of a product line item type */
$handler->display->display_options['filters']['product_line_item_type']['id'] = 'product_line_item_type';
$handler->display->display_options['filters']['product_line_item_type']['table'] = 'commerce_line_item';
$handler->display->display_options['filters']['product_line_item_type']['field'] = 'product_line_item_type';
$handler->display->display_options['filters']['product_line_item_type']['value'] = '1';
$translatables['commerce_line_item_table'] = array(
  t('Defaults'),
  t('more'),
  t('Apply'),
  t('Reset'),
  t('Sort by'),
  t('Asc'),
  t('Desc'),
  t('Empty line item text.'),
  t('No line items found.'),
  t('ID'),
  t('.'),
  t(','),
  t('Type'),
  t('Title'),
  t('Label'),
  t('([line_item_label])'),
  t('Unit price'),
  t('Quantity'),
  t('Total'),
  t('All'),
);