Ejemplo n.º 1
0
 public function quote()
 {
     global $osC_ShoppingCart, $osC_Weight;
     $dest_country = $osC_ShoppingCart->getShippingAddress('country_iso_code_2');
     $dest_zone = 0;
     $error = false;
     $shipping_method = null;
     $shipping_cost = null;
     $shipping_weight = 0;
     foreach ($osC_ShoppingCart->getProducts() as $product) {
         $osC_Product = new osC_Product($product['id']);
         if ($osC_Product->isTypeActionAllowed('apply_shipping_fees')) {
             $shipping_weight += $osC_Weight->convert($product['weight'], SHIPPING_WEIGHT_UNIT, MODULE_SHIPPING_ZONES_WEIGHT_UNIT) * $product['quantity'];
         }
     }
     for ($i = 1; $i <= $this->num_zones; $i++) {
         $countries_table = constant('MODULE_SHIPPING_ZONES_COUNTRIES_' . $i);
         $country_zones = preg_split("/[,]/", $countries_table);
         if (in_array($dest_country, $country_zones)) {
             $dest_zone = $i;
             break;
         }
     }
     if ($dest_zone == 0) {
         $error = true;
     } else {
         $shipping = -1;
         $zones_cost = constant('MODULE_SHIPPING_ZONES_COST_' . $dest_zone);
         $zones_table = preg_split("/[:,]/", $zones_cost);
         $size = sizeof($zones_table);
         for ($i = 0; $i < $size; $i += 2) {
             if ($shipping_weight <= $zones_table[$i]) {
                 $shipping = $zones_table[$i + 1];
                 $shipping_method = __('shipping_zones_method') . ' ' . $dest_country . ' : ' . $osC_Weight->display($osC_ShoppingCart->getWeight(), MODULE_SHIPPING_ZONES_WEIGHT_UNIT);
                 break;
             }
         }
         if ($shipping == -1) {
             $shipping_cost = 0;
             $shipping_method = __('shipping_zones_undefined_rate');
         } else {
             $shipping_cost = $shipping * $osC_ShoppingCart->numberOfShippingBoxes() + constant('MODULE_SHIPPING_ZONES_HANDLING_' . $dest_zone);
         }
     }
     $this->quotes = array('id' => $this->_code, 'module' => $this->_title, 'methods' => array(array('id' => $this->_code, 'title' => $shipping_method, 'cost' => $shipping_cost)), 'tax_class_id' => $this->tax_class);
     if (!empty($this->icon)) {
         $this->quotes['icon'] = osc_image($this->icon, $this->_title);
     }
     if ($error == true) {
         $this->quotes['error'] = __('shipping_zones_invalid_zone');
     }
     return $this->quotes;
 }
Ejemplo n.º 2
0
 public function quote()
 {
     global $osC_ShoppingCart;
     $number_of_items = 0;
     foreach ($osC_ShoppingCart->getProducts() as $product) {
         $osC_Product = new osC_Product($product['id']);
         if ($osC_Product->isTypeActionAllowed('apply_shipping_fees')) {
             $number_of_items += $product['quantity'];
         }
     }
     $this->quotes = array('id' => $this->_code, 'module' => $this->_title, 'methods' => array(array('id' => $this->_code, 'title' => __('shipping_item_method'), 'cost' => MODULE_SHIPPING_ITEM_COST * $number_of_items + MODULE_SHIPPING_ITEM_HANDLING)), 'tax_class_id' => $this->tax_class);
     if (!empty($this->icon)) {
         $this->quotes['icon'] = osc_image($this->icon, $this->_title);
     }
     return $this->quotes;
 }
Ejemplo n.º 3
0
 public function quote()
 {
     global $osC_ShoppingCart;
     $this->_setMachinable('False');
     $this->_setContainer('None');
     $this->_setSize('REGULAR');
     // usps doesnt accept zero weight
     $shipping_weight = 0.1;
     foreach ($osC_ShoppingCart->getProducts() as $product) {
         $osC_Product = new osC_Product($product['id']);
         if ($osC_Product->isTypeActionAllowed('apply_shipping_fees')) {
             $shipping_weight += $product['weight'] * $product['quantity'];
         }
     }
     $shipping_pounds = floor($shipping_weight);
     $shipping_ounces = round(16 * ($shipping_weight - floor($shipping_weight)));
     $this->_setWeight($shipping_pounds, $shipping_ounces);
     $uspsQuote = $this->_getQuote();
     if (is_array($uspsQuote)) {
         if (isset($uspsQuote['error'])) {
             $this->quotes = array('module' => $this->_title, 'error' => $uspsQuote['error']);
         } else {
             $this->quotes = array('id' => $this->_code, 'module' => $this->_title . ' (' . $osC_ShoppingCart->numberOfShippingBoxes() . ' x ' . ($osC_ShoppingCart->getShippingBoxesWeight() < 0.1 ? 0.1 : $osC_ShoppingCart->getShippingBoxesWeight()) . 'lbs)', 'tax_class_id' => $this->tax_class);
             $methods = array();
             $size = sizeof($uspsQuote);
             for ($i = 0; $i < $size; $i++) {
                 list($type, $cost) = each($uspsQuote[$i]);
                 $methods[] = array('id' => $type, 'title' => isset($this->types[$type]) ? $this->types[$type] : $type, 'cost' => ($cost + MODULE_SHIPPING_USPS_HANDLING) * $osC_ShoppingCart->numberOfShippingBoxes());
             }
             $this->quotes['methods'] = $methods;
         }
     } else {
         $this->quotes = array('module' => $this->_title, 'error' => __('shipping_usps_error'));
     }
     if (!empty($this->icon)) {
         $this->quotes['icon'] = osc_image($this->icon, $this->_title);
     }
     return $this->quotes;
 }
Ejemplo n.º 4
0
 public function quote()
 {
     global $osC_Currencies, $osC_Tax, $osC_ShoppingCart, $osC_Weight;
     $order_total = 0;
     if (MODULE_SHIPPING_TABLE_MODE == 'price') {
         foreach ($osC_ShoppingCart->getProducts() as $product) {
             $osC_Product = new osC_Product($product['id']);
             if ($osC_Product->isTypeActionAllowed('apply_shipping_fees')) {
                 $tax = $osC_Tax->getTaxRate($product['tax_class_id'], $osC_ShoppingCart->getTaxingAddress('country_id'), $osC_ShoppingCart->getTaxingAddress('zone_id'));
                 $order_total += $osC_Currencies->addTaxRateToPrice($product['price'], $tax, $product['quantity']);
             }
         }
     } else {
         foreach ($osC_ShoppingCart->getProducts() as $product) {
             $osC_Product = new osC_Product($product['id']);
             if ($osC_Product->isTypeActionAllowed('apply_shipping_fees')) {
                 $order_total += $osC_Weight->convert($product['weight'], $product['weight_class_id'], MODULE_SHIPPING_TABLE_WEIGHT_UNIT) * $product['quantity'];
             }
         }
     }
     $table_cost = preg_split("/[:,]/", MODULE_SHIPPING_TABLE_COST);
     $size = sizeof($table_cost);
     for ($i = 0, $n = $size; $i < $n; $i += 2) {
         if ($order_total <= $table_cost[$i]) {
             $shipping = $table_cost[$i + 1];
             break;
         }
     }
     if (MODULE_SHIPPING_TABLE_MODE == 'weight') {
         $shipping = $shipping * $osC_ShoppingCart->numberOfShippingBoxes();
     }
     $this->quotes = array('id' => $this->_code, 'module' => $this->_title, 'methods' => array(array('id' => $this->_code, 'title' => __('shipping_table_method'), 'cost' => $shipping + MODULE_SHIPPING_TABLE_HANDLING)), 'tax_class_id' => $this->tax_class);
     if (!empty($this->icon)) {
         $this->quotes['icon'] = osc_image($this->icon, $this->_title);
     }
     return $this->quotes;
 }