protected function onAfterSave(&$table) { $store = J2Store::storeProfile(); if ($store->get('config_currency_auto', 1)) { $this->updateCurrencies(false); } }
protected function onDisplay($tpl = null) { $app = JFactory::getApplication(); $session = JFactory::getSession(); $user = JFactory::getUser(); $view = $this->input->getCmd('view', 'checkout'); $this->params = J2Store::config(); $this->currency = J2Store::currency(); $this->storeProfile = J2Store::storeProfile(); $this->user = $user; return true; }
public function __construct($config = array()) { $this->session = JFactory::getSession(); $this->input = JFactory::getApplication()->input; if (count($this->currencies) < 1) { $rows = F0FModel::getTmpInstance('Currencies', 'J2StoreModel')->enabled(1)->getList(); foreach ($rows as $result) { $this->currencies[$result->currency_code] = (array) $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(J2Store::storeProfile()->get('config_currency')); } }
function display($field, $value, $map, $inside, $options = '', $test = false, $allFields = null, $allValues = null) { $app = JFactory::getApplication(); $store = J2Store::storeProfile(); $stateId = $currentZoneId = $store->get('zone_id') > 0 ? $store->get('zone_id') : ''; $country_id = $store->get('country_id') > 0 ? $store->get('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)) { F0FTable::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_j2store/tables'); $table = F0FTable::getAnInstance('Zone', 'J2StoreTable'); if ($table->load($field->field_default)) { $country = $table->country_id; } } //still no. Set it to store default. if (empty($country)) { $country = $store->get('country_id'); if (empty($value)) { $value = $store->get('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); }
function _updateCurrency() { $session = JFactory::getSession(); //if auto update currency is set, then call the update function $store_config = J2Store::storeProfile(); //session based check. We dont want to update currency when we load each and every item. if ($store_config->get('config_currency_auto') && !$session->has('currency_updated', 'j2store')) { F0FModel::getTmpInstance('Currencies', 'J2StoreModel')->updateCurrencies(); $session->set('currency_updated', '1', 'j2store'); } }
public function generateInvoiceNumber() { if (empty($this->order_id)) { return; } $db = JFactory::getDbo(); $status = true; $store = J2Store::storeProfile(); $store_invoice_prefix = $store->get('invoice_prefix'); if (!isset($store_invoice_prefix) || empty($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->get('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; } $this->invoice_number = $invoice_number; $this->invoice_prefix = $store->get('invoice_prefix'); } }
function shipping_payment_method() { $app = JFactory::getApplication(); $session = JFactory::getSession(); $user = JFactory::getUser(); $params = J2Store::config(); $address_model = F0FModel::getTmpInstance('Addresses', 'J2StoreModel'); $view = $this->getThisView(); if ($model = $this->getThisModel()) { // Push the model into the view (as default) $view->setModel($model, true); } $order = F0FModel::getTmpInstance('Orders', 'J2StoreModel')->initOrder()->getOrder(); if ($order->getItemCount() < 1) { $msg = JText::_('J2STORE_NO_ITEMS_IN_CART'); $link = JRoute::_('index.php?option=com_j2store&view=carts'); $app->redirect($link, $msg); } JPluginHelper::importPlugin('j2store'); //custom fields $selectableBase = J2Store::getSelectableBase(); $view->assign('fieldsClass', $selectableBase); $address_table = F0FTable::getAnInstance('Address', 'J2StoreTable'); $fields = $selectableBase->getFields('payment', $address, 'address'); $view->assign('fields', $fields); $view->assign('address', $address_table); //get layout settings $view->assign('storeProfile', J2Store::storeProfile()); //shipping $showShipping = false; if ($params->get('show_shipping_address', 0)) { $showShipping = true; } if ($isShippingEnabled = $order->isShippingEnabled()) { $showShipping = true; } $view->assign('showShipping', $showShipping); if ($showShipping) { $shipping_layout = "shipping_yes"; $shipping_method_form = $this->getShippingHtml($shipping_layout, $order); $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); $payment_plugins = J2Store::plugin()->getPluginsWithEvent('onJ2StoreGetPaymentPlugins'); $default_method = $params->get('default_payment_method', ''); $plugins = array(); if ($payment_plugins) { foreach ($payment_plugins as $plugin) { $results = $app->triggerEvent("onJ2StoreGetPaymentOptions", array($plugin->element, $order)); if (!in_array(false, $results, false)) { if (!empty($default_method) && $default_method == $plugin->element) { $plugin->checked = true; $html = $this->getPaymentForm($plugin->element, true); $view->assign('payment_form_div', $html); } $plugins[] = $plugin; } } } if (count($plugins) == 1) { $plugins[0]->checked = true; $html = $this->getPaymentForm($plugins[0]->element, true); $view->assign('payment_form_div', $html); } $view->assign('plugins', $plugins); $view->assign('order', $order); $view->assign('params', $params); $view->setLayout('default_shipping_payment'); $html = ''; ob_start(); $view->display(); $html .= ob_get_contents(); ob_end_clean(); echo $html; $app->close(); }
public function getQuantityRestriction(&$variant) { $store = J2Store::storeProfile(); if (isset($variant->use_store_config_min_sale_qty) && $variant->use_store_config_min_sale_qty > 0) { $variant->min_sale_qty = (double) $store->get('store_min_sale_qty'); } if (isset($variant->use_store_config_max_sale_qty) && $variant->use_store_config_max_sale_qty > 0) { $variant->max_sale_qty = (double) $store->get('store_max_sale_qty'); } if (isset($variant->use_store_config_notify_qty) && $variant->use_store_config_notify_qty > 0) { $variant->notify_qty = (double) $store->get('store_notify_qty'); } }
protected function onDisplay($tpl = null) { $app = JFactory::getApplication(); $session = JFactory::getSession(); $view = $this->input->getCmd('view', 'cpanel'); $params = J2Store::config(); J2Store::utilities()->nocache(); $this->currency = J2Store::currency(); $this->store = J2Store::storeProfile(); if (in_array($view, array('cpanel', 'cpanels'))) { return; } $country_id = $this->input->getInt('country_id'); if (isset($country_id)) { $session->set('billing_country_id', $country_id, 'j2store'); $session->set('shipping_country_id', $country_id, 'j2store'); } elseif ($session->has('shipping_country_id', 'j2store')) { $country_id = $session->get('shipping_country_id', '', 'j2store'); } else { $country_id = $this->store->get('country_id'); } $zone_id = $this->input->getInt('zone_id'); if (isset($zone_id)) { $session->set('billing_zone_id', $zone_id, 'j2store'); $session->set('shipping_zone_id', $zone_id, 'j2store'); } elseif ($session->has('shipping_zone_id', 'j2store')) { $zone_id = $session->get('shipping_zone_id', '', 'j2store'); } else { $zone_id = $this->store->get('zone_id'); } $postcode = $this->input->getString('postcode'); if (isset($postcode)) { $session->set('shipping_postcode', $postcode, 'j2store'); } elseif ($session->has('shipping_postcode', 'j2store')) { $postcode = $session->get('shipping_postcode', '', 'j2store'); } else { $postcode = $this->store->get('zip'); } $this->country_id = $country_id; $this->zone_id = $zone_id; $this->postcode = $postcode; if ($params->get('hide_shipping_untill_address_selection', 1) == 0) { $session->set('billing_country_id', $country_id, 'j2store'); $session->set('shipping_country_id', $country_id, 'j2store'); $session->set('billing_zone_id', $zone_id, 'j2store'); $session->set('shipping_zone_id', $zone_id, 'j2store'); $session->set('shipping_postcode', $postcode, 'j2store'); $session->set('force_calculate_shipping', 1, 'j2store'); } // Load the model $model = $this->getModel(); $items = $model->getItems(); //plugin trigger $this->before_display_cart = ''; $before_results = J2Store::plugin()->event('BeforeDisplayCart', array($items)); foreach ($before_results as $result) { $this->before_display_cart .= $result; } //trigger plugin events $i = 0; $onDisplayCartItem = array(); foreach ($items as $item) { ob_start(); J2Store::plugin()->event('DisplayCartItem', array($i, $item)); $cartItemContents = ob_get_contents(); ob_end_clean(); if (!empty($cartItemContents)) { $onDisplayCartItem[$i] = $cartItemContents; } $i++; } $this->onDisplayCartItem = $onDisplayCartItem; $order = F0FModel::getTmpInstance('Orders', 'J2StoreModel')->populateOrder($items)->getOrder(); $order->validate_order_stock(); $this->order = $order; $this->items = $order->getItems(); foreach ($this->items as $item) { if (isset($item->orderitemattributes) && count($item->orderitemattributes)) { foreach ($item->orderitemattributes as &$attribute) { if ($attribute->orderitemattribute_type == 'file') { unset($table); $table = F0FTable::getInstance('Upload', 'J2StoreTable'); if ($table->load(array('mangled_name' => $attribute->orderitemattribute_value))) { $attribute->orderitemattribute_value = $table->original_name; } } } } } $this->taxes = $order->getOrderTaxrates(); $this->shipping = $order->getOrderShippingRate(); $this->coupons = $order->getOrderCoupons(); $this->vouchers = $order->getOrderVouchers(); $this->taxModel = F0FModel::getTmpInstance('TaxProfiles', 'J2StoreModel'); //do we have shipping methods $this->shipping_methods = $session->get('shipping_methods', array(), 'j2store'); $this->shipping_values = $session->get('shipping_values', array(), 'j2store'); $this->checkout_url = $model->getCheckoutUrl(); $this->continue_shopping_url = $model->getContinueShoppingUrl(); $this->after_display_cart = ''; $results = J2Store::plugin()->event('AfterDisplayCart', array($order)); foreach ($results as $result) { $this->after_display_cart .= $result; } // Pass page params on frontend only if (F0FPlatform::getInstance()->isFrontend()) { $this->params = $params; } return true; }