diff --git a/uc_cart/uc_cart.module b/uc_cart/uc_cart.module index f9cf3d7..d67f7ee 100644 --- a/uc_cart/uc_cart.module +++ b/uc_cart/uc_cart.module @@ -1361,23 +1361,9 @@ function uc_cart_get_contents($cid = NULL, $action = NULL) { continue 2; } } - $product = node_load($item->nid); - $item->cost = $product->cost; - $item->price = $product->sell_price; - $item->weight = $product->weight; - $item->weight_units = $product->weight_units; + $item->data = unserialize($item->data); - $item->module = $item->data['module']; - $item->model = $product->model; - - // Invoke hook_cart_item() with $op = 'load' in enabled modules. - foreach (module_list() as $module) { - $func = $module .'_cart_item'; - if (function_exists($func)) { - // $item must be passed by reference. - $func('load', $item); - } - } + uc_cart_prepare_item($item); $items[$cid][] = $item; } @@ -1441,24 +1427,27 @@ function uc_cart_get_item($cart_item_id) { if (empty($item)) { return; } + $item->data = unserialize($item->data); + uc_cart_prepare_item($item); + return $item; +} + +/** + * Prepare a cart item object. + */ +function uc_cart_prepare_item($item) { $product = node_load($item->nid); $item->cost = $product->cost; $item->price = $product->sell_price; $item->weight = $product->weight; - $item->data = unserialize($item->data); + $item->weight_units = $product->weight_units; $item->module = $item->data['module']; $item->model = $product->model; - // Invoke hook_cart_item() with $op = 'load' in enabled modules. - foreach (module_list() as $module) { - $func = $module .'_cart_item'; - if (function_exists($func)) { - // $item must be passed by reference. - $func('load', $item); - } + foreach (module_implements('cart_item') as $module) { + $func = $module . '_cart_item'; + $func('load', $item); } - - return $item; } /** @@ -1529,6 +1518,27 @@ function uc_cart_add_item($nid, $qty = 1, $data = NULL, $cid = NULL, $msg = TRUE } } + // We need the full cart item including SKU to discover shippability. + $item = new stdClass; + $item->nid = $nid; + $item->qty = $qty; + $item->data = $data; + uc_cart_prepare_item($item); + $data = $item->data; + + $results = array(); + foreach (module_implements('cart_item') as $module) { + $func = $module .'_cart_item'; + $return = $func('can_ship', $item); + if (!is_null($return)) { + $results[] = $return; + } + } + + // The product is shippable if any module says that it is shippable, + // or if no module returned a result and the product node is shippable. + $data['shippable'] = !empty($results) ? in_array(TRUE, $results) : $node->shippable; + $item = db_fetch_object(db_query("SELECT * FROM {uc_cart_products} WHERE cart_id = '%s' AND nid = %d AND data = '%s'", $cid, $node->nid, serialize($data))); // If the item isn't in the cart yet, add it. @@ -1706,35 +1716,10 @@ function uc_cart_is_shippable($cart_id = NULL, $action = '') { } /** - * Determine whether a product is shippable or not. + * Determine whether an item is shippable or not. */ -function uc_cart_product_is_shippable($product) { - // Return FALSE if the product form specifies this as not shippable. - if ($product->data['shippable'] == FALSE) { - return FALSE; - } - - $result = array(); - - // See if any other modules have a say in the matter... - foreach (module_list() as $module) { - $func = $module .'_cart_item'; - if (function_exists($func)) { - // $product must be passed by reference. - $return = $func('can_ship', $product); - - if (!is_null($return)) { - $result[] = $return; - } - } - } - - // Return TRUE by default. - if (empty($result) || in_array(TRUE, $result)) { - return TRUE; - } - - return FALSE; +function uc_cart_product_is_shippable($item) { + return !empty($item->data['shippable']); } /** diff --git a/uc_order/uc_order.module b/uc_order/uc_order.module index 3fdf9b0..c1ccc18 100644 --- a/uc_order/uc_order.module +++ b/uc_order/uc_order.module @@ -1544,33 +1544,12 @@ function uc_order_is_shippable($order) { } foreach ($order->products as $product) { - // Return FALSE if the product form specifies this as not shippable. - if ($product->data['shippable'] == FALSE) { - $results[] = FALSE; - continue; + if (!empty($product->data['shippable'])) { + return TRUE; } - - // See if any other modules have a say in the matter... - foreach (module_list() as $module) { - $function = $module .'_cart_item'; - if (function_exists($function)) { - // $product must be passed by reference to hook_cart_item. - $can_ship = $function('can_ship', $product); - if (!is_null($can_ship)) { - $result[] = $can_ship; - } - } - } - - // Return TRUE by default. - if (empty($result) || in_array(TRUE, $result)) { - $results[] = TRUE; - continue; - } - $results[] = FALSE; } - return in_array(TRUE, $results); + return FALSE; } /** diff --git a/uc_product/uc_product.module b/uc_product/uc_product.module index 9693fc3..e2ca5fb 100644 --- a/uc_product/uc_product.module +++ b/uc_product/uc_product.module @@ -1273,14 +1273,6 @@ function uc_product_update_cart_item($nid, $data = array(), $qty, $cid = NULL) { } /** - * Implements hook_add_to_cart_data(). - */ -function uc_product_add_to_cart_data($form_values) { - $node = node_load($form_values['nid']); - return array('shippable' => $node->shippable); -} - -/** * Implements hook_product_class(). */ function uc_product_product_class($pcid, $op) {