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); }
function test_set() { $country = new WPSC_Country(self::COUNTRY_ID_WITHOUT_REGIONS); $country->set('name', 'XXX'); // This should not set the property. $name = $country->get('name'); $this->assertEquals(self::COUNTRY_NAME_WITHOUT_REGIONS, $name); $country->set('isocode', 'XX'); // This should not set the property. $isocode = $country->get('isocode'); $this->assertEquals(self::COUNTRY_ISOCODE_WITHOUT_REGIONS, $isocode); $country->set('omgwtfbbq_new', 'OMG'); // This SHOULD set the property. $omg = $country->get('omgwtfbbq_new'); $this->assertEquals('OMG', $omg); $country->set('omgwtfbbq_new', ''); // Clear it out. $omg = $country->get('omgwtfbbq_new'); $this->assertEquals('', $omg); }
/** * 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; }
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; }
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); 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, array('JPY', 'HUF', 'VND')); $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('symbol'), $isocode); $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; }
/** * validate_forms method, validates the input from the checkout page * @access public */ function validate_forms() { global $wpsc_cart, $wpdb, $current_user, $user_ID, $wpsc_gateway_error_messages, $wpsc_checkout_error_messages, $wpsc_customer_checkout_details, $wpsc_registration_error_messages; $any_bad_inputs = false; $bad_input_message = ''; $wpsc_gateway_error_messages = array(); $wpsc_checkout_error_messages = array(); $wpsc_registration_error_messages = array(); // Credit Card Number Validation for PayPal Pro and maybe others soon if (isset($_POST['card_number'])) { //should do some php CC validation here~ } else { $wpsc_gateway_error_messages['card_number'] = ''; } if (isset($_POST['card_number1']) && isset($_POST['card_number2']) && isset($_POST['card_number3']) && isset($_POST['card_number4'])) { if ($_POST['card_number1'] != '' && $_POST['card_number2'] != '' && $_POST['card_number3'] != '' && $_POST['card_number4'] != '' && is_numeric($_POST['card_number1']) && is_numeric($_POST['card_number2']) && is_numeric($_POST['card_number3']) && is_numeric($_POST['card_number4'])) { $wpsc_gateway_error_messages['card_number'] = ''; } else { $any_bad_inputs = true; $bad_input = true; $wpsc_gateway_error_messages['card_number'] = __('Please enter a valid credit card number.', 'wp-e-commerce'); $wpsc_customer_checkout_details['card_number'] = ''; } } if (isset($_POST['expiry'])) { if (!empty($_POST['expiry']['month']) && !empty($_POST['expiry']['month']) && is_numeric($_POST['expiry']['month']) && is_numeric($_POST['expiry']['year'])) { $wpsc_gateway_error_messages['expdate'] = ''; } else { $any_bad_inputs = true; $bad_input = true; $wpsc_gateway_error_messages['expdate'] = __('Please enter a valid expiry date.', 'wp-e-commerce'); $wpsc_customer_checkout_details['expdate'] = ''; } } if (isset($_POST['card_code'])) { if (empty($_POST['card_code']) || !is_numeric($_POST['card_code'])) { $any_bad_inputs = true; $bad_input = true; $wpsc_gateway_error_messages['card_code'] = __('Please enter a valid CVV.', 'wp-e-commerce'); $wpsc_customer_checkout_details['card_code'] = ''; } else { $wpsc_gateway_error_messages['card_code'] = ''; } } if (isset($_POST['cctype'])) { if ($_POST['cctype'] == '') { $any_bad_inputs = true; $bad_input = true; $wpsc_gateway_error_messages['cctype'] = __('Please enter a valid CVV.', 'wp-e-commerce'); $wpsc_customer_checkout_details['cctype'] = ''; } else { $wpsc_gateway_error_messages['cctype'] = ''; } } if (isset($_POST['log']) || isset($_POST['pwd']) || isset($_POST['user_email'])) { $results = wpsc_add_new_user($_POST['log'], $_POST['pwd'], $_POST['user_email']); if (is_callable(array($results, 'get_error_code')) && $results->get_error_code()) { foreach ($results->get_error_codes() as $code) { foreach ($results->get_error_messages($code) as $error) { $wpsc_registration_error_messages[] = $error; } $any_bad_inputs = true; } } if (property_exists($results, 'ID') && $results->ID > 0) { $our_user_id = $results->ID; } else { $any_bad_inputs = true; $our_user_id = ''; } } if (isset($our_user_id) && $our_user_id < 1) { $our_user_id = $user_ID; } // check we have a user id if (isset($our_user_id) && $our_user_id > 0) { $user_ID = $our_user_id; } //Basic Form field validation for billing and shipping details foreach ($this->checkout_items as $form_data) { $value = wpsc_get_customer_meta($form_data->unique_name); $wpsc_customer_checkout_details[$form_data->id] = $value; $bad_input = false; if ($form_data->mandatory == 1 || $form_data->type == 'coupon') { if ($form_data->unique_name == 'billingstate' && empty($value)) { $value = wpsc_get_customer_meta('billingregion'); if (empty($value)) { $any_bad_inputs = true; $bad_input = true; $country = new WPSC_Country(wpsc_get_customer_meta('billingcountry')); $name = $country->get('region_label'); } } else { if ($form_data->unique_name == 'shippingstate' && empty($value)) { $value = wpsc_get_customer_meta('shippingregion'); if (empty($value)) { $any_bad_inputs = true; $bad_input = true; $country = new WPSC_Country(wpsc_get_customer_meta('shippingcountry')); $name = $country->get('region_label'); } } else { $name = $form_data->name; switch ($form_data->type) { case 'email': if (!is_email($value)) { $any_bad_inputs = true; $bad_input = true; } break; case 'delivery_country': case 'country': if (empty($value)) { $any_bad_inputs = true; $bad_input = true; } break; case 'heading': break; case 'select': if ($value == '-1') { $any_bad_inputs = true; $bad_input = true; } break; default: if (empty($value)) { $any_bad_inputs = true; $bad_input = true; } break; } } } if ($bad_input === true) { $wpsc_checkout_error_messages[$form_data->id] = sprintf(__('Please enter a valid <span class="wpsc_error_msg_field_name">%s</span>.', 'wp-e-commerce'), strtolower(esc_attr($name))); $wpsc_customer_checkout_details[$form_data->id] = ''; } } } wpsc_update_customer_meta('checkout_error_messages', $wpsc_checkout_error_messages); wpsc_update_customer_meta('gateway_error_messages', $wpsc_gateway_error_messages); wpsc_update_customer_meta('registration_error_messages', $wpsc_registration_error_messages); $filtered_checkout_details = apply_filters('wpsc_update_customer_checkout_details', $wpsc_customer_checkout_details); // legacy filter if (is_user_logged_in()) { $filtered_checkout_details = apply_filters('wpsc_checkout_user_profile_update', $wpsc_customer_checkout_details, get_current_user_id()); } // Check if the shoppers location has changed _wpsc_has_visitor_location_changed(); $states = array('is_valid' => !$any_bad_inputs, 'error_messages' => $bad_input_message); $states = apply_filters('wpsc_checkout_form_validation', $states); return $states; }
function ic_cr_get_country_name($country_code) { $countries = new WPSC_Country($country_code, 'isocode'); return $countries->get('country'); }