diff --git a/README.md b/README.md
index 3d8b857..35127f5 100644
--- a/README.md
+++ b/README.md
@@ -1,9 +1,98 @@
-# Add your own trigger.
+CONTENTS OF THIS FILE
+---------------------
+
+* About Commerce Ajax Cart
+* Requirements
+* Installation
+* Configuration
+* Theming
+* Developers
+* Demo
+* Notes
+* ToDo
+* Maintainers
+
+ABOUT COMMERCE AJAX CART
+------------------------
+
+https://www.drupal.org/project/commerce_ajax_cart
+Making default commerce cart to be "ajax cart".
+
+REQUIREMENTS
+------------
+
+1. http://drupal.org/project/commerce (commerce_cart submodule)
+
+INSTALLATION
+------------
+
+Install as usual, see http://drupal.org/documentation/install/modules-themes/modules-7 for further information.
+
+CONFIGURATION
+-------------
+
+1. enable "Shopping cart" on your theme: admin/structure/block;
+2. visit module configure: admin/commerce/config/advanced-settings/ajax-cart
+3. "Positioning of cart preview" (TODO: add some helping info here instead of link);
+4. select "Shopping cart to use". Select "Shopping cart form", if you are not sure what to choose;
+5. select "Commerce cart block": you should select cart block from #1;
+6. "Use dialog" - popup dialog window appear, instead of showing message in status (see #7);
+7. if "Use dialog" disabled, you should set "Content id or class" - place, where status should appear.
+ Usually it's #block-system-main;
+6. "Fly to cart" - when you click "Add to Cart" on product(s) page, first image will fly to cart;
+7. if you enable "Flu to cart", you should fill "Image and add to cart container class" -
+ CSS class name of closest parent container,
+ that contain image of product and add to cart form. For example, .node or .views-row.
+ Be sure, that doesn't contain other products images and add to cart forms.
+
+THEMING
+-------
+
+1. "Show cart" link theming:
+ 1.1 Copy /theme/commerce-ajax-cart.tpl.php to your theme templates folder;
+ 1.2 See comments for ready-to-use available variables or use $order;
+2. confirm dialog theming:
+ 2.1 Copy /theme/commerce_ajax_cart_dialog.tpl.php to your theme templates folder;
+ 2.2 Use commerce line item array $line_item. Some useful elements of this variable listed in comment.
+
+DEVELOPERS
+----------
-
+
+DEMO
+----
+
+http://shop.shaque.net/
+
+NOTES
+-----
+
+You can use prepared cart views: "shopping cart commerce ajax cart":
+1. Visit and enable it: admin/structure/views.
+2. On commerce_ajax_cart configuration page select this View (see Configuration #4).
+
+TODO
+----
+
+1. Seek TODO comments in code;
+2. form #ajax is bad: Increasing size of "cache_form" DB table for list of products, where "add to form" enabled for each product.
+ Solutions:
+ 2.1 $form_state['no_cache'] = TRUE; ?
+ 2.2 https://www.drupal.org/sandbox/xandeadx/2270819 ?
+3. Make Views cart form ajaxable.
+
+MAINTAINERS
+-----------
+Erik Seifert (Erik Seifert) https://www.drupal.org/u/erik-seifert
+Joël Pittet (joelpittet) https://www.drupal.org/u/joelpittet
diff --git a/commerce_ajax_cart.admin.inc b/commerce_ajax_cart.admin.inc
index 2de5e7d..9a44ac4 100644
--- a/commerce_ajax_cart.admin.inc
+++ b/commerce_ajax_cart.admin.inc
@@ -52,42 +52,61 @@ function commerce_ajax_cart_settings_form() {
'#options' => $view_settings,
'#title' => t('Shopping cart to use'),
'#default_value' => variable_get('commerce_ajax_cart_view', COMMERCE_AJAX_CART_DEFAULT_VIEW),
+ '#description' => t('Select Shopping cart block, if you are not sure...'),
);
- $behaviours = commerce_ajax_cart_script_examples();
+ module_load_include('inc', 'block', 'block.admin');
+ $current_theme = variable_get('theme_default', 'bartik');
+ $blocks = block_admin_display_prepare_blocks($current_theme);
+ $blocks_list = array();
+ foreach ($blocks as $block) {
+ if ($block['module'] == 'commerce_cart') {
+ $blocks_list[$block['bid']] = $block['info'];
+ }
+ }
- $form['commerce_ajax_cart_behaves'] = array(
- '#type' => 'container',
- '#tree' => TRUE,
- '#title' => t('Example behaviours'),
+ $form['commerce_ajax_cart_block'] = array(
+ '#type' => 'select',
+ '#options' => $blocks_list,
+ '#title' => t('Commerce cart block'),
+ '#default_value' => variable_get('commerce_ajax_cart_block'),
);
- $behaviours_default = variable_get('commerce_ajax_cart_behaves', array(
- 'show_cart' => 0,
- 'fly_to_cart' => 0,
- ));
+ $form['commerce_ajax_cart_use_dialog'] = array(
+ '#type' => 'checkbox',
+ '#title' => t('Use dialog'),
+ '#default_value' => variable_get('commerce_ajax_cart_use_dialog'),
+ '#description ' => t('This popup dialog inform about adding to cart. If disabled, adding to cart message will appear as status message.'),
+ );
+ $form['commerce_ajax_cart_content_name'] = array(
+ '#type' => 'textfield',
+ '#title' => t('Content id or class'),
+ '#default_value' => variable_get('commerce_ajax_cart_content_name', '#block-system-main'),
+ '#description' => t('Main container, where status message will appear. Usually, by default is #block-system-main
'),
+ '#states' => array(
+ 'invisible' => array(
+ ':input[name="commerce_ajax_cart_use_dialog"]' => array('checked' => TRUE),
+ ),
+ ),
+ );
- foreach ($behaviours as $id => $b) {
- $form['behaves'][$id] = array(
- '#type' => 'checkbox',
- '#title' => check_plain($b['title']),
- '#return_value' => 1,
- '#default_value' => $behaviours_default[$id],
- );
- $form['behaves'][$id . '_example'] = array(
- '#type' => 'fieldset',
- '#collapsible' => TRUE,
- '#collapsed' => TRUE,
- '#title' => t('Show code'),
- );
- $form['behaves'][$id . '_example']['code'] = array(
- '#markup' => '
',
- );
- }
+ $form['commerce_ajax_cart_fly2cart'] = array(
+ '#type' => 'checkbox',
+ '#title' => t('Fly to cart'),
+ '#default_value' => variable_get('commerce_ajax_cart_fly2cart'),
+ );
- $form['actions']['submit'] = array(
- '#type' => 'submit',
- '#value' => t('Save settings'),
+ // TODO Better solution?
+ $form['commerce_ajax_cart_fly2cart_parent'] = array(
+ '#type' => 'textfield',
+ '#title' => t('Image and add to cart container classes or IDs'),
+ '#default_value' => variable_get('commerce_ajax_cart_fly2cart_parent'),
+ '#description' => t('Class or ID names of closest parent element, separated by comma in order of distance increasing, that contain both image of product and "add to cart" form' . $b['content'] . '
For example, .node,.views-row
- .node will seeked first, then if not found, .views-row
Be sure, it shouldn\'t contain other products images and add to cart forms.'),
+ '#states' => array(
+ 'invisible' => array(
+ ':input[name="commerce_ajax_cart_fly2cart"]' => array('checked' => FALSE),
+ ),
+ ),
);
return system_settings_form($form);
diff --git a/commerce_ajax_cart.info b/commerce_ajax_cart.info
index d693e0a..c96d662 100644
--- a/commerce_ajax_cart.info
+++ b/commerce_ajax_cart.info
@@ -5,9 +5,3 @@ core = 7.x
dependencies[] = commerce_cart
stylesheets[all][] = css/commerce_ajax_cart.css
-; Information added by Drupal.org packaging script on 2014-01-17
-version = "7.x-1.0-beta2"
-core = "7.x"
-project = "commerce_ajax_cart"
-datestamp = "1389966808"
-
diff --git a/commerce_ajax_cart.module b/commerce_ajax_cart.module
index edf0d83..60a0fd4 100644
--- a/commerce_ajax_cart.module
+++ b/commerce_ajax_cart.module
@@ -64,16 +64,30 @@ function commerce_ajax_cart_get_defaults() {
}
/**
+ * Implements hook_theme().
+ */
+function commerce_ajax_cart_theme() {
+ return array(
+ 'commerce_ajax_cart' => array(
+ 'variables' => array('product_count' => NULL, 'total_quantity' => NULL, 'total_amount' => NULL, 'order' => NULL),
+ 'path' => drupal_get_path('module', 'commerce_ajax_cart') . '/theme',
+ 'template' => 'commerce-ajax-cart',
+ ),
+ 'commerce_ajax_cart_dialog' => array(
+ 'variables' => array('line_item' => NULL),
+ 'path' => drupal_get_path('module', 'commerce_ajax_cart') . '/theme',
+ 'template' => 'commerce-ajax-cart-dialog',
+ ),
+ );
+}
+
+/**
* Implements hook_preprocess_block().
*/
function commerce_ajax_cart_preprocess_block(&$variables) {
- if ('commerce_cart' == $variables['block']->module && $variables['block_id'] == 1) {
- $variables['content'] = l('' . t('Show cart') . '', 'cart', array(
- 'html' => TRUE,
- 'attributes' => array(
- 'class' => array('commerce-ajax-cart-loader'),
- ),
- ));
+ if ($variables['block']->bid == variable_get('commerce_ajax_cart_block')) {
+ $params = commerce_ajax_cart_block_params();
+ $variables['content'] = theme('commerce_ajax_cart', $params);
}
}
@@ -81,8 +95,8 @@ function commerce_ajax_cart_preprocess_block(&$variables) {
* Menu callback to print the contents block.
*/
function commerce_ajax_cart_show_contents_block() {
- $content = commerce_cart_block_view('cart');
- print $content['content'];
+ $params = commerce_ajax_cart_block_params();
+ print theme('commerce_ajax_cart', $params);
}
/**
@@ -108,31 +122,20 @@ function commerce_ajax_cart_preprocess_html() {
'weight' => 9,
));
$commerce_ajax_cart_view = commerce_ajax_cart_get_view_name();
- drupal_add_js(array(
- 'commerce_ajax_cart' => array(
- 'position' => $defaults,
- 'update_url' => url('cart/ajax/update'),
- 'form_id' => $commerce_ajax_cart_view['view'],
- 'update_url_block' => url('cart/ajax/block'),
- 'ajax_url' => url('cart/ajax'),
- 'text' => variable_get('commerce_ajax_cart_text', t('There is no product in your cart')),
- ),
- ), 'setting');
- $behaves = commerce_ajax_cart_script_examples();
- $behaviours_default = variable_get('commerce_ajax_cart_behaves', array());
- foreach ($behaviours_default as $key => $status) {
- if ($status == 1) {
- $cmd = "jQuery(window).bind('commerce_ajax_cart_update',function(e,formId) {";
- $cmd .= $behaves[$key]['content'];
- $cmd .= "});";
- drupal_add_js($cmd, array(
- 'type' => 'inline',
- 'scope' => 'footer',
- 'weight' => 10,
- ));
- $cmd = '';
- }
+ $setting['commerce_ajax_cart']= array(
+ 'position' => $defaults,
+ 'update_url' => url('cart/ajax/update'),
+ 'form_id' => $commerce_ajax_cart_view['view'],
+ 'update_url_block' => url('cart/ajax/block'),
+ 'ajax_url' => url('cart/ajax'),
+ 'text' => variable_get('commerce_ajax_cart_text', t('There is no product in your cart')),
+ );
+ if (variable_get('commerce_ajax_cart_fly2cart')) {
+ $parents = explode(',', variable_get('commerce_ajax_cart_fly2cart_parent'));
+ $setting['commerce_ajax_cart']['fly2cart_parent'] = $parents;
}
+ drupal_add_js($setting, 'setting');
+
}
/**
@@ -188,6 +191,10 @@ function commerce_ajax_cart_entity_info_alter(&$entity_info) {
* Implements hook_form_FORM_ID_alter().
*/
function commerce_ajax_cart_form_commerce_cart_add_to_cart_form_alter(&$form, $form_state, $form_id) {
+ if (variable_get('commerce_ajax_cart_use_dialog')) {
+ $form['#attached']['library'][] = array('system', 'ui.dialog');
+ }
+
$form['submit']['#ajax'] = array(
'callback' => 'commerce_ajax_cart_callback',
);
@@ -202,13 +209,40 @@ function commerce_ajax_cart_callback($form, &$form_state) {
$form = drupal_rebuild_form($form['#form_id'], $form_state, $form);
$commands[] = array('command' => 'commerce_ajax_cart_update');
- $commands[] = ajax_command_prepend('#block-system-main', theme('status_messages'));
+
+ if (variable_get('commerce_ajax_cart_use_dialog')) {
+ // TODO Theme should have more control for title, content, close button
+ $dialog = theme('commerce_ajax_cart_dialog', array('line_item' => $form_state['line_item']));
+ $commands[] = ajax_command_remove('#commerce-ajax-cart-dialog');
+ $commands[] = ajax_command_append('body', '