diff -urpN --strip-trailing-cr original_uc_alternative_price/uc_alternative_price.info uc_alternative_price/uc_alternative_price.info --- original_uc_alternative_price/uc_alternative_price.info 2009-04-14 10:40:02.000000000 +1000 +++ uc_alternative_price/uc_alternative_price.info 2009-06-13 01:37:42.923691200 +1000 @@ -1,11 +1,9 @@ ; $Id: uc_alternative_price.info,v 1.1 2009/03/03 13:01:25 greggles Exp $ name = Alternative Price description = Allows an alternative price product feature for product nodes. -dependencies = uc_product +dependencies[] = uc_product package = "Ubercart - extra" -version = "5.x-1.0" -; Information added by drupal.org packaging script on 2009-04-14 -version = "5.x-1.x-dev" +version = "6.x-1.x-dev" project = "uc_alternative_price" datestamp = "1239669601" - +core = 6.x \ No newline at end of file diff -urpN --strip-trailing-cr original_uc_alternative_price/uc_alternative_price.install uc_alternative_price/uc_alternative_price.install --- original_uc_alternative_price/uc_alternative_price.install 2009-04-14 03:00:18.000000000 +1000 +++ uc_alternative_price/uc_alternative_price.install 2009-06-13 01:37:42.933705600 +1000 @@ -1,28 +1,106 @@ t('alternative price table for Ubercart'), + 'fields' => array( + 'pfid' => array( + 'description' => t('price id'), + 'type' => 'int', + 'size' => 'medium', + 'not null' => TRUE, + ), + 'alternative_price' => array( + 'description' => t('alternative price'), + 'type' => 'numeric', + 'precision' => 10, + 'scale' => 2, + 'not null' => TRUE, + 'default' => 0.00, + ), + 'price_low' => array( + 'description' => t('low price'), + 'type' => 'numeric', + 'precision' => 10, + 'scale' => 2, + 'not null' => FALSE, + ), + 'price_high' => array( + 'description' => t('high price'), + 'type' => 'numeric', + 'precision' => 10, + 'scale' => 2, + 'not null' => FALSE, + ), + 'discount' => array( + 'description' => t('the discount'), + 'type' => 'numeric', + 'precision' => 10, + 'scale' => 2, + 'not null' => FALSE, + ), + 'alternative_description' => array( + 'description' => t('alternative description'), + 'type' => 'varchar', + 'length' => 255, + 'not null' => FALSE, + ), + 'standard_description' => array( + 'description' => t('normal or standard description'), + 'type' => 'varchar', + 'length' => 255, + 'not null' => FALSE, + ), + ), + 'indexes' => array( + 'pfid' => array('pfid'), + ), + ); + return $schema; +} + +/** + * Implementation of hook_schema_alter(). + */ +function uc_alternative_price_schema_alter(&$schema) { + $schema['uc_products']['fields']['unique'] = array( + 'description' => t('makes product unique'), + 'type' => 'int', + 'size' => 'tiny', + 'unsigned' => TRUE, + 'not null' => TRUE, + 'default' => 0, + ); +} + +/** +* Implementation of hook_install(). +*/ function uc_alternative_price_install() { - switch ($GLOBALS['db_type']) { - case 'mysqli': - case 'mysql': - db_query("CREATE TABLE {uc_alternative_prices} ( - `pfid` mediumint(9) NOT NULL, - `alternative_price` decimal(10,2) NOT NULL default 0.00, - `price_low` decimal(10,2) default NULL, - `price_high` decimal(10,2) default NULL, - `discount` decimal(10,2) default NULL, - `alternative_description` varchar(255) default NULL, - `standard_description` varchar(255) default NULL, - KEY pfid (pfid) - ) /*!40100 DEFAULT CHARACTER SET UTF8 COLLATE utf8_unicode_ci */ "); - db_query("ALTER TABLE {uc_products} ADD `unique` tinyint(2) default 0 AFTER `shippable`"); - break; - case 'pgsql': - break; + + drupal_install_schema('uc_alternative_price'); + $ret = array(); + $schema['uc_products'] = array(); + uc_alternative_price_schema_alter($schema); + foreach ($schema['uc_products']['fields'] as $name => $spec) { + db_add_field($ret, 'uc_products', $name, $spec); } } - +/** +* Implementation of hook_uninstall(). +*/ function uc_alternative_price_uninstall() { - db_query("DROP TABLE IF EXISTS {uc_alternative_prices}"); - db_query("ALTER TABLE {uc_products} DROP `unique`"); + + drupal_uninstall_schema('uc_alternative_price'); + $ret = array(); + $schema['uc_products'] = array(); + uc_alternative_price_schema_alter($schema); + foreach ($schema['uc_products']['fields'] as $name => $spec) { + db_drop_field($ret, 'uc_products', $name, $spec); + } } \ No newline at end of file diff -urpN --strip-trailing-cr original_uc_alternative_price/uc_alternative_price.module uc_alternative_price/uc_alternative_price.module --- original_uc_alternative_price/uc_alternative_price.module 2009-04-14 03:00:18.000000000 +1000 +++ uc_alternative_price/uc_alternative_price.module 2009-06-17 17:56:30.885054400 +1000 @@ -1,5 +1,66 @@ 'image_button', + '#title' => t('My button'), + '#return_value' => 'my_data', + '#src' => 'my/image/path.jpg', +); */ + +/* TODO Remove $row argument from db_result() method + The $row argument of db_result() was removed from the database abstraction + layer in 6.x core, as it was a database dependent option. Developers need to + use other handling to replace the needs of this method. */ + +/* TODO Change 'Submit' to 'Save' on buttons + It has been agreed on that the description 'Submit' for a button is not a + good choice since it does not indicate what actually happens. While for + example on node editing forms, 'Preview' and 'Delete' describe exactly what + will happen when the user clicks on the button, 'Submit' only gives a vague + idea. When labelling your buttons, make sure that it is clear what this + button does when the user clicks on it. */ + +/* TODO New user_mail_tokens() method may be useful. + user.module now provides a user_mail_tokens() function to return an array + of the tokens available for the email notification messages it sends when + accounts are created, activated, blocked, etc. Contributed modules that + wish to make use of the same tokens for their own needs are encouraged + to use this function. */ + +/* TODO + There is a new hook_watchdog in core. This means that contributed modules + can implement hook_watchdog to log Drupal events to custom destinations. + Two core modules are included, dblog.module (formerly known as watchdog.module), + and syslog.module. Other modules in contrib include an emaillog.module, + included in the logging_alerts module. See syslog or emaillog for an + example on how to implement hook_watchdog. +function example_watchdog($log = array()) { + if ($log['severity'] == WATCHDOG_ALERT) { + mysms_send($log['user']->uid, + $log['type'], + $log['message'], + $log['variables'], + $log['severity'], + $log['referer'], + $log['ip'], + format_date($log['timestamp'])); + } +} */ + +/* TODO You may want to take advantage of new form-specific alter hooks. + The hook_form_alter() is complemented by hook_form_$form-id_alter(). + Optionally, modules can implement form-specific alteration functions rather + than a single hook_form_alter() with many conditional switch statements. + This is optional, and is most useful for tidying the code of modules that + alter many forms to customize a site's operations. + The new function names are built using the following format: + [your-module-name]_form_[$form_id]_alter. */ /** * @file @@ -24,7 +85,7 @@ define('UC_ALTERNATIVE_PRICE_FID', 'alte /** * Implementation of hook_form_alter(). */ -function uc_alternative_price_form_alter($form_id, &$form) { +function uc_alternative_price_form_alter(&$form, &$form_state, $form_id) { //Alter add to cart form with new labels and new add to cart button if (strpos($form_id, 'uc_product_add_to_cart_form') !== FALSE) { @@ -38,8 +99,8 @@ function uc_alternative_price_form_alter '#type' => 'submit', '#value' => $alternative_price->alternative_button, ); - $form['#validate']['uc_alternative_price_add_to_cart_validate'] = array(); - $form['#submit']['uc_alternative_price_add_to_cart_submit'] = array(); + $form['#validate'][] = 'uc_alternative_price_add_to_cart_validate'; + $form['#submit'][] = 'uc_alternative_price_add_to_cart_submit'; } if (!empty($alternative_price->standard_button)) { $form['submit']['#value'] = $alternative_price->standard_button; @@ -47,7 +108,9 @@ function uc_alternative_price_form_alter } //Alter product edit form to include a unique checkbox - if ($form_id == 'product_node_form') { + //changed line below + //if ($form_id == 'product_node_form') { + if (preg_match('/(.+)_node_form/', $form_id, $matches) && in_array($matches[1], module_invoke_all('product_types'))) { $unique = (!empty($form['nid']['#value'])) ? db_result(db_query("SELECT `unique` FROM {uc_products} WHERE nid = %d", $form['nid']['#value'])) : FALSE; $description = (variable_get('uc_alternative_price_unpublish_alternative', FALSE)) ? t('A unique product will become unpublished once purchased by a customer at the alternative price.') : t('A unique product will become unpublished once purchased by a customer'); $form['base']['unique'] = array( @@ -56,7 +119,7 @@ function uc_alternative_price_form_alter '#default_value' => $unique, '#description' => $description, ); - $form['#submit']['uc_alternative_product_node_form_submit'] = array(); + $form['#submit'][] = 'uc_alternative_product_node_form_submit'; } //Alter product field settings for to add alternative_price and selected_attributes field @@ -81,14 +144,34 @@ function uc_alternative_price_form_alter /** * Implementation of hook_menu(). */ -function uc_alternative_price_menu($may_cache) { +function uc_alternative_price_menu() { +/* TODO + Non menu code that was placed in hook_menu under the '!$may_cache' block + so that it could be run during initialization, should now be moved to hook_init. + Previously we called hook_init twice, once early in the bootstrap process, second + just after the bootstrap has finished. The first instance is now called boot + instead of init. + + In Drupal 6, there are now two hooks that can be used by modules to execute code + at the beginning of a page request. hook_boot() replaces hook_boot() in Drupal 5 + and runs on each page request, even for cached pages. hook_boot() now only runs + for non-cached pages and thus can be used for code that was previously placed in + hook_menu() with $may_cache = FALSE: + + Dynamic menu items under a '!$may_cache' block can often be simplified + to remove references to arg(n) and use of '%' to check + conditions. See http://drupal.org/node/103114. + + The title and description arguments should not have strings wrapped in t(), + because translation of these happen in a later stage in the menu system. +*/ if (!$may_cache) { drupal_add_css(drupal_get_path('module', 'uc_alternative_price') .'/uc_alternative_price.css'); } } /** -* Implementation of hook_view(). +* Implementation of hook_nodeapi(). */ function uc_alternative_price_nodeapi(&$node, $op, $a3 = NULL, $a4 = NULL) { switch ($op) { @@ -116,6 +199,12 @@ function uc_alternative_price_nodeapi(&$ } } break; + case 'insert': + drupal_set_message('insert'); + case 'update': + drupal_set_message('update'); + db_query("UPDATE {uc_products} SET `unique` = %d WHERE nid = %d", $node->unique, $node->nid); + break; default: break; } @@ -124,41 +213,56 @@ function uc_alternative_price_nodeapi(&$ /** * Implementation of hook_views_tables(). */ -function uc_alternative_price_views_tables() { - $tables['uc_product_features'] = array( - 'name' => 'uc_product_features', - 'join' => array( - 'left' => array( - 'table' => 'node', - 'field' => 'nid', - ), - 'right' => array( - 'field' => 'nid', - ), - 'extra' => array( - 'fid' => UC_ALTERNATIVE_PRICE_FID - ), - ), - 'fields' => array( - 'pfid' => array( - 'name' => t('Product: Alternative Price'), - 'help' => t('The alternative price product feature (if applicable).'), - 'handler' => 'uc_alternative_price_views_handler_alternative_price', - ) - ), - 'filters' => array( - 'has_alternative_price' => array( - 'name' => t('Product: Has alternative price'), - 'operator' => array('=' => 'Equals'), - 'list' => array(1 => 'Yes'), - 'list-type' => 'select', - 'handler' => 'uc_alternative_price_views_handler_has_alternative_price', - 'help' => t('Filter the product node based on whether it has an alternative price.'), - ), - ), - ); - return $tables; -} +//changed this +//function uc_alternative_price_views_tables() { +// function uc_alternative_price_views_data() { + // $data['uc_product_features']['table']['join'] = array( + // 'node' => array( + // 'left_field' => 'nid', + // 'field' => 'nid', + // ), + // ); + // $data['uc_product_features']['alternative price'] = array( + // 'title' => t('Product:Alternative Price'), + // 'help' => t('The alternative price product feature (if applicable).'), + // 'handler' => 'uc_alternative_price_views_handlers_alternative_price', + // 'group' => t('Product'), + // ); + // $data['uc_product_features']= array( + // 'name' => 'uc_product_features', + // 'join' => array( + // 'left' => array( + // 'table' => 'node', + // 'field' => 'nid', + // ), + // 'right' => array( + // 'field' => 'nid', + // ), + // 'extra' => array( + // 'fid' => UC_ALTERNATIVE_PRICE_FID + // ), + // ), + // 'fields' => array( + // 'pfid' => array( + // 'name' => t('Product: Alternative Price'), + // 'help' => t('The alternative price product feature (if applicable).'), + // 'handler' => 'uc_alternative_price_views_handler_alternative_price', + // ) + // ), + // 'filters' => array( + // 'has_alternative_price' => array( + // 'name' => t('Product: Has alternative price'), + // 'operator' => array('=' => 'Equals'), + // 'list' => array(1 => 'Yes'), + // 'list-type' => 'select', + // 'handler' => 'uc_alternative_price_views_handler_has_alternative_price', + // 'help' => t('Filter the product node based on whether it has an alternative price.'), + // ), + // ), + // ); + // return $tables; + // return $data; +// } /** * Views handler for alternative price @@ -171,19 +275,19 @@ function uc_alternative_price_views_hand /** * Views handler for has_alternative_price filter */ -function uc_alternative_price_views_handler_has_alternative_price($op, $filter, $filterinfo, &$query) { - switch ($op) { - case 'handler': - if ($filter['value']) { - $query->add_table('uc_product_features'); - $query->add_field('fid', 'uc_product_features'); - $query->add_where("uc_product_features.fid != ''"); - } - break; - default: - break; - } -} +// function uc_alternative_price_views_handler_has_alternative_price($op, $filter, $filterinfo, &$query) { + // switch ($op) { + // case 'handler': + // if ($filter['value']) { + // $query->add_table('uc_product_features'); + // $query->add_field('fid', 'uc_product_features'); + // $query->add_where("uc_product_features.fid != ''"); + // } + // break; + // default: + // break; + // } +// } /******************************************************************************* * Übercart Hooks @@ -259,6 +363,22 @@ function uc_alternative_price_product_fe *******************************************************************************/ /** + * hook_themes() + */ +function uc_alternative_price_theme() { + return array( + 'uc_alternative_price_discount' => array( + 'arguments' => array('discount' => NULL), + ), + 'uc_alternative_price_settings_form' => array( + 'arguments' => array('form' => NULL), + ), + 'uc_alternative_price_selected_attributes' => array( + 'arguments' => array('nid' => NULL), + ), + ); +} +/** * Theme the form fields for apply alternative price discount * @ingroup themeable */ @@ -330,14 +450,20 @@ function theme_uc_alternative_price_sele /** * Validation & submit functions for altered add to cart form */ -function uc_alternative_price_add_to_cart_validate($form_id, $form_values) { - $add_alternative = ($form_values['op'] == $form_values['alternative_price']->alternative_button) ? TRUE : FALSE; - $descriptions = array('!alternative_description' => $form_values['alternative_price']->alternative_description, '!standard_description' => $form_values['alternative_price']->standard_description); - if ($add_unique && $form_values['qty'] > 1) { +function uc_alternative_price_add_to_cart_validate($form, &$form_state) { +/* TODO The 'op' element in the form values is deprecated. + Each button can have #validate and #submit functions associated with it. + Thus, there should be one button that submits the form and which invokes + the normal form_id_validate and form_id_submit handlers. Any additional + buttons which need to invoke different validate or submit functionality + should have button-specific functions. */ + $add_alternative = ($form_state['values']['op'] == $form_state['values']['alternative_price']->alternative_button) ? TRUE : FALSE; + $descriptions = array('!alternative_description' => $form_state['values']['alternative_price']->alternative_description, '!standard_description' => $form_state['values']['alternative_price']->standard_description); + if ($add_unique && $form_state['values']['qty'] > 1) { form_set_error('', t('You may only add one !alternative_description product to your cart', $descriptions)); } foreach (uc_cart_get_contents() as $item) { - if ($item->nid == $form_values['nid']) { + if ($item->nid == $form_state['values']['nid']) { if ($item->data['alternative_price'] && !$add_alternative) { form_set_error('', t("You must remove the !alternative_description items from your cart before you can add !standard_description items to your cart.", $descriptions)); } @@ -347,11 +473,17 @@ function uc_alternative_price_add_to_car } } } -function uc_alternative_price_add_to_cart_submit($form_id, $form_values) { - if ($form_values['op'] == $form_values['alternative_price']->alternative_button) { - $data = unserialize(db_result(db_query("SELECT `data` FROM {uc_cart_products} WHERE cart_id = '%s' AND nid = %d", uc_cart_get_id(), $form_values['nid']))); +function uc_alternative_price_add_to_cart_submit($form, &$form_state) { +/* TODO The 'op' element in the form values is deprecated. + Each button can have #validate and #submit functions associated with it. + Thus, there should be one button that submits the form and which invokes + the normal form_id_validate and form_id_submit handlers. Any additional + buttons which need to invoke different validate or submit functionality + should have button-specific functions. */ + if ($form_state['values']['op'] == $form_state['values']['alternative_price']->alternative_button) { + $data = unserialize(db_result(db_query("SELECT `data` FROM {uc_cart_products} WHERE cart_id = '%s' AND nid = %d", uc_cart_get_id(), $form_state['values']['nid']))); $data['alternative_price'] = TRUE; - db_query("UPDATE {uc_cart_products} SET `data` = '%s' WHERE cart_id = '%s' AND nid = %d", serialize($data), uc_cart_get_id(), $form_values['nid']); + db_query("UPDATE {uc_cart_products} SET `data` = '%s' WHERE cart_id = '%s' AND nid = %d", serialize($data), uc_cart_get_id(), $form_state['values']['nid']); } } @@ -366,7 +498,7 @@ function uc_alternative_price_feature_de * Form builder for hook_product_feature * @see theme_uc_alternative_price_discount */ -function uc_alternative_price_feature_form($node, $feature) { +function uc_alternative_price_feature_form(&$form_state, $node, $feature) { if (empty($feature) && db_result(db_query("SELECT pfid FROM {uc_product_features} WHERE nid = %d AND fid = '%s'", $node->nid, UC_ALTERNATIVE_PRICE_FID))) { drupal_set_message(t("Product nodes can only have one alternative price feature. Either delete or edit the existing alternative price feature."), 'error'); drupal_goto("node/". $node->nid ."/edit/features"); @@ -435,40 +567,57 @@ function uc_alternative_price_feature_fo return uc_product_feature_form($form); } -function uc_alternative_price_feature_form_validate($form_id, $form_values) { - $all_empty = empty($form_values['price_high']) && empty($form_values['discount_price']) && empty($form_values['price_low']); - $all_entry = !empty($form_values['price_high']) && !empty($form_values['discount_price']) && !empty($form_values['price_low']); +function uc_alternative_price_feature_form_validate($form, &$form_state) { + $all_empty = empty($form_state['values']['price_high']) && empty($form_state['values']['discount_price']) && empty($form_state['values']['price_low']); + $all_entry = !empty($form_state['values']['price_high']) && !empty($form_state['values']['discount_price']) && !empty($form_state['values']['price_low']); if (!$all_empty && !$all_entry) { $fields = array('price_high' => t("High price"), 'discount_price' => t("Discount price"), 'price_low' => t("Low price")); foreach (array_keys($fields) as $field) { - if (empty($form_values[$field])) { + if (empty($form_state['values'][$field])) { form_set_error($field, t("!form_element is required to apply discount to the alternative price.", array('!form_element' => $fields[$field]))); } } } } -function uc_alternative_price_feature_form_submit($form_id, $form_values) { - $description = t("Alternative price: ") . check_plain(uc_currency_format($form_values['alternative_price'])) ."
\n"; - $description .= (empty($form_values['discount_price'])) ? '' : t("High price:") . check_plain(uc_currency_format($form_values['price_high'])) ."
\n". t("Low price: ") . check_plain(uc_currency_format($form_values['price_low'])) ."
\n". t("Discount price: ") . check_plain(uc_currency_format($form_values['discount_price'])) ."
\n"; - $description .= (empty($form_values['alternative_description'])) ? '' : t("Alternative price description: ") . check_plain($form_values['alternative_description']) ."
\n"; - $description .= (empty($form_values['standard_description'])) ? '' : t("Standard price description: ") . check_plain($form_values['standard_description']) ."
\n"; - $pfid = (empty($form_values['pfid'])) ? db_next_id('{uc_product_features}_pfid') + 1 : $form_values['pfid']; - if (!empty($form_values['pfid'])) { - db_query("DELETE FROM {uc_alternative_prices} WHERE pfid = %d", $pfid); - } - if (empty($form_values['discount_price'])) { - db_query("INSERT INTO {uc_alternative_prices} (`pfid`,`alternative_price`,`alternative_description`,`standard_description`) VALUES (%d, %f, '%s', '%s')", $pfid, $form_values['alternative_price'], $form_values['alternative_description'], $form_values['standard_description']); - } - else { - db_query("INSERT INTO {uc_alternative_prices} (`pfid`,`alternative_price`,`price_low`,`price_high`,`discount`,`alternative_description`,`standard_description`) VALUES (%d, %f, %f, %f, %f, '%s', '%s')", $pfid, $form_values['alternative_price'], $form_values['price_low'], $form_values['price_high'], $form_values['discount_price'], $form_values['alternative_description'], $form_values['standard_description']); - } +function uc_alternative_price_feature_form_submit($form, &$form_state) { + $description = t("Alternative price: ") . check_plain(uc_currency_format($form_state['values']['alternative_price'])) ."
\n"; + $description .= (empty($form_state['values']['discount_price'])) ? '' : t("High price:") . check_plain(uc_currency_format($form_state['values']['price_high'])) ."
\n". t("Low price: ") . check_plain(uc_currency_format($form_state['values']['price_low'])) ."
\n". t("Discount price: ") . check_plain(uc_currency_format($form_state['values']['discount_price'])) ."
\n"; + $description .= (empty($form_state['values']['alternative_description'])) ? '' : t("Alternative price description: ") . check_plain($form_state['values']['alternative_description']) ."
\n"; + $description .= (empty($form_state['values']['standard_description'])) ? '' : t("Standard price description: ") . check_plain($form_state['values']['standard_description']) ."
\n"; + + //get the product feature ID + $pfid = $form_state['values']['pfid']; + $data = array( 'pfid' => $pfid, - 'nid' => $form_values['nid'], + 'nid' => $form_state['values']['nid'], 'fid' => UC_ALTERNATIVE_PRICE_FID, 'description' => $description, ); - return uc_product_feature_save($data); + //update uc_product_feature table first (handle by uc_products module) + uc_product_feature_save($data); + + //then update uc_alternative_feature table + //reason why is because pfid could be NULL when a new feature is added and need to query + //the uc_product_feature for the its pfid to reference + if (empty($form_state['values']['pfid'])) { + $temp_object = db_fetch_object(db_query("SELECT pfid FROM {uc_product_features} WHERE nid = %d", $form_state['values']['nid'])); + $pfid = $temp_object->pfid; + } + + if (!empty($form_state['values']['pfid'])) { + //TODO, this should be an update. It works as it gets update somewhere else which i don't know of. + db_query("DELETE FROM {uc_alternative_prices} WHERE pfid = %d", $pfid); + } + if (empty($form_state['values']['discount_price'])) { + db_query("INSERT INTO {uc_alternative_prices} (`pfid`,`alternative_price`,`alternative_description`,`standard_description`) VALUES (%d, %f, '%s', '%s')", $pfid, $form_state['values']['alternative_price'], $form_state['values']['alternative_description'], $form_state['values']['standard_description']); + } + else { + db_query("INSERT INTO {uc_alternative_prices} (`pfid`,`alternative_price`,`price_low`,`price_high`,`discount`,`alternative_description`,`standard_description`) VALUES (%d, %f, %f, %f, %f, '%s', '%s')", $pfid, $form_state['values']['alternative_price'], $form_state['values']['price_low'], $form_state['values']['price_high'], $form_state['values']['discount_price'], $form_state['values']['alternative_description'], $form_state['values']['standard_description']); + } + + //redirect to feature page + $form_state['redirect'] = 'node/'. $form_state['values']['nid'] .'/edit/features'; } /** @@ -504,9 +653,12 @@ function uc_alternative_price_feature_se /** * Submit handler for product node edit form */ -function uc_alternative_product_node_form_submit($form_id, $form_values) { - $nid = (!empty($form_values['nid'])) ? $form_values['nid'] : db_result(db_query("SELECT `id` FROM {sequences} WHERE `name` = 'node_nid'")); - db_query("UPDATE {uc_products} SET `unique` = %d WHERE nid = %d", $form_values['unique'], $nid); +function uc_alternative_product_node_form_submit($form, &$form_state) { + //alter next line when converting 5 to 6 + //$nid = (!empty($form_state['values']['nid'])) ? $form_state['values']['nid'] : db_result(db_query("SELECT `id` FROM {sequences} WHERE `name` = 'node_nid'")); + //$nid = $form_state['value']['nid']; + //most of the code went to hook_nodeapi $op === insert because sequence table is now gone with 6 and + //nid is not avaiable when creating a new node, and its needs to be created first } /******************************************************************************* @@ -524,6 +676,7 @@ function uc_alternative_product_node_for */ function _uc_alternative_price_get_alternative_price($nid) { $alternative_price = db_fetch_object(db_query("SELECT * FROM {uc_product_features} as f LEFT JOIN {uc_alternative_prices} as a ON f.pfid = a.pfid WHERE f.nid = %d AND f.fid = '%s'", $nid, UC_ALTERNATIVE_PRICE_FID)); + $alternative_price->alternative_description = (!empty($alternative_price->alternative_description)) ? $alternative_price->alternative_description : t("Alternative Price"); $alternative_price->alternative_button = t('Add !alternative_description to cart', array('!alternative_description' => $alternative_price->alternative_description)); $alternative_price->standard_button = t('Add !standard_description to cart', array('!standard_description' => $alternative_price->standard_description)); @@ -534,3 +687,13 @@ function _uc_alternative_price_get_alter } return FALSE; } + +/** + * Implementation of hook_views_api(). + */ +function uc_alternative_price_views_api() { + return array( + 'api' => '2.0', + 'path' => drupal_get_path('module', 'uc_alternative_price') .'/views', + ); +} diff -urpN --strip-trailing-cr original_uc_alternative_price/views/uc_alternative_price.views.inc uc_alternative_price/views/uc_alternative_price.views.inc --- original_uc_alternative_price/views/uc_alternative_price.views.inc 1970-01-01 10:00:00.000000000 +1000 +++ uc_alternative_price/views/uc_alternative_price.views.inc 2009-06-17 18:32:37.370307200 +1000 @@ -0,0 +1,171 @@ + array( + 'left_table' => 'uc_product_features', + 'left_field' => 'pfid', + 'field' => 'pfid', + ), + ); + + //then joins the product features table to the node table + $data['uc_product_features']['table']['join'] = array( + 'node' => array( + 'left_field' => 'nid', + 'field' => 'nid', + ), + ); + + + $data['uc_alternative_prices']['alternative_price'] = array( + 'title' => t('Alternative Price'), + 'help' => t('The alternative price product feature (if applicable).'), + 'field' => array( + 'handler' => 'uc_alternative_price_handler_field_alternative_price', + 'click sortable' => TRUE, + ), + 'sort' => array( + 'handler' => 'views_handler_sort', + ), + 'filter' => array( + 'handler' => 'views_handler_filter_numeric', + ), + ); + + $data['uc_product_features']['description'] = array( + 'title' => t('Alternative Price Description'), + 'help' => t('The alternative price product feature (if applicable).'), + 'field' => array( + 'handler' => 'views_handler_field', + //'handler' => 'uc_alternative_price_handler_field_alternative_price', + 'click sortable' => TRUE, + ), + 'sort' => array( + 'handler' => 'views_handler_sort', + ), + 'filter' => array( + 'handler' => 'views_handler_filter_numeric', + ), + ); + + $data['uc_product_features']['has_alternative_price'] = array( + 'title' => t('Has a product feature of alternative price'), + 'help' => t('Filter the product feature based on whether it has an alternative price.'), + 'group' => t('Product Feature'), + 'filter' => array( + 'handler' => 'uc_alternative_price_handler_filter_alternative_price', + 'label' => t('Has an alternative price'), + ), + ); + + return $data; +} + + +/** + * Implementation of hook_views_handlers(). + */ +function uc_alternative_price_views_handlers() { + return array( + 'info' => array( + 'path' => drupal_get_path('module', 'uc_alternative_price') .'/views', + ), + 'handlers' => array( + 'uc_alternative_price_handler_field_alternative_price' => array( + 'parent' => 'views_handler_field', + ), + 'uc_alternative_price_handler_filter_alternative_price' => array( + 'parent' => 'views_handler_filter_boolean_operator', + ), + ), + ); +} + + +// /** + // * Conditionally add editablefields support. + // */ +// function uc_product_views_tables_alter(&$tables) { + // if (module_exists('editablefields')) { + // if (is_array($tables['uc_products']['fields']['model']['option'])) { + // $tables['uc_products']['fields']['model']['option']['#options']['editable'] = t('Editable'); + // } + // else { + // $tables['uc_products']['fields']['model']['option'] = array( + // '#type' => 'select', + // '#options' => array( + // 'display' => t('Display'), + // 'editable' => t('Editable'), + // ), + // ); + // } + // $tables['uc_products']['fields']['model']['form_parents'] = 'base][model'; + // if (is_array($tables['uc_products']['fields']['list_price']['option'])) { + // $tables['uc_products']['fields']['list_price']['option']['#options']['editable'] = t('Editable'); + // } + // else { + // $tables['uc_products']['fields']['list_price']['option'] = array( + // '#type' => 'select', + // '#options' => array( + // 'display' => t('Display'), + // 'editable' => t('Editable'), + // ), + // ); + // } + // $tables['uc_products']['fields']['list_price']['form_parents'] = 'base][prices][list_price'; + // if (is_array($tables['uc_products']['fields']['cost']['option'])) { + // $tables['uc_products']['fields']['cost']['option']['#options']['editable'] = t('Editable'); + // } + // else { + // $tables['uc_products']['fields']['cost']['option'] = array( + // '#type' => 'select', + // '#options' => array( + // 'display' => t('Display'), + // 'editable' => t('Editable'), + // ), + // ); + // } + // $tables['uc_products']['fields']['cost']['form_parents'] = 'base][prices][cost'; + // if (is_array($tables['uc_products']['fields']['sell_price']['option'])) { + // $tables['uc_products']['fields']['sell_price']['option']['#options']['editable'] = t('Editable'); + // } + // else { + // $tables['uc_products']['fields']['sell_price']['option'] = array( + // '#type' => 'select', + // '#options' => array( + // 'display' => t('Display'), + // 'editable' => t('Editable'), + // ), + // ); + // } + // $tables['uc_products']['fields']['sell_price']['form_parents'] = 'base][prices][sell_price'; + // if (is_array($tables['uc_products']['fields']['weight']['option'])) { + // $tables['uc_products']['fields']['weight']['option']['#options']['editable'] = t('Editable'); + // } + // else { + // $tables['uc_products']['fields']['weight']['option'] = array( + // '#type' => 'select', + // '#options' => array( + // 'display' => t('Display'), + // 'editable' => t('Editable'), + // ), + // ); + // } + // $tables['uc_products']['fields']['weight']['form_parents'] = 'base][weight'; + // } +// } diff -urpN --strip-trailing-cr original_uc_alternative_price/views/uc_alternative_price_handler_field_alternative_price.inc uc_alternative_price/views/uc_alternative_price_handler_field_alternative_price.inc --- original_uc_alternative_price/views/uc_alternative_price_handler_field_alternative_price.inc 1970-01-01 10:00:00.000000000 +1000 +++ uc_alternative_price/views/uc_alternative_price_handler_field_alternative_price.inc 2009-06-17 18:20:59.176353600 +1000 @@ -0,0 +1,30 @@ + 'views-price-handler', + 'class' => $this->field, + 'subject' => array( + 'node' => $values, + 'field' => $this->real_field, + ), + ); + $table_alias_len = strlen($this->table_alias); + foreach ($values as $key => $value) { + if (substr($key, 0, $table_alias_len) == $this->table_alias) { + $values->{substr($key, $table_alias_len + 1)} = $value; + } + } + return uc_price($values->{$this->field_alias}, $context); + } +} diff -urpN --strip-trailing-cr original_uc_alternative_price/views/uc_alternative_price_handler_filter_alternative_price.inc uc_alternative_price/views/uc_alternative_price_handler_filter_alternative_price.inc --- original_uc_alternative_price/views/uc_alternative_price_handler_filter_alternative_price.inc 1970-01-01 10:00:00.000000000 +1000 +++ uc_alternative_price/views/uc_alternative_price_handler_filter_alternative_price.inc 2009-06-17 18:30:29.175972800 +1000 @@ -0,0 +1,17 @@ +query->add_field('uc_product_features', 'fid'); + $this->query->add_where($this->options['group'], "uc_product_features.fid ". (empty($this->value) ? "NOT " : "") ."IN ('alternative_price')", $this->value); + } +}