Пример #1
0
 /**
  * Create visitor class from visitor id
  * @param  $visitor_id int unique visitor id
  * @since 3.8.14
  */
 function __construct($visitor_id)
 {
     $this->_cart = new wpsc_cart();
     $visitor = _wpsc_get_visitor($visitor_id);
     if ($visitor == false) {
         $this->valid = false;
         return;
     }
     if ($visitor) {
         foreach ($visitor as $key => $value) {
             $property_name = '_' . $key;
             $this->{$property_name} = $value;
         }
     }
     $visitor_meta = wpsc_get_visitor_meta($visitor_id);
     if (!empty($visitor_meta)) {
         foreach ($visitor_meta as $meta_key => $meta_value) {
             if (($i = strpos($meta_key, 'cart.')) === false) {
                 $property_name = '_' . $meta_key;
                 $this->{$property_name} = $meta_value[0];
             } else {
                 $property_name = substr($meta_key, strlen('_wpsc_cart.'));
                 $this->_cart->{$property_name} = $meta_value[0];
             }
         }
     }
     $this->_cart = wpsc_get_visitor_cart($visitor_id);
 }
Пример #2
0
/**
 * Return an array containing all metadata of a customer
 *
 * Implement your own system by hooking into 'wpsc_get_all_customer_meta'.
 *
 * @access public
 * @since 3.8.9
 * @param  mixed $id Customer ID. Default to the current user ID.
 * @return WP_Error|array Return an array of metadata if no error occurs, WP_Error
 *                        if otherwise.
 */
function wpsc_get_all_customer_meta($id = false)
{
    global $wpdb;
    if (!$id) {
        $id = wpsc_get_current_customer_id();
    }
    $result = apply_filters('wpsc_get_all_customer_meta', null, $id);
    if ($result) {
        return $result;
    }
    $meta = wpsc_get_visitor_meta($id);
    $blog_prefix = is_multisite() ? $wpdb->get_blog_prefix() : '';
    $key_pattern = "{$blog_prefix}_wpsc_";
    $return = array();
    foreach ($meta as $key => $value) {
        if (strpos($key, $key_pattern) === FALSE) {
            continue;
        }
        $short_key = str_replace($key_pattern, '', $key);
        $return[$short_key] = $value[0];
    }
    return $return;
}
/**
 * Update any values dependant on billing country
 *
 * @since 3.8.14
 *
 * @access private
 * @param mixed $meta_value Optional. Metadata value.
 * @param string $meta_key Metadata name.
 * @param int $visitor_id visitor ID
 * @return none
*/
function _wpsc_updated_visitor_meta_billingcountry($meta_value, $meta_key, $visitor_id)
{
    $old_billing_state = wpsc_get_visitor_meta($visitor_id, 'billingstate', true);
    $old_billing_region = wpsc_get_visitor_meta($visitor_id, 'billingregion', true);
    if (!empty($meta_value)) {
        // check the current state and region values, if either isn't valid for the new country delete them
        $wpsc_country = new WPSC_Country($meta_value);
        if (!empty($old_billing_state) && $wpsc_country->has_regions() && !$wpsc_country->has_region($old_billing_state)) {
            wpsc_delete_visitor_meta($visitor_id, 'billingstate');
        }
        if (!empty($old_billing_region) && $wpsc_country->has_regions() && !$wpsc_country->has_region($old_billing_region)) {
            wpsc_delete_visitor_meta($visitor_id, 'billingregion');
        }
    } else {
        wpsc_delete_visitor_meta($visitor_id, 'billingstate');
        wpsc_delete_visitor_meta($visitor_id, 'billingregion');
    }
}
/**
 * when visitor meta is updated we need to check if the shipping same as billing
 * option is selected.  If so we need to update the corresponding meta value.
 *
 * @since 3.8.14
 * @access private
 * @param $meta_value varies value being stored
 * @param $meta_key string name of the attribute being stored
 * @param $visitor_id int id of the visitor to which the attribute applies
 * @return n/a
 */
function _wpsc_vistor_shipping_same_as_billing_meta_update($meta_value, $meta_key, $visitor_id)
{
    // remove the action so we don't cause an infinite loop
    remove_action('wpsc_updated_visitor_meta', '_wpsc_vistor_shipping_same_as_billing_meta_update', _WPSC_USER_META_HOOK_PRIORITY);
    // if the shipping same as billing option is being checked then copy meta from billing to shipping
    if ($meta_key == 'shippingSameBilling') {
        $meta_value = _wpsc_make_value_into_bool($meta_value);
        if ($meta_value) {
            $checkout_names = wpsc_checkout_unique_names();
            foreach ($checkout_names as $meta_key) {
                $meta_key_starts_with_billing = strpos($meta_key, 'billing', 0) === 0;
                if ($meta_key_starts_with_billing) {
                    $other_meta_key_name = 'shipping' . substr($meta_key, strlen('billing'));
                    if (in_array($other_meta_key_name, $checkout_names)) {
                        $billing_meta_value = wpsc_get_customer_meta($meta_key);
                        wpsc_update_visitor_meta($visitor_id, $other_meta_key_name, $billing_meta_value);
                    }
                }
            }
        }
    } else {
        $shipping_same_as_billing = wpsc_get_visitor_meta($visitor_id, 'shippingSameBilling', true);
        if ($shipping_same_as_billing) {
            $meta_key_starts_with_billing = strpos($meta_key, 'billing', 0) === 0;
            $meta_key_starts_with_shipping = strpos($meta_key, 'shipping', 0) === 0;
            if ($meta_key_starts_with_billing) {
                $checkout_names = wpsc_checkout_unique_names();
                $other_meta_key_name = 'shipping' . substr($meta_key, strlen('billing'));
                if (in_array($other_meta_key_name, $checkout_names)) {
                    wpsc_update_visitor_meta($visitor_id, $other_meta_key_name, $meta_value);
                }
            } elseif ($meta_key_starts_with_shipping) {
                $checkout_names = wpsc_checkout_unique_names();
                $other_meta_key_name = 'billing' . substr($meta_key, strlen('shipping'));
                if (in_array($other_meta_key_name, $checkout_names)) {
                    wpsc_update_visitor_meta($visitor_id, $other_meta_key_name, $meta_value);
                }
            }
        }
    }
    // restore the action we removed at the start
    add_action('wpsc_updated_visitor_meta', '_wpsc_vistor_shipping_same_as_billing_meta_update', _WPSC_USER_META_HOOK_PRIORITY, 3);
}
Пример #5
0
function _wpsc_has_visitor_location_changed($visitor_id = false)
{
    $what_about_the_visitor_location_changed = wpsc_get_visitor_meta($visitor_id, 'location_attributes_changed', true);
    if (!is_array($what_about_the_visitor_location_changed) && !empty($what_about_the_visitor_location_changed)) {
        do_action('wpsc_visitor_location_changing', $what_about_the_visitor_location_changed, $visitor_id);
    }
    $what_about_the_visitor_location_changed = wpsc_get_visitor_meta($visitor_id, 'location_attributes_changed', true);
    if (!is_array($what_about_the_visitor_location_changed) && !empty($what_about_the_visitor_location_changed)) {
        do_action('wpsc_visitor_location_changed', $what_about_the_visitor_location_changed, $visitor_id);
    }
}
Пример #6
0
 /**
  * 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;
 }