Example #1
0
 /**
  * returns shipping quotes using this shipping module.
  *
  * @param boolean $for_display (optional) (unused)
  * @return array collection of rates applicable.
  */
 function getQuote($for_display = false)
 {
     global $wpdb, $wpsc_cart;
     $quote_shipping_method = wpsc_get_customer_meta('quote_shipping_method');
     $quote_shipping_option = wpsc_get_customer_meta('quote_shipping_option');
     $country = '';
     if (isset($_POST['country'])) {
         $country = sanitize_text_field($_POST['country']);
         wpsc_update_customer_meta('shipping_country', $country);
     } else {
         $country = (string) wpsc_get_customer_meta('shipping_country');
     }
     if (is_object($wpsc_cart)) {
         $cart_total = $wpsc_cart->calculate_subtotal(true);
     }
     if (get_option('base_country') != $country) {
         $results = WPSC_Countries::get_continent($country);
         $flatrates = get_option('flat_rates');
         if ($flatrates != '') {
             if ($quote_shipping_method == $this->internal_name && $quote_shipping_option != __("Flat Rate", 'wp-e-commerce')) {
                 wpsc_delete_customer_meta('quote_shipping_option');
             }
             if (isset($flatrates[$results])) {
                 if (stristr($flatrates[$results], '%')) {
                     $shipping_percent = str_replace('%', '', $flatrates[$results]);
                     $shipping_amount = $cart_total * ($shipping_percent / 100);
                     $flatrates[$results] = (double) $shipping_amount;
                 }
                 return array(__("Flat Rate", 'wp-e-commerce') => (double) $flatrates[$results]);
             }
         }
     } else {
         $flatrates = get_option('flat_rates');
         $shipping_quotes = array();
         switch ($country) {
             case 'NZ':
                 if (isset($flatrates['northisland']) && strlen($flatrates['northisland']) > 0) {
                     $shipping_quotes[__('North Island', 'wp-e-commerce')] = esc_attr($flatrates['northisland']);
                 }
                 if (isset($flatrates['southisland']) && strlen($flatrates['southisland']) > 0) {
                     $shipping_quotes[__('South Island', 'wp-e-commerce')] = esc_attr($flatrates['southisland']);
                 }
                 break;
             case 'US':
                 if (isset($flatrates['continental']) && strlen($flatrates['continental']) > 0) {
                     $shipping_quotes[__('Continental 48 States', 'wp-e-commerce')] = esc_attr($flatrates['continental']);
                 }
                 if (isset($flatrates['all']) && strlen($flatrates['all']) > 0) {
                     $shipping_quotes[__('All 50 States', 'wp-e-commerce')] = esc_attr($flatrates['all']);
                 }
                 break;
             default:
                 if (isset($flatrates['local']) && strlen($flatrates['local']) > 0) {
                     $shipping_quotes[__('Local Shipping', 'wp-e-commerce')] = esc_attr($flatrates['local']);
                 }
                 break;
         }
         // Deal with % shipping rates
         foreach (array_keys($shipping_quotes) as $quote_name) {
             if (stristr($shipping_quotes[$quote_name], '%')) {
                 $shipping_percent = str_replace('%', '', $shipping_quotes[$quote_name]);
                 $shipping_amount = $cart_total * ($shipping_percent / 100);
                 $shipping_quotes[$quote_name] = (double) $shipping_amount;
             } else {
                 $shipping_quotes[$quote_name] = (double) $shipping_quotes[$quote_name];
             }
         }
         if ($quote_shipping_method == $this->internal_name) {
             $shipping_options = array_keys($shipping_quotes);
             if (array_search($quote_shipping_option, $shipping_options) === false) {
                 wpsc_delete_customer_meta('quote_shipping_option');
             }
         }
         return $shipping_quotes;
     }
 }