Exemplo n.º 1
0
 /**
  * General entry point for WPEC external shipping calculator
  * This function expects no arguments but requires POST data
  * and configuration from the plugin settings
  * @return array $rate_table List of rates in "Service"=>"Rate" format
  */
 function getQuote()
 {
     global $wpdb, $wpec_ash, $wpec_ash_tools;
     $this->shipment = $wpec_ash->get_shipment();
     $this->shipment->set_destination($this->internal_name);
     // Check to see if the cached shipment is still accurate, if not we need new rate
     $cache = $wpec_ash->check_cache($this->internal_name, $this->shipment);
     //if ($cache){
     //    return $cache["rate_table"];
     //}
     $data = array();
     //*** WPEC Configuration values ***\\
     $settings = get_option("wpec_usps");
     $this->env = $settings["test_server"];
     $data["fcl_type"] = !empty($settings["fcl_type"]) ? $settings["fcl_type"] : "PARCEL";
     $data["mail_type"] = !empty($settings["intl_pkg"]) ? $settings["intl_pkg"] : "Package";
     $data["base_zipcode"] = get_option("base_zipcode");
     $data["services"] = !empty($settings["services"]) ? $settings["services"] : array("PRIORITY", "EXPRESS", "FIRST CLASS");
     $data["user_id"] = $settings["id"];
     $data["adv_rate"] = !empty($settings["adv_rate"]) ? $settings["adv_rate"] : FALSE;
     // Use advanced shipping for Domestic Rates ? Not available
     //*** Set up the destination country ***\
     $country = $this->shipment->destination["country"];
     $data["dest_country"] = $wpec_ash_tools->get_full_country($country);
     $data["dest_country"] = $this->_update_country($data["dest_country"]);
     //************ GET THE RATE ************\\
     $rate_table = $this->_run_quote($data);
     //************ CACHE the Results ************\\
     $wpec_ash->cache_results($this->internal_name, $rate_table, $this->shipment);
     return $rate_table;
 }
Exemplo n.º 2
0
    /**
     * General entry point for WPEC external shipping calculator
     * This function expects no arguments but requires POST data
     * and configuration from the plugin settings
     * @return array $rate_table List of rates in "Service"=>"Rate" format
     */
    function getQuote()
    {
        global $wpdb, $wpec_ash, $wpec_ash_tools, $wpsc_cart;
        $data = array();
        //************** These values are common to all entry points **************
        //*** User/Customer Entered Values ***\\
        //*** Set up the destination country ***\
        $data["dest_country"] = wpsc_get_customer_meta('shipping_country');
        $settings = get_option('wpec_usps');
        //Disable International Shipping. Default: Enabled as it currently is.
        $data['intl_rate'] = isset($settings['intl_rate']) && !empty($settings['intl_rate']) ? FALSE : TRUE;
        if (!$data['intl_rate'] && $data['dest_country'] != get_option('base_country')) {
            return array();
        }
        // If ths zip code is provided via a form post use it!
        $data["dest_zipcode"] = (string) wpsc_get_customer_meta('shippingpostcode');
        if (!is_object($wpec_ash_tools)) {
            $wpec_ash_tools = new ASHTools();
        }
        if (empty($data["dest_zipcode"]) && $wpec_ash_tools->needs_post_code($data["dest_country"])) {
            // We cannot get a quote without a zip code so might as well return!
            return array();
        }
        //*** Grab Total Weight from the shipment object for simple shipping
        $data["weight"] = wpsc_cart_weight_total();
        if (empty($data["weight"])) {
            return array();
        }
        // If the region code is provided via a form post use it!
        if (isset($_POST['region']) && !empty($_POST['region'])) {
            $data['dest_state'] = wpsc_get_region(sanitize_text_field($_POST['region']));
        } else {
            if ($dest_state = wpsc_get_customer_meta('shipping_state')) {
                // Well, we have a zip code in the session and no new one provided
                $data['dest_state'] = $dest_state;
            } else {
                $data['dest_state'] = "";
            }
        }
        $data["dest_country"] = $wpec_ash_tools->get_full_country($data["dest_country"]);
        $data["dest_country"] = $this->_update_country($data["dest_country"]);
        if (!is_object($wpec_ash)) {
            $wpec_ash = new ASH();
        }
        $shipping_cache_check['state'] = $data['dest_state'];
        $shipping_cache_check['country'] = $data['dest_country'];
        $shipping_cache_check['zipcode'] = $data["dest_zipcode"];
        $this->shipment = $wpec_ash->get_shipment();
        $this->shipment->set_destination($this->internal_name, $shipping_cache_check);
        $this->shipment->rates_expire = date('Y-m-d');
        //Date will be checked against the cached date.
        $data['shipper'] = $this->internal_name;
        $data["adv_rate"] = !empty($settings["adv_rate"]) ? $settings["adv_rate"] : FALSE;
        // Use advanced shipping for Domestic Rates ? Not available
        if ($data["weight"] > 70 && !(bool) $data["adv_rate"]) {
            //USPS has a weight limit: https://www.usps.com/send/can-you-mail-it.htm?#3.
            $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.', 'wp-e-commerce'), $data);
            $shipping_quotes[$over_weight_txt] = 0;
            // yes, a constant.
            $wpec_ash->cache_results($this->internal_name, array($shipping_quotes), $this->shipment);
            return array($shipping_quotes);
        }
        // Check to see if the cached shipment is still accurate, if not we need new rate
        $cache = $wpec_ash->check_cache($this->internal_name, $this->shipment);
        // We do not want to spam USPS (and slow down our process) if we already
        // have a shipping quote!
        if (count($cache["rate_table"]) >= 1) {
            //$cache['rate_table'] could be array(0).
            return $cache["rate_table"];
        }
        //*** WPEC Configuration values ***\\
        $this->use_test_env = !isset($settings["test_server"]) ? false : (bool) $settings['test_server'];
        $data["fcl_type"] = !empty($settings["fcl_type"]) ? $settings["fcl_type"] : "PARCEL";
        $data["mail_type"] = !empty($settings["intl_pkg"]) ? $settings["intl_pkg"] : "Package";
        $data["base_zipcode"] = get_option("base_zipcode");
        $data["services"] = !empty($settings["services"]) ? $settings["services"] : array("STANDARD POST", "PRIORITY", "PRIORITY EXPRESS", "FIRST CLASS");
        foreach ($data["services"] as $id => $service) {
            if ($service == 'PARCEL') {
                $data["services"][$id] = 'STANDARD POST';
            }
            if ($service == 'EXPRESS') {
                $data["services"][$id] = 'PRIORITY EXPRESS';
            }
        }
        $data["user_id"] = $settings["id"];
        $data["value"] = $wpsc_cart->calculate_subtotal(true);
        //Required by $this->_build_intl_shipment.
        $data = apply_filters('wpsc_shipment_data', $data, $this->shipment);
        if (isset($data['stop'])) {
            //Do not get rates.
            return array();
        }
        //************ GET THE RATE ************\\
        $rate_table = apply_filters('wpsc_rates_table', $this->_run_quote($data), $data, $this->shipment);
        //Avoid trying getting rates again and again when the stored zip code is incorrect.
        //************ CACHE the Results ************\\
        $wpec_ash->cache_results($this->internal_name, $rate_table, $this->shipment);
        return $rate_table;
    }
Exemplo n.º 3
0
 /**
  * Builds a shipment object representing the cart contents from WPEC
  * @author Greg Gullett (greg@ecsquest.com)
  * @return ASHShipment
  */
 function get_shipment()
 {
     global $wpdb, $wpsc_cart;
     $shipment = new ASHShipment();
     if (!$wpsc_cart) {
         return $shipment;
     }
     foreach ($wpsc_cart->cart_items as $cart_item) {
         $package = new ASHPackage();
         //*** Set package dimensions ***\\
         $dimensions = get_product_meta($cart_item->product_id, 'dimensions');
         $dim_array = array();
         $dim_array["weight"] = $cart_item->weight;
         $dim_array["height"] = !empty($dimensions["height"]) && is_numeric($dimensions["height"]) ? $dimensions["height"] : 1;
         $dim_array["width"] = !empty($dimensions["width"]) && is_numeric($dimensions["width"]) ? $dimensions["width"] : 1;
         $dim_array["length"] = !empty($dimensions["length"]) && is_numeric($dimensions["length"]) ? $dimensions["length"] : 1;
         $package->set_dimensions($dim_array);
         //*** Set other meta ***\\
         $package->hazard = get_product_meta($cart_item->product_id, "ship_hazard") === FALSE ? FALSE : TRUE;
         $package->insurance = get_product_meta($cart_item->product_id, "ship_insurance");
         $package->insured_amount = get_product_meta($cart_item->product_id, "ship_insured_amount");
         $package->value = $cart_item->unit_price;
         $package->contents = $cart_item->product_name;
         if ($shipment->hazard === FALSE and $package->hazard === TRUE) {
             $shipment->set_hazard(TRUE);
         }
         $quantity = (int) $cart_item->quantity;
         for ($i = 1; $i <= $quantity; $i++) {
             $shipment->add_package($package);
         }
     }
     return $shipment;
 }
Exemplo n.º 4
0
 /**
  * Builds a shipment object representing the cart contents from WPEC
  *
  * @return ASHShipment
  */
 function get_shipment()
 {
     global $wpdb, $wpsc_cart;
     $shipment = new ASHShipment();
     if (!$wpsc_cart) {
         return $shipment;
     }
     foreach ($wpsc_cart->cart_items as $cart_item) {
         $package = new ASHPackage();
         //*** Set package dimensions ***\\
         $dimensions = get_product_meta($cart_item->product_id, 'product_metadata');
         //The 'dimensions' meta doesn't exist.
         if (isset($dimensions[0]['dimensions'])) {
             $dimensions = $dimensions[0]['dimensions'];
         }
         $dim_array = array();
         $dim_array["weight"] = $cart_item->weight;
         $dim_array["height"] = !empty($dimensions["height"]) && is_numeric($dimensions["height"]) ? $dimensions["height"] : 1;
         $dim_array["width"] = !empty($dimensions["width"]) && is_numeric($dimensions["width"]) ? $dimensions["width"] : 1;
         $dim_array["length"] = !empty($dimensions["length"]) && is_numeric($dimensions["length"]) ? $dimensions["length"] : 1;
         $package->set_dimensions($dim_array);
         /* Set other meta */
         $package->hazard = get_product_meta($cart_item->product_id, "ship_hazard", TRUE) === TRUE ? TRUE : FALSE;
         //Fixed ternary evaluation.
         $package->insurance = get_product_meta($cart_item->product_id, "ship_insurance", TRUE) === TRUE ? TRUE : FALSE;
         //Fixed ternary evaluation.
         $package->insured_amount = get_product_meta($cart_item->product_id, "ship_insured_amount", TRUE);
         //Fixed ternary evaluation.
         $package->value = $cart_item->unit_price;
         $package->contents = $cart_item->product_name;
         $package->this_side_up = get_post_meta($cart_item->product_id, "h:this_side_up", TRUE) === TRUE ? TRUE : FALSE;
         //Prod. page hide, prod. UI display
         if ($shipment->hazard === FALSE and $package->hazard === TRUE) {
             $shipment->set_hazard(TRUE);
         }
         $quantity = (int) $cart_item->quantity;
         $package->product_id[$cart_item->product_id] = 1;
         // The product in this package.
         for ($i = 1; $i <= $quantity; $i++) {
             $shipment->add_package($package);
         }
     }
     return $shipment;
 }