/**
  * Validate the current customer, get the current customer id
  * @param string
  * @return JSON encoded array with results, results include original request parameters
  * @since 3.8.14
  */
 function wpsc_validate_customer_ajax()
 {
     // most of the validation should be done by the WPEC initialization, just return the current customer values
     $response = array('valid' => _wpsc_validate_customer_cookie() !== false, 'id' => wpsc_get_current_customer_id());
     $response = apply_filters('_wpsc_validate_customer_ajax', $response);
     wp_send_json_success($response);
 }
/**
 * 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;
}
function wpsc_shopping_cart($input = null, $override_state = null)
{
    global $wpdb, $wpsc_cart;
    $customer_id = wpsc_get_current_customer_id();
    if (is_numeric($override_state)) {
        $state = $override_state;
    } else {
        $state = get_option('cart_location');
    }
    if (get_option('show_sliding_cart') == 1) {
        if (isset($_SESSION['slider_state']) && is_numeric($_SESSION['slider_state'])) {
            if ($_SESSION['slider_state'] == 0) {
                $collapser_image = 'plus.png';
            } else {
                $collapser_image = 'minus.png';
            }
            $fancy_collapser = "<a href='#' onclick='return shopping_cart_collapser()' id='fancy_collapser_link'><img src='" . WPSC_CORE_IMAGES_URL . "/{$collapser_image}' title='' alt='' id='fancy_collapser' /></a>";
        } else {
            if ($customer_id) {
                $collapser_image = 'minus.png';
            } else {
                $collapser_image = 'plus.png';
            }
            $fancy_collapser = "<a href='#' onclick='return shopping_cart_collapser()' id='fancy_collapser_link'><img src='" . WPSC_CORE_IMAGES_URL . "/{$collapser_image}' title='' alt='' id='fancy_collapser' /></a>";
        }
    } else {
        $fancy_collapser = "";
    }
    if ($state == 1) {
        if ($input != '') {
            echo "<div id='sideshoppingcart'><div id='shoppingcartcontents'>";
            echo wpsc_shopping_basket_internals();
            echo "</div></div>";
        }
    } else {
        if ($state == 3 || $state == 4) {
            if ($state == 4) {
                echo "<div id='widgetshoppingcart'>";
                echo "<h3>" . __('Shopping Cart', 'wp-e-commerce') . "{$fancy_collapser}</h3>";
                echo "  <div id='shoppingcartcontents'>";
                echo wpsc_shopping_basket_internals(false, false, true);
                echo "  </div>";
                echo "</div>";
                $dont_add_input = true;
            } else {
                echo "<div id='sideshoppingcart'>";
                echo "<h3>" . __('Shopping Cart', 'wp-e-commerce') . "{$fancy_collapser}</h3>";
                echo "  <div id='shoppingcartcontents'>";
                echo wpsc_shopping_basket_internals(false, false, true);
                echo "  </div>";
                echo "</div>";
            }
        } else {
            if (isset($GLOBALS['nzshpcrt_activateshpcrt']) && $GLOBALS['nzshpcrt_activateshpcrt'] === true) {
                echo "<div id='shoppingcart'>";
                echo "<h3>" . __('Shopping Cart', 'wp-e-commerce') . "{$fancy_collapser}</h3>";
                echo "  <div id='shoppingcartcontents'>";
                echo wpsc_shopping_basket_internals(false, false, true);
                echo "  </div>";
                echo "</div>";
            }
        }
    }
    return $input;
}
Example #4
0
 function validate_cart()
 {
     /*
      * action: wpsc_pre_validate_cart
      *
      * Prior to validating the cart we give anyone whoe is interested a chance to do a little setup with this
      * wpsc_pre_validate_cart.
      *
      * This action can be used as a convenient point to change the logic that is esecuted when the 'wpsc_validate_cart'
      * action is fired.  For example, if you want to do different address checks based on which country is being shipped
      * to you can call add_action with different function paramters.  Or if you wnated to some extra validation when shipping
      * address is differnet than billing, perhaps a quick SOAP call to a fraud check service, you can conditionally do an
      * add action to your function that does the fraud check.
      *
      * @param wpsc_cart the cart object
      * @param current visitor id (use this to get customer meta for the current user
      */
     do_action('wpsc_pre_validate_cart', $this, wpsc_get_current_customer_id());
     /*
      * action: wpsc_validate_cart
      *
      * Validate that the cart contents is valid.  Typically done just prior to checkout.  Most often error conditions
      * will be recorded to special customer meta values, but other processing can be implemented based on specific needs
      *
      * These are the customer/visitor meta values that are typically added to when errors are found:
      * 			checkout_error_messages
      * 			gateway_error_messages
      * 			registration_error_messages
      *
      * @param wpsc_cart the cart object
      * @param current visitor id (use this to get customer meta for the current user
      */
     do_action('wpsc_validate_cart', $this, wpsc_get_current_customer_id());
 }
/**
 * deprecating user log filter for getting all customer meta as an array.
 *
 *@deprecated 3.8.14
 *
 * @return none
 */
function wpsc_deprecated_filter_user_log_get()
{
    if (has_filter('wpsc_user_log_get')) {
        $meta_data = wpsc_get_customer_meta('checkout_details');
        $meta_data = apply_filters('wpsc_user_log_get', $meta_data, wpsc_get_current_customer_id());
        wpsc_update_customer_meta('checkout_details', $meta_data);
        _wpsc_doing_it_wrong('wpsc_user_log_get', __('The filter being used has been deprecated. Use wpsc_get_visitor_meta or wpsc_get_visitor_meta_$meta_name instead.', 'wp-e-commerce'), '3.8.14');
    }
}
 private function submit_payment_method()
 {
     global $wpsc_cart;
     if (!$this->verify_nonce('wpsc-checkout-form-payment-method')) {
         return;
     }
     if (empty($_POST['wpsc_payment_method']) && !wpsc_is_free_cart()) {
         $this->message_collection->add(__('Please select a payment method', 'wp-e-commerce'), 'validation');
     }
     $valid = apply_filters('_wpsc_merchant_v2_validate_payment_method', true, $this);
     if (!$valid) {
         return;
     }
     $purchase_log_id = wpsc_get_customer_meta('current_purchase_log_id');
     $purchase_log = new WPSC_Purchase_Log($purchase_log_id);
     $submitted_gateway = $_POST['wpsc_payment_method'];
     $purchase_log->set(array('gateway' => $submitted_gateway, 'base_shipping' => $wpsc_cart->calculate_base_shipping(), 'totalprice' => $wpsc_cart->calculate_total_price()));
     if ($this->maybe_add_guest_account() && isset($_POST['wpsc_create_account'])) {
         $email = wpsc_get_customer_meta('billingemail');
         $user_id = wpsc_register_customer($email, $email, false);
         $purchase_log->set('user_ID', $user_id);
         wpsc_update_customer_meta('checkout_details', wpsc_get_customer_meta('checkout_details'), $user_id);
         update_user_meta($user_id, '_wpsc_visitor_id', wpsc_get_current_customer_id());
     }
     $purchase_log->save();
     $wpsc_cart->empty_db($purchase_log_id);
     $wpsc_cart->save_to_db($purchase_log_id);
     $wpsc_cart->submit_stock_claims($purchase_log_id);
     $wpsc_cart->log_id = $purchase_log_id;
     $this->wizard->completed_step('payment');
     do_action('wpsc_submit_checkout', array('purchase_log_id' => $purchase_log_id, 'our_user_id' => isset($user_id) ? $user_id : get_current_user_id()));
     do_action('wpsc_submit_checkout_gateway', $submitted_gateway, $purchase_log);
 }
/**
 * Update the current customer's last active time
 *
 * @access private
 * @since  3.8.13
 */
function _wpsc_action_customer_used_cart()
{
    do_action('_wpsc_action_customer_used_cart');
    // get the current users id
    $id = wpsc_get_current_customer_id();
    // go through the common update routine that allows any users last active time to be changed
    wpsc_set_visitor_expiration($id, DAY_IN_SECONDS * 2);
    // also extend cookie expiration
    _wpsc_create_customer_id_cookie($id);
}
Example #8
0
/**
 * does the customer have purchases
 * @since 3.8.14
 * @access public
 * @param string $id
 * @return int
 */
function wpsc_customer_has_purchases($id = false)
{
    if (!$id) {
        $id = wpsc_get_current_customer_id();
    }
    return wpsc_visitor_has_purchases($id);
}
Example #9
0
/**
 * Update the customer's last active time
 *
 * Last active time is automatically set for certain AJAX transactions (see customer.php) but
 * can be updated manually for specific  customer id as necessary in admin or plugin logic
 *
 * @param string $id     the customer id.
 * @access public
 * @since  3.8.13
 * @return int
 */
function wpsc_update_customer_last_active($id = false)
{
    if (!$id) {
        $id = wpsc_get_current_customer_id();
    }
    wpsc_set_visitor_last_active($id);
    return $id;
}
Example #10
0
 private function save_shipping_and_billing_info()
 {
     global $wpsc_cart;
     // see if an existing purchase log has been set for this user
     // otherwise create one
     $purchase_log_id = (int) wpsc_get_customer_meta('current_purchase_log_id');
     if ($purchase_log_id) {
         $purchase_log = new WPSC_Purchase_Log($purchase_log_id);
     } else {
         $purchase_log = new WPSC_Purchase_Log();
     }
     $sessionid = mt_rand(100, 999) . time();
     wpsc_update_customer_meta('checkout_session_id', $sessionid);
     $purchase_log->set(array('user_ID' => wpsc_get_current_customer_id(), 'date' => time(), 'plugin_version' => WPSC_VERSION, 'statusno' => '0', 'sessionid' => $sessionid));
     $form = WPSC_Checkout_Form::get();
     $fields = $form->get_fields();
     foreach ($fields as $field) {
         if (!array_key_exists($field->id, $_POST['wpsc_checkout_details'])) {
             continue;
         }
         $value = $_POST['wpsc_checkout_details'][$field->id];
         switch ($field->unique_name) {
             case 'billingstate':
                 wpsc_update_customer_meta('billing_region', $value);
                 $purchase_log->set('billing_region', $value);
                 break;
             case 'shippingstate':
                 wpsc_update_customer_meta('shipping_region', $value);
                 $purchase_log->set('shipping_region', $value);
                 break;
             case 'billingcountry':
                 wpsc_update_customer_meta('billing_country', $value);
                 $purchase_log->set('billing_country', $value);
                 break;
             case 'shippingcountry':
                 wpsc_update_customer_meta('shipping_country', $value);
                 $purchase_log->set('shipping_region', $value);
                 break;
             case 'shippingpostcode':
                 wpsc_update_customer_meta('shipping_zip', $value);
                 break;
         }
     }
     _wpsc_update_location();
     if (wpsc_is_tax_included()) {
         $tax = $wpsc_cart->calculate_total_tax();
         $tax_percentage = $wpsc_cart->tax_percentage;
     } else {
         $tax = 0;
         $tax_percentage = 0;
     }
     $purchase_log->set(array('wpec_taxes_total' => $tax, 'wpec_taxes_rate' => $tax_percentage));
     $purchase_log->save();
     $wpsc_cart->log_id = $purchase_log->get('id');
     wpsc_update_customer_meta('current_purchase_log_id', $purchase_log->get('id'));
     $this->save_form($purchase_log, $fields);
     $this->init_shipping_calculator();
     if (wpsc_uses_shipping() && !$this->shipping_calculator->has_quotes) {
         $this->message_collection->add(__('Sorry but we cannot ship products to your submitted address. Please either provide another shipping address or contact the store administrator about product availability to your location.', 'wpsc'), 'error');
         return;
     }
     $this->wizard->completed_step('shipping-and-billing');
     wp_redirect(wpsc_get_checkout_url($this->wizard->pending_step));
     exit;
 }
Example #11
0
/**
 * Update the customer mata values that are passed to the application from the checkout form POST
 *
 * With the submit checkout we should get an array of all the checkout values.  These values should already
 * be stored as customer meta, bet there are cases where the submit processing may arrive before or in parallel
 * with the request to update meta.  There is also value in cehcking to be sure the meta stored is what is coming
 * with the POST as it preserves non-js compatibility and being able to use the submit action as an API
 *
 * @since  3.8.14.1
 *
 * @access private
 *
 * @param  array $checkout_post_data
 *
 * @return none
 */
function _wpsc_checkout_customer_meta_update($checkout_post_data)
{
    global $wpdb;
    if (empty($checkout_post_data) || !is_array($checkout_post_data)) {
        return;
    }
    $id = wpsc_get_current_customer_id();
    $form_sql = 'SELECT * FROM `' . WPSC_TABLE_CHECKOUT_FORMS . '` WHERE `active` = "1" ORDER BY `checkout_set`, `checkout_order`;';
    $form_data = $wpdb->get_results($form_sql, ARRAY_A);
    foreach ($form_data as $index => $form_field) {
        if (isset($checkout_post_data[$form_field['id']])) {
            $meta_key = $form_field['unique_name'];
            $meta_value = $checkout_post_data[$form_field['id']];
            switch ($form_field['type']) {
                case 'delivery_country':
                    if (is_array($meta_value)) {
                        if (isset($meta_value[0])) {
                            wpsc_update_visitor_meta($id, 'shippingcountry', $meta_value[0]);
                        }
                        if (isset($meta_value[1])) {
                            wpsc_update_visitor_meta($id, 'shippingregion', $meta_value[1]);
                        }
                    } else {
                        // array had only country, update the country
                        wpsc_update_visitor_meta($id, 'shippingcountry', $meta_value);
                    }
                    break;
                case 'country':
                    if (is_array($meta_value) && count($meta_value) == 2) {
                        wpsc_update_visitor_meta($id, 'billingcountry', $meta_value[0]);
                        wpsc_update_visitor_meta($id, 'billingregion', $meta_value[1]);
                    } else {
                        if (is_array($meta_value)) {
                            $meta_value = $meta_value[0];
                        }
                        wpsc_update_visitor_meta($id, 'billingcountry', $meta_value);
                    }
                    break;
                default:
                    wpsc_update_visitor_meta($id, $meta_key, $meta_value);
                    break;
            }
        }
    }
}
function _wpsc_visitor_location_clear_tracked_changes($visitor_id = false)
{
    if (!$visitor_id) {
        $visitor_id = wpsc_get_current_customer_id();
    }
    wpsc_delete_visitor_meta($visitor_id, 'location_attributes_changed');
    return true;
}
 /**
  * Get a deprecated customer meta value that mirrors what was once "checkout_details".
  *
  * @since  3.8.14
  * @param  string|int $id Customer ID. Optional. Defaults to current customer
  * @return array        checkout details array
  */
 function _wpsc_update_deprecated_visitor_meta_checkout_details($meta_data_in_old_format, $key = 'checkout_details', $id = null)
 {
     global $wpdb;
     if (!$id) {
         $id = wpsc_get_current_customer_id();
     }
     $form_sql = 'SELECT * FROM `' . WPSC_TABLE_CHECKOUT_FORMS . '` WHERE `active` = "1" ORDER BY `checkout_set`, `checkout_order`;';
     $form_data = $wpdb->get_results($form_sql, ARRAY_A);
     foreach ($form_data as $index => $form_field) {
         if (isset($meta_data_in_old_format[$form_field['id']])) {
             $meta_key = $form_field['unique_name'];
             $meta_value = $meta_data_in_old_format[$form_field['id']];
             switch ($form_field['type']) {
                 case 'delivery_country':
                     if (is_array($meta_value) && count($meta_value) == 2) {
                         wpsc_update_visitor_meta($id, 'shippingcountry', $meta_value[0]);
                         wpsc_update_visitor_meta($id, 'shippingregion', $meta_value[1]);
                     } else {
                         if (is_array($meta_value)) {
                             $meta_value = $meta_value[0];
                         }
                         wpsc_update_visitor_meta($id, 'shippingcountry', $meta_value);
                         wpsc_update_visitor_meta($id, 'shippingregion', '');
                     }
                     break;
                 case 'country':
                     if (is_array($meta_value) && count($meta_value) == 2) {
                         wpsc_update_visitor_meta($id, 'billingcountry', $meta_value[0]);
                         wpsc_update_visitor_meta($id, 'billingregion', $meta_value[1]);
                     } else {
                         if (is_array($meta_value)) {
                             $meta_value = $meta_value[0];
                         }
                         wpsc_update_visitor_meta($id, 'billingcountry', $meta_value);
                         wpsc_update_visitor_meta($id, 'billingregion', '');
                     }
                     break;
                 default:
                     wpsc_update_visitor_meta($id, $meta_key, $meta_value);
                     break;
             }
         }
     }
     $deprecated_meta_value = wpsc_get_visitor_meta($id, $key, true);
     if (!empty($deprecated_meta_value)) {
         wpsc_delete_visitor_meta($id, $key);
     }
     return $meta_data_in_old_format;
 }
Example #14
0
/**
 * Create customer ID upon 'plugins_loaded' to make sure there's one exists before
 * anything else.
 *
 * @access private
 * @since  3.8.9
 */
function _wpsc_action_create_customer_id()
{
    wpsc_get_current_customer_id('create');
}