/**
  * constructor for a region object
  *
  * If null is passed for parameters an empty region is created
  *
  * @access public
  *
  * @since 3.8.14
  *
  * @param int|string|null       required    $country    The country identifier, can be the string ISO code,
  *                                                      or the numeric wpec country id
  *
  * @param int|string|null|array required    $region     The region identifier, can be the text region code,
  *                                                      or the numeric region id, if an array is passed a
  *                                                      new region will be created and saved in the permanent
  *                                                      data store
  */
 public function __construct($country, $region)
 {
     // if a country id or code is passed make sure we have a valid country_id
     $country_id = $country ? WPSC_Countries::get_country_id($country) : 0;
     // if we are creating a region use the country_id we just validated and get the region code
     if (is_array($region)) {
         $region['country_id'] = $country_id;
         $region_id_or_code = $this->_save_region_data($region);
     } else {
         $region_id_or_code = $region;
     }
     // if we have both a country country id and a region id/code we can construct this object
     if ($country && $region_id_or_code) {
         $region_id = WPSC_Countries::get_region_id($country_id, $region_id_or_code);
         if ($country_id && $region_id) {
             $wpsc_country = new WPSC_Country($country_id);
             $wpsc_region = $wpsc_country->get_region($region_id);
             if ($wpsc_region) {
                 $this->_code = $wpsc_region->_code;
                 $this->_id = $wpsc_region->_id;
                 $this->_country_id = $wpsc_region->_country_id;
                 $this->_name = $wpsc_region->_name;
                 $this->_tax = $wpsc_region->_tax;
             }
         }
     }
 }
Exemple #2
0
/**
 * 3.8.14 supports country meta and a feature that let's a countries regions be called by the
 * proper name.  Here we initialize the values.
 *
 * @access private
 * @since 3.8.14
 *
 */
function _wpsc_add_region_name_meta()
{
    $wpsc_country = new WPSC_Country('US');
    $wpsc_country->set('region_label', __('State', 'wp-e-commerce'));
    $wpsc_country = new WPSC_Country('CA');
    $wpsc_country->set('region_label', __('Province', 'wp-e-commerce'));
}
Exemple #3
0
/**
 * Format a price amount.
 *
 * The available options that you can specify in the $args argument include:
 *     'display_currency_symbol' - Whether to attach the currency symbol to the figure.
 *                                 Defaults to true.
 *     'display_decimal_point'   - Whether to display the decimal point.
 *                                 Defaults to true.
 *     'display_currency_code'   - Whether to attach the currency code to the figure.
 *                                 Defaults to fault.
 *     'isocode'                 - Specify the isocode of the base country that you want to use for
 *                                 this price.
 *                                 Defaults to the settings in Settings->Store->General.
 *
 * @since 4.0
 * @uses  apply_filters() Applies 'wpsc_format_currency'                     filter
 * @uses  apply_filters() Applies 'wpsc_format_currency_currency_code'       filter.
 * @uses  apply_filters() Applies 'wpsc_format_currency_currency_symbol'     filter.
 * @uses  apply_filters() Applies 'wpsc_format_currency_decimal_separator'   filter.
 * @uses  apply_filters() Applies 'wpsc_format_currency_thousands_separator' filter.
 * @uses  apply_filters() Applies 'wpsc_modify_decimals' filter.
 * @uses  get_option()    Gets the value of 'currency_sign_location' in Settings->Store->General.
 * @uses  get_option()    Gets the value of 'currency_type' in Settings->Store->General.
 * @uses  WPSC_Country::__construct()
 * @uses  WPSC_Country::get()
 * @uses  wp_parse_args()
 *
 * @param  float|int|string $amt  The price you want to format.
 * @param  string|array     $args A query string or array containing the options. Defaults to ''.
 * @return string                 The formatted price.
 */
function wpsc_format_currency($amt, $args = '')
{
    $defaults = array('display_currency_symbol' => true, 'display_decimal_point' => true, 'display_currency_code' => false, 'isocode' => false, 'currency_code' => false);
    $args = wp_parse_args($args);
    // Either display symbol or code, not both
    if (array_key_exists('display_currency_symbol', $args)) {
        $args['display_currency_code'] = !$args['display_currency_symbol'];
    } elseif (array_key_exists('display_currency_code', $args)) {
        $args['display_currency_symbol'] = !$args['display_currency_code'];
    }
    $r = wp_parse_args($args, $defaults);
    extract($r);
    $currencies_without_fractions = WPSC_Payment_Gateways::currencies_without_fractions();
    if ($isocode) {
        $currency = new WPSC_Country($isocode);
    } else {
        $currency = new WPSC_Country(get_option('currency_type'));
    }
    $currency_code = $currency->get_currency_code();
    // No decimal point, no decimals
    if (!$display_decimal_point || in_array($currency_code, $currencies_without_fractions)) {
        $decimals = 0;
    } else {
        $decimals = 2;
        // default is 2
    }
    $decimals = apply_filters('wpsc_modify_decimals', $decimals, $isocode);
    $decimal_separator = apply_filters('wpsc_format_currency_decimal_separator', wpsc_get_option('decimal_separator'), $isocode);
    $thousands_separator = apply_filters('wpsc_format_currency_thousands_separator', wpsc_get_option('thousands_separator'), $isocode);
    // Format the price for output
    $formatted = number_format($amt, $decimals, $decimal_separator, $thousands_separator);
    if (!$display_currency_code) {
        $currency_code = '';
    }
    $symbol = $display_currency_symbol ? $currency->get_currency_symbol() : '';
    $symbol = esc_html($symbol);
    $symbol = apply_filters('wpsc_format_currency_currency_symbol', $symbol, $isocode);
    $currency_sign_location = get_option('currency_sign_location');
    // Rejig the currency sign location
    switch ($currency_sign_location) {
        case 1:
            $format_string = '%3$s%1$s%2$s';
            break;
        case 2:
            $format_string = '%3$s %1$s%2$s';
            break;
        case 4:
            $format_string = '%1$s%2$s  %3$s';
            break;
        case 3:
        default:
            $format_string = '%1$s %2$s%3$s';
            break;
    }
    $currency_code = apply_filters('wpsc_format_currency_currency_code', $currency_code, $isocode);
    // Compile the output
    $output = trim(sprintf($format_string, $currency_code, $symbol, $formatted));
    return $output;
}
Exemple #4
0
function _wpsc_maybe_create_UK()
{
    $country = new WPSC_Country('GB', 'isocode');
    if (!$country->exists()) {
        $country->set(array('id' => 138, 'country' => __('United Kingdom', 'wpsc'), 'currency' => __('Pound Sterling', 'wpsc'), 'symbol' => __('£', 'wpsc'), 'symbol_html' => __('£', 'wpsc'), 'code' => __('GBP', 'wpsc'), 'continent' => 'europe'));
        $country->save();
    }
}
function wpsc_format_price($amt, $currency = false)
{
    $currencies_without_fractions = array('JPY', 'HUF');
    if (!$currency) {
        $country = new WPSC_Country(get_option('currency_type'));
        $currency = $country->get('code');
    }
    $dec = in_array($currency, $currencies_without_fractions) ? 0 : 2;
    return number_format($amt, $dec);
}
Exemple #6
0
/**
 * Reset United Kingdom country data to default, hide ISO code 'UK'
 *
 * @access private
 * @since 3.8.14
 */
function _wpsc_fix_united_kingdom()
{
    if ($wpsc_country = WPSC_Countries::get_country('UK')) {
        $legacy_ok_country_was_visible = $wpsc_country->is_visible();
        $wpsc_country = new WPSC_Country(array('visible' => '0', 'isocode' => 'UK'));
        $wpsc_country->set('_is_country_legacy', true);
    }
    $wpsc_country = new WPSC_Country(array('country' => __('United Kingdom', 'wpsc'), 'isocode' => 'GB', 'currency' => __('Pound Sterling', 'wpsc'), 'symbol' => __('£', 'wpsc'), 'symbol_html' => __('£', 'wpsc'), 'code' => __('GBP', 'wpsc'), 'continent' => 'europe', 'visible' => $legacy_ok_country_was_visible ? '0' : '1', 'has_regions' => '0', 'tax' => '0'));
    //make sure base country is ok after the UK/GB fix
    $base_country = get_option('base_country', '');
    if (!empty($base_country) && is_numeric($base_country)) {
        $wpsc_country = new WPSC_Country($base_country);
        if ('UK' == $wpsc_country->get_isocode()) {
            $wpsc_country = new WPSC_Country('GB');
            update_option('base_country', $wpsc_country->get_id());
        }
    }
}
/**
 * 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');
    }
}
/**
 * Template tag for base country currency code.
 *
 * Helpful for templates using structured data, likely other use cases.
 * Temporarily located here, until #1865 lands.
 *
 * @since  4.0
 *
 * @return  string Base country currency code.
 */
function wpsc_base_country_code()
{
    $base = new WPSC_Country(wpsc_get_base_country());
    echo esc_attr($base->get_currency_code());
}
Exemple #9
0
function _wpsc_create_south_sudan()
{
    $country = new WPSC_Country(array('id' => '242', 'country' => __('South Sudan', 'wpsc'), 'isocode' => __('SS', 'wpsc'), 'currency' => __('South Sudanese Pound', 'wpsc'), 'code' => __('SSP', 'wpsc'), 'continent' => 'africa'));
    $country->save();
}
/**
 * On the checkout page create a hidden element holding the acceptable shipping countries
 *
 * This let's the wp-e-commerce javascript process any dependency rules even if the store has configured
 * the checkout forms so that some fields are hidden.  The most important of these fields are the
 * country, region and state fields. But it's just as easy to include all of them and not worry about
 * what various parts of WPeC, themes or plugs may be doing.
 *
 * @since 3.8.14
 *
 * @access private
 */
function _wpsc_acceptable_shipping_countries_into_checkout_page()
{
    $acceptable_countries = wpsc_get_acceptable_countries();
    // if the acceptable countries is true all available countries can be shipped to,
    // otherwise we are going to restrict the countries list
    if ($acceptable_countries !== true) {
        $country_code_list = array();
        foreach ($acceptable_countries as $key => $country_id) {
            $wpsc_country = new WPSC_Country($country_id);
            $country_code_list[$wpsc_country->get_isocode()] = $wpsc_country->get_name();
        }
        ?>
		<script type="text/javascript">
		/* <![CDATA[ */
			var wpsc_acceptable_shipping_countries = <?php 
        echo json_encode($country_code_list);
        ?>
;
		/* ]]> */
		</script>
		<?php 
    }
}
Exemple #11
0
/**
 * Displays notice if user has Great Britain selected as their base country
 * Since 3.8.9, we have deprecated Great Britain in favor of the UK
 *
 * @since 3.8.9
 * @access private
 * @link http://code.google.com/p/wp-e-commerce/issues/detail?id=1079
 *
 * @uses get_option()             Retrieves option from the WordPress database
 * @uses get_outdate_isocodes()   Returns outdated isocodes
 * @uses admin_url()              Returns admin_url of the site
 *
 * @return string  The admin notices for deprecated countries
 */
function _wpsc_action_admin_notices_deprecated_countries_notice()
{
    $base_country = get_option('base_country');
    if (!in_array($base_country, WPSC_Country::get_outdated_isocodes())) {
        return;
    }
    switch ($base_country) {
        case 'YU':
            $message = __('Yugoslavia is no longer a valid official country name according to <a href="%1$s">ISO 3166</a> while both Serbia and Montenegro have been added to the country list.<br /> As a result, we highly recommend changing your <em>Base Country</em> to reflect this change on the <a href="%2$s">General Settings</a> page.', 'wpsc');
            break;
        case 'UK':
            $message = __('Prior to WP e-Commerce 3.8.9, in your database, United Kingdom\'s country code is UK and you have already selected that country code as the base country. However, now that you\'re using WP e-Commerce version %3$s, it is recommended that you change your base country to the official "GB" country code, according to <a href="%1$s">ISO 3166</a>.<br /> Please go to <a href="%2$s">General Settings</a> page to make this change.<br />The legacy "UK" item will be marked as "U.K. (legacy)" on the country drop down list. Simply switch to the official "United Kingdom (ISO 3166)" to use the "GB" country code.', 'wpsc');
            break;
        case 'AN':
            $message = __('Netherlands Antilles is no longer a valid official country name according to <a href="%1$s">ISO 3166</a>.<br />Please consider changing your <em>Base Country</em> to reflect this change on the <a href="%2$s">General Settings</a> page.', 'wpsc');
        case 'TP':
            $message = __('Prior to WP e-Commerce 3.8.9, in your database, East Timor\'s country code is TP and you have already selected that country code as the base country. However, now that you\'re using WP e-Commerce version %3$s, it is recommended that you change your base country to the official "TL" country code, according to <a href="%1$s">ISO 3166</a>.<br /> Please go to <a href="%2$s">General Settings</a> page to make this change.<br />The legacy "TP" item will be marked as "East Timor (legacy)" on the country drop down list. Simply switch to the official "Timor-Leste (ISO 3166)" to use the "TL" country code.', 'wpsc');
            break;
    }
    $message = sprintf($message, 'http://en.wikipedia.org/wiki/ISO_3166-1', admin_url('options-general.php?page=wpsc-settings&tab=general'), WPSC_VERSION);
    echo '<div id="wpsc-warning" class="error"><p>' . $message . '</p></div>';
}
/**
 * get the output used to show a shipping state and region select drop down
 *
 * @since 3.8.14
 *
 * @param wpsc_checkout|null  $wpsc_checkout checkout object
 * @return string
 */
function wpsc_checkout_shipping_state_and_region($wpsc_checkout = null)
{
    // just in case the checkout form was not presented, like when we are doing the shipping calculator
    if (empty($wpsc_checkout)) {
        $wpsc_checkout = new wpsc_checkout();
        $doing_checkout_form = false;
    } else {
        $doing_checkout_form = true;
    }
    // if we aren't showing the shipping state on the cor we have no work to do
    if (!$wpsc_checkout->get_checkout_item('shippingstate')) {
        return '';
    }
    // save the current checkout item in case we adjust it in the routine, we'll put it back before return
    $saved_checkout_item = $wpsc_checkout->checkout_item;
    // check a new checkout form with all fields
    $checkout_form = new WPSC_Checkout_Form(null, false);
    // is the shipping country visible on the form, let's find out
    $shipping_country_form_element = $checkout_form->get_field_by_unique_name('shippingcountry');
    $showing_shipping_country = (bool) $shipping_country_form_element->active;
    // make sure the shipping state is the current checkout element
    $wpsc_checkout->checkout_item = $wpsc_checkout->get_checkout_item('shippingstate');
    // setup the edit field, aka 'shippingstate'
    $shipping_country = wpsc_get_customer_meta('shippingcountry');
    $shipping_region = wpsc_get_customer_meta('shippingregion');
    $shipping_state = wpsc_get_customer_meta('shippingstate');
    // if we are showing the billing country on the form then we use the value that can be
    // changed by the user, otherwise we will use the base country as configured in store admin
    if ($showing_shipping_country) {
        $wpsc_country = new WPSC_Country($shipping_country);
    } else {
        $wpsc_country = new WPSC_Country(wpsc_get_base_country());
    }
    $region_list = $wpsc_country->get_regions();
    $placeholder = $wpsc_country->get('region_label');
    if (empty($placeholder)) {
        $placeholder = $wpsc_checkout->checkout_item->name;
    }
    $placeholder = apply_filters('wpsc_checkout_field_placeholder', apply_filters('wpsc_checkout_field_name', $placeholder), $wpsc_checkout->checkout_item);
    $form_element_id = $wpsc_checkout->form_element_id();
    if ($doing_checkout_form) {
        $id_attribute = ' id="' . $form_element_id . '" ';
    } else {
        $id_attribute = '';
    }
    // if there are regions for the current country we are going to
    // create the billing state edit, but hide it
    $style = ' ';
    if (!empty($region_list)) {
        $style = 'style="display: none;"';
    }
    $output = '<input class="shipping_region text  wpsc-visitor-meta" ' . ' data-wpsc-meta-key="' . $wpsc_checkout->checkout_item->unique_name . '" ' . ' title="' . $wpsc_checkout->checkout_item->unique_name . '" ' . ' type="text" ' . $id_attribute . ' placeholder="' . esc_attr($placeholder) . '" ' . ' value="' . esc_attr($shipping_state) . '" ' . ' name="collected_data[' . $wpsc_checkout->checkout_item->id . ']" ' . $style . ' />' . "\n\r";
    // setup the drop down field, aka 'shippingregion'
    // move the checkout item pointer to the billing country, so we can generate form element ids, highly lame
    $wpsc_checkout->checkout_item = $checkout_form->get_field_by_unique_name('shippingcountry');
    // if there aren't any regions for the current country we are going to
    // create the empty region select, but hide it
    $style = ' ';
    if (empty($region_list)) {
        $style = 'style="display: none;"';
    }
    $title = 'shippingregion';
    $region_form_id = $wpsc_checkout->form_element_id() . '_region';
    $output .= '<select id="' . $region_form_id . '" ' . ' class="current_region wpsc-visitor-meta wpsc-region-dropdown" ' . ' data-wpsc-meta-key="shippingregion" ' . ' title="' . $title . '" ' . 'name="collected_data[' . $wpsc_checkout->checkout_item->id . '][1]" ' . $style . ">\n\r";
    $wpsc_current_region = $wpsc_country->get_region($shipping_region);
    if (!empty($region_list)) {
        if (count($region_list) > 1) {
            $label = $wpsc_country->get('region_label');
            $please_select_message = sprintf(__('Please select a %s', 'wp-e-commerce'), $label);
            $output .= "<option value='0'>" . $please_select_message . "</option>\n\r";
        }
        foreach ($region_list as $wpsc_region) {
            if ((bool) $wpsc_current_region && $wpsc_current_region->get_id() == $wpsc_region->get_id()) {
                $selected = "selected='selected'";
            } else {
                $selected = '';
            }
            $output .= "<option value='" . $wpsc_region->get_id() . "' {$selected}>" . esc_html($wpsc_region->get_name()) . "</option>\n\r";
        }
    }
    $output .= "</select>\n\r";
    // restore the checkout item in case we messed with it
    $wpsc_checkout->checkout_item = $saved_checkout_item;
    return $output;
}
Exemple #13
0
 /**
  * get_tax_rate method, gets the tax rate as a percentage, based on the selected country and region
  * * EDIT: Replaced with WPEC Taxes - this function should probably be deprecated
  * Note: to refresh cart items use wpsc_refresh_cart_items
  *
  * @access public
  */
 function get_tax_rate()
 {
     $country = new WPSC_Country(get_option('base_country'));
     $country_data = WPSC_Countries::get_country(get_option('base_country'), true);
     $add_tax = false;
     if ($this->selected_country == get_option('base_country')) {
         // Tax rules for various countries go here, if your countries tax rules
         // deviate from this, please supply code to add your region
         switch ($this->selected_country) {
             case 'US':
                 // USA!
                 $tax_region = get_option('base_region');
                 if ($this->selected_region == get_option('base_region') && get_option('lock_tax_to_shipping') != '1') {
                     // if they in the state, they pay tax
                     $add_tax = true;
                 } else {
                     if ($this->delivery_region == get_option('base_region')) {
                         // if they live outside the state, but are delivering to within the state, they pay tax also
                         $add_tax = true;
                     }
                 }
                 break;
             case 'CA':
                 // Canada! apparently in canada, the region that you are in is used for tax purposes
                 if ($this->selected_region != null) {
                     $tax_region = $this->selected_region;
                 } else {
                     $tax_region = get_option('base_region');
                 }
                 $add_tax = true;
                 break;
             default:
                 // Everywhere else!
                 $tax_region = get_option('base_region');
                 if ($country->has_regions()) {
                     if (get_option('base_region') == $region) {
                         $add_tax = true;
                     }
                 } else {
                     $add_tax = true;
                 }
                 break;
         }
     }
     if ($add_tax == true) {
         if ($country->has_regions()) {
             $region = $country->get_region($tax_region);
             $tax_percentage = $region->get_tax();
         } else {
             $tax_percentage = $country->get_tax();
         }
     } else {
         // no tax charged = tax equal to 0%
         $tax_percentage = 0;
     }
     if ($this->tax_percentage != $tax_percentage) {
         $this->clear_cache();
         $this->tax_percentage = $tax_percentage;
         $this->wpsc_refresh_cart_items();
     }
 }
 private function get_shipping_method_js_vars()
 {
     global $wpsc_cart;
     $js_var = array('subtotal' => (double) $wpsc_cart->calculate_subtotal(), 'shipping' => array(), 'tax' => wpsc_is_tax_enabled() && !wpsc_is_tax_included() ? (double) wpsc_cart_tax(false) : 0, 'discount' => wpsc_coupon_amount(false) > 0 ? wpsc_coupon_amount(false) : 0);
     foreach ($this->shipping_calculator->sorted_quotes as $module_name => $quotes) {
         foreach ($quotes as $option => $cost) {
             $id = $this->shipping_calculator->ids[$module_name][$option];
             $js_var['shipping'][$id] = $cost;
         }
     }
     $currency = new WPSC_Country(get_option('currency_type'));
     $currency_code = $currency->get_currency_code();
     $isocode = $currency->get_isocode();
     $without_fractions = in_array($currency_code, WPSC_Payment_Gateways::currencies_without_fractions());
     $decimals = $without_fractions ? 0 : 2;
     $decimals = apply_filters('wpsc_modify_decimals', $decimals, $isocode);
     $decimal_separator = apply_filters('wpsc_format_currency_decimal_separator', wpsc_get_option('decimal_separator'), $isocode);
     $thousands_separator = apply_filters('wpsc_format_currency_thousands_separator', wpsc_get_option('thousands_separator'), $isocode);
     $symbol = apply_filters('wpsc_format_currency_currency_symbol', $currency->get_currency_symbol());
     $sign_location = get_option('currency_sign_location');
     $js_var['formatter'] = array('currency_code' => $currency_code, 'without_fractions' => $without_fractions, 'decimals' => $decimals, 'decimal_separator' => $decimal_separator, 'thousands_separator' => $thousands_separator, 'symbol' => $symbol, 'sign_location' => $sign_location);
     return $js_var;
 }
 /**
  * callback that creates / re-creates the data map mapping all active country ids to all active countries
  *
  * @access private
  * @since 3.8.14
  *
  * @param WPSC_Data_Map    $data_map     Data map object being intitilized
  */
 public static function _create_active_countries_map($data_map)
 {
     global $wpdb;
     // there are also invisible countries
     $sql = 'SELECT ' . ' id, country, isocode, currency, symbol, symbol_html, code, has_regions, tax, continent, visible ' . ' FROM `' . WPSC_TABLE_CURRENCY_LIST . '` WHERE `visible`= "1" ' . ' ORDER BY id ASC';
     $countries_array = $wpdb->get_results($sql, OBJECT_K);
     // build an array to map from iso code to country, while we do this get any region data for the country
     foreach ($countries_array as $country_id => $country) {
         // create a new empty country object, add the properties we know about, then we add our region info
         $wpsc_country = new WPSC_Country(null);
         $wpsc_country->_copy_properties_from_stdclass($country);
         if ($country->has_regions) {
             $sql = 'SELECT id, code, country_id, name, tax ' . ' FROM `' . WPSC_TABLE_REGION_TAX . '` ' . ' WHERE `country_id` = %d ' . ' ORDER BY code ASC ';
             // put the regions list into our country object
             $regions = $wpdb->get_results($wpdb->prepare($sql, $country_id), OBJECT_K);
             /*
              * any properties that came in as text that should be numbers or boolean
              * get adjusted here, we also build an array to map from region code to region id
              */
             foreach ($regions as $region_id => $region) {
                 $region->id = intval($region_id);
                 $region->country_id = intval($region->country_id);
                 $region->tax = floatval($region->tax);
                 // create a new empty region object, then copy our region data into it.
                 $wpsc_region = new WPSC_Region(null, null);
                 $wpsc_region->_copy_properties_from_stdclass($region);
                 $wpsc_country->_regions->map($region->id, $wpsc_region);
                 $wpsc_country->_region_id_by_region_code->map($region->code, $region->id);
                 $wpsc_country->_region_id_by_region_name->map(strtolower($region->name), $region->id);
             }
         }
         $data_map->map($country_id, $wpsc_country);
     }
     self::$_dirty = true;
 }
function _wpsc_filter_validation_rule_state_of($error, $value, $field, $props, $matched_field, $matched_value, $matched_props)
{
    global $wpdb;
    if ($value == '') {
        return $error;
    }
    $country_code = $_POST['wpsc_checkout_details'][$matched_field];
    $country = new WPSC_Country($country_code);
    if (!$country->has_regions()) {
        return $error;
    }
    // state should have been converted into a numeric value already
    // if not, it's an invalid state
    if (!is_numeric($value)) {
        $message = apply_filters('wpsc_validation_rule_invalid_state_message', __('%1$s is not a valid state or province in %2$s', 'wpsc'));
        $message = sprintf($message, $value, $country->get_name());
        $error->add($field, $message, array('value' => $value, 'props' => $props));
        return $error;
    }
    $sql = $wpdb->prepare('SELECT COUNT(id) FROM ' . WPSC_TABLE_REGION_TAX . ' WHERE id = %d', $value);
    $count = $wpdb->get_var($sql);
    if ($count == 0) {
        $message = apply_filters('wpsc_validation_rule_invalid_state_id_message', __('You specified or were assigned an invalid state or province. Please contact administrator for assistance', 'wpsc'));
        $error->add($field, $message, array('value' => $value, 'props' => $props));
    }
    return $error;
}
Exemple #17
0
/**
 * Add the county region label to the uk
 *
 * @access private
 * @since 3.8.14.1
 */
function _wpsc_add_region_label_to_uk()
{
    $wpsc_country = new WPSC_Country('GB');
    $wpsc_country->set('region_label', __('County', 'wpsc'));
}
 /**
  * Given an ISO country code, it will return the full country name
  *
  * @since 0.0.1
  * @param string $short_country
  * @return string
  */
 function get_full_country($short_country)
 {
     $country = new WPSC_Country($short_country);
     return $country->get_name();
 }
function wpsc_get_country($country_code)
{
    $wpsc_country = new WPSC_Country($country_code);
    return $wpsc_country->get_name();
}
 /**
  * @description: wpec_taxes_get_region_code_by_id - given an id this funciton will
  * return the region code.
  * @param: id - a region id
  * @return: int or false
  * */
 function wpec_taxes_get_region_code_by_id($region)
 {
     $region_code = false;
     if (!empty($region)) {
         $country_id = WPSC_Countries::get_country_id_by_region_id($region);
         if ($country_id) {
             $wpsc_country = new WPSC_Country($country_id);
         }
         if (isset($wpsc_country)) {
             $wpsc_region = $wpsc_country->get_region($region);
             if ($wpsc_region) {
                 $region_code = $wpsc_region->get_code();
             }
         }
     }
     return $region_code;
 }
Exemple #21
0
function wpsc_shipping_country_list($shippingdetails = false)
{
    global $wpsc_shipping_modules;
    $wpsc_checkout = new wpsc_checkout();
    $wpsc_checkout->checkout_item = $shipping_country_checkout_item = $wpsc_checkout->get_checkout_item('shippingcountry');
    $output = '';
    if ($shipping_country_checkout_item && $shipping_country_checkout_item->active) {
        if (!$shippingdetails) {
            $output = "<input type='hidden' name='wpsc_ajax_action' value='update_location' />";
        }
        $acceptable_countries = wpsc_get_acceptable_countries();
        // if there is only one country to choose from we are going to set that as the shipping country,
        // later in the UI generation the same thing will happen to make the single country the current
        // selection
        $countries = WPSC_Countries::get_countries(false);
        if (count($countries) == 1) {
            reset($countries);
            $id_of_only_country_available = key($countries);
            $wpsc_country = new WPSC_Country($id_of_only_country_available);
            wpsc_update_customer_meta('shippingcountry', $wpsc_country->get_isocode());
        }
        $selected_country = wpsc_get_customer_meta('shippingcountry');
        $additional_attributes = 'data-wpsc-meta-key="shippingcountry" ';
        $output .= wpsc_get_country_dropdown(array('id' => 'current_country', 'name' => 'country', 'class' => 'current_country wpsc-visitor-meta', 'acceptable_ids' => $acceptable_countries, 'selected' => $selected_country, 'additional_attributes' => $additional_attributes, 'placeholder' => __('Please select a country', 'wp-e-commerce')));
    }
    $output .= wpsc_checkout_shipping_state_and_region();
    $zipvalue = (string) wpsc_get_customer_meta('shippingpostcode');
    $zip_code_text = __('Your Zipcode', 'wp-e-commerce');
    if ($zipvalue != '' && $zipvalue != $zip_code_text) {
        $color = '#000';
        wpsc_update_customer_meta('shipping_zip', $zipvalue);
    } else {
        $zipvalue = $zip_code_text;
        $color = '#999';
    }
    $uses_zipcode = false;
    $custom_shipping = get_option('custom_shipping_options');
    foreach ((array) $custom_shipping as $shipping) {
        if (isset($wpsc_shipping_modules[$shipping]->needs_zipcode) && $wpsc_shipping_modules[$shipping]->needs_zipcode == true) {
            $uses_zipcode = true;
        }
    }
    if ($uses_zipcode) {
        $output .= " <input data-wpsc-meta-key='shippingpostcode' class='wpsc-visitor-meta' type='text' style='color:" . $color . ";' onclick='if (this.value==\"" . esc_js($zip_code_text) . "\") {this.value=\"\";this.style.color=\"#000\";}' onblur='if (this.value==\"\") {this.style.color=\"#999\"; this.value=\"" . esc_js($zip_code_text) . "\"; }' value='" . esc_attr($zipvalue) . "' size='10' name='zipcode' id='zipcode'>";
    }
    return $output;
}
Exemple #22
0
/**
 * submit checkout function, used through ajax and in normal page loading.
 * No parameters, returns nothing
 */
function wpsc_submit_checkout($collected_data = true)
{
    global $wpdb, $wpsc_cart, $user_ID, $nzshpcrt_gateways, $wpsc_shipping_modules, $wpsc_gateways;
    if ($collected_data && isset($_POST['collected_data']) && is_array($_POST['collected_data'])) {
        _wpsc_checkout_customer_meta_update($_POST['collected_data']);
    }
    // initialize our checkout status variab;e, we start be assuming
    // checkout is falid, until we find a reason otherwise
    $is_valid = true;
    $num_items = 0;
    $use_shipping = 0;
    $disregard_shipping = 0;
    do_action('wpsc_before_submit_checkout');
    $error_messages = wpsc_get_customer_meta('checkout_misc_error_messages');
    if (!is_array($error_messages)) {
        $error_messages = array();
    }
    $wpsc_checkout = new wpsc_checkout();
    $selected_gateways = get_option('custom_gateway_options');
    $submitted_gateway = isset($_POST['custom_gateway']) ? $_POST['custom_gateway'] : '';
    if ($collected_data) {
        $form_validity = $wpsc_checkout->validate_forms();
        extract($form_validity);
        // extracts $is_valid and $error_messages
        if (wpsc_has_tnc() && (!isset($_POST['agree']) || $_POST['agree'] != 'yes')) {
            $error_messages[] = __('Please agree to the terms and conditions, otherwise we cannot process your order.', 'wpsc');
            $is_valid = false;
        }
    } else {
        $is_valid = true;
        $error_messages = array();
    }
    $wpsc_country = new WPSC_Country(wpsc_get_customer_meta('shippingcountry'));
    $country_id = $wpsc_country->get_id();
    $country_name = $wpsc_country->get_name();
    foreach ($wpsc_cart->cart_items as $cartitem) {
        if (!empty($cartitem->meta[0]['no_shipping'])) {
            continue;
        }
        $categoriesIDs = $cartitem->category_id_list;
        foreach ((array) $categoriesIDs as $catid) {
            if (is_array($catid)) {
                $countries = wpsc_get_meta($catid[0], 'target_market', 'wpsc_category');
            } else {
                $countries = wpsc_get_meta($catid, 'target_market', 'wpsc_category');
            }
            if (!empty($countries) && !in_array($country_id, (array) $countries)) {
                $errormessage = sprintf(__('%s cannot be shipped to %s. To continue with your transaction please remove this product from the list below.', 'wpsc'), $cartitem->get_title(), $country_name);
                wpsc_update_customer_meta('category_shipping_conflict', $errormessage);
                $is_valid = false;
            }
        }
        //count number of items, and number of items using shipping
        $num_items++;
        if ($cartitem->uses_shipping != 1) {
            $disregard_shipping++;
        } else {
            $use_shipping++;
        }
    }
    // check to see if the current gateway is in the list of available gateways
    if (array_search($submitted_gateway, $selected_gateways) !== false) {
        wpsc_update_customer_meta('selected_gateway', $submitted_gateway);
    } else {
        $is_valid = false;
    }
    if ($collected_data) {
        // Test for required shipping information
        if (wpsc_core_shipping_enabled() && $num_items != $disregard_shipping) {
            // for shipping to work we need a method, option and a quote
            if (!$wpsc_cart->shipping_method_selected() || !$wpsc_cart->shipping_quote_selected()) {
                $error_messages[] = __('Please select one of the available shipping options, then we can process your order.', 'wpsc');
                $is_valid = false;
            }
            // if we don't have a valid zip code ( the function also checks if we need it ) we have an error
            if (!wpsc_have_valid_shipping_zipcode()) {
                wpsc_update_customer_meta('category_shipping_conflict', __('Please enter a Zipcode and click calculate to proceed', 'wpsc'));
                $is_valid = false;
            }
        }
    }
    wpsc_update_customer_meta('checkout_misc_error_messages', $error_messages);
    if ($is_valid == true) {
        wpsc_delete_customer_meta('category_shipping_conflict');
        // check that the submitted gateway is in the list of selected ones
        $sessionid = mt_rand(100, 999) . time();
        wpsc_update_customer_meta('checkout_session_id', $sessionid);
        $subtotal = $wpsc_cart->calculate_subtotal();
        if ($wpsc_cart->has_total_shipping_discount() == false) {
            $base_shipping = $wpsc_cart->calculate_base_shipping();
        } else {
            $base_shipping = 0;
        }
        $delivery_country = $wpsc_cart->delivery_country;
        $delivery_region = $wpsc_cart->delivery_region;
        if (wpsc_uses_shipping()) {
            $shipping_method = $wpsc_cart->selected_shipping_method;
            $shipping_option = $wpsc_cart->selected_shipping_option;
        } else {
            $shipping_method = '';
            $shipping_option = '';
        }
        if (isset($_POST['how_find_us'])) {
            $find_us = $_POST['how_find_us'];
        } else {
            $find_us = '';
        }
        //keep track of tax if taxes are exclusive
        $wpec_taxes_controller = new wpec_taxes_controller();
        if (!$wpec_taxes_controller->wpec_taxes_isincluded()) {
            $tax = $wpsc_cart->calculate_total_tax();
            $tax_percentage = $wpsc_cart->tax_percentage;
        } else {
            $tax = 0.0;
            $tax_percentage = 0.0;
        }
        $total = $wpsc_cart->calculate_total_price();
        $args = array('totalprice' => $total, 'statusno' => '0', 'sessionid' => $sessionid, 'user_ID' => (int) $user_ID, 'date' => time(), 'gateway' => $submitted_gateway, 'billing_country' => $wpsc_cart->selected_country, 'shipping_country' => $delivery_country, 'billing_region' => $wpsc_cart->selected_region, 'shipping_region' => $delivery_region, 'base_shipping' => $base_shipping, 'shipping_method' => $shipping_method, 'shipping_option' => $shipping_option, 'plugin_version' => WPSC_VERSION, 'discount_value' => $wpsc_cart->coupons_amount, 'discount_data' => $wpsc_cart->coupons_name, 'find_us' => $find_us, 'wpec_taxes_total' => $tax, 'wpec_taxes_rate' => $tax_percentage);
        $purchase_log = new WPSC_Purchase_Log($args);
        $purchase_log->save();
        $purchase_log_id = $purchase_log->get('id');
        if ($collected_data) {
            $wpsc_checkout->save_forms_to_db($purchase_log_id);
        }
        $wpsc_cart->save_to_db($purchase_log_id);
        $wpsc_cart->submit_stock_claims($purchase_log_id);
        if (!isset($our_user_id) && isset($user_ID)) {
            $our_user_id = $user_ID;
        }
        $wpsc_cart->log_id = $purchase_log_id;
        do_action('wpsc_submit_checkout', array('purchase_log_id' => $purchase_log_id, 'our_user_id' => $our_user_id));
        do_action('wpsc_submit_checkout_gateway', $submitted_gateway, $purchase_log);
    }
}
 public function get_currency_code()
 {
     if (!$this->currency_code) {
         $country = new WPSC_Country(get_option('currency_type'));
         $currency = $country->get('currency_code');
     } else {
         $currency = $this->currency_code;
     }
     return $currency;
 }
/**
 * Product Shipping Forms
 *
 * @uses  wpsc_validate_weight_unit()
 * @uses  wpsc_validate_dimension_unit()
 */
function wpsc_product_shipping_forms($product = false, $field_name_prefix = 'meta[_wpsc_product_metadata]', $bulk = false)
{
    if (!$product) {
        $product_id = get_the_ID();
    } else {
        $product_id = $product->ID;
    }
    $meta = get_post_meta($product_id, '_wpsc_product_metadata', true);
    if (!is_array($meta)) {
        $meta = array();
    }
    $defaults = array('weight' => '', 'weight_unit' => wpsc_validate_weight_unit(), 'demension_unit' => wpsc_validate_dimension_unit(), 'dimensions' => array(), 'shipping' => array(), 'no_shipping' => '', 'display_weight_as' => '');
    $dimensions_defaults = array('height' => 0, 'width' => 0, 'length' => 0);
    $shipping_defaults = array('local' => '', 'international' => '');
    $meta = array_merge($defaults, $meta);
    $meta['dimensions'] = array_merge($dimensions_defaults, $meta['dimensions']);
    $meta['shipping'] = array_merge($shipping_defaults, $meta['shipping']);
    extract($meta, EXTR_SKIP);
    foreach ($shipping as $key => &$val) {
        $val = wpsc_format_number($val);
    }
    $weight = wpsc_convert_weight($weight, 'pound', $weight_unit);
    $dimension_units = wpsc_dimension_units();
    $weight_units = wpsc_weight_units();
    // Why we need this????
    $measurements = $dimensions;
    $measurements['weight'] = $weight;
    $measurements['weight_unit'] = $weight_unit;
    // End why
    ?>
	<div class="wpsc-stock-editor<?php 
    if ($bulk) {
        echo ' wpsc-bulk-edit';
    }
    ?>
">
		<p class="wpsc-form-field">
			<input type="checkbox" id="wpsc-product-no-shipping" name="<?php 
    echo esc_attr($field_name_prefix);
    ?>
[no_shipping]" value="1" <?php 
    checked($no_shipping && !$bulk);
    ?>
>
			<label for="wpsc-product-no-shipping"><?php 
    _e('Product will <em>not</em> be shipped to customer', 'wp-e-commerce');
    ?>
</label>
		</p>

		<div class="wpsc-product-shipping-section wpsc-product-shipping-weight-dimensions">
			<p><strong><?php 
    esc_html_e('Calculate Shipping Costs based on measurements', 'wp-e-commerce');
    ?>
</strong></p>

			<!-- WEIGHT INPUT -->
			<p class="wpsc-form-field">
				<?php 
    if ($bulk) {
        ?>
					<input class="wpsc-bulk-edit-fields" type="checkbox" name="wpsc_bulk_edit[fields][measurements][weight]" value="1" />
				<?php 
    }
    ?>
				<label for="wpsc-product-shipping-weight"><?php 
    echo esc_html_e('Weight', 'wp-e-commerce');
    ?>
</label>
				<span class="wpsc-product-shipping-input">
					<input type="text" id="wpsc-product-shipping-weight" name="<?php 
    echo esc_attr($field_name_prefix);
    ?>
[weight]" value="<?php 
    if (!$bulk) {
        echo esc_attr(wpsc_format_number($weight));
    }
    ?>
" />
					<select id="wpsc-product-shipping-weight-unit" name="<?php 
    echo $field_name_prefix;
    ?>
[weight_unit]">
							<?php 
    foreach ($weight_units as $unit => $unit_label) {
        ?>
								<option value="<?php 
        echo esc_attr($unit);
        ?>
" <?php 
        if (!$bulk) {
            selected($unit, $measurements['weight_unit']);
        }
        ?>
><?php 
        echo esc_html($unit_label);
        ?>
</option>
							<?php 
    }
    ?>
						</select>
				</span>
			</p>
			<!-- END WEIGHT INPUT -->

			<!-- DIMENSIONS INPUT -->
			<p class="wpsc-form-field">
				<?php 
    if ($bulk) {
        ?>
					<input class="wpsc-bulk-edit-fields" type="checkbox" name="wpsc_bulk_edit[fields][measurements][dimensions]" value="1" />
				<?php 
    }
    ?>
				<label for="wpsc-product-shipping-weight"><?php 
    echo esc_html_e('Dimensions', 'wp-e-commerce');
    ?>
</label>
				<span class="wpsc-product-shipping-input">
					<input placeholder="L" type="text" id="wpsc-product-shipping-length" name="<?php 
    echo esc_attr($field_name_prefix);
    ?>
[dimensions][length]" value="<?php 
    if (!$bulk && $dimensions['length'] > 0) {
        echo esc_attr(wpsc_format_number($dimensions['length']));
    }
    ?>
" />&nbsp;&times;&nbsp;
					<input placeholder="W" type="text" id="wpsc-product-shipping-width" name="<?php 
    echo esc_attr($field_name_prefix);
    ?>
[dimensions][width]" value="<?php 
    if (!$bulk && $dimensions['width'] > 0) {
        echo esc_attr(wpsc_format_number($dimensions['width']));
    }
    ?>
" />&nbsp;&times;&nbsp;
					<input placeholder="H" type="text" id="wpsc-product-shipping-height" name="<?php 
    echo esc_attr($field_name_prefix);
    ?>
[dimensions][height]" value="<?php 
    if (!$bulk && $dimensions['height'] > 0) {
        echo esc_attr(wpsc_format_number($dimensions['height']));
    }
    ?>
" />
					<select id="wpsc-product-shipping-dimensions-unit" name="<?php 
    echo $field_name_prefix;
    ?>
[dimension_unit]">
						<?php 
    foreach ($dimension_units as $unit => $unit_label) {
        ?>
							<option value="<?php 
        echo esc_attr($unit);
        ?>
" <?php 
        if (!$bulk && isset($meta['dimension_unit'])) {
            selected($unit, $meta['dimension_unit']);
        }
        // Dirty code
        ?>
><?php 
        echo esc_html($unit_label);
        ?>
</option>
						<?php 
    }
    ?>
					</select>
				</span>
			</p>
			<!-- END DEMENSION INPUT -->

		</div>

		<?php 
    $currency_type = get_option('currency_type');
    $country = new WPSC_Country($currency_type);
    $ct_symb = $country->get_currency_symbol_html();
    ?>

		<div class="wpsc-product-shipping-section wpsc-product-shipping-flat-rate">
			<p><strong><?php 
    esc_html_e('Flat Rate Settings', 'wp-e-commerce');
    ?>
</strong></p>
			<p class="wpsc-form-field">
				<?php 
    if ($bulk) {
        ?>
					<input class="wpsc-bulk-edit-fields" type="checkbox" name="wpsc_bulk_edit[fields][shipping][local]" value="1" />
				<?php 
    }
    ?>
				<label for="wpsc-product-shipping-flatrate-local"><?php 
    esc_html_e('Local Shipping Fee', 'wp-e-commerce');
    ?>
</label>
				<span>
					<?php 
    echo esc_html($ct_symb);
    ?>
					<input type="text" id="wpsc-product-shipping-flatrate-local" name="<?php 
    echo esc_html($field_name_prefix);
    ?>
[shipping][local]" value="<?php 
    if (!$bulk) {
        echo $shipping['local'];
    }
    ?>
"  />
				</span>
			</p>
			<p class="wpsc-form-field">
				<?php 
    if ($bulk) {
        ?>
					<input class="wpsc-bulk-edit-fields" type="checkbox" name="wpsc_bulk_edit[fields][shipping][international]" value="1" />
				<?php 
    }
    ?>
				<label for="wpsc-product-shipping-flatrate-international"><?php 
    esc_html_e('International Shipping Fee', 'wp-e-commerce');
    ?>
</label>
				<span>
					<?php 
    echo esc_html($ct_symb);
    ?>
					<input type="text" id="wpsc-product-shipping-flatrate-international" name="<?php 
    echo esc_html($field_name_prefix);
    ?>
[shipping][international]" value="<?php 
    if (!$bulk) {
        echo $shipping['international'];
    }
    ?>
"  />
				</span>
			</p>
		</div>
	</div>
	<?php 
    wp_nonce_field('update', 'wpsc_product_shipping_nonce');
}
Exemple #25
0
function _wpsc_fix_guernsey_country_code()
{
    $existing_wpsc_country = new WPSC_Country('GF');
    // replace the ISO country code in the existing country
    $updated_wpsc_country = new WPSC_Country(array('id' => $existing_wpsc_country->get_id(), 'isocode' => 'GG'));
}
 /**
  * Refund a payment
  *
  * @param  string $capture_id
  * @param  float  $amount
  * @param  string $note
  */
 public function refund_payment($capture_id, $amount, $note)
 {
     if ($this->log->get('gateway') == 'amazon-payments') {
         if ($this->doing_ipn) {
             return;
         }
         $base_country = new WPSC_Country(wpsc_get_base_country());
         if ('US' == $base_country->get_isocode() && $amount > $this->log->get('totalprice')) {
             $this->log->set('amazon-status', __('Unable to refund funds via amazon:', 'wpsc') . ' ' . __('Refund amount is greater than order total.', 'wpsc'))->save();
             return;
         } elseif ($amount > min($this->log->get('totalprice') * 1.15, $this->log->get('totalprice') + 75)) {
             $this->log->set('amazon-status', __('Unable to refund funds via amazon:', 'wpsc') . ' ' . __('Refund amount is greater than the max refund amount.', 'wpsc'))->save();
             return;
         }
         $response = $this->gateway->api_request(array('Action' => 'Refund', 'AmazonCaptureId' => $capture_id, 'RefundReferenceId' => $this->log->get('id') . '-' . current_time('timestamp', true), 'RefundAmount.Amount' => $amount, 'RefundAmount.CurrencyCode' => strtoupper($this->gateway->get_currency_code()), 'SellerRefundNote' => $note));
         if (is_wp_error($response)) {
             $this->log->set('amazon-status', __('Unable to refund funds via amazon:', 'wpsc') . ' ' . $response->get_error_message())->save();
         } elseif (isset($response['Error']['Message'])) {
             $this->log->set('amazon-status', $response['Error']['Message'])->save();
         } else {
             $refund_id = $response['RefundResult']['RefundDetails']['AmazonRefundId'];
             $this->log->set('amazon-status', sprintf(__('Refunded %s (%s)', 'wpsc'), wpsc_currency_display($amount), $note))->save();
             $this->log->set('processed', WPSC_Purchase_Log::REFUNDED)->save();
             wpsc_add_purchase_meta($this->log->get('id'), 'amazon_refund_id', $refund_id);
         }
     }
 }
 function test_as_array()
 {
     $country = new WPSC_Country(self::COUNTRY_ID_WITHOUT_REGIONS);
     $regions = $country->as_array();
     $this->assertInternalType('array', $regions);
 }
Exemple #28
0
 /**
  * validate_forms method, validates the input from the checkout page
  * @access public
  */
 function save_forms_to_db($purchase_id)
 {
     foreach ($this->checkout_items as $form_data) {
         if ($form_data->type == 'heading') {
             continue;
         }
         $customer_meta_key = !empty($form_data->unique_name) ? $form_data->unique_name : sanitize_title($form_data->name) . '_' . $form_data->id;
         $checkout_item_values = wpsc_get_customer_meta($customer_meta_key);
         // Prior to release 3.8.14 the billingstate and shippingstate checkout items were used
         // differently depending on if the billingcountry and shippingcountry values contained countries
         // that used regions.  When countries with regions were present, the billing state field was
         // set to the numeric region id, rather than the string name of the region.  A better long term
         // solution may be to have a distinct checkout item to hold the billingregion or shippingregion
         // code when available.
         if ($customer_meta_key == 'billingstate') {
             $current_country = wpsc_get_customer_meta('billingcountry');
             if (!empty($current_country)) {
                 $wpsc_country = new WPSC_Country($current_country);
                 if ($wpsc_country->has_regions()) {
                     $region = wpsc_get_customer_meta('billingregion');
                     if (!empty($region)) {
                         $checkout_item_values = $region;
                     }
                 }
             }
         } elseif ($customer_meta_key == 'shippingstate') {
             $current_country = wpsc_get_customer_meta('shippingcountry');
             if (!empty($current_country)) {
                 $wpsc_country = new WPSC_Country($current_country);
                 if ($wpsc_country->has_regions()) {
                     $region = wpsc_get_customer_meta('shippingregion');
                     if (!empty($region)) {
                         $checkout_item_values = $region;
                     }
                 }
             }
         }
         if (!is_array($checkout_item_values)) {
             $checkout_item_values = array($checkout_item_values);
         }
         global $wpdb;
         foreach ($checkout_item_values as $checkout_item_value) {
             $prepared_query = $wpdb->insert(WPSC_TABLE_SUBMITTED_FORM_DATA, array('log_id' => $purchase_id, 'form_id' => $form_data->id, 'value' => $checkout_item_value), array('%d', '%d', '%s'));
         }
     }
 }
Exemple #29
0
 function getQuote()
 {
     global $wpdb, $wpec_ash, $wpsc_cart, $wpec_ash_tools;
     // Arguments array for various functions to use
     $args = array();
     $args['dest_ccode'] = wpsc_get_customer_meta('shippingcountry');
     // Get the ups settings from the ups account info page (Shipping tab)
     $wpsc_ups_settings = get_option('wpsc_ups_settings', array());
     //Disable International Shipping. Default: Enabled, as it currently is.
     $args['intl_rate'] = isset($wpsc_ups_settings['intl_rate']) && !empty($wpsc_ups_settings['intl_rate']) ? FALSE : TRUE;
     if (!$args['intl_rate'] && $args['dest_ccode'] != get_option('base_country')) {
         return array();
     }
     // Destination zip code
     $args['dest_pcode'] = (string) wpsc_get_customer_meta('shippingpostcode');
     if (!is_object($wpec_ash_tools)) {
         $wpec_ash_tools = new ASHTools();
     }
     if (empty($args['dest_pcode']) && $wpec_ash_tools->needs_post_code($args['dest_ccode'])) {
         // We cannot get a quote without a zip code so might as well return!
         return array();
     }
     // Get the total weight from the shopping cart
     $args['weight'] = wpsc_cart_weight_total();
     if (empty($args['weight'])) {
         return array();
     }
     $args['dest_state'] = '';
     $wpsc_country = new WPSC_Country(wpsc_get_customer_meta('shippingcountry'));
     if ($wpsc_country->has_regions()) {
         $wpsc_region = $wpsc_country->get_region(wpsc_get_customer_meta('shippingregion'));
         if (is_a($wpsc_region, 'WPSC_Region')) {
             $args['dest_state'] = $wpsc_region->get_code();
         }
     }
     if (empty($args['dest_state'])) {
         $args['dest_state'] = wpsc_get_customer_meta('shippingstate');
     }
     if (!is_object($wpec_ash)) {
         $wpec_ash = new ASH();
     }
     $shipping_cache_check['state'] = $args['dest_state'];
     //The destination is needed for cached shipment check.
     $shipping_cache_check['country'] = $args['dest_ccode'];
     $shipping_cache_check['zipcode'] = $args['dest_pcode'];
     $this->shipment = $wpec_ash->get_shipment();
     $this->shipment->set_destination($this->internal_name, $shipping_cache_check);
     //Set this shipment's destination.
     $this->shipment->rates_expire = date('Y-m-d');
     $args['shipper'] = $this->internal_name;
     $args['singular_shipping'] = array_key_exists('singular_shipping', $wpsc_ups_settings) ? $wpsc_ups_settings['singular_shipping'] : '0';
     if ($args['weight'] > 150 && !(bool) $args['singular_shipping']) {
         // This is where shipping breaks out of UPS if weight is higher than 150 LBS
         $over_weight_txt = apply_filters('wpsc_shipment_over_weight', __('Your order exceeds the standard shipping weight limit. Please contact us to quote other shipping alternatives.', 'wpsc'), $args);
         $shipping_quotes[$over_weight_txt] = 0;
         // yes, a constant.
         $wpec_ash->cache_results($this->internal_name, array($shipping_quotes), $this->shipment);
         //Update shipment cache.
         return array($shipping_quotes);
     }
     $cache = $wpec_ash->check_cache($this->internal_name, $this->shipment);
     //And now, we're ready to check cache.
     // We do not want to spam UPS (and slow down our process) if we already
     // have a shipping quote!
     if (count($cache['rate_table']) >= 1) {
         return $cache['rate_table'];
     }
     // Final rate table
     $rate_table = array();
     // API Auth settings //
     $args['username'] = array_key_exists('upsaccount', $wpsc_ups_settings) ? $wpsc_ups_settings['upsusername'] : '';
     $args['password'] = array_key_exists('upspassword', $wpsc_ups_settings) ? $wpsc_ups_settings['upspassword'] : '';
     $args['api_id'] = array_key_exists('upsid', $wpsc_ups_settings) ? $wpsc_ups_settings['upsid'] : '';
     $args['account_number'] = array_key_exists('upsaccount', $wpsc_ups_settings) ? $wpsc_ups_settings['upsaccount'] : '';
     $args['negotiated_rates'] = array_key_exists('ups_negotiated_rates', $wpsc_ups_settings) ? $wpsc_ups_settings['ups_negotiated_rates'] : '';
     $args['residential'] = $wpsc_ups_settings['49_residential'];
     $args['insured_shipment'] = array_key_exists('insured_shipment', $wpsc_ups_settings) ? $wpsc_ups_settings['insured_shipment'] : '0';
     // What kind of pickup service do you use ?
     $args['DropoffType'] = $wpsc_ups_settings['DropoffType'];
     $args['packaging'] = $wpsc_ups_settings['48_container'];
     // Preferred Currency to display
     $currency_data = WPSC_Countries::get_currency_code(get_option('currency_type'));
     if (!empty($currency_data)) {
         $args['currency'] = $currency_data;
     } else {
         $args['currency'] = 'USD';
     }
     // Shipping billing / account address
     $region = new WPSC_Region(get_option('base_country'), get_option('base_region'));
     $args['shipr_state'] = $region->get_code();
     $args['shipr_city'] = get_option('base_city');
     $args['shipr_ccode'] = get_option('base_country');
     $args['shipr_pcode'] = get_option('base_zipcode');
     // Physical Shipping address being shipped from
     $args['shipf_state'] = $args['shipr_state'];
     $args['shipf_city'] = $args['shipr_city'];
     $args['shipf_ccode'] = $args['shipr_ccode'];
     $args['shipf_pcode'] = $args['shipr_pcode'];
     $args['units'] = 'LBS';
     $args['cart_total'] = $wpsc_cart->calculate_subtotal(true);
     $args = apply_filters('wpsc_shipment_data', $args, $this->shipment);
     if (isset($args['stop'])) {
         //Do not get rates.
         return array();
     }
     // Build the XML request
     $request = $this->_buildRateRequest($args);
     // Now that we have the message to send ... Send it!
     $raw_quote = $this->_makeRateRequest($request);
     // Now we have the UPS response .. unfortunately its not ready
     // to be viewed by normal humans ...
     $quotes = $this->_parseQuote($raw_quote);
     // If we actually have rates back from UPS we can use em!
     if ($quotes != false) {
         $rate_table = apply_filters('wpsc_rates_table', $this->_formatTable($quotes, $args['currency']), $args, $this->shipment);
     } else {
         if (isset($wpsc_ups_settings['upsenvironment'])) {
             echo '<strong>:: GetQuote ::DEBUG OUTPUT::</strong><br />';
             echo 'Arguments sent to UPS';
             print_r($args);
             echo '<hr />';
             print $request;
             echo '<hr />';
             echo 'Response from UPS';
             echo $raw_quote;
             echo '</strong>:: GetQuote ::End DEBUG OUTPUT::';
         }
     }
     $wpec_ash->cache_results($this->internal_name, $rate_table, $this->shipment);
     // return the final formatted array !
     return $rate_table;
 }
Exemple #30
0
function _wpsc_fix_zimbabwe_currency()
{
    $country = new WPSC_Country('ZW', 'isocode');
    $country->set(array('currency' => __('US Dollar', 'wpsc'), 'symbol' => __('$', 'wpsc'), 'symbol_html' => __('&#036', 'wpsc'), 'code' => 'USD', 'continent' => 'asiapacific'));
    $country->save();
}