Example #1
0
# ------------------------------------------------------------------------
# author    Ramesh Elamathi - Weblogicx India http://www.weblogicxindia.com
# copyright Copyright (C) 2014 - 19 Weblogicxindia.com. All Rights Reserved.
# @license - http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL
# Websites: http://j2store.org
# Technical Support:  Forum - http://j2store.org/forum/index.html
-------------------------------------------------------------------------*/
//no direct access
defined('_JEXEC') or die('Restricted access');
/**
 * Get the document.
 */
$document = JFactory::getDocument();
$document->addScript(JUri::root() . 'administrator/modules/mod_j2store_chart/media/chart_api.js');
require_once JPATH_ADMINISTRATOR . '/components/com_j2store/library/base.php';
$currency = J2StoreFactory::getCurrencyObject();
//chart script.
$script = '
 google.load("visualization", "1", {packages:["corechart"]});
      google.setOnLoadCallback(drawChart);

         function drawChart() {

        //year chart axis.

        var yearchart = google.visualization.arrayToDataTable([

         ["' . JText::_("J2STORE_YEAR") . '","' . JText::_("J2STORE_AMOUNT") . '"],

         ';
/**
Example #2
0
 /**
  * Method to get rates from the USPS shipping API
  *
  * @param array $address
  * @return array rates array
  */
 private function getRates($address)
 {
     $rates = array();
     $status = true;
     $shipping_status = false;
     //first check if shippable items are in cart
     JModelLegacy::addIncludePath(JPATH_SITE . '/components/com_j2store/models');
     $model = JModelLegacy::getInstance('Mycart', 'J2StoreModel');
     $products = $model->getDataNew();
     foreach ($products as $product) {
         if ($product['shipping']) {
             $shipping_status = true;
         }
     }
     if ($shipping_status === false) {
         return $rates;
     }
     $currencyObject = J2StoreFactory::getCurrencyObject();
     $store_address = J2StoreHelperCart::getStoreAddress();
     $domestic_services = $this->params->get('domestic_services');
     $inernational_services = $this->params->get('international_services');
     $quote_data = array();
     $method_data = array();
     $cart_weight_total = J2StoreHelperCart::getWeight();
     $weightObject = J2StoreFactory::getWeightObject();
     $weight = $weightObject->convert($cart_weight_total, $store_address->config_weight_class_id, $this->params->get('usps_weight_class_id'));
     $weight = $weight < 0.1 ? 0.1 : $weight;
     $pounds = floor($weight);
     $ounces = round(16 * ($weight - $pounds), 2);
     // max 5 digits
     $postcode = str_replace(' ', '', $address['postal_code']);
     //get country data
     $countryObject = $this->getCountry($address['country_id']);
     if ($countryObject->country_isocode_2 == 'US') {
         $xml = '<RateV4Request USERID="' . $this->usps_username . '">';
         $xml .= '	<Package ID="1">';
         $xml .= '		<Service>ALL</Service>';
         $xml .= '		<ZipOrigination>' . substr($this->params->get('usps_postcode'), 0, 5) . '</ZipOrigination>';
         $xml .= '		<ZipDestination>' . substr($postcode, 0, 5) . '</ZipDestination>';
         $xml .= '		<Pounds>' . $pounds . '</Pounds>';
         $xml .= '		<Ounces>' . $ounces . '</Ounces>';
         // Prevent common size mismatch error from USPS (Size cannot be Regular if Container is Rectangular for some reason)
         if ($this->params->get('usps_container') == 'RECTANGULAR' && $this->params->get('usps_size') == 'REGULAR') {
             $this->params->set('usps_container', 'VARIABLE');
         }
         $xml .= '		<Container>' . $this->params->get('usps_container') . '</Container>';
         $xml .= '		<Size>' . $this->params->get('usps_size') . '</Size>';
         $xml .= '		<Width>' . $this->params->get('usps_width') . '</Width>';
         $xml .= '		<Length>' . $this->params->get('usps_length') . '</Length>';
         $xml .= '		<Height>' . $this->params->get('usps_height') . '</Height>';
         // Calculate girth based on usps calculation
         $xml .= '		<Girth>' . round((double) $this->params->get('usps_length') + (double) $this->params->get('usps_width') * 2 + (double) $this->params->get('usps_height') * 2, 1) . '</Girth>';
         $xml .= '		<Machinable>' . ($this->params->get('usps_machinable') ? 'true' : 'false') . '</Machinable>';
         $xml .= '	</Package>';
         $xml .= '</RateV4Request>';
         $request = 'API=RateV4&XML=' . urlencode($xml);
     } else {
         $countries = $this->getCountries();
         if (isset($countries[$countryObject->country_isocode_2])) {
             $xml = '<IntlRateV2Request USERID="' . $this->usps_username . '">';
             $xml .= '	<Package ID="1">';
             $xml .= '		<Pounds>' . $pounds . '</Pounds>';
             $xml .= '		<Ounces>' . $ounces . '</Ounces>';
             $xml .= '		<MailType>All</MailType>';
             $xml .= '		<GXG>';
             $xml .= '		  <POBoxFlag>N</POBoxFlag>';
             $xml .= '		  <GiftFlag>N</GiftFlag>';
             $xml .= '		</GXG>';
             $xml .= '		<ValueOfContents>' . J2StoreHelperCart::getSubTotal() . '</ValueOfContents>';
             $xml .= '		<Country>' . $countries[$countryObject->country_isocode_2] . '</Country>';
             // Intl only supports RECT and NONRECT
             if ($this->params->get('usps_container') == 'VARIABLE') {
                 $this->params->set('usps_container', 'NONRECTANGULAR');
             }
             $xml .= '		<Container>' . $this->params->get('usps_container') . '</Container>';
             $xml .= '		<Size>' . $this->params->get('usps_size') . '</Size>';
             $xml .= '		<Width>' . $this->params->get('usps_width') . '</Width>';
             $xml .= '		<Length>' . $this->params->get('usps_length') . '</Length>';
             $xml .= '		<Height>' . $this->params->get('usps_height') . '</Height>';
             $xml .= '		<Girth>' . $this->params->get('usps_girth') . '</Girth>';
             $xml .= '		<CommercialFlag>N</CommercialFlag>';
             $xml .= '	</Package>';
             $xml .= '</IntlRateV2Request>';
             $request = 'API=IntlRateV2&XML=' . urlencode($xml);
         } else {
             $status = false;
         }
     }
     if ($status) {
         $result = $this->_sendRequest($request);
         $handling = $this->params->get('handling', '0');
         if ($result) {
             if ($this->params->get('show_debug')) {
                 $this->_log("USPS DATA SENT: " . urldecode($request));
                 $this->_log("USPS DATA RECV: " . $result);
             }
             $dom = new DOMDocument('1.0', 'UTF-8');
             $dom->loadXml($result);
             $rate_response = $dom->getElementsByTagName('RateV4Response')->item(0);
             $intl_rate_response = $dom->getElementsByTagName('IntlRateV2Response')->item(0);
             $error = $dom->getElementsByTagName('Error')->item(0);
             $firstclasses = array('First-Class Mail Parcel', 'First-Class Mail Large Envelope', 'First-Class Mail Letter', 'First-Class Mail Postcards');
             if ($rate_response || $intl_rate_response) {
                 if ($countryObject->country_isocode_2 == 'US') {
                     $allowed = array(0, 1, 2, 3, 4, 5, 6, 7, 12, 13, 16, 17, 18, 19, 22, 23, 25, 27, 28, 30, 31, 55, 56, 62, 63);
                     $package = $rate_response->getElementsByTagName('Package')->item(0);
                     $postages = $package->getElementsByTagName('Postage');
                     if ($postages->length) {
                         foreach ($postages as $postage) {
                             $classid = $postage->getAttribute('CLASSID');
                             if (in_array($classid, $allowed)) {
                                 if ($classid == '0') {
                                     $mailservice = $postage->getElementsByTagName('MailService')->item(0)->nodeValue;
                                     foreach ($firstclasses as $k => $firstclass) {
                                         if ($firstclass == $mailservice) {
                                             $classid = $classid . $k;
                                             break;
                                         }
                                     }
                                     if (in_array('usps_domestic_' . $classid, $domestic_services)) {
                                         $cost = $postage->getElementsByTagName('Rate')->item(0)->nodeValue;
                                         $price = $currencyObject->convert($cost, 'USD', $store_address->config_currency);
                                         $rate = array();
                                         $rate['name'] = $postage->getElementsByTagName('MailService')->item(0)->nodeValue;
                                         $rate['code'] = 'usps.' . $classid;
                                         $rate['price'] = $price;
                                         $rate['extra'] = (double) $handling;
                                         $rate['total'] = $price;
                                         $rate['tax'] = "0.00";
                                         $rate['element'] = $this->_element;
                                         $rates[] = $rate;
                                     }
                                 } elseif (in_array('usps_domestic_' . $classid, $domestic_services)) {
                                     $cost = $postage->getElementsByTagName('Rate')->item(0)->nodeValue;
                                     $price = $currencyObject->convert($cost, 'USD', $store_address->config_currency);
                                     $rate = array();
                                     $rate['name'] = $postage->getElementsByTagName('MailService')->item(0)->nodeValue;
                                     $rate['code'] = 'usps.' . $classid;
                                     $rate['price'] = $price;
                                     $rate['extra'] = (double) $handling;
                                     $rate['total'] = $price;
                                     $rate['tax'] = "0.00";
                                     $rate['element'] = $this->_element;
                                     $rates[] = $rate;
                                 }
                             }
                         }
                     } else {
                         $error = $package->getElementsByTagName('Error')->item(0);
                         $method_data = array('code' => 'usps', 'title' => JText::_('usps_error_text'), 'quote' => $quote_data, 'error' => $error->getElementsByTagName('Description')->item(0)->nodeValue);
                     }
                 } else {
                     $allowed = array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27);
                     $package = $intl_rate_response->getElementsByTagName('Package')->item(0);
                     $services = $package->getElementsByTagName('Service');
                     if (isset($inernational_services) && !empty($inernational_services)) {
                         foreach ($services as $service) {
                             $id = $service->getAttribute('ID');
                             if (in_array($id, $allowed) && in_array('usps_international_' . $id, $inernational_services)) {
                                 $title = $service->getElementsByTagName('SvcDescription')->item(0)->nodeValue;
                                 if ($this->params->get('usps_display_time')) {
                                     $title .= ' (' . JText::_('usps_text_eta') . ' ' . $service->getElementsByTagName('SvcCommitments')->item(0)->nodeValue . ')';
                                 }
                                 $cost = $service->getElementsByTagName('Postage')->item(0)->nodeValue;
                                 $price = $currencyObject->convert($cost, 'USD', $store_address->config_currency);
                                 $rate = array();
                                 $rate['name'] = $title;
                                 $rate['code'] = 'usps.' . $id;
                                 $rate['price'] = $price;
                                 $rate['extra'] = (double) $handling;
                                 $rate['total'] = $price;
                                 $rate['tax'] = "0.00";
                                 $rate['element'] = $this->_element;
                                 $rates[] = $rate;
                             }
                         }
                     }
                 }
             } elseif ($error) {
                 $method_data = array('code' => 'usps', 'title' => JText::_('usps_error_text'), 'quote' => $quote_data, 'error' => $error->getElementsByTagName('Description')->item(0)->nodeValue);
             }
         }
     }
     if (count($rates)) {
         //if the shipping is taxable, calculate it here.
         $tax_class_id = $this->params->get('usps_tax_class_id', '');
         if ($tax_class_id) {
             $j2tax = new J2StoreTax();
             $newRates = array();
             foreach ($rates as $rate) {
                 $newRate = array();
                 $newRate['name'] = JText::_($rate['name']);
                 $newRate['code'] = $rate['code'];
                 $newRate['price'] = $rate['price'];
                 $newRate['extra'] = $rate['extra'];
                 $shipping_method_tax_total = $j2tax->getTax($newRate['price'] + $newRate['extra'], $tax_class_id);
                 $newRate['tax'] = round($shipping_method_tax_total, 2);
                 $newRate['total'] = $rate['total'] + $newRate['tax'];
                 $newRate['element'] = $rate['element'];
                 $newRates[] = $newRate;
             }
             unset($rates);
             $rates = $newRates;
         }
     }
     return $rates;
 }
Example #3
0
 function getAmount($value, $currency_code, $currency_value, $convert = false)
 {
     if (version_compare($this->_j2version, '2.6.7', 'lt')) {
         return J2StoreUtilities::number($value, array('thousands' => '', 'num_decimals' => '2', 'decimal' => '.'));
     } else {
         include_once JPATH_ADMINISTRATOR . '/components/com_j2store/library/base.php';
         $currencyObject = J2StoreFactory::getCurrencyObject();
         $amount = $currencyObject->format($value, $currency_code, $currency_value, false);
         return $amount;
     }
 }
Example #4
0
# author    Ramesh Elamathi - Weblogicx India http://www.weblogicxindia.com
# copyright Copyright (C) 2014 - 19 Weblogicxindia.com. All Rights Reserved.
# @license - http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL
# Websites: http://j2store.org
# Technical Support:  Forum - http://j2store.org/forum/index.html
-------------------------------------------------------------------------*/
//no direct access
defined('_JEXEC') or die('Restricted access');
$row = @$this->row;
$order = @$this->order;
$items = @$order->getItems();
require_once JPATH_ADMINISTRATOR . '/components/com_j2store/library/popup.php';
require_once JPATH_ADMINISTRATOR . '/components/com_j2store/library/j2item.php';
require_once JPATH_SITE . '/components/com_j2store/helpers/orders.php';
require_once JPATH_ADMINISTRATOR . '/components/com_j2store/library/base.php';
$selectableBase = J2StoreFactory::getSelectableBase();
JHtml::_('behavior.modal');
$order_state_save_link = JRoute::_('index.php?option=com_j2store&view=orders&task=orderstatesave');
$showShipping = true;
if (isset($row->is_shippable) && !empty($row->is_shippable)) {
    if ($row->is_shippable == '0') {
        $showShipping = false;
    }
} else {
    if (!$this->params->get('show_shipping_address')) {
        $showShipping = false;
    }
}
?>
<script type="text/javascript">
function j2storeOpenModal(url) {
 function getCurrency($order)
 {
     $results = array();
     $convert = false;
     $params = JComponentHelper::getParams('com_j2store');
     if (version_compare($this->_j2version, '2.6.7', 'lt')) {
         $currency_code = $params->get('currency_code', 'USD');
         $currency_value = 1;
     } else {
         include_once JPATH_ADMINISTRATOR . '/components/com_j2store/library/base.php';
         $currencyObject = J2StoreFactory::getCurrencyObject();
         $currency_code = $order->currency_code;
         $currency_value = $order->currency_value;
         // accepted currencies
         $currencies = $this->getAcceptedCurrencies();
         if (!in_array($order->currency_code, $currencies)) {
             $default_currency = 'USD';
             if ($currencyObject->has($default_currency)) {
                 $currencyObject->set($default_currency);
                 $currency_code = $default_currency;
                 $currency_value = $currencyObject->getValue($default_currency);
                 $convert = true;
             }
         }
     }
     $results['currency_code'] = $currency_code;
     $results['currency_value'] = $currency_value;
     $results['convert'] = $convert;
     return $results;
 }
Example #6
0
 public static function number($amount, $currency = '', $value = '', $format = true)
 {
     if ($value == 0) {
         $value = '';
     }
     //backward compatibility
     if (is_array($currency)) {
         $currency = '';
     }
     $currencyobject = J2StoreFactory::getCurrencyObject();
     return $currencyobject->format($amount, $currency, $value, $format);
 }
Example #7
0
 function view()
 {
     // initialise variables
     $app = JFactory::getApplication();
     $user_id = JFactory::getUser()->id;
     $session = JFactory::getSession();
     $params = JComponentHelper::getParams('com_j2store');
     $guest_token = $session->get('guest_order_token');
     $guest_order_email = $session->get('guest_order_email');
     if (empty($user_id)) {
         if (empty($guest_token) || empty($guest_order_email)) {
             $this->messagetype = 'notice';
             $this->message = JText::_('J2STORE_ORDER_INVALID');
             $redirect = "index.php?option=com_j2store&view=orders";
             $redirect = JRoute::_($redirect, false);
             $this->setRedirect($redirect, $this->message, $this->messagetype);
             return;
         }
     }
     // if the user cannot view order, fail
     $model = $this->getModel('orders');
     $order = $model->getTable('orders');
     $view = $this->getView('orders', 'html');
     if ($user_id) {
         $model->getId();
         $order->load($model->getId());
     } elseif ($guest_token && $guest_order_email) {
         $id = $model->loadFromToken($guest_token, $guest_order_email);
         if ($id) {
             $model->setId($id);
             $order->load($model->getId());
             $view->assign('guest', true);
         } else {
             // an error occured.
             $this->messagetype = 'notice';
             $this->message = JText::_('J2STORE_ORDER_INVALID');
             //null the value of the token
             $session->set('guest_order_token', '');
             $redirect = "index.php?option=com_j2store&view=orders";
             $redirect = JRoute::_($redirect, false);
             $this->setRedirect($redirect, $this->message, $this->messagetype);
             return;
         }
     }
     if (JFactory::getApplication()->isSite() && $params->get('show_incomplete_orders', 0) == 0) {
         $model->setState('restrict_filter_orderstate', 5);
     }
     $orderitems = $order->getItems();
     $row = $model->getItem();
     $ordertaxes = $order->getOrderTax();
     //check current user is the owner of this order. One more check.
     $error = '';
     if ($user_id) {
         if ($row->user_id != $user_id) {
             $error = JText::_('J2STORE_ORDER_INVALID');
         }
     } else {
         if ($row->user_email != $guest_order_email || $row->token != $guest_token) {
             $error = JText::_('J2STORE_ORDER_INVALID');
         }
     }
     if (!empty($error)) {
         $this->messagetype = 'notice';
         $this->message = $error;
         $redirect = "index.php?option=com_j2store&view=orders";
         $redirect = JRoute::_($redirect, false);
         $this->setRedirect($redirect, $this->message, $this->messagetype);
         return;
     }
     $shipping_info = $model->getShippingInfo($row);
     //all is good now. So proceed.
     $view->set('_controller', 'orders');
     $view->set('_view', 'orders');
     $view->set('_doTask', true);
     $view->set('hidemenu', false);
     $view->setModel($model, true);
     $view->assign('row', $row);
     $view->assign('shipping_info', $shipping_info);
     $show_tax = $params->get('show_tax_total');
     $view->assign('show_tax', $show_tax);
     foreach ($orderitems as &$item) {
         $item->orderitem_price = $item->orderitem_price + floatval($item->orderitem_attributes_price);
         $taxtotal = 0;
         if ($show_tax) {
             $taxtotal = $item->orderitem_tax / $item->orderitem_quantity;
         }
         $item->orderitem_price = $item->orderitem_price + $taxtotal;
         $item->orderitem_final_price = $item->orderitem_price * $item->orderitem_quantity;
         $order->order_subtotal += $taxtotal * $item->orderitem_quantity;
     }
     $model->executePlugins($order);
     $view->assign('order', $order);
     $view->assign('ordertaxes', $ordertaxes);
     $view->assign('params', $params);
     $view->assign('currency', J2StoreFactory::getCurrencyObject());
     $view->setLayout('view');
     $this->_setModelState();
     $view->display();
 }
Example #8
0
 public static function getWeight()
 {
     $weight = 0;
     $weightObject = J2StoreFactory::getWeightObject();
     JModelLegacy::addIncludePath(JPATH_SITE . '/components/com_j2store/models');
     $model = JModelLegacy::getInstance('Mycart', 'J2StoreModel');
     $products = $model->getDataNew();
     foreach ($products as $product) {
         if ($product['shipping']) {
             $weight += $weightObject->convert($product['weight_total'], $product['weight_class_id'], self::getStoreAddress()->config_weight_class_id);
         }
     }
     return $weight;
 }
Example #9
0
 public function processCustomFields($type, $data)
 {
     $selectableBase = J2StoreFactory::getSelectableBase();
     $address = JTable::getInstance('address', 'Table');
     $orderinfo = JTable::getInstance('Orderinfo', 'Table');
     $fields = $selectableBase->getFields($type, $address, 'address');
     $values = array();
     foreach ($fields as $fieldName => $oneExtraField) {
         if (isset($data[$fieldName])) {
             if (!property_exists($orderinfo, $type . '_' . $fieldName) && !property_exists($orderinfo, 'user_' . $fieldName) && $fieldName != 'country_id' && $fieldName != 'zone_id' && $fieldName != 'option' && $fieldName != 'task' && $fieldName != 'view') {
                 $values[$fieldName]['label'] = $oneExtraField->field_name;
                 $values[$fieldName]['value'] = $data[$fieldName];
             }
         }
     }
     $registry = new JRegistry();
     $registry->loadArray($values);
     $json = $registry->toString('JSON');
     return $json;
 }
Example #10
0
    function display($tpl = null)
    {
        $app = JFactory::getApplication();
        $doc = JFactory::getDocument();
        $model = $this->getModel('field');
        $params = JComponentHelper::getParams('com_j2store');
        $selectableBase = J2StoreFactory::getSelectableBase();
        $fieldid = $app->input->getInt('field_id');
        if (!empty($fieldid)) {
            $field = $selectableBase->getField($fieldid);
            $data = null;
            $allFields = $selectableBase->getFields('', $data, $field->field_table);
        } else {
            $field = $model->getTable();
            $field->field_table = 'address';
            $field->field_published = 1;
            $field->field_type = 'text';
            $field->field_backend = 1;
            $allFields = array();
        }
        $this->allFields = $allFields;
        $this->field = $field;
        $this->fieldsClass = $selectableBase;
        $lists = array();
        //get the field type
        $fieldtype = J2StoreFactory::getSelectableFields();
        $this->assignRef('fieldtype', $fieldtype);
        $script = 'function addLine(){
		var myTable=window.document.getElementById("tablevalues");
		var newline = document.createElement(\'tr\');
		var column = document.createElement(\'td\');
		var column2 = document.createElement(\'td\');
		var column3 = document.createElement(\'td\');
		var input = document.createElement(\'input\');
		var input2 = document.createElement(\'input\');
		var input3 = document.createElement(\'select\');
		var option1 = document.createElement(\'option\');
		var option2 = document.createElement(\'option\');
		input.type = \'text\';
		input2.type = \'text\';
		option1.value= \'0\';
		option2.value= \'1\';
		input.name = \'field_values[title][]\';
		input2.name = \'field_values[value][]\';
		input3.name = \'field_values[disabled][]\';
		option1.text= \'' . JText::_('J2STORE_NO', true) . '\';
		option2.text= \'' . JText::_('J2STORE_YES', true) . '\';
		try { input3.add(option1, null); } catch(ex) { input3.add(option1); }
		try { input3.add(option2, null); } catch(ex) { input3.add(option2); }
		column.appendChild(input);
		column2.appendChild(input2);
		column3.appendChild(input3);
		newline.appendChild(column);
		newline.appendChild(column2);
		newline.appendChild(column3);
		myTable.appendChild(newline);
		}

		function deleteRow(divName,inputName,rowName){
			var d = document.getElementById(divName);
			var olddiv = document.getElementById(inputName);
			if(d && olddiv){
				d.removeChild(olddiv);
				document.getElementById(rowName).style.display="none";
			}
			return false;
		}

		function setVisible(value){
			if(value=="product" || value=="item" || value=="category"){
				document.getElementById(\'category_field\').style.display = "";
			}else{
				document.getElementById(\'category_field\').style.display = \'none\';
			}
		}';
        $doc->addScriptDeclaration($script);
        //	$lists['value_type'] = JHTML::_('select.radiolist', $value_type_options, 'value_type', null, 'value', 'text', $data->value_type);
        //	$logged_options = array(JHTML::_('select.option', '0', JText::_('No') ),
        //			JHTML::_('select.option', '1', JText::_('Yes') )	);
        //	$lists['logged'] = JHTML::_('select.radiolist', $logged_options, 'logged', null, 'value', 'text', $data->logged);
        //country, zone type
        $zoneType = new j2storeZoneType();
        $this->assignRef('zoneType', $zoneType);
        $this->assignRef('lists', $lists);
        $this->assignRef('params', $params);
        $this->addToolBar();
        $toolbar = new J2StoreToolBar();
        $toolbar->renderLinkbar();
        parent::display($tpl);
    }
Example #11
0
 public static function getSelectableFields()
 {
     if (!self::$fields) {
         require_once 'selectable/fields.php';
         self::$fields = J2StoreSelectableFields::getInstance();
     }
     return self::$fields;
 }