Esempio n. 1
0
 /**
  * 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;
 }
Esempio n. 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;
     }
     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);
 }
Esempio n. 3
0
 /**
  * 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);
         }
     }
 }
Esempio n. 4
0
 function checkShippingHash($values)
 {
     $ship_values = array();
     $ship_values['type'] = @$values['shipping_plugin'];
     $ship_values['name'] = @$values['shipping_name'];
     $ship_values['price'] = @$values['shipping_price'];
     $ship_values['tax'] = @$values['shipping_tax'];
     $ship_values['code'] = @$values['shipping_code'];
     $ship_values['extra'] = @$values['shipping_extra'];
     Tienda::load('TiendaHelperShipping', 'helpers.shipping');
     $gh = TiendaHelperShipping::generateShippingHash($ship_values);
     return $gh == @$values['shipping_hash'];
 }
Esempio n. 5
0
 /**
  * Returns a shipping estimate, unformatted.
  *
  * @param int $shipping_method_id
  * @param int $geozone_id
  * @param array $orderItems     an array of TiendaTableOrderItems objects, each with ->product_id and ->orderitem_quantity
  *
  * @return object with ->shipping_rate_price and ->shipping_rate_handling and ->shipping_tax_total, all decimal(12,5)
  */
 public function getTotal($shipping_method_id, $geozone_id, $orderItems)
 {
     $return = new JObject();
     $return->shipping_rate_price = '0.00000';
     $return->shipping_rate_handling = '0.00000';
     $return->shipping_tax_rate = '0.00000';
     $return->shipping_tax_total = '0.00000';
     // cast product_id as an array
     $orderItems = (array) $orderItems;
     // determine the shipping method type
     JTable::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_tienda/tables');
     $shippingmethod = JTable::getInstance('ShippingMethods', 'TiendaTable');
     $shippingmethod->load($shipping_method_id);
     if (empty($shippingmethod->shipping_method_id)) {
         // TODO if this is an object, setError, otherwise return false, or 0.000?
         $return->setError(JText::_('COM_TIENDA_UNDEFINED_SHIPPING_METHOD'));
         return $return;
     }
     switch ($shippingmethod->shipping_method_type) {
         case "2":
             // 2 = per order
             // if any of the products in the order require shipping
             $order_ships = false;
             JTable::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_tienda/tables');
             foreach ($orderItems as $item) {
                 //$pid = $orderItems[$i]->product_id;
                 $pid = $item->product_id;
                 $product = JTable::getInstance('Products', 'TiendaTable');
                 $product->load($pid);
                 if (!empty($product->product_ships)) {
                     $product_id = $item->product_id;
                     $order_ships = true;
                 }
             }
             if ($order_ships) {
                 //$shippingrate = TiendaHelperShipping::getRate( $shipping_method_id, $geozone_id, $product_id );
                 //$return->shipping_rate_price      = $shippingrate->shipping_rate_price;
                 //$return->shipping_rate_handling   = $shippingrate->shipping_rate_handling;
             }
             break;
         case "1":
         case "0":
             // 0 = per item
             // 1 = weight based
             $rates = array();
             foreach ($orderItems as $item) {
                 $pid = $item->product_id;
                 $qty = $item->orderitem_quantity;
                 //$rates[$pid] = TiendaHelperShipping::getRate( $shipping_method_id, $geozone_id, $pid, $shippingmethod->shipping_method_type );
                 //$return->shipping_rate_price      += ($rates[$pid]->shipping_rate_price * $qty);
                 //$return->shipping_rate_handling   += ($rates[$pid]->shipping_rate_handling * $qty);
             }
             break;
         default:
             // TODO if this is an object, setError, otherwise return false, or 0.000?
             $return->setError(JText::_('COM_TIENDA_INVALID_SHIPPING_METHOD_TYPE'));
             return $return;
             break;
     }
     // get the shipping tax rate and total
     $return->shipping_tax_rate = TiendaHelperShipping::getTaxRate($shipping_method_id, $geozone_id);
     $return->shipping_tax_total = $return->shipping_tax_rate / 100 * ($return->shipping_rate_price + $return->shipping_rate_handling);
     return $return;
 }
Esempio n. 6
0
    ?>
                    </a>
                    <div class="shipping_rates">
                        <?php 
    Tienda::load('TiendaUrl', 'library.url');
    ?>
                        <?php 
    Tienda::load('TiendaHelperShipping', 'helpers.shipping');
    $id = JRequest::getInt('id', '0');
    ?>
                        <span style="float: right;">[<?php 
    echo TiendaUrl::popup("index.php?option=com_tienda&view=shipping&task=view&id={$id}&shippingTask=setRates&tmpl=component&sid={$item->shipping_method_id}", JText::_('Set Rates'));
    ?>
]</span>
                        <?php 
    if ($shipping_method_type = TiendaHelperShipping::getType($item->shipping_method_type)) {
        echo "<b>" . JText::_('COM_TIENDA_TYPE') . "</b>: " . $shipping_method_type->title;
    }
    if ($item->subtotal_minimum > '0') {
        echo "<br/><b>" . JText::_('COM_TIENDA_MINIMUM_ORDER_REQUIRED') . "</b>: " . TiendaHelperBase::currency($item->subtotal_minimum);
    }
    if ($item->subtotal_maximum > '-1') {
        echo "<br/><b>" . JText::_('COM_TIENDA_SHIPPING_METHODS_SUBTOTAL_MAX') . "</b>: " . TiendaHelperBase::currency($item->subtotal_maximum);
    }
    ?>
                    </div>
				</td>
				<td style="text-align: center;">
				    <?php 
    echo $item->tax_class_name;
    ?>
Esempio n. 7
0
 function validateAddress($values, $type = "billing")
 {
     Tienda::load('TiendaHelperShipping', 'helpers.shipping');
     //special case
     $sameasbilling = !empty($values['sameasbilling']) ? true : false;
     $msg = array();
     switch ($type) {
         case 'shipping':
             $text = 'Shipping';
             if ($sameasbilling) {
                 $prefix = 'billing_input_';
                 $validate_id = '1';
                 $text = 'Billing';
             } else {
                 $prefix = 'shipping_input_';
                 $validate_id = '2';
             }
             break;
         case 'billing':
         default:
             $prefix = 'billing_input_';
             $validate_id = '1';
             $text = 'Billing';
             break;
     }
     // check if we already have an address id
     // if found we return an empty msg
     $addressInput = $prefix . 'address_id';
     if (!empty($values[$addressInput])) {
         return $msg;
     }
     $config = Tienda::getInstance();
     $field_title = $config->get('validate_field_title');
     $field_name = $config->get('validate_field_name');
     $field_middle = $config->get('validate_field_middle');
     $field_last = $config->get('validate_field_last');
     $field_company = $config->get('validate_field_company');
     $field_address1 = $config->get('validate_field_address1');
     $field_address2 = $config->get('validate_field_address2');
     $field_country = $config->get('validate_field_country');
     $field_zone = $config->get('validate_field_zone');
     $field_city = $config->get('validate_field_city');
     $field_zip = $config->get('validate_field_zip');
     $field_phone = $config->get('validate_field_phone');
     if (TiendaHelperShipping::shouldBeValidated($validate_id, $field_title, $sameasbilling) && empty($values["{$prefix}title"])) {
         $msg[] = JText::sprintf("COM_TIENDA_ENTRY_TITLE_FIELD_REQUIRED", $text);
     }
     if (TiendaHelperShipping::shouldBeValidated($validate_id, $field_name, $sameasbilling) && empty($values["{$prefix}first_name"])) {
         $msg[] = JText::sprintf("COM_TIENDA_ENTRY_FIRST_NAME_FIELD_REQUIRED", $text);
     }
     if (TiendaHelperShipping::shouldBeValidated($validate_id, $field_middle, $sameasbilling) && empty($values["{$prefix}middle_name"])) {
         $msg[] = JText::sprintf("COM_TIENDA_ENTRY_MIDDLE_NAME_FIELD_REQUIRED", $text);
     }
     if (TiendaHelperShipping::shouldBeValidated($validate_id, $field_last, $sameasbilling) && empty($values["{$prefix}last_name"])) {
         $msg[] = JText::sprintf("COM_TIENDA_ENTRY_LAST_NAME_FIELD_REQUIRED", $text);
     }
     if (TiendaHelperShipping::shouldBeValidated($validate_id, $field_company, $sameasbilling) && empty($values["{$prefix}company"])) {
         $msg[] = JText::sprintf("COM_TIENDA_ENTRY_COMPANY_FIELD_REQUIRED", $text);
     }
     if (TiendaHelperShipping::shouldBeValidated($validate_id, $field_address1, $sameasbilling) && empty($values["{$prefix}address_1"])) {
         $msg[] = JText::sprintf("COM_TIENDA_ENTRY_ADDRESS_LINE_1_FIELD_REQUIRED", $text);
     }
     if (TiendaHelperShipping::shouldBeValidated($validate_id, $field_address2, $sameasbilling) && empty($values["{$prefix}address_2"])) {
         $msg[] = JText::sprintf("COM_TIENDA_ENTRY_ADDRESS_LINE_2_FIELD_REQUIRED", $text);
     }
     if (TiendaHelperShipping::shouldBeValidated($validate_id, $field_city, $sameasbilling) && empty($values["{$prefix}city"])) {
         $msg[] = JText::sprintf("COM_TIENDA_ENTRY_CITY_FIELD_REQUIRED", $text);
     }
     if (TiendaHelperShipping::shouldBeValidated($validate_id, $field_country, $sameasbilling) && empty($values["{$prefix}country_id"])) {
         $msg[] = JText::sprintf("COM_TIENDA_ENTRY_COUNTRY_FIELD_REQUIRED", $text);
     }
     if (TiendaHelperShipping::shouldBeValidated($validate_id, $field_zone, $sameasbilling) && empty($values["{$prefix}zone_id"])) {
         $msg[] = JText::sprintf("COM_TIENDA_ENTRY_ZONE_FIELD_REQUIRED", $text);
     }
     if (TiendaHelperShipping::shouldBeValidated($validate_id, $field_zip, $sameasbilling) && empty($values["{$prefix}postal_code"])) {
         $msg[] = JText::sprintf("COM_TIENDA_ENTRY_POSTAL_CODE_FIELD_REQUIRED", $text);
     }
     if (TiendaHelperShipping::shouldBeValidated($validate_id, $field_phone, $sameasbilling) && empty($values["{$prefix}phone_1"])) {
         $msg[] = JText::sprintf("COM_TIENDA_ENTRY_PHONE_FIELD_REQUIRED", $text);
     }
     return $msg;
 }
Esempio n. 8
0
 /**
  * Generates shipping hash
  * @param $rate		Array with a shipping rate which is actually set
  * 
  * @return	Shipping hash as a string
  */
 function generateHash($rate)
 {
     Tienda::load('TiendaHelperShipping', 'helpers.shipping');
     $ship_values = array();
     $ship_values['type'] = $rate->shipping_type;
     $ship_values['name'] = $rate->shipping_name;
     $ship_values['price'] = $rate->shipping_price;
     $ship_values['tax'] = $rate->shipping_tax;
     $ship_values['code'] = $rate->shipping_code;
     $ship_values['extra'] = $rate->shipping_extra;
     return TiendaHelperShipping::generateShippingHash($ship_values);
 }
Esempio n. 9
0
 /**
  * Generates shipping method type list
  *
  * @param string The value of the HTML name attribute
  * @param string Additional HTML attributes for the <select> tag
  * @param mixed The key that is selected
  * @returns string HTML for the radio list
  */
 public static function shippingtype($selected, $name = 'filter_shipping_method_type', $attribs = array('class' => 'inputbox'), $idtag = null, $allowAny = false, $title = 'Select Shipping Type')
 {
     $list = array();
     if ($allowAny) {
         $list[] = self::option('', "- " . JText::_($title) . " -");
     }
     Tienda::load('TiendaHelperShipping', 'helpers.shipping');
     $items = TiendaHelperShipping::getTypes();
     foreach ($items as $item) {
         $list[] = JHTML::_('select.option', $item->id, $item->title);
     }
     return self::genericlist($list, $name, $attribs, 'value', 'text', $selected, $idtag);
 }