/** * This serializes the shopping cart variable as a backup in case the * unserialized one gets butchered by various things */ function wpsc_serialize_shopping_cart() { global $wpsc_cart; if (is_admin() && !(defined('DOING_AJAX') && DOING_AJAX)) { return; } if (is_object($wpsc_cart)) { $wpsc_cart->errors = array(); } // need to prevent set_cookie from being called at this stage in case the user just logged out // because by now, some output must have been printed out $customer_id = wpsc_get_current_customer_id(); if ($customer_id) { wpsc_update_customer_cart($wpsc_cart, $customer_id); } return true; }
/** * 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); }