/** * Gets a user's geozone * @param int $userid * @return unknown_type */ public static function getGeoZones($userid) { Tienda::load('TiendaHelperShipping', 'helpers.shipping'); $address = TiendaHelperUser::getPrimaryAddress($userid, 'billing'); if (empty($address->zone_id)) { return array(); } $geozones = TiendaHelperShipping::getGeoZones($address->zone_id, '1', $address->postal_code); return $geozones; }
/** * 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; } Tienda::load('TiendaHelperShipping', 'helpers.shipping'); Tienda::load('TiendaQuery', 'library.query'); Tienda::load('TiendaTools', 'library.tools'); if ($billing_address) { $billing_zones = TiendaHelperShipping::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 = TiendaHelperUser::getGeoZones(JFactory::getUser()->id); if (empty($geozones)) { // use the default $billing_zones = array(Tienda::getInstance()->get('default_tax_geozone')); } else { foreach ($geozones as $key => $value) { $billing_zones[$key] = $value->geozone_id; } } } return TiendaHelperTax::calculateGeozonesTax($products, $source, $billing_zones); }
/** * Based on the object's addresses, * sets the shipping and billing geozones * * @return unknown_type */ function setGeozones($geozones = null, $type = 'billing') { if (!empty($geozones)) { switch ($type) { case "shipping": $this->_shipping_geozones = $geozones; break; case "billing": default: $this->_billing_geozones = $geozones; break; } } else { Tienda::load('TiendaHelperShipping', 'helpers.shipping'); if (!empty($this->_billing_address)) { $this->_billing_geozones = TiendaHelperShipping::getGeoZones($this->_billing_address->zone_id, '1', $this->_billing_address->postal_code); } if (!empty($this->_shipping_address)) { $this->_shipping_geozones = TiendaHelperShipping::getGeoZones($this->_shipping_address->zone_id, '2', $this->_shipping_address->postal_code); } } }