Exemple #1
0
 /**
  * Gets a user's geozone
  * @param int $userid
  * @return unknown_type
  */
 public static function getGeoZones($userid)
 {
     Citruscart::load('CitruscartHelperShipping', 'helpers.shipping');
     $address = CitruscartHelperUser::getPrimaryAddress($userid, 'billing');
     if (empty($address->zone_id)) {
         return array();
     }
     $geozones = CitruscartHelperShipping::getGeoZones($address->zone_id, '1', $address->postal_code);
     return $geozones;
 }
Exemple #2
0
 /**
  * Calculate taxes on list of products
  *
  * @param $products						Array of products
  * @param $source						Source of tax calculation (final_price '1', product_price '2', orderitem_price '3')
  * @param $billing_address		Actual customer's billing address
  * @param $shipping_address		Actual customer's shipping address
  * @param $tax_type						for the future use
  *
  * @return Associative array with indexes product_id of products with arrays with list of their tax rates (names and rates)
  */
 public static function calculateTax($products, $source = 1, $billing_address = null, $shipping_address = null, $tax_type = null)
 {
     $result = new stdClass();
     $result->tax_total = 0.0;
     $result->tax_rate_rates = array();
     $result->tax_class_rates = array();
     $result->product_taxes = array();
     if (!is_array($products)) {
         return $result;
     }
     Citruscart::load('CitruscartHelperShipping', 'helpers.shipping');
     Citruscart::load('CitruscartQuery', 'library.query');
     Citruscart::load('CitruscartTools', 'library.tools');
     if ($billing_address) {
         $billing_zones = CitruscartHelperShipping::getGeoZones($billing_address->zone_id, '1', $billing_address->postal_code);
     } else {
         $billing_zones = array();
     }
     if (!empty($billing_zones)) {
         foreach ($billing_zones as $key => $value) {
             $billing_zones[$key] = $value->geozone_id;
         }
     }
     //load the default geozones when user is logged out and the config is to show tax
     if (empty($billing_zones)) {
         $geozones = CitruscartHelperUser::getGeoZones(JFactory::getUser()->id);
         if (empty($geozones)) {
             // use the default
             $billing_zones = array(Citruscart::getInstance()->get('default_tax_geozone'));
         } else {
             foreach ($geozones as $key => $value) {
                 $billing_zones[$key] = $value->geozone_id;
             }
         }
     }
     return CitruscartHelperTax::calculateGeozonesTax($products, $source, $billing_zones);
 }
Exemple #3
0
 /**
  * Based on the object's addresses,
  * sets the shipping and billing geozones
  *
  * @return unknown_type
  */
 function setGeozones($geozones = null, $type = 'billing')
 {
     //print_r($geozones); exit;
     if (!empty($geozones)) {
         switch ($type) {
             case "shipping":
                 $this->_shipping_geozones = $geozones;
                 break;
             case "billing":
             default:
                 $this->_billing_geozones = $geozones;
                 break;
         }
     } else {
         Citruscart::load('CitruscartHelperShipping', 'helpers.shipping');
         if (!empty($this->_billing_address)) {
             $this->_billing_geozones = CitruscartHelperShipping::getGeoZones($this->_billing_address->zone_id, '1', $this->_billing_address->postal_code);
         }
         if (!empty($this->_shipping_address)) {
             $this->_shipping_geozones = CitruscartHelperShipping::getGeoZones($this->_shipping_address->zone_id, '2', $this->_shipping_address->postal_code);
         }
     }
 }