as i understand, this module is limited to

if ($form_id == 'views_form_commerce_cart_form_default') {
    if (isset($form['edit_quantity'])) {
      $form['#attached']['js'][] = drupal_get_path('module', 'commerce_extra_quantity') . '/commerce_extra_quantity.js';
      $form['#attached']['css'][] = drupal_get_path('module', 'commerce_extra_quantity') . '/commerce_extra_quantity.css';
      foreach ($form['edit_quantity'] as $key => $value) {
        if (is_numeric($key) && drupal_substr($key, 0, 1) != '#' && is_array($value)) {
          $form['edit_quantity'][$key]['#theme_wrappers'] = array('quantity_plusminus_wrapper', 'form_element');
        }
      }
    }
  }

how to apply decrease/increase to any quantity field? thank you.

Comments

imho i think this "support request" should be actually a "feature request" if not a "task".

Commerce Extra Quantity full scenario:
Instead of having a checkbox on Commerce Extra settings page and some form alters, there should be:

  • Extra setting for the "Add to Cart form" formmater
  • - this could be as extra setting if the "Display a textfield quantity widget on the add to cart form." is checked
    or
    - independent setting : "Display a textfield with +/- quantity widget on the add to cart form."

  • New Quantity Views field handler that could be used as alternative to the current "Quantity text field" handler.
    - in "Shopping cart contents" pane there's a setting to change the summary cart view with a custom one
    - for Cart page : Commerce Cart View Override

indeed at this moment it easy/ready to use, but i think that way it will be more just.

Title:decrease/increase doesnt work Quantity input field custom view.Convert quantity decrease/increase functionality into a formatter
Category:support» feature

I think Vasike is on right track here. I was planning some point to convert this as it's own formatter but never thought far enough to think about views.

I would be happy to see this going that way! However, I'm little bit worried how this change would affect on sites using this feature already and built theming on top of it, but it's in alpha state, so I think it's forgivable :)

Title:Convert quantity decrease/increase functionality into a formatterQuantity decrease/increase functionality to be set in add to cart form formatter or
Component:General» Quantity module
Status:Active» Needs work

@iMiksu : as I said in the previous comment i will alter the formatter based on new settings for this and not building a new formatter.
For this one we'll need a contrib module : Field formatter settings (https://drupal.org/project/field_formatter_settings).
And ofcourse about having new Views Field handler for the Shopping cart views.

So i changed the title. I'll back soon with the patch for the new approach.

Status:Needs work» Needs review
StatusFileSize
new30.57 KB

and here is the patch:

1. Add to cart formatter: It requires the Field formatter settings module.
With this will have 2 new settings : "Add +/- buttons to increase/decrease the quantity value." and "Quantity cardinality".
This approach also needs a Drupal Commerce patch (at least a little part of it) : #1226466-23: Possibility to show price difference/total price in attributes Select List / Radio Buttons.
If this helper module is not installed will work old way (for now).

2. New Quantity Views field handler : "Quantity edit with +/- buttons".
- This field handler has an option settings for cardinality
- A new shopping cart view using this new Field was built and put in the module to be used: "Commerce Extra Quantity Shopping cart form" (commerce_extra_quantity_shopping_cart_form)
- in the Cart page : Commerce Cart View Override module it's needed, where you can choose to use the View defined by this module.
- in the Checkout page : "Shopping cart contents" pane settings, the View could be changed - Cart contents View.

a little correction for the previous patch : rename the machine name of the view to "commerce_cart_form_commerce_extra_quantity", required by "Commerce Cart View Override" module.

new patch with a little change for the "name" argument in the form_set_error(), use the parents form element, could be helpful if the view form gets embedded in other form (somehow).

Hi @vasike, thank you for great(30kb!) patch.
Great job. Its hard to do deep review your patch. But I want to do this.
Before we can commit this patch, we need to know that we do not brake production sites...
So lets test it...

I get next warnings when enable field_formatter_settings and setup formatter.

    Notice: Undefined index: field in commerce_extra_quantity_form_alter() (line 54 of /home/snoopy/www/dc/ce/htdocs/sites/all/modules/commerce_extra/modules/quantity/commerce_extra_quantity.module).
    Notice: Undefined index: bundle in commerce_extra_quantity_form_alter() (line 54 of /home/snoopy/www/dc/ce/htdocs/sites/all/modules/commerce_extra/modules/quantity/commerce_extra_quantity.module).
    Strict warning: Only variables should be passed by reference in commerce_extra_quantity_form_alter() (line 55 of /home/snoopy/www/dc/ce/htdocs/sites/all/modules/commerce_extra/modules/quantity/commerce_extra_quantity.module).
    Notice: Undefined index: view modes in field_view_mode_settings() (line 627 of /home/snoopy/www/dc/ce/htdocs/modules/field/field.module).
    Warning: Invalid argument supplied for foreach() in field_view_mode_settings() (line 627 of /home/snoopy/www/dc/ce/htdocs/modules/field/field.module).

dsm($field_context):

    entity_type (String, 4 characters ) node
    view_mode (String, 9 characters ) node_full
    display (String, 4 characters ) full
    language (String, 2 characters ) en
    entity_id (String, 1 characters ) 1
    class_prefix (String, 6 characters ) node-1

Status:Needs review» Needs work