/** * Setup current user object and customer ID as well as cart. * * @uses do_action() Calls 'wpsc_setup_customer' after customer data is ready * @access private * @since 3.8.13 * @return int visitor id * */ function _wpsc_action_setup_customer() { ///////////////////////////////////////////////////////////////////////// // Setting up the customer happens after WPEC is initialized AND after // WordPress has loaded. The reason for this is that the conditional // query tags are checked to see if the request is a 404 or a feed or // some other request that should not create a visitor profile. The // conditional query tags are not available until after the // posts_selection hook is processed. The 'wp' action is fired after // the 'posts_selection' hook. ///////////////////////////////////////////////////////////////////////// if (!did_action('init')) { _wpsc_doing_it_wrong(__FUNCTION__, __('Customer cannot be reliably setup until at least the "init" hook as been fired during AJAX processing.', 'wpsc'), '3.8.14'); } // if the customer cookie is invalid, unset it $visitor_id_from_cookie = _wpsc_validate_customer_cookie(); if ($visitor_id_from_cookie && is_user_logged_in()) { $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)) { _wpsc_update_wp_user_visitor_id(get_current_user_id(), $visitor_id_from_cookie); } elseif ($visitor_id_from_cookie != $id_from_wp_user) { // save the old visitor id so the merge cart function can do its work wpsc_update_customer_meta('merge_cart_vistor_id', $visitor_id_from_cookie); // make the current customer cookie match the cookie that is in the WordPress user meta _wpsc_create_customer_id_cookie($id_from_wp_user); // merging cart requires the taxonomies to have been initialized if (did_action('wpsc_register_taxonomies_after')) { _wpsc_merge_cart(); } else { add_action('wpsc_register_taxonomies_after', '_wpsc_merge_cart', 1); } } } // initialize customer ID if it's not already there $visitor_id = wpsc_get_current_customer_id(); // if there wasn't a visitor id in the cookies we set it now if ($visitor_id && empty($visitor_id_from_cookie) && is_user_logged_in()) { _wpsc_create_customer_id_cookie($visitor_id); } // setup the cart and restore its items wpsc_core_setup_cart(); do_action('wpsc_setup_customer', $visitor_id); }
/** * _wpsc_action_init_shipping_method() * * The cart was setup at the beginning of the init sequence, and that's * too early to do shipping calculations because custom taxonomies, types * and other plugins may not have been initialized. So we save the shipping * method initialization for the end of the init sequence. */ function _wpsc_action_init_shipping_method() { global $wpsc_cart; if (!is_object($wpsc_cart)) { wpsc_core_setup_cart(); } if (empty($wpsc_cart->selected_shipping_method)) { $wpsc_cart->get_shipping_method(); } }
/** * Setup the WPEC core */ function load() { // Before setup do_action('wpsc_pre_load'); // Legacy action do_action('wpsc_before_init'); // Setup the core WPEC globals wpsc_core_setup_globals(); // Setup the core WPEC cart wpsc_core_setup_cart(); // Load the thumbnail sizes wpsc_core_load_thumbnail_sizes(); // Load the purchase log statuses wpsc_core_load_purchase_log_statuses(); // Load unique names and checout form types wpsc_core_load_checkout_data(); // Load the gateways wpsc_core_load_gateways(); // Load the shipping modules wpsc_core_load_shipping_modules(); // Set page title array for important WPSC pages wpsc_core_load_page_titles(); // WPEC is fully loaded do_action('wpsc_loaded'); }