From f7e2d4596427ed831fad243faea25cd5e82bef02 Mon Sep 17 00:00:00 2001 From: kotnik Date: Wed, 13 Jun 2012 12:18:50 +0200 Subject: [PATCH] Issue #1029002 by kotnik, liupascal, fterrier: Added to cart form should optionally show when there is only one associated product. --- modules/cart/commerce_cart.module | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/modules/cart/commerce_cart.module b/modules/cart/commerce_cart.module index 1a2ec5a..de2e73b 100644 --- a/modules/cart/commerce_cart.module +++ b/modules/cart/commerce_cart.module @@ -1481,9 +1481,10 @@ function commerce_cart_add_to_cart_form($form, &$form_state, $line_item, $show_q ); } else { - // If the form is for a single product, store the product_id in a hidden - // form field for use by the submit handler. - if (count($products) == 1) { + // If the form is for a single product and displaying single product + // attributes is hidden in add to cart formatter, store the product_id + // in a hidden form field for use by the submit handler. + if (count($products) == 1 && !$line_item->data['context']['show_if_only_product']) { $form_state['default_product'] = reset($products); $form['product_id'] = array( @@ -2101,6 +2102,7 @@ function commerce_cart_field_formatter_info() { 'show_quantity' => FALSE, 'default_quantity' => 1, 'combine' => TRUE, + 'show_if_only_product' => FALSE, 'line_item_type' => 'product', ), ), @@ -2138,6 +2140,12 @@ function commerce_cart_field_formatter_settings_form($field, $instance, $view_mo '#default_value' => $settings['combine'], ); + $element['show_if_only_product'] = array( + '#type' => 'checkbox', + '#title' => t('Display attributes in add to cart form even if there is only one product.'), + '#default_value' => $settings['show_if_only_product'], + ); + // Add a conditionally visible line item type element. $types = commerce_product_line_item_types(); @@ -2183,6 +2191,7 @@ function commerce_cart_field_formatter_settings_summary($field, $instance, $view t('Quantity widget: !status', array('!status' => $settings['show_quantity'] ? t('Enabled') : t('Disabled'))), t('Default quantity: @quantity', array('@quantity' => $settings['default_quantity'])), t('Combine like items: !status', array('!status' => $settings['combine'] ? t('Enabled') : t('Disabled'))), + t('Single product attributes: !status', array('!status' => $settings['show_if_only_product'] ? t('Enabled') : t('Disabled'))), ); if (count(commerce_product_line_item_types()) > 1) { @@ -2217,6 +2226,7 @@ function commerce_cart_field_formatter_view($entity_type, $entity, $field, $inst $line_item = commerce_product_line_item_new(reset($products), $settings['default_quantity'], 0, array(), $type); $line_item->data['context']['product_ids'] = array_keys($products); $line_item->data['context']['add_to_cart_combine'] = $settings['combine']; + $line_item->data['context']['show_if_only_product'] = $settings['show_if_only_product']; $result[] = array( '#arguments' => array( -- 1.7.10.4