From bca7035d5ab983daa8c726e3d30ecc5744034ee1 Mon Sep 17 00:00:00 2001 From: Jordan Fei Date: Wed, 6 Feb 2013 13:26:39 +0800 Subject: [PATCH] Issue #1899458: Added taxed product type update when product type changes --- uc_product/uc_product.api.php | 20 ++++++++++++++++++++ uc_product/uc_product.module | 4 ++++ uc_taxes/uc_taxes.module | 17 +++++++++++++++++ 3 files changed, 41 insertions(+) diff --git a/uc_product/uc_product.api.php b/uc_product/uc_product.api.php index 67f9bfb..3ec15f5 100644 --- a/uc_product/uc_product.api.php +++ b/uc_product/uc_product.api.php @@ -191,5 +191,25 @@ function hook_uc_product_types() { } /** + * Update the reference(like product type in uc_tax) of product type when the node type was updated. + * + * @param $old_type + * Old product type. + * @param $new_type + * New product type. + */ +function hook_uc_product_type_update($old_type, $new_type){ + if($old_type!=$new_type) + { + db_update('uc_taxed_product_types') + ->fields(array( + 'type' => $new_type, + )) + ->condition('type', $old_type) + ->execute(); + } +} + +/** * @} End of "addtogroup hooks". */ diff --git a/uc_product/uc_product.module b/uc_product/uc_product.module index 6e7b657..3cfa181 100644 --- a/uc_product/uc_product.module +++ b/uc_product/uc_product.module @@ -309,6 +309,10 @@ function uc_product_node_type_update($info) { // Reset static variable data and load new info. uc_product_node_info(TRUE); + + if($existing_type != $info->type) { + module_invoke_all('uc_product_type_update', $existing_type, $info->type); + } } /** diff --git a/uc_taxes/uc_taxes.module b/uc_taxes/uc_taxes.module index 5cdaed9..657d978 100644 --- a/uc_taxes/uc_taxes.module +++ b/uc_taxes/uc_taxes.module @@ -235,6 +235,23 @@ function uc_taxes_uc_order($op, $order, $arg2) { } /** + * Implements hook_uc_product_type_update(). + * + * Updates product type in taxed product types. + */ +function uc_taxes_uc_product_type_update($old_type, $new_type) { + if($old_type!=$new_type) + { + db_update('uc_taxed_product_types') + ->fields(array( + 'type' => $new_type, + )) + ->condition('type', $old_type) + ->execute(); + } +} + +/** * Tax line item callback. */ function uc_line_item_tax_display($op, $order) { -- 1.8.0.msysgit.0