? uc_ajax_cart.coder.patch ? uc_ajax_cart.info.new Index: uc_ajax_cart.admin.inc =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/uc_ajax_cart/Attic/uc_ajax_cart.admin.inc,v retrieving revision 1.1.2.6 diff -u -p -r1.1.2.6 uc_ajax_cart.admin.inc --- uc_ajax_cart.admin.inc 2 Nov 2009 20:34:35 -0000 1.1.2.6 +++ uc_ajax_cart.admin.inc 9 Jan 2010 04:39:25 -0000 @@ -1,83 +1,72 @@ - 'fieldset', - '#title' => t('Message settings'), - '#description' => t('You can switch beetween blockUI and growl like messages.'), - '#collapsible' => true , - 'messages' => array - ( - '#type' => 'radios', - '#title' => t('Message effect') , - '#required' => true , - '#options' => array( 1 => 'jQuery block UI messages.', 2 => 'Growl like messages.' ), - '#default_value' => variable_get('ajax_cart_message_effect' , UC_AJAX_CART_DEFAULT_EFFECT ) - ), - 'timeout' => array - ( - '#type' => 'textfield' , - '#size' => 6 , - '#required' => true , - '#title' => t('Standard message timeout') , - '#default_value' => variable_get('ajax_cart_message_timeout' , UC_AJAX_CART_DEFAULT_TIMEOUT ) - ), - /** - 'display_remove_message' => array - ( - '#type' => 'checkbox' , - '#title' => t('Should show a message if product is removed from cart.') , - '#default_value' => variable_get('ajax_cart_message_remove_display' , 1 ) - ), - - 'display_add_message' => array - ( - '#type' => 'checkbox' , - '#title' => t('Should show a message if product is added from cart.') , - '#default_value' => variable_get('ajax_cart_message_add_display' , 1 ) - ), - **/ - - ); - - $form['cache_settings'] = array - ( - '' - ); - - $form['cart_view_on'] = array - ( - '#type' => 'checkbox', - '#default_value' => variable_get('uc_ajax_cart_cart_view',0) , - '#title' => t('Enable ajax cart view') - ); - - - $form['submit'] = array - ( - '#type' => 'submit', - '#value' => t('Submit') - ); +function uc_ajax_cart_settings_overview() { + $form = array(); + $form['settings_messages'] = array( + '#type' => 'fieldset', + '#title' => t('Message settings'), + '#description' => t('You can switch beetween blockUI and growl like messages.'), + '#collapsible' => TRUE, + 'messages' => array( + '#type' => 'radios', + '#title' => t('Message effect'), + '#required' => TRUE, + '#options' => array(1 => 'jQuery block UI messages.', 2 => 'Growl like messages.'), + '#default_value' => variable_get('ajax_cart_message_effect', UC_AJAX_CART_DEFAULT_EFFECT), + ), + 'timeout' => array( + '#type' => 'textfield', + '#size' => 6, + '#required' => TRUE, + '#title' => t('Standard message timeout'), + '#default_value' => variable_get('ajax_cart_message_timeout', UC_AJAX_CART_DEFAULT_TIMEOUT), + ), + /** + 'display_remove_message' => array( + '#type' => 'checkbox', + '#title' => t('Should show a message if product is removed from cart.'), + '#default_value' => variable_get('ajax_cart_message_remove_display', 1), + ), + + 'display_add_message' => array( + '#type' => 'checkbox', + '#title' => t('Should show a message if product is added from cart.'), + '#default_value' => variable_get('ajax_cart_message_add_display', 1), + ), + **/ + ); + + $form['cache_settings'] = array( + '', + ); + + $form['cart_view_on'] = array( + '#type' => 'checkbox', + '#default_value' => variable_get('uc_ajax_cart_cart_view', 0), + '#title' => t('Enable ajax cart view'), + ); + + $form['submit'] = array( + '#type' => 'submit', + '#value' => t('Submit'), + ); - return $form ; + return $form; } -function uc_ajax_cart_settings_overview_validate() -{ - //here validation + +function uc_ajax_cart_settings_overview_validate() { + //here validation } -function uc_ajax_cart_settings_overview_submit( $form , $form_state) -{ - variable_set('ajax_cart_message_timeout' , $form_state['values']['timeout'] ); - variable_set('ajax_cart_message_effect' , $form_state['values']['messages'] ); - variable_set('uc_ajax_cart_cart_view' , $form_state['values']['cart_view_on']); - /** - variable_set('ajax_cart_message_remove_display' , $form_state['values']['display_remove_message'] ); - variable_set('ajax_cart_message_add_display' , $form_state['values']['display_add_message'] ); - **/ -} \ No newline at end of file + +function uc_ajax_cart_settings_overview_submit($form, $form_state) { + variable_set('ajax_cart_message_timeout', $form_state['values']['timeout']); + variable_set('ajax_cart_message_effect', $form_state['values']['messages']); + variable_set('uc_ajax_cart_cart_view', $form_state['values']['cart_view_on']); + /** + variable_set('ajax_cart_message_remove_display', $form_state['values']['display_remove_message']); + variable_set('ajax_cart_message_add_display', $form_state['values']['display_add_message']); + **/ +} Index: uc_ajax_cart.install =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/uc_ajax_cart/Attic/uc_ajax_cart.install,v retrieving revision 1.4.6.9 diff -u -p -r1.4.6.9 uc_ajax_cart.install --- uc_ajax_cart.install 2 Nov 2009 21:09:43 -0000 1.4.6.9 +++ uc_ajax_cart.install 9 Jan 2010 04:39:25 -0000 @@ -4,9 +4,8 @@ * * */ -function uc_ajax_cart_uninstall() -{ - variable_del('ajax_cart_message_timeout') ; - variable_del('ajax_cart_message_effect') ; - variable_del('uc_ajax_cart_cart_view') ; -} \ No newline at end of file +function uc_ajax_cart_uninstall() { + variable_del('ajax_cart_message_timeout'); + variable_del('ajax_cart_message_effect'); + variable_del('uc_ajax_cart_cart_view'); +} Index: uc_ajax_cart.module =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/uc_ajax_cart/Attic/uc_ajax_cart.module,v retrieving revision 1.13.2.13.2.10 diff -u -p -r1.13.2.13.2.10 uc_ajax_cart.module --- uc_ajax_cart.module 2 Nov 2009 21:09:43 -0000 1.13.2.13.2.10 +++ uc_ajax_cart.module 9 Jan 2010 04:39:25 -0000 @@ -1,7 +1,7 @@ - $product->title )) ); - } - break; - } -} - - -function uc_ajax_cart_menu() -{ - /** Default Settings URL **/ - $items['admin/store/settings/uc_ajax_cart'] = array( - 'title' => t('UC Ajax cart settings'), - 'description' => 'Configure the uc ajax cart settings.', - 'page callback' => 'drupal_get_form', - 'page arguments' => array('uc_ajax_cart_settings_overview'), - 'access arguments' => array('administer store'), - 'file' => 'uc_ajax_cart.admin.inc', - ); - $items[UC_AJAX_CART_ADD_CALLBACK] = array( - 'page callback' => 'uc_ajax_cart_callback', - 'page arguments' => array('add'), - 'access arguments' => array('access content'), - 'type' => MENU_CALLBACK - ); - $items[UC_AJAX_CART_REMOVE_CALLBACK] = array( - 'page callback' => 'uc_ajax_cart_callback', - 'page arguments' => array('remove'), - 'access arguments' => array('access content'), - 'type' => MENU_CALLBACK - ); - $items[UC_AJAX_CART_SHOW_CALLBACK] = array( - 'page callback' => 'uc_ajax_cart_callback', - 'page arguments' => array('show'), - 'access arguments' => array('access content'), - 'type' => MENU_CALLBACK - ); - $items[UC_AJAX_CART_LINK_CALLBACK] = array( - 'page callback' => 'uc_ajax_cart_callback', - 'page arguments' => array('link'), - 'access arguments' => array('access content'), - 'type' => MENU_CALLBACK, - 'file' => 'uc_cart_links.pages.inc' - ); - $items[UC_AJAX_CART_UPDATE_CALLBACK] = array( - 'page callback' => 'uc_ajax_cart_callback', - 'page arguments' => array('update'), - 'access arguments' => array('access content'), - 'type' => MENU_CALLBACK, - ); - $items[UC_AJAX_CART_SHOW_VIEW_CALLBACK] = array( - 'page callback' => 'uc_ajax_cart_callback', - 'page arguments' => array('show-cart-view'), - 'access arguments' => array('access content'), - 'type' => MENU_CALLBACK, - ); - - return $items ; -} - -function uc_ajax_cart_callback( $op , $nid = null , $data = null ) -{ - - switch ( $op ) - { - case 'remove': - uc_ajax_cart_remove_item( $_GET['nid'], unserialize(base64_decode($_GET['data'])) ); - print theme('status_messages'); - break ; - case 'add': - uc_ajax_cart_add_item($_POST); - print theme('status_messages'); - break ; - case 'show': - uc_ajax_cart_show_cart(); - break ; - case 'show-cart-view': - include_once( drupal_get_path('module','uc_cart') .'/uc_cart.pages.inc' ); - print uc_cart_view(); - break ; - case 'update': - $formValues = array('values' => $_POST) ; - $cart = new UcAjaxCart(); - $items = $cart->getCartContents(); - drupal_execute('uc_cart_view_form',$formValues,$items); - print theme('status_messages'); - break ; - case 'link': - if ( module_exists('uc_cart_links') ) - { - $link = array_pop(explode('/',$_GET['href'])); - uc_ajax_cart_links_process($link); - } else { - drupal_set_message(t('Sorry link is not valid'),'error') ; - } - print theme('status_messages'); - break ; - } -} -function uc_ajax_cart_show_cart() -{ - $cartContent = uc_cart_get_contents(); - if ( count($cartContent) > 0 ) print theme('uc_ajax_cart_block_content',$cartContent); - else print theme('uc_ajax_cart_block_content_empty',$cartContent); -} - - -function uc_ajax_cart_remove_item( $nid, $data ) -{ - $cart = new UcAjaxCart(); - try { - $cart->removeItemFromCart( $nid , $data ); - } catch ( NoProductException $ex ) - { - drupal_set_message(t('No valid product')); - } catch ( CartException $ex ) - { - foreach ( $ex->getMessages() as $message ) - { - drupal_set_message( $message , 'warning' ); - } - } -} - -function uc_ajax_cart_add_item( $data ) -{ - if ( !isset($data['qty']) ) $data['qty'] = 1 ; - - $formID = explode('_',$data['form_id']) ; - $nodeID = array_pop($formID) ; - $formID = implode('_',$formID ) ; - - $product = node_load($nodeID); - uc_product_load($product) ; - - $formValues = array('values' => $data ); - - drupal_execute($formID, $formValues, $product ); - return ; -} - -function uc_ajax_cart_theme() -{ - return array - ( - 'uc_ajax_cart_block' => array( - 'arguments' => array('title' => NULL , 'collapsible' => FALSE), - 'file' => 'uc_ajax_cart.theme.inc' - ), - 'uc_ajax_cart_attributes' => array( - 'arguments' => array('title' => NULL , 'collapsible' => FALSE), - 'file' => 'uc_ajax_cart.theme.inc' - ), - 'uc_ajax_cart_block_header' => array( - 'arguments' => array('text' => NULL, 'hasItems' => NULL ), - 'template' => 'templates/uc_ajax_cart_block_header' - ), - 'uc_ajax_cart_block_content' => array( - 'arguments' => array('items' => NULL), - 'template' => 'templates/uc_ajax_cart_block_content', - 'file' => 'uc_ajax_cart.theme.inc' - ), - 'uc_ajax_cart_block_content_empty' => array( - 'arguments' => array('items' => NULL), - 'template' => 'templates/uc_ajax_cart_block_content_empty', - ), - 'uc_ajax_cart_cart_links' => array( - 'file' => 'uc_ajax_cart.theme.inc' - ), - 'uc_ajax_cart_messages' => array( - 'arguments' => array('messages' => NULL), - 'template' => 'templates/uc_ajax_cart_messages' - ), - 'uc_ajax_cart_block_content_cached' => array( - 'arguments' => array('total' => NULL, 'collapsible' => FALSE), - 'file' => 'uc_ajax_cart.theme.inc' - ), - ); -} - -function uc_ajax_cart_block($op = 'list', $delta = 0, $edit = array()) -{ - if ($op == 'list') - { - // Retrieve block informations - $blocks[0] = array( - 'info' => t('Ajax shopping cart'), - 'cache' => BLOCK_NO_CACHE, - ); - - return $blocks; - } elseif ($op == 'view') - { - //Only a wrapper to uc_cart_block - $cartContent = uc_cart_get_contents(); - if ( count($cartContent) > 0 ) $hasItems = true ; - - $content['subject'] = theme('uc_ajax_cart_block_header', $hasItems ); - if ( $hasItems == true ) - { - $content['content'] = '
' . theme('uc_ajax_cart_block_content',$cartContent) . '
' ; - } else { - $content['content'] = '
' . theme('uc_ajax_cart_block_content_empty') . '
' ; - } - return $content ; - } elseif ($op == 'configure') - { - $form['text'] = array - ( - '#title' => t('Ajax cart settings') , - '#type' => 'fieldset', - '#description' => t('Advanced settings for ajax cart are !here',array('!here' => l(t('here'),'admin/store/settings/uc_ajax_cart'))) - ); - return $form ; - } elseif ( $op == 'save' ) - { - } +/** + * Implementation of hook_perm(). + */ +function uc_ajax_cart_perm() { + return array('show uncached cart', 'use cart'); +} + + +/** + * Implementation of hook_cart_item(). + */ +function uc_ajax_cart_cart_item($op, $product) { + switch ($op) { + case 'remove': + if (variable_get('ajax_cart_message_remove_display', 1)) { + $message = variable_get('ajax_cart_message_remove', '!product successfully remove from cart.'); + drupal_set_message(t($message, array('!product' => $product->title))); + } + break; + } +} + + +/** + * Implementation of hook_menu(). + */ +function uc_ajax_cart_menu() { + + /** Default Settings URL **/ + $items['admin/store/settings/uc_ajax_cart'] = array( + 'title' => t('UC Ajax cart settings'), + 'description' => 'Configure the uc ajax cart settings.', + 'page callback' => 'drupal_get_form', + 'page arguments' => array('uc_ajax_cart_settings_overview'), + 'access arguments' => array('administer store'), + 'file' => 'uc_ajax_cart.admin.inc', + ); + + $items[UC_AJAX_CART_ADD_CALLBACK] = array( + 'page callback' => 'uc_ajax_cart_callback', + 'page arguments' => array('add'), + 'access arguments' => array('access content'), + 'type' => MENU_CALLBACK, + ); + + $items[UC_AJAX_CART_REMOVE_CALLBACK] = array( + 'page callback' => 'uc_ajax_cart_callback', + 'page arguments' => array('remove'), + 'access arguments' => array('access content'), + 'type' => MENU_CALLBACK, + ); + + $items[UC_AJAX_CART_SHOW_CALLBACK] = array( + 'page callback' => 'uc_ajax_cart_callback', + 'page arguments' => array('show'), + 'access arguments' => array('access content'), + 'type' => MENU_CALLBACK, + ); + + $items[UC_AJAX_CART_LINK_CALLBACK] = array( + 'page callback' => 'uc_ajax_cart_callback', + 'page arguments' => array('link'), + 'access arguments' => array('access content'), + 'type' => MENU_CALLBACK, + 'file' => 'uc_cart_links.pages.inc', + ); + + $items[UC_AJAX_CART_UPDATE_CALLBACK] = array( + 'page callback' => 'uc_ajax_cart_callback', + 'page arguments' => array('update'), + 'access arguments' => array('access content'), + 'type' => MENU_CALLBACK, + ); + + $items[UC_AJAX_CART_SHOW_VIEW_CALLBACK] = array( + 'page callback' => 'uc_ajax_cart_callback', + 'page arguments' => array('show-cart-view'), + 'access arguments' => array('access content'), + 'type' => MENU_CALLBACK, + ); + + return $items; +} + + +function uc_ajax_cart_callback($op, $nid = NULL, $data = NULL) { + + switch ($op) { + case 'remove': + uc_ajax_cart_remove_item($_GET['nid'], unserialize(base64_decode($_GET['data']))); + print theme('status_messages'); + break; + case 'add': + uc_ajax_cart_add_item($_POST); + print theme('status_messages'); + break; + case 'show': + uc_ajax_cart_show_cart(); + break; + case 'show-cart-view': + include_once(drupal_get_path('module', 'uc_cart') .'/uc_cart.pages.inc'); + print uc_cart_view(); + break; + case 'update': + $formValues = array('values' => $_POST); + $cart = new UcAjaxCart(); + $items = $cart->getCartContents(); + drupal_execute('uc_cart_view_form', $formValues, $items); + print theme('status_messages'); + break; + case 'link': + if (module_exists('uc_cart_links')) { + $link = array_pop(explode('/', $_GET['href'])); + uc_ajax_cart_links_process($link); + } + else { + drupal_set_message(t('Sorry link is not valid'), 'error'); + } + print theme('status_messages'); + break; + } +} + + +function uc_ajax_cart_show_cart() { + $cartContent = uc_cart_get_contents(); + if (count($cartContent) > 0) { + print theme('uc_ajax_cart_block_content', $cartContent); + } + else { + print theme('uc_ajax_cart_block_content_empty', $cartContent); + } +} + + +function uc_ajax_cart_remove_item($nid, $data) { + $cart = new UcAjaxCart(); + try { + $cart->removeItemFromCart($nid, $data); + } + catch (NoProductException $ex) { + drupal_set_message(t('No valid product')); + } + catch (CartException $ex) { + foreach ($ex->getMessages() as $message) { + drupal_set_message($message, 'warning'); + } + } +} + +function uc_ajax_cart_add_item($data) { + if (!isset($data['qty'])) { + $data['qty'] = 1; + } + + $formID = explode('_', $data['form_id']); + $nodeID = array_pop($formID); + $formID = implode('_', $formID); + + $product = node_load($nodeID); + uc_product_load($product); + + $formValues = array('values' => $data); + + drupal_execute($formID, $formValues, $product); + return; } -function _uc_ajax_cart_load_res() -{ - static $loaded ; - - if ( isset($loaded) && $loaded === true ) return ; - - /** Add standard js **/ - drupal_add_js( drupal_get_path('module', 'uc_ajax_cart') .'/js/jquery.form.js' ); - drupal_add_js( drupal_get_path('module', 'uc_ajax_cart') .'/js/jquery.blockUI.js' ); - drupal_add_js( drupal_get_path('module', 'uc_ajax_cart') .'/js/uc_ajax_cart.js' ); - drupal_add_js( drupal_get_path('module', 'uc_ajax_cart') .'/js/jquery.cookie.js' ); - - drupal_add_css( drupal_get_path('module', 'uc_ajax_cart') .'/css/ajax.cart.css' ); - - $settings = array( - 'CALLBACK' => url(UC_AJAX_CART_ADD_CALLBACK), - 'SHOW_CALLBACK' => url(UC_AJAX_CART_SHOW_CALLBACK) , - 'ADD_MESSAGE' => t('Add product to cart'), - 'ADD_TITLE' => t('Please wait'), - 'REMOVE_MESSAGE' => t('Remove product from cart'), - 'REMOVE_TITLE' => t('Please wait'), - 'CART_LINK_CALLBACK' => url(UC_AJAX_CART_LINK_CALLBACK), - 'BLOCK_UI' => (int) variable_get('ajax_cart_message_effect' , UC_AJAX_CART_DEFAULT_EFFECT ) , - 'TIMEOUT' => (int) variable_get('ajax_cart_message_timeout', UC_AJAX_CART_DEFAULT_TIMEOUT ) , - 'UPDATE_CALLBACK' => url(UC_AJAX_CART_UPDATE_CALLBACK) , - 'UPDATE_MESSAGE' => t('Update cart') , - 'SESSION' => session_id(), - 'CART_OPERATION' => t('Cart'), - 'CART_VIEW_ON' => variable_get('uc_ajax_cart_cart_view',0), - 'SHOW_VIEW_CALLBACK' => url(UC_AJAX_CART_SHOW_VIEW_CALLBACK) - ); - - drupal_add_js( array('uc_ajax_cart' => $settings) , "setting"); - $loaded = true ; -} - -function uc_ajax_cart_form_uc_cart_links_settings_form_alter( &$form ) -{ - $form['instructions']['#value'] .= '
'. t('Ajax Cart driven cart links') . '
'. t('For use with Ajax Cart add class ajax-cart-link to links.') .'
'; -} - -function uc_ajax_cart_alter_cart_form( &$form, $formState, $formId ) -{ - if ( preg_match('/^uc_catalog_buy_it_now_form_/', $formId ) ) - { - $ucAjaxCart = new UcAjaxCart(); - $product = node_load($form['nid']['#value']); - uc_product_load($product); - if ( $product->type == 'product_kit' ) - { - - } else { - - if ( $ucAjaxCart->hasRequiredAttributes($product) ) - { - $form['submit']['#value'] = t('Please choose an option') ; - return ; - } - } - } - if ( !is_array($form['#attributes']) ) $form['#attributes'] = array(); - $form['product-nid'] = array('#type' => 'hidden' , '#value' => $form['nid']['#value'] ) ; + +/** + * Implementation of hook_theme(). + */ +function uc_ajax_cart_theme() { + return array( + 'uc_ajax_cart_block' => array( + 'arguments' => array('title' => NULL, 'collapsible' => FALSE), + 'file' => 'uc_ajax_cart.theme.inc' + ), + 'uc_ajax_cart_attributes' => array( + 'arguments' => array('title' => NULL, 'collapsible' => FALSE), + 'file' => 'uc_ajax_cart.theme.inc' + ), + 'uc_ajax_cart_block_header' => array( + 'arguments' => array('text' => NULL, 'hasItems' => NULL), + 'template' => 'templates/uc_ajax_cart_block_header' + ), + 'uc_ajax_cart_block_content' => array( + 'arguments' => array('items' => NULL), + 'template' => 'templates/uc_ajax_cart_block_content', + 'file' => 'uc_ajax_cart.theme.inc' + ), + 'uc_ajax_cart_block_content_empty' => array( + 'arguments' => array('items' => NULL), + 'template' => 'templates/uc_ajax_cart_block_content_empty', + ), + 'uc_ajax_cart_cart_links' => array( + 'file' => 'uc_ajax_cart.theme.inc' + ), + 'uc_ajax_cart_messages' => array( + 'arguments' => array('messages' => NULL), + 'template' => 'templates/uc_ajax_cart_messages' + ), + 'uc_ajax_cart_block_content_cached' => array( + 'arguments' => array('total' => NULL, 'collapsible' => FALSE), + 'file' => 'uc_ajax_cart.theme.inc' + ), + ); +} + + +function uc_ajax_cart_block($op = 'list', $delta = 0, $edit = array()) { + if ($op == 'list') { + // Retrieve block informations + $blocks[0] = array( + 'info' => t('Ajax shopping cart'), + 'cache' => BLOCK_NO_CACHE, + ); + + return $blocks; + } + elseif ($op == 'view') { + //Only a wrapper to uc_cart_block + $cartContent = uc_cart_get_contents(); + if (count($cartContent) > 0) { + $hasItems = TRUE; + } + $content['subject'] = theme('uc_ajax_cart_block_header', $hasItems); + if ($hasItems == TRUE) { + $content['content'] = '
' . theme('uc_ajax_cart_block_content', $cartContent) . '
'; + } + else { + $content['content'] = '
' . theme('uc_ajax_cart_block_content_empty') . '
'; + } + return $content; + } + elseif ($op == 'configure') { + $form['text'] = array( + '#title' => t('Ajax cart settings'), + '#type' => 'fieldset', + '#description' => t('Advanced settings for ajax cart are !here', array('!here' => l(t('here'), 'admin/store/settings/uc_ajax_cart'))) + ); + return $form; + } + elseif ($op == 'save') { + } +} + + +function _uc_ajax_cart_load_res() { + static $loaded; + + if (isset($loaded) && $loaded === TRUE) { + return; + } + + /** Add standard js **/ + drupal_add_js(drupal_get_path('module', 'uc_ajax_cart') .'/js/jquery.form.js'); + drupal_add_js(drupal_get_path('module', 'uc_ajax_cart') .'/js/jquery.blockUI.js'); + drupal_add_js(drupal_get_path('module', 'uc_ajax_cart') .'/js/uc_ajax_cart.js'); + drupal_add_js(drupal_get_path('module', 'uc_ajax_cart') .'/js/jquery.cookie.js'); + + drupal_add_css(drupal_get_path('module', 'uc_ajax_cart') .'/css/ajax.cart.css'); + + $settings = array( + 'CALLBACK' => url(UC_AJAX_CART_ADD_CALLBACK), + 'SHOW_CALLBACK' => url(UC_AJAX_CART_SHOW_CALLBACK), + 'ADD_MESSAGE' => t('Add product to cart'), + 'ADD_TITLE' => t('Please wait'), + 'REMOVE_MESSAGE' => t('Remove product from cart'), + 'REMOVE_TITLE' => t('Please wait'), + 'CART_LINK_CALLBACK' => url(UC_AJAX_CART_LINK_CALLBACK), + 'BLOCK_UI' => (int) variable_get('ajax_cart_message_effect', UC_AJAX_CART_DEFAULT_EFFECT), + 'TIMEOUT' => (int) variable_get('ajax_cart_message_timeout', UC_AJAX_CART_DEFAULT_TIMEOUT), + 'UPDATE_CALLBACK' => url(UC_AJAX_CART_UPDATE_CALLBACK), + 'UPDATE_MESSAGE' => t('Update cart'), + 'SESSION' => session_id(), + 'CART_OPERATION' => t('Cart'), + 'CART_VIEW_ON' => variable_get('uc_ajax_cart_cart_view', 0), + 'SHOW_VIEW_CALLBACK' => url(UC_AJAX_CART_SHOW_VIEW_CALLBACK) + ); + + drupal_add_js(array('uc_ajax_cart' => $settings), "setting"); + $loaded = TRUE; +} + +function uc_ajax_cart_form_uc_cart_links_settings_form_alter(&$form) { + $form['instructions']['#value'] .= '
'. t('Ajax Cart driven cart links') . '
'. t('For use with Ajax Cart add class ajax-cart-link to links.') .'
'; +} + + +function uc_ajax_cart_alter_cart_form(&$form, $formState, $formId) { + if (preg_match('/^uc_catalog_buy_it_now_form_/', $formId)) { + $ucAjaxCart = new UcAjaxCart(); + $product = node_load($form['nid']['#value']); + uc_product_load($product); + if ($product->type == 'product_kit') { + } + else { + if ($ucAjaxCart->hasRequiredAttributes($product)) { + $form['submit']['#value'] = t('Please choose an option'); + return; + } + } + } + if (!is_array($form['#attributes'])) { + $form['#attributes'] = array(); + } + $form['product-nid'] = array('#type' => 'hidden', '#value' => $form['nid']['#value']); $form['#attributes']['class'] .= 'ajax-cart-submit-form'; - $form['submit']['#attributes']['class'] .= ' ajax-cart-submit-form-button'; + $form['submit']['#attributes']['class'] .= ' ajax-cart-submit-form-button'; } -function uc_ajax_cart_form_alter( &$form, $form_state , $formId ) -{ - if ( preg_match('/^uc_product_add_to_cart_form_/',$formId) - || preg_match('/^uc_catalog_buy_it_now_form_/', $formId ) - || preg_match('/^uc_product_kit_add_to_cart_form/', $formId ) ) - { - uc_ajax_cart_alter_cart_form( $form, $formState, $formId ); - } elseif ( 'uc_cart_view_form' == $formId ) - { - $form['update']['#attributes']['class'] .= ' ajax-cart-submit-form-button'; - } + +function uc_ajax_cart_form_alter(&$form, $form_state, $formId) { + if (preg_match('/^uc_product_add_to_cart_form_/', $formId) + || preg_match('/^uc_catalog_buy_it_now_form_/', $formId) + || preg_match('/^uc_product_kit_add_to_cart_form/', $formId)) { + uc_ajax_cart_alter_cart_form($form, $formState, $formId); + } + elseif ('uc_cart_view_form' == $formId) { + $form['update']['#attributes']['class'] .= ' ajax-cart-submit-form-button'; + } } + + /** * doesnt work in for views!!! -function uc_ajax_cart_uc_form_alter( &$form, $formState, $formId ) -{ +function uc_ajax_cart_uc_form_alter(&$form, $formState, $formId) { - if ( $formId == 'uc_product_add_to_cart_form' - || $formId == 'uc_catalog_buy_it_now_form' - || $formId == 'uc_product_kit_add_to_cart_form' ) - { - uc_ajax_cart_alter_cart_form( $form, $formState, $formId ); - } + if ($formId == 'uc_product_add_to_cart_form' + || $formId == 'uc_catalog_buy_it_now_form' + || $formId == 'uc_product_kit_add_to_cart_form') { + uc_ajax_cart_alter_cart_form($form, $formState, $formId); + } } -**/ \ No newline at end of file +**/ Index: uc_ajax_cart.theme.inc =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/uc_ajax_cart/Attic/uc_ajax_cart.theme.inc,v retrieving revision 1.1.2.5 diff -u -p -r1.1.2.5 uc_ajax_cart.theme.inc --- uc_ajax_cart.theme.inc 2 Nov 2009 20:34:35 -0000 1.1.2.5 +++ uc_ajax_cart.theme.inc 9 Jan 2010 04:39:25 -0000 @@ -1,86 +1,85 @@ -aid) ; - $items[] = $attribute->name .': '. $option->name ; - } - - return theme('item_list',$items, null, 'ul' , array('class' => 'product-description')); +function theme_uc_ajax_cart_attributes($item, $options) { + foreach ($options as $option) { + $attribute = uc_attribute_load($option->aid); + $items[] = $attribute->name .': '. $option->name; + } + + return theme('item_list', $items, NULL, 'ul', array('class' => 'product-description')); } -function theme_uc_ajax_cart_cart_links() -{ - $items[] = array( - 'data' => l(t('View cart'),'cart',array('attributes' => array('rel' => 'nofollow'))), - 'class' => 'cart-block-view-cart' +function theme_uc_ajax_cart_cart_links() { + $items[] = array( + 'data' => l(t('View cart'), 'cart', array('attributes' => array('rel' => 'nofollow'))), + 'class' => 'cart-block-view-cart' + ); + // Only add the checkout link if checkout is enabled. + if (variable_get('uc_checkout_enabled', TRUE)) { + $items[] = array( + 'data' => l(t('Checkout'), 'cart/checkout', array('attributes' => array('rel' => 'nofollow'))), + 'class' => 'cart-block-checkout' ); - // Only add the checkout link if checkout is enabled. - if (variable_get('uc_checkout_enabled', TRUE)) - { - $items[] = array( - 'data' => l(t('Checkout'),'cart/checkout',array('attributes' => array('rel' => 'nofollow'))), - 'class' => 'cart-block-checkout' - ); - } - return theme('item_list',$items,null,'ul',array('class' => 'links')); + } + return theme('item_list', $items, NULL, 'ul', array('class' => 'links')); } -function uc_ajax_cart_preprocess_uc_ajax_cart_block_content( &$vars ) -{ - $cartContent = $vars['items'] ; - $items = array(); - - $contextTotal = array( - 'revision' => 'themed', - 'type' => 'price', - ); - - $total = 0 ; - $total_items = 0 ; - - foreach ( $cartContent as $item ) - { - $display_item = module_invoke($item->module, 'cart_display', $item); - if ( !empty($display_item) ) - { - $total += $display_item['#total'] ; - $total_items += $display_item['qty']['#default_value'] ; - $items[] = array( - 'nid' => $display_item['nid']['#value'], - 'qty' => t('@qty×', array('@qty' => $display_item['qty']['#default_value'])), - 'title' => $display_item['title']['#value'], - 'descr' => isset($display_item['description']['#value']) ? $display_item['description']['#value'] : FALSE, - 'link' => url('node/'.$item->nid ), - 'item' => $item , - 'image' => uc_product_get_picture($display_item['nid']['#value'], 'cart'), - 'node' => node_load($item->nid), - 'total' => uc_price($display_item['#total'],array( - 'revision' => 'themed-original', - 'type' => 'amount', - )) , - 'attributes' => (is_array($attributes) && count($attributes)>0) ? theme('uc_ajax_cart_attributes' , $item , $attributes ) : '' , - 'remove_link' => l(t('Remove product'), - UC_AJAX_CART_REMOVE_CALLBACK, - array( - 'attributes' => - array( - 'onclick' => "ajaxCartBlockUIRemove(this.href);return false; ", - 'class' => 'remove-cart-link remove-cart-link-' . $display_item['nid']['#value'] - ), - 'query' => array( - 'nid' => $display_item['nid']['#value'] , - 'destination' => $_GET['q'], - 'data' => base64_encode($display_item['data']['#value']), 'action' => 'remove' )) - ) - ); - } - } - $vars['total'] = uc_price($total,$contextTotal) ; - $vars['items'] = $items ; - $vars['cart_links'] = theme('uc_ajax_cart_cart_links') ; - $vars['items_text'] = format_plural( $total_items , '@count Item', '@count Items'); -} \ No newline at end of file +function uc_ajax_cart_preprocess_uc_ajax_cart_block_content(&$vars) { + $cartContent = $vars['items']; + $items = array(); + + $contextTotal = array( + 'revision' => 'themed', + 'type' => 'price', + ); + + $total = 0; + $total_items = 0; + + foreach ($cartContent as $item) { + $display_item = module_invoke($item->module, 'cart_display', $item); + if (!empty($display_item)) { + $total += $display_item['#total']; + $total_items += $display_item['qty']['#default_value']; + $items[] = array( + 'nid' => $display_item['nid']['#value'], + 'qty' => t('@qty×', array('@qty' => $display_item['qty']['#default_value'])), + 'title' => $display_item['title']['#value'], + 'descr' => isset($display_item['description']['#value']) ? $display_item['description']['#value'] : FALSE, + 'link' => url('node/'. $item->nid), + 'item' => $item, + 'image' => uc_product_get_picture($display_item['nid']['#value'], 'cart'), + 'node' => node_load($item->nid), + 'total' => uc_price( + $display_item['#total'], + array( + 'revision' => 'themed-original', + 'type' => 'amount', + ) + ), + 'attributes' => (is_array($attributes) && count($attributes)>0) ? theme('uc_ajax_cart_attributes', $item, $attributes ) : '', + 'remove_link' => l( + t('Remove product'), + UC_AJAX_CART_REMOVE_CALLBACK, + array( + 'attributes' => array( + 'onclick' => "ajaxCartBlockUIRemove(this.href);return false; ", + 'class' => 'remove-cart-link remove-cart-link-' . $display_item['nid']['#value'] + ), + 'query' => array( + 'nid' => $display_item['nid']['#value'], + 'destination' => $_GET['q'], + 'data' => base64_encode($display_item['data']['#value']), + 'action' => 'remove' + ) + ) + ) + ); + } + } + $vars['total'] = uc_price($total, $contextTotal); + $vars['items'] = $items; + $vars['cart_links'] = theme('uc_ajax_cart_cart_links'); + $vars['items_text'] = format_plural( $total_items, '@count Item', '@count Items'); +}