Esempio n. 1
0
 function display($tpl = null)
 {
     //run the update if auto update is enabled
     require_once JPATH_SITE . '/components/com_j2store/helpers/cart.php';
     $storeprofile = J2StoreHelperCart::getStoreAddress();
     if ($storeprofile->config_currency_auto) {
         $model = $this->getModel('currencies');
         $model->updateCurrencies();
     }
     // Get data from the model
     $this->items = $this->get('Items');
     $this->pagination = $this->get('Pagination');
     // inturn calls getState in parent class and populateState() in model
     $this->state = $this->get('State');
     // Check for errors.
     if (count($errors = $this->get('Errors'))) {
         JError::raiseError(500, implode('<br />', $errors));
         return false;
     }
     //add toolbar
     $this->addToolBar();
     $toolbar = new J2StoreToolBar();
     $toolbar->renderLinkbar();
     // Display the template
     parent::display($tpl);
     $this->setDocument();
 }
Esempio n. 2
0
 public function display($tpl = null)
 {
     $app = JFactory::getApplication();
     //get the active menu details
     $menu = $app->getMenu()->getActive();
     //if any menu template choosen then that template will
     if (isset($menu->params)) {
         //first get the subtemplate from the menu
         $template = $menu->params->get('sub_template');
         if (empty($template)) {
             //now get it from the store profile
             $store = J2StoreHelperCart::getStoreAddress();
             $template = isset($store->store_default_template) ? $store->store_default_template : '';
         }
     }
     if (empty($template)) {
         $template = 'default';
     }
     //look for the in the views/products folder
     $this->_addPath('template', JPATH_SITE . '/components/com_j2store/templates');
     $this->_addPath('template', JPATH_SITE . '/components/com_j2store/templates/' . $template);
     // Look for overrides in J2Store template structure
     $this->_addPath('template', JPATH_SITE . '/templates/' . $app->getTemplate() . '/html/com_j2store/templates/' . $template);
     $this->_addPath('template', JPATH_SITE . '/templates/' . $app->getTemplate() . '/html/com_j2store/templates/default');
     //look for in the template overrides folder (Joomla structure)
     $this->_addPath('template', JPATH_SITE . '/templates/' . $app->getTemplate() . '/html/com_j2store/products/default');
     $this->_addPath('template', JPATH_SITE . '/templates/' . $app->getTemplate() . '/html/com_j2store/products/' . $template);
     parent::display($tpl);
 }
Esempio n. 3
0
 public function checkCurrency()
 {
     $db = JFactory::getDbo();
     require_once JPATH_SITE . '/components/com_j2store/helpers/cart.php';
     $storeProfile = J2StoreHelperCart::getStoreAddress();
     //first check if the currency table has a default records at least.
     $query = $db->getQuery(true)->select('*')->from('#__j2store_currency');
     $db->setQuery($query);
     $rows = $db->loadObjectList();
     if (count($rows) < 1) {
         //no records found. Dumb default data
         JTable::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_j2store/tables');
         $item = JTable::getInstance('Currency', 'Table');
         $item->currency_title = 'US Dollar';
         $item->currency_code = 'USD';
         $item->currency_position = 'pre';
         $item->currency_symbol = '$';
         $item->currency_num_decimals = '2';
         $item->currency_decimal = '.';
         $item->currency_thousands = ',';
         $item->currency_value = '1.00000';
         //default currency is one always
         $item->currency_modified = JFactory::getDate()->toSql();
         $item->state = 1;
         $item->store();
     }
     $query = $db->getQuery(true)->select('*')->from('#__j2store_currency')->where('currency_value=' . $db->q('1.00000'));
     $db->setQuery($query);
     try {
         $currency = $db->loadObject();
     } catch (Exception $e) {
         //do nothing
     }
     //if currency is empty, set it
     if (empty($storeProfile->config_currency) || JString::strlen($storeProfile->config_currency) < 3) {
         if ($currency) {
             $sql = $db->getQuery(true)->update('#__j2store_storeprofiles')->set('config_currency=' . $db->q($currency->currency_code))->where('store_id=' . $db->q($storeProfile->store_id));
             $db->setQuery($sql);
             $db->execute();
         }
     }
     //check for a default layout. If not, create one.
     $query = $db->getQuery(true)->select('*')->from('#__j2store_layouts')->where('state=1');
     $db->setQuery($query);
     $rows = $db->loadObjectList();
     if (count($rows) < 1) {
         //no records found. Dumb default data
         JTable::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_j2store/tables');
         $item = JTable::getInstance('Layout', 'Table');
         $item->layout_name = 'Default Layout';
         $item->state = 1;
         $item->store();
     }
     return true;
 }
Esempio n. 4
0
 function save($key = null, $urlVar = null)
 {
     if (parent::save($key, $urlVar)) {
         require_once JPATH_SITE . '/components/com_j2store/helpers/cart.php';
         $storeprofile = J2StoreHelperCart::getStoreAddress();
         if ($storeprofile->config_currency_auto) {
             $model = $this->getModel('currencies');
             $model->updateCurrencies(true);
         }
     }
 }
Esempio n. 5
0
 public function __construct()
 {
     require_once JPATH_SITE . '/components/com_j2store/helpers/cart.php';
     $storeprofile = J2StoreHelperCart::getStoreAddress();
     $this->config = $storeprofile;
     $this->session = JFactory::getSession();
     $this->input = JFactory::getApplication()->input;
     $rows = self::getCurrencyList();
     foreach ($rows as $result) {
         $this->currencies[$result['currency_code']] = $result;
     }
     $currency = $this->input->get('currency');
     if (isset($currency) && array_key_exists($currency, $this->currencies)) {
         $this->set($currency);
     } elseif ($this->session->has('currency', 'j2store') && array_key_exists($this->session->get('currency', '', 'j2store'), $this->currencies)) {
         $this->set($this->session->get('currency', '', 'j2store'));
     } else {
         $this->set($this->config->config_currency);
     }
 }
Esempio n. 6
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;
 }
Esempio n. 7
0
 function view()
 {
     //get the app object
     $app = JFactory::getApplication();
     //get the document obj
     $document = JFactory::getDocument();
     //get the component params
     $params = JComponentHelper::getParams('com_j2store');
     //get the model
     $model = $this->getModel('products');
     //get the view
     $view = $this->getView('products', 'html');
     //get the active menu
     $menu = $app->getMenu()->getActive();
     // see if a layout has been chosen for this menu
     /*
      * TODO showing error when redirecting from list to detailed view product
      */
     if (isset($menu->params) && $menu->params->get('j2store_product_layout')) {
         $layoutId = $menu->params->get('j2store_product_layout');
     } else {
         //take it from the store config
         $store = J2StoreHelperCart::getStoreAddress();
         //TODO to set default product layout value incase store product layout is empty
         $layoutId = isset($store->store_default_layout) ? $store->store_default_layout : 1;
     }
     //TODO: Remove this
     //$layoutId = 1;
     //get product data
     $product = $model->getItem();
     //get the layout data based on the id
     $layout_data = $this->getLayoutData($layoutId);
     if (isset($layout_data->params)) {
         $layoutparams = new JRegistry();
         $layoutparams->loadString($layout_data->params);
         $view->assign('layout_params', $layoutparams);
     }
     //load the product options html
     $product->optionhtml = $this->getProductOptionHtml($product, $layout_data);
     //htmlspecialchars($product->product_name, ENT_QUOTES, 'UTF-8')
     //get the website url
     $uri = JURI::getInstance();
     //now set the url
     $document->setMetaData('og:url', $uri->toString());
     //set the title
     $document->setMetaData('og:title', $product->product_name);
     //set the type
     $document->setMetaData('og:type', 'article');
     $image = isset($product->main_image) && $product->main_image ? $product->main_image : "";
     //check main image exists
     if (isset($prduct->main_image)) {
         $p_image = JURI::root() . $image;
         $document->setMetaData('og:image', $p_image);
     }
     //set the descriptionshort_description
     $document->setMetaData('og:description', strip_tags($product->short_description));
     if (isset($product->metakey)) {
         $document->setDescription($product->metakey);
         $document->setMetadata('keywords', $product->metakey);
     }
     if ($product->metadesc) {
         $document->setDescription($product->metadesc);
         $document->setMetadata('keywords', $product->metadesc);
     }
     //now set the metadata into html
     if ($product->metadata) {
         $registry = new JRegistry();
         $registry->loadString($product->metadata);
         $mdata = $registry->toArray();
         foreach ($mdata as $key => $value) {
             $document->setMetadata($key, $value);
         }
     }
     //assing the model
     $view->assign('model', $model);
     //assign the item
     $view->assign('item', $product);
     //assign the  params
     $view->assign('params', $params);
     //now assisgn the layout
     $view->setLayout('view');
     $view->display();
 }
Esempio n. 8
0
 function createInvoiceNumber($order_id)
 {
     $db = JFactory::getDbo();
     $status = true;
     $invoice = new JObject();
     $invoice->number = 0;
     $invoice->prefix = '';
     require_once JPATH_SITE . '/components/com_j2store/helpers/cart.php';
     $store = J2StoreHelperCart::getStoreAddress();
     if (!isset($store->store_invoice_prefix) || empty($store->store_invoice_prefix)) {
         //backward compatibility. If no prefix is set, retain the invoice number is the table primary key.
         $status = false;
     }
     if ($status) {
         //get the last row
         $query = $db->getQuery(true)->select('MAX(invoice_number) AS invoice_number')->from('#__j2store_orders')->where('invoice_prefix=' . $db->q($store->store_invoice_prefix));
         $db->setQuery($query);
         $row = $db->loadObject();
         if (isset($row->invoice_number) && $row->invoice_number) {
             $invoice_number = $row->invoice_number + 1;
         } else {
             $invoice_number = 1;
         }
         $invoice->number = $invoice_number;
         $invoice->prefix = $store->store_invoice_prefix;
     }
     return $invoice;
 }
Esempio n. 9
0
 public function updateCurrencies($force = false)
 {
     if (extension_loaded('curl')) {
         $data = array();
         require_once JPATH_SITE . '/components/com_j2store/helpers/cart.php';
         $storeprofile = J2StoreHelperCart::getStoreAddress();
         $db = JFactory::getDbo();
         $query = $db->getQuery(true);
         $query->select('*')->from('#__j2store_currency')->where('currency_code !=' . $db->q($storeprofile->config_currency));
         if ($force) {
             $query->where('currency_modified=' . $db->q(date('Y-m-d H:i:s', strtotime('-1 day'))));
         }
         $db->setQuery($query);
         $rows = $db->loadAssocList();
         foreach ($rows as $result) {
             $data[] = $storeprofile->config_currency . $result['currency_code'] . '=X';
         }
         $curl = curl_init();
         curl_setopt($curl, CURLOPT_URL, 'http://download.finance.yahoo.com/d/quotes.csv?s=' . implode(',', $data) . '&f=sl1&e=.csv');
         curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
         $content = curl_exec($curl);
         curl_close($curl);
         $lines = explode("\n", trim($content));
         foreach ($lines as $line) {
             $currency = utf8_substr($line, 4, 3);
             $value = utf8_substr($line, 11, 6);
             if ((double) $value) {
                 $query = $db->getQuery(true);
                 $query->update('#__j2store_currency')->set('currency_value =' . $db->q((double) $value))->set('currency_modified=' . $db->q(date('Y-m-d H:i:s')))->where('currency_code=' . $db->q($currency));
                 $db->setQuery($query);
                 $db->query();
             }
         }
         //update the default currency
         $query = $db->getQuery(true);
         $query->update('#__j2store_currency')->set('currency_value =' . $db->q('1.00000'))->set('currency_modified=' . $db->q(date('Y-m-d H:i:s')))->where('currency_code=' . $db->q($storeprofile->config_currency));
         $db->setQuery($query);
         $db->query();
     }
 }
Esempio n. 10
0
-------------------------------------------------------------------------*/
// no direct access
defined('_JEXEC') or die('Restricted access');
require_once JPATH_ADMINISTRATOR . '/components/com_j2store/library/j2item.php';
require_once JPATH_SITE . '/components/com_j2store/helpers/cart.php';
require_once JPATH_ADMINISTRATOR . '/components/com_j2store/library/inventory.php';
$items = $this->cartobj;
//$mysubtotal = J2StoreHelperCart::getSubtotal();
//$state = $this->state;
$quantities = array();
$action = JRoute::_('index.php');
$checkout_url = JRoute::_('index.php?option=com_j2store&view=checkout');
$com_path = JPATH_SITE . '/components/com_content/';
require_once $com_path . 'router.php';
require_once $com_path . 'helpers/route.php';
$storeAddress = J2StoreHelperCart::getStoreAddress();
if (isset($storeAddress->config_default_category) && $storeAddress->config_default_category != 0) {
    $continue_shopping_url = JRoute::_(ContentHelperRoute::getCategoryRoute($storeAddress->config_default_category));
}
if (isset($storeAddress->config_continue_shopping_url) && JString::strlen($storeAddress->config_continue_shopping_url) > 5) {
    $continue_shopping_url = $storeAddress->config_continue_shopping_url;
}
?>
<div class="j2store">
<div class="row-fluid">
<div class="span12">
<?php 
if (!isset($this->remove)) {
    ?>
	<div id="j2storeCartPopup">
<?php 
Esempio n. 11
0
 function display($field, $value, $map, $inside, $options = '', $test = false, $allFields = null, $allValues = null)
 {
     $app = JFactory::getApplication();
     require_once JPATH_SITE . '/components/com_j2store/helpers/cart.php';
     $store = J2StoreHelperCart::getStoreAddress();
     $stateId = $currentZoneId = $store->zone_id > 0 ? $store->zone_id : '';
     $country_id = $store->country_id > 0 ? $store->country_id : '';
     //if no default value was set in the fields, then use the country id set in the store profile.
     if (empty($field->field_default)) {
         $defaultCountry = $country_id;
     }
     if (empty($value)) {
         $value = $field->field_default;
     }
     if ($field->field_options['zone_type'] == 'country') {
         if (isset($defaultCountry)) {
             $field->field_default = $defaultCountry;
         }
         if (empty($value)) {
             $value = $field->field_default;
         }
     } elseif ($field->field_options['zone_type'] == 'zone') {
         $stateId = str_replace(array('[', ']'), array('_', ''), $map);
         $dropdown = '';
         if ($allFields != null) {
             $country = null;
             foreach ($allFields as $f) {
                 if ($f->field_type == 'zone' && !empty($f->field_options['zone_type']) && $f->field_options['zone_type'] == 'country') {
                     $key = $f->field_namekey;
                     if (!empty($allValues->{$key})) {
                         $country = $allValues->{$key};
                     } else {
                         $country = $f->field_default;
                     }
                     break;
                 }
             }
             //no country id, then load it based on the zone default.
             if (empty($country) && isset($field->field_default)) {
                 JTable::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_j2store/tables');
                 $table = JTable::getInstance('zone', 'Table');
                 if ($table->load($field->field_default)) {
                     $country = $table->country_id;
                 }
             }
             //still no. Set it to store default.
             if (empty($country)) {
                 $country = $store->country_id;
                 if (empty($value)) {
                     $value = $store->zone_id;
                 }
             }
             if (!empty($country)) {
                 $countryType = new j2storeCountryType();
                 $countryType->type = 'zone';
                 $countryType->country_id = $country;
                 $countryType->published = true;
                 $dropdown = $countryType->displayZone($map, $value, true);
             }
         }
         $html = '<span id="' . $stateId . '_container">' . $dropdown . '</span>' . '<input type="hidden" id="' . $stateId . '_default_value" name="' . $stateId . '_default_value" value="' . $value . '"/>';
         return $html;
     }
     return parent::display($field, $value, $map, $inside, $options, $test, $allFields, $allValues);
 }
Esempio n. 12
0
 public function getStoreAddress()
 {
     require_once JPATH_SITE . '/components/com_j2store/helpers/cart.php';
     return J2StoreHelperCart::getStoreAddress();
 }
Esempio n. 13
0
 function _updateCurrency()
 {
     $session = JFactory::getSession();
     //if auto update currency is set, then call the update function
     $store_config = J2StoreHelperCart::getStoreAddress();
     //session based check. We dont want to update currency when we load each and every item.
     if ($store_config->config_currency_auto && !$session->has('currency_updated', 'j2store')) {
         require_once JPATH_ADMINISTRATOR . '/components/com_j2store/models/currencies.php';
         $currency_model = new J2StoreModelCurrencies();
         $currency_model->updateCurrencies();
         $session->set('currency_updated', '1', 'j2store');
     }
 }
Esempio n. 14
0
 public static function getItemInfo($id)
 {
     static $itemsets;
     if (!is_array($itemsets)) {
         $itemsets = array();
     }
     if (!isset($itemsets[$id])) {
         $row = J2StoreItem::getArticle($id);
         //create an object and return
         $item = J2StorePrices::getJ2Product($id);
         $item->product_id = $id;
         $item->product_name = $row->title;
         $item->short_description = $row->introtext;
         $item->long_description = $row->fulltext;
         $item->metakey = $row->metakey;
         $item->metadesc = $row->metadesc;
         $item->metadata = $row->metadata;
         $item->price = $item->item_price;
         $item->product_sku = $item->item_sku;
         $item->tax_profile_id = $item->item_tax;
         $store_config = J2StoreHelperCart::getStoreAddress();
         if ($item->use_store_config_min_out_qty > 0) {
             $item->min_out_qty = (double) $store_config->store_min_out_qty;
         }
         if ($item->use_store_config_min_sale_qty > 0) {
             $item->min_sale_qty = (double) $store_config->store_min_sale_qty;
         }
         if ($item->use_store_config_max_sale_qty > 0) {
             $item->max_sale_qty = (double) $store_config->store_max_sale_qty;
         }
         if ($item->use_store_config_notify_qty > 0) {
             $item->notify_qty = (double) $store_config->store_notify_qty;
         }
         $item->product = $row;
         //$item = $j2item;
         $itemsets[$id] = $item;
     }
     return $itemsets[$id];
 }
Esempio n. 15
0
 public static function getStock($product_id)
 {
     $stock = J2StorePrices::getJ2Product($product_id);
     if (!isset($stock) || J2STORE_PRO != 1) {
         $stock = JTable::getInstance('Prices', 'Table');
     }
     //prepare data. We may have some settings in the store global
     require_once JPATH_SITE . '/components/com_j2store/helpers/cart.php';
     $store_config = J2StoreHelperCart::getStoreAddress();
     if ($stock->use_store_config_min_out_qty > 0) {
         $stock->min_out_qty = (double) $store_config->store_min_out_qty;
     }
     if ($stock->use_store_config_min_sale_qty > 0) {
         $stock->min_sale_qty = (double) $store_config->store_min_sale_qty;
     }
     if ($stock->use_store_config_max_sale_qty > 0) {
         $stock->max_sale_qty = (double) $store_config->store_max_sale_qty;
     }
     if ($stock->use_store_config_notify_qty > 0) {
         $stock->notify_qty = (double) $store_config->store_notify_qty;
     }
     return $stock;
 }
Esempio n. 16
0
 function shipping_payment_method()
 {
     $app = JFactory::getApplication();
     $view = $this->getView('checkout', 'html');
     $task = JRequest::getVar('task');
     $model = $this->getModel('checkout');
     $cart_helper = new J2StoreHelperCart();
     $cart_model = $this->getModel('mycart');
     if (!$cart_helper->hasProducts()) {
         $msg = JText::_('J2STORE_NO_ITEMS_IN_CART');
         $link = JRoute::_('index.php?option=com_j2store&view=mycart');
         $app->redirect($link, $msg);
     }
     //prepare order
     $order = $this->_order;
     $order = $this->populateOrder(false);
     // get the order totals
     $order->calculateTotals();
     //print_r($order->order_discount);
     //print_r($order->order_tax);
     $dispatcher = JDispatcher::getInstance();
     JPluginHelper::importPlugin('j2store');
     //custom fields
     $selectableBase = J2StoreFactory::getSelectableBase();
     $view->assign('fieldsClass', $selectableBase);
     $address_table = JTable::getInstance('address', 'Table');
     $fields = $selectableBase->getFields('payment', $address, 'address');
     $view->assign('fields', $fields);
     $view->assign('address', $address_table);
     //get layout settings
     $view->assign('storeProfile', J2StoreHelperCart::getStoreAddress());
     //shipping
     $showShipping = false;
     if ($this->params->get('show_shipping_address', 0)) {
         $showShipping = true;
     }
     if ($isShippingEnabled = $cart_model->getShippingIsEnabled()) {
         $showShipping = true;
         //$this->setShippingMethod();
     }
     $view->assign('showShipping', $showShipping);
     if ($showShipping) {
         $rates = $this->getShippingRates();
         $shipping_layout = "shipping_yes";
         //	if (!$this->session->has('shipping_address_id', 'j2store'))
         //	{
         //		$shipping_layout = "shipping_calculate";
         //	}
         $shipping_method_form = $this->getShippingHtml($shipping_layout);
         $view->assign('showShipping', $showShipping);
         $view->assign('shipping_method_form', $shipping_method_form);
         $view->assign('rates', $rates);
     }
     //process payment plugins
     $showPayment = true;
     if ((double) $order->order_total == (double) '0.00') {
         $showPayment = false;
     }
     $view->assign('showPayment', $showPayment);
     require_once JPATH_SITE . '/components/com_j2store/helpers/plugin.php';
     $payment_plugins = J2StoreHelperPlugin::getPluginsWithEvent('onJ2StoreGetPaymentPlugins');
     $plugins = array();
     if ($payment_plugins) {
         foreach ($payment_plugins as $plugin) {
             $results = $dispatcher->trigger("onJ2StoreGetPaymentOptions", array($plugin->element, $order));
             if (in_array(true, $results, true)) {
                 $plugins[] = $plugin;
             }
         }
     }
     if (count($plugins) == 1) {
         $plugins[0]->checked = true;
         //ob_start();
         $html = $this->getPaymentForm($plugins[0]->element, true);
         //$html = json_decode( ob_get_contents() );
         //ob_end_clean();
         $view->assign('payment_form_div', $html);
     }
     //print_r($plugins);
     $view->assign('plugins', $plugins);
     //also set the payment methods to session
     //terms and conditions
     if ($this->params->get('termsid')) {
         $tos_link = JRoute::_('index.php?option=com_content&view=article&tmpl=component&id=' . $this->params->get('termsid'));
     } else {
         $tos_link = null;
     }
     $view->assign('tos_link', $tos_link);
     //Get and Set Model
     $view->setModel($model, true);
     $view->assign('order', $order);
     $view->assign('params', $this->params);
     $view->setLayout('checkout_shipping_payment');
     ob_start();
     $view->display();
     $html = ob_get_contents();
     ob_end_clean();
     echo $html;
     $app->close();
 }