function test_set() { $region = new WPSC_Region(self::COUNTRY_ID_WITH_REGIONS, self::REGION_ID); $region->set('name', self::INVALID_REGION_NAME); // This should not set the value $this->assertEquals(self::REGION_NAME, $region->get('name')); $region = new WPSC_Region(self::COUNTRY_ID_WITH_REGIONS, self::REGION_ID); $region->set('omgwtfbbq', 'OMG'); // This should set the value $this->assertEquals('OMG', $region->get('omgwtfbbq')); $region->set('omgwtfbbq', ''); }
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; }
/** * generates a row for use in tax settings tables * * @param string specifies mode of row to generate. Options: rates, bands * @param string the key number for the row * @param array tax rate settings (used keys: rate, name, country_code, region_code, shipping, index, row_class) * */ function wpsc_build_taxes_row($row_mode = 'rates', $row_key = 0, $tax_rate = false) { $defaults = array('rate' => null, 'name' => null, 'country_code' => null, 'region_code' => null, 'shipping' => null, 'index' => null, 'row_class' => null); $tax_rate = array_merge($defaults, (array) $tax_rate); $countries = $this->wpec_taxes->wpec_taxes_get_countries(); if (!empty($tax_rate['country_code']) && $tax_rate['country_code'] != 'all-markets') { $selected_country = array('isocode' => $tax_rate['country_code'], 'country' => wpsc_get_country($tax_rate['country_code'])); } else { $selected_country = array('isocode' => 'all-markets', 'country' => __('All Markets', 'wpsc')); } ob_start(); ?> <tr id='wpsc-taxes-<?php esc_attr_e($row_mode); ?> -row-<?php esc_attr_e($row_key); ?> ' data-row-key="<?php esc_attr_e($row_key); ?> " class='wpsc-tax-<?php esc_attr_e($row_mode); ?> -row <?php esc_attr_e($tax_rate['row_class']); ?> '> <?php if ($row_mode == 'bands') { // BAND NAME ?> <td> <input type='hidden' id='band-index-<?php esc_attr_e($row_key); ?> ' name="wpsc_options[wpec_taxes_bands][<?php esc_attr_e($row_key); ?> ][index]" value="<?php esc_attr_e($row_key); ?> " /> <input id='band-name-<?php esc_attr_e($row_key); ?> ' name="wpsc_options[wpec_taxes_bands][<?php esc_attr_e($row_key); ?> ][name]" class='taxes-band' type='text' value='<?php esc_attr_e($tax_rate['name']); ?> ' /> </td> <?php } ?> <td> <?php // MARKET COUNTRY SELECT echo $this->wpec_taxes_build_select_options($countries, 'isocode', 'country', $selected_country, array('id' => $row_mode . "-country-" . $row_key, 'name' => "wpsc_options[wpec_taxes_" . $row_mode . "][" . $row_key . "][country_code]", 'class' => 'wpsc-taxes-country-drop-down', 'data-row-key' => $row_key, 'data-row-mode' => $row_mode)); // MARKET REGION SELECT if (!empty($tax_rate['region_code'])) { $regions = $this->wpec_taxes->wpec_taxes_get_regions($tax_rate['country_code']); if (!empty($regions)) { if ($tax_rate['region_code'] == 'all-markets') { $region_name = 'All Markets'; } else { $region = new WPSC_Region($tax_rate['country_code'], $tax_rate['region_code']); $region_name = $region->get_name(); } echo $this->wpec_taxes_build_select_options($regions, 'region_code', 'name', array('region_code' => $tax_rate['region_code'], 'name' => $region_name), array('id' => $row_mode . "-region-" . $row_key, 'name' => "wpsc_options[wpec_taxes_" . $row_mode . "][" . $row_key . "][region_code]", 'class' => 'wpsc-taxes-region-drop-down')); } } // if ?> <img src="<?php echo esc_url(wpsc_get_ajax_spinner()); ?> " class="ajax-feedback" title="" alt="" /> </td> <td><?php // TAX RATE ?> <input type='text' size='3' id="<?php esc_attr_e($row_mode); ?> -rate-<?php esc_attr_e($row_key); ?> " name="wpsc_options[wpec_taxes_<?php esc_attr_e($row_mode); ?> ][<?php esc_attr_e($row_key); ?> ][rate]" class="taxes-<?php esc_attr_e($row_mode); ?> " value="<?php esc_attr_e($tax_rate['rate']); ?> " /> % </td> <?php if ($row_mode == 'rates') { // TAX SHIPPING ? ?> <td> <label> <input type='checkbox' id="shipping-<?php esc_attr_e($row_key); ?> " name="wpsc_options[wpec_taxes_<?php esc_attr_e($row_mode); ?> ][<?php esc_attr_e($row_key); ?> ][shipping]" class="taxes-<?php esc_attr_e($row_mode); ?> " <?php checked($tax_rate['shipping'] == 1); ?> /> <?php _e('Apply to Shipping', 'wpsc'); ?> </label> </td> <?php } ?> <?php // ACTIONS ?> <td> <a tabindex="-1" title="<?php _e('Delete Field', 'wpsc'); ?> " class="button-secondary wpsc-button-round wpsc-button-minus wpsc-taxes-<?php esc_attr_e($row_mode); ?> -delete" id="wpsc-taxes-<?php esc_attr_e($row_mode); ?> -delete-<?php esc_attr_e($row_key); ?> " href="#"><?php echo _x('–', 'delete item', 'wpsc'); ?> </a> <a tabindex="-1" title="<?php _e('Add Field', 'wpsc'); ?> " class="button-secondary wpsc-button-round wpsc-button-plus wpsc-taxes-<?php esc_attr_e($row_mode); ?> -add" href="#"><?php echo _x('+', 'add item', 'wpsc'); ?> </a> </td> </tr> <?php return ob_get_clean(); }
function wpsc_get_region($region_id) { $country_id = WPSC_Countries::get_country_id_by_region_id($region_id); $wpsc_region = new WPSC_Region($country_id, $region_id); return $wpsc_region->get_name(); }
/** * 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; }