Since there is the great uc_views module out there, I thought it would be fun to add Draggable support to the Ubercart Weight field for products, AKA "List Postion".

I've attached my module code. Requires uc_views

I couldn't think of a good reason to enable the "Parent" function, but I also don't know that I could disable it, either. I suppose we could add an error message?

CommentFileSizeAuthor
draggableviews_ubercart.tgz1.22 KBliberatr

Comments

sevi’s picture

I couldn't think of a good reason to enable the "Parent" function, but I also don't know that I could disable it, either. I suppose we could add an error message?

I think documentation would be enough.

I've attached my module code. Requires uc_views

Thanks. Would you like to create a new project or do you want me to add this handler to the DraggableViews Family :)

EDDYL’s picture

I installed both views and draggableviews_ubercart but I haven't figured how to configure it properly.

Could you make a small tutorial on how to build a view that would allow us to draft products easily. (or add such code directly in the module so that people just have to adapt it to their needs.)

Regards,

Edouard

liberatr’s picture

1. Install draggableviews_ubercart
2. Make sure you assign the "Allow Reordering" permission to any user roles who will be able to reorder products
3. Create a new View
4. Assign filters - "Node: Is a product (True)"
5. Assign Sort criteria - "Product: List position (asc)"
6. Add Fields - "Title"
7. Add Fields - "Product: List postion" (list position may not be the first field in the list)
8. Add any other desired fields. "Product: Sell Price" and "Content: Image" are recommended
9. Set display Style to "Draggable Table"
10. Under Settings for Draggable Table > Page: Style options: Draggable Table Settings, Set the Order Field - Field: List Position - Handler: Ubercart
11. Create a Page display
12. Provide a path for the Page - example: admin/store/products/ordering
13. Set Access restrictions for the Page - Permission: edit all products (or by role if desired)
14. You may also wish to edit Items per page, or add an exposed filter for Taxonomy Term: Catalog (dropdown), Node: Published filter, or other fields

liberatr’s picture

You can use the "Import" feature of Views to create a new view using this code:

$view = new view;
$view->name = 'uc_products_ordering';
$view->description = 'Drag to reorder products.';
$view->tag = 'Ubercart';
$view->view_php = '';
$view->base_table = 'node';
$view->is_cacheable = FALSE;
$view->api_version = 2;
$view->disabled = FALSE; /* Edit this to true to make a default view disabled initially */
$handler = $view->new_display('default', 'Defaults', 'default');
$handler->override_option('fields', array(
  'title' => array(
    'label' => 'Title',
    'link_to_node' => 1,
    'exclude' => 0,
    'id' => 'title',
    'table' => 'node',
    'field' => 'title',
    'relationship' => 'none',
  ),
  'sell_price' => array(
    'label' => 'Sell price',
    'exclude' => 0,
    'id' => 'sell_price',
    'table' => 'uc_products',
    'field' => 'sell_price',
    'relationship' => 'none',
  ),
  'buyitnowbutton' => array(
    'label' => 'Buy it now button',
    'exclude' => 0,
    'id' => 'buyitnowbutton',
    'table' => 'uc_products',
    'field' => 'buyitnowbutton',
    'relationship' => 'none',
  ),
  'field_image_cache_fid' => array(
    'label' => '',
    'link_to_node' => 1,
    'label_type' => 'widget',
    'format' => 'product_list_linked',
    'multiple' => array(
      'group' => 1,
      'multiple_number' => '1',
      'multiple_from' => '0',
      'multiple_reversed' => 0,
    ),
    'exclude' => 0,
    'id' => 'field_image_cache_fid',
    'table' => 'node_data_field_image_cache',
    'field' => 'field_image_cache_fid',
    'relationship' => 'none',
    'override' => array(
      'button' => 'Override',
    ),
  ),
  'ordering' => array(
    'label' => 'List position',
    'alter' => array(
      'alter_text' => 0,
      'text' => '',
      'make_link' => 0,
      'path' => '',
      'link_class' => '',
      'alt' => '',
      'prefix' => '',
      'suffix' => '',
      'target' => '',
      'help' => '',
      'trim' => 0,
      'max_length' => '',
      'word_boundary' => 1,
      'ellipsis' => 1,
      'strip_tags' => 0,
      'html' => 0,
    ),
    'empty' => '0',
    'hide_empty' => 0,
    'empty_zero' => 1,
    'set_precision' => FALSE,
    'precision' => 0,
    'decimal' => '.',
    'separator' => ',',
    'prefix' => '',
    'suffix' => '',
    'exclude' => 0,
    'id' => 'ordering',
    'table' => 'uc_products',
    'field' => 'ordering',
    'relationship' => 'none',
  ),
));
$handler->override_option('sorts', array(
  'ordering' => array(
    'order' => 'ASC',
    'id' => 'ordering',
    'table' => 'uc_products',
    'field' => 'ordering',
    'relationship' => 'none',
  ),
));
$handler->override_option('filters', array(
  'status' => array(
    'operator' => '=',
    'value' => 1,
    'group' => '0',
    'exposed' => FALSE,
    'expose' => array(
      'operator' => FALSE,
      'label' => '',
    ),
    'id' => 'status',
    'table' => 'node',
    'field' => 'status',
    'relationship' => 'none',
  ),
  'is_product' => array(
    'operator' => '=',
    'value' => 1,
    'group' => '0',
    'exposed' => FALSE,
    'expose' => array(
      'operator' => FALSE,
      'label' => '',
    ),
    'id' => 'is_product',
    'table' => 'uc_products',
    'field' => 'is_product',
    'relationship' => 'none',
  ),
  'tid' => array(
    'operator' => 'or',
    'value' => array(
      '1' => '1',
      '2' => '2',
      '6' => '6',
    ),
    'group' => '0',
    'exposed' => TRUE,
    'expose' => array(
      'use_operator' => 0,
      'operator' => 'tid_op',
      'identifier' => 'tid',
      'label' => 'Catalog',
      'optional' => 0,
      'single' => 1,
      'remember' => 0,
      'reduce' => 1,
    ),
    'type' => 'select',
    'limit' => TRUE,
    'vid' => '1',
    'id' => 'tid',
    'table' => 'term_node',
    'field' => 'tid',
    'hierarchy' => 0,
    'override' => array(
      'button' => 'Override',
    ),
    'relationship' => 'none',
    'reduce_duplicates' => 0,
  ),
));
$handler->override_option('access', array(
  'type' => 'perm',
  'perm' => 'edit all products',
));
$handler->override_option('cache', array(
  'type' => 'none',
));
$handler->override_option('title', 'Product Ordering');
$handler->override_option('use_pager', '1');
$handler->override_option('style_plugin', 'draggabletable');
$handler->override_option('style_options', array(
  'override' => 1,
  'sticky' => 0,
  'order' => 'asc',
  'columns' => array(
    'title' => 'title',
    'sell_price' => 'sell_price',
    'buyitnowbutton' => 'buyitnowbutton',
    'field_image_cache_fid' => 'field_image_cache_fid',
    'ordering' => 'ordering',
  ),
  'info' => array(
    'title' => array(
      'sortable' => 0,
      'separator' => '',
    ),
    'sell_price' => array(
      'sortable' => 0,
      'separator' => '',
    ),
    'buyitnowbutton' => array(
      'separator' => '',
    ),
    'field_image_cache_fid' => array(
      'separator' => '',
    ),
    'ordering' => array(
      'separator' => '',
    ),
  ),
  'default' => '-1',
  'tabledrag_hierarchy' => array(
    'field' => 'none',
    'handler' => 'native',
  ),
  'tabledrag_order' => array(
    'field' => 'ordering',
    'handler' => 'ubercart',
  ),
  'draggableviews_extensions' => array(
    'extension_top' => '3',
    'extension_bottom' => '3',
  ),
  'tabledrag_order_visible' => array(
    'visible' => 0,
  ),
  'tabledrag_hierarchy_visible' => array(
    'visible' => 0,
  ),
  'draggableviews_depth_limit' => '-1',
  'draggableviews_repair' => array(
    'repair' => 'repair',
  ),
  'tabledrag_types_add' => 'Add type',
  'tabledrag_expand' => array(
    'expand_links' => 'expand_links',
    'collapsed' => 0,
    'by_uid' => 0,
  ),
  'tabledrag_lock' => array(
    'lock' => 0,
  ),
  'draggableviews_default_on_top' => '1',
  'draggableviews_button_text' => 'Save order',
  'draggableviews_arguments' => array(
    'use_args' => 0,
  ),
));
$handler = $view->new_display('page', 'Page', 'page_1');
$handler->override_option('path', 'admin/store/products/ordering');
$handler->override_option('menu', array(
  'type' => 'normal',
  'title' => 'Product Ordering',
  'description' => '',
  'weight' => '0',
  'name' => 'navigation',
));
$handler->override_option('tab_options', array(
  'type' => 'none',
  'title' => '',
  'description' => '',
  'weight' => 0,
));
liberatr’s picture

Sevi, I guess you never did add this to the DraggableViews family, but that was certainly my intention behind uploading the code.

I think there are enough similar features behind most Ubercart sites that it might make sense to include that default view code as well... it could be disabled by default, with a line in the readme to tell people to turn it on.

stefan81’s picture

subscribe

summit’s picture

Subscribing, greetings, Martijn

mattcasey’s picture

Wow, awesome thanks for this! It should definitely be part of Ubercart/Draggable Views

zach harkey’s picture

I can't believe how well this works. Definitely include this functionality and the uc_products_ordering view with the core module.

Adriano72’s picture

Huge Thanks! It works like a charm!!
Ciao

Adriano

jasonabc’s picture

Just a note to anyone who can't get this to work (as I initially could not) - if you upgrade to latest versions of uc_views, Ubercart and Views this will work great (I had slightly outdated versions of all 3 and the page where the order can be changed was breaking). Thanks to the authors for this really great and much needed feature.

sumit.ggn’s picture

Hi Guys,

I did what all is suggested here and this works very well until we have a big number of records to be sorted for a product category.

I have a category where it has more than 250 products. Initially, there was a paging on this view which I removed so that I have all the products on a single page. But when I save the ordering form, I see it saves the order from 0-127 and after that all the records keep the order value as 127 only.

Can someone throw a light on this issue? or ask if you need any more details.

Thanks
Sumit

istryker’s picture

Category: Task » Feature request
Issue summary: View changes
Status: Active » Closed (won't fix)

Drupal 6.x is no longer supported. Closing issue.