/** * Merge cart from anonymous user with cart from logged in user * * @since 3.8.13 * @access private */ function _wpsc_merge_cart() { $id_from_wp_user = get_user_meta(get_current_user_id(), _wpsc_get_visitor_meta_key('visitor_id'), true); if (empty($id_from_wp_user)) { return; } do_action('_wpsc_merge_cart', $id_from_wp_user); $id_from_customer_meta = wpsc_get_customer_meta('merge_cart_vistor_id'); wpsc_delete_customer_meta('merge_cart_vistor_id'); $old_cart = wpsc_get_customer_cart($id_from_customer_meta); $items = $old_cart->get_items(); $new_cart = wpsc_get_customer_cart($id_from_wp_user); // first of all empty the old cart so that the claimed stock and related // hooks are released $old_cart->empty_cart(); // add each item to the new cart foreach ($items as $item) { $new_cart->set_item($item->product_id, array('quantity' => $item->quantity, 'variation_values' => $item->variation_values, 'custom_message' => $item->custom_message, 'provided_price' => $item->provided_price, 'time_requested' => $item->time_requested, 'custom_file' => $item->custom_file, 'is_customisable' => $item->is_customisable, 'meta' => $item->meta, 'item_meta' => $item->get_meta())); } wpsc_update_customer_cart($new_cart); // The old profile is no longer needed _wpsc_abandon_temporary_customer_profile($id_from_customer_meta); }
/** * wpsc_core_setup_cart() * * Setup the cart */ function wpsc_core_setup_cart() { if (2 == get_option('cart_location')) { add_filter('the_content', 'wpsc_shopping_cart', 14); } $GLOBALS['wpsc_cart'] = wpsc_get_customer_cart(); }
/** * Prior to using the global cart variable cart template API functions should check * to be sure the global cart variable has been initialized. * * @access private * @static * @since 3.8.14 * * @uses wpsc_cart * @return boolean true if we have a valid cart, false otherwise * */ function _wpsc_verify_global_cart_has_been_initialized($function = __FUNCTION__) { global $wpsc_cart; $we_have_a_valid_cart = !empty($wpsc_cart) && is_a($wpsc_cart, 'wpsc_cart'); if (!$we_have_a_valid_cart) { $wpsc_cart = wpsc_get_customer_cart(); $we_have_a_valid_cart = !empty($wpsc_cart) && is_a($wpsc_cart, 'wpsc_cart'); } // We will try to give a helpful message to the developer so that they can adjust their code static $already_gave_no_valid_cart_message = false; if (!$we_have_a_valid_cart && !$already_gave_no_valid_cart_message) { _wpsc_doing_it_wrong($function, __('The WPeC global cart is not yet initialized. Accessing global cart properties and methods will not work.', 'wpsc'), '3.8.14'); $already_gave_no_valid_cart_message = true; } return $we_have_a_valid_cart; }