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); }
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(); }
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; }
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); } } }
function _postPayment($data) { $orderpayment_id = JRequest::getVar('orderpayment_id'); $offline_payment_method = JRequest::getVar('offline_payment_method'); $formatted = array('offline_payment_method' => $offline_payment_method); $nw_uname = JRequest::getVar('nw_username'); $nw_uemail = JRequest::getVar('nw_useremail'); $nw_uphone = JRequest::getVar('nw_userphone'); JTable::addIncludePath(JPATH_ADMINISTRATOR . DS . 'components' . DS . 'com_j2store' . DS . 'tables'); $orderpayment = JTable::getInstance('Orders', 'Table'); $orderpayment->load($orderpayment_id); $orderpayment->transaction_details = '訂單完成,等待付款!'; $orderpayment->transaction_status = '本次交易使用第三方線上金流模組。'; $orderpayment->order_state = 'Pending'; $orderpayment->order_state_id = 4; // PENDING 4 if ($orderpayment->save()) { JLoader::register('J2StoreHelperCart', JPATH_SITE . DS . 'components' . DS . 'com_j2store' . DS . 'helpers' . DS . 'cart.php'); J2StoreHelperCart::removeOrderItems($orderpayment->id); } else { $errors[] = $orderpayment->getError(); } $user = JFactory::getUser(); if ($user->id > 0) { $userprofile = JUserHelper::getProfile($user->id); $vars = new JObject(); $vars->user_name = $user->name; $vars->user_email = $user->email; } else { $vars->user_name = $nw_uname; $vars->user_email = $nw_uemail; $vars->user_phone = $nw_uphone; } $vars->orderpayment_id = $orderpayment->id; $vars->ezship_email = $this->params->get('ezmail'); $vars->ret_url = JURI::base() . 'index.php/component/nicepayment'; $vars->orderpayment_amount = ceil($orderpayment->orderpayment_amount); $vars->paymethod = $offline_payment_method; $pay2go_message = ''; $pay2go_message = $this->Pay2go_MPG($orderpayment->orderpayment_amount, $orderpayment->id); require_once JPATH_SITE . DS . 'components' . DS . 'com_j2store' . DS . 'helpers' . DS . 'orders.php'; // 寄信錯誤 // J2StoreOrdersHelper::sendUserEmail($orderpayment->user_id, $orderpayment->order_id, $orderpayment->transaction_status, $orderpayment->order_state, $orderpayment->order_state_id); return $pay2go_message; }
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); } }
public static function getItems() { $list = array(); $j2params = JComponentHelper::getParams('com_j2store'); if (J2StoreHelperCart::hasProducts()) { require_once JPATH_SITE . '/components/com_j2store/models/mycart.php'; $cart_model = new J2StoreModelMyCart(); $totals = $cart_model->getTotals(); $product_count = J2StoreHelperCart::countProducts(); if ($j2params->get('auto_calculate_tax', 1)) { $total = $totals['total']; } else { $total = $totals['total_without_tax']; } $list['total'] = $total; $list['product_count'] = $product_count; //$html = JText::sprintf('J2STORE_CART_TOTAL', $product_count, J2StorePrices::number($total)); } else { $list['total'] = 0; $list['product_count'] = 0; //$html = JText::_('J2STORE_NO_ITEMS_IN_CART'); } return $list; }
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(); } }
/** * Processes the payment * This method process only real time (simple) payments * * @return string unknown_type. * * @return string * * @access protected * */ public function _process() { if (!JRequest::checkToken()) { return $this->_renderHtml(JText::_('J2STORE_PAYMILL_INVALID_TOKEN')); } $app = JFactory::getApplication(); $data = $app->input->getArray($_POST); $json = array(); $errors = array(); // Get order information JTable::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_j2store/tables'); $order = JTable::getInstance('Orders', 'Table'); $order->load($data['orderpayment_id']); // Check for exisiting things if (empty($order->order_id)) { $json['error'] = JText::_('J2STORE_PAYMILL_INVALID_ORDER'); } if (empty($data['token'])) { $json['error'] = JText::_('J2STORE_PAYMILL_TOKEN_MISSING'); } if (!$json) { $currency_values = $this->getCurrency($order); $amount = $this->getAmount($order->orderpayment_amount, $currency_values['currency_code'], $currency_values['currency_value'], $currency_values['convert']) * 100; try { require JPath::clean(dirname(__FILE__) . "/library/autoload.php"); $request = new Paymill\Request($this->private_key); $request->setSource('J2Store'); $transaction = new Paymill\Models\Request\Transaction(); $transaction->setAmount($amount)->setCurrency($currency_values['currency_code'])->setToken($data['token'])->setDescription(JText::_('J2STORE_PAYMILL_ORDER_DESCRIPTION')); $response = $request->create($transaction); $paymentId = $response->getId(); $responseCode = $response->getResponseCode(); $raw = $request->getLastResponse(); $rawResponse = $raw['body']['data']; $transaction_details = $this->_getFormattedTransactionDetails($rawResponse); $order->transaction_id = $paymentId; $order->transaction_details = $transaction_details; $order->transaction_status = $rawResponse['status']; $sendEmail = false; if (isset($rawResponse['error'])) { $order->order_state_id = 3; $order->order_state = JText::_('J2STORE_DECLINED'); $errors[] = $resp['error']; } elseif (strtolower($rawResponse['status']) == 'closed') { $order->order_state_id = 1; $order->order_state = JText::_('J2STORE_COMPLETED'); $sendEmail = true; } elseif (strtolower($rawResponse['status']) == 'pending') { $order->order_state_id = 4; $order->order_state = JText::_('J2STORE_PENDING'); } elseif (strtolower($rawResponse['status']) == 'failed') { $order->order_state_id = 3; $order->order_state = JText::_('J2STORE_FAILED'); } else { $order->order_state_id = 3; $order->order_state = JText::_('J2STORE_FAILED'); $errors[] = JText::_("J2STORE_PAYMILL_ERROR_PROCESSING_PAYMENT"); } // save the orderpayment if (!$order->save()) { $errors[] = $order->getError(); } } catch (PaymillException $e) { //Do something with the error informations below $e->getResponseCode(); $e->getStatusCode(); $errMsg = $e->getErrorMessage(); $errors[] = $errMsg; $this->_log($errMsg, 'payment response error'); } if (empty($errors)) { // remove items from cart J2StoreHelperCart::removeOrderItems($order->id); if ($sendEmail) { //let us inform the user that the payment is successful J2StoreOrdersHelper::sendUserEmail($order->user_id, $order->order_id, $order->order_state, $order->order_state, $order->order_state_id); } $json['success'] = JText::_($this->params->get('onafterpayment', '')); $json['redirect'] = JRoute::_('index.php?option=com_j2store&view=checkout&task=confirmPayment&orderpayment_type=' . $this->_element . '&paction=display'); } if (count($errors)) { $json['error'] = implode("\n", $errors); } } return $json; }
-------------------------------------------------------------------------*/ // 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
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; }
/** * Processes the payment form * and returns HTML to be displayed to the user * generally with a success/failed message * * @param $data array form post data * @return string HTML to display */ function _postPayment($data) { // Process the payment $vars = new JObject(); $orderpayment_id = JRequest::getVar('orderpayment_id'); $offline_payment_method = JRequest::getVar('offline_payment_method'); $formatted = array('offline_payment_method' => $offline_payment_method); // load the orderpayment record and set some values JTable::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_j2store/tables'); $orderpayment = JTable::getInstance('Orders', 'Table'); //remove this after live. //$orderpayment_id = substr($orderpayment_id, 2, 3); $orderpayment->load($orderpayment_id); $orderpayment->transaction_details = implode("\n", $formatted); //$orderpayment->transaction_status = JText::_('Pending_Payment'); //$orderpayment->order_state = JText::_('Pending'); $payment_status = $this->getPaymentStatus($this->params->get('payment_status', 4)); $orderpayment->transaction_status = $payment_status; $orderpayment->order_state = $payment_status; $orderpayment->order_state_id = $this->params->get('payment_status', 4); // DEFAULT: PENDING // save the orderpayment if ($orderpayment->save()) { JLoader::register('J2StoreHelperCart', JPATH_SITE . '/components/com_j2store/helpers/cart.php'); // remove items from cart J2StoreHelperCart::removeOrderItems($orderpayment->id); } else { $errors[] = $orderpayment->getError(); } // let us inform the user that the order is successful require_once JPATH_SITE . '/components/com_j2store/helpers/orders.php'; J2StoreOrdersHelper::sendUserEmail($orderpayment->user_id, $orderpayment->order_id, $orderpayment->transaction_status, $orderpayment->order_state, $orderpayment->order_state_id); $vars->onafterpayment_text = $this->params->get('onafterpayment', ''); // display the layout $html = $this->_getLayout('postpayment', $vars); // append the article with offline payment information $html .= $this->_displayArticle(); return $html; }
</span> </span> <?php } ?> <!-- we may have a customer group price --> <?php if (isset($this->item->prices->product_customer_groupprice) && !empty($this->item->prices->product_customer_groupprice)) { ?> <span itemprop="offers" itemscope itemtype="http://schema.org/Offer"> <span itemprop="price" id="product_special_price_<?php echo $this->item->product_id; ?> " class="product-special-price"> <?php echo J2StoreHelperCart::dispayPriceWithTax($this->item->prices->product_price, $this->taxClass->getProductTax($this->item->prices->product_price, $this->item->product_id), $this->params->get('price_display_options', 1)); ?> </span> </span> <?php } ?> </div> <div class="j2store-after-display-product-price"> <?php echo $this->item->event->J2StoreAfterDisplayProductPrice; ?> </div>
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; }
?> "><?php echo $option_value['optionvalue_name']; ?> <?php if ($option_value['product_optionvalue_price'] > 0) { ?> <?php //get the tax $tax = $this->tax_class->getProductTax($option_value['product_optionvalue_price'], $this->item->product_id); ?> (<?php echo $option_value['product_optionvalue_prefix']; ?> <?php echo J2StoreHelperCart::dispayPriceWithTax($option_value['product_optionvalue_price'], $tax, $this->params->get('price_display_options', 1)); ?> ) <?php } ?> </label> <br /> <?php } ?> </div> <br /> <?php } ?>
/** * Processes the payment form * and returns HTML to be displayed to the user * generally with a success/failed message * * @param $data array form post data * @return string HTML to display */ function _postPayment($data) { // Process the payment $app = JFactory::getApplication(); $vars = new JObject(); $html = ''; $orderpayment_id = $app->input->getInt('orderpayment_id'); // load the orderpayment record and set some values JTable::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_j2store/tables'); $orderpayment = JTable::getInstance('Orders', 'Table'); $orderpayment->load($orderpayment_id); if ($orderpayment->id == $orderpayment_id) { $payment_status = $this->getPaymentStatus($this->params->get('payment_status', 4)); $orderpayment->transaction_status = $payment_status; $orderpayment->order_state = $payment_status; $orderpayment->order_state_id = $this->params->get('payment_status', 4); // DEFAULT: PENDING // save the orderpayment if ($orderpayment->save()) { JLoader::register('J2StoreHelperCart', JPATH_SITE . '/components/com_j2store/helpers/cart.php'); // remove items from cart J2StoreHelperCart::removeOrderItems($orderpayment->id); } else { $errors[] = $orderpayment->getError(); } // let us inform the user that the order is successful require_once JPATH_SITE . '/components/com_j2store/helpers/orders.php'; J2StoreOrdersHelper::sendUserEmail($orderpayment->user_id, $orderpayment->order_id, $orderpayment->transaction_status, $orderpayment->order_state, $orderpayment->order_state_id); $vars->onafterpayment_text = $this->params->get('onafterpayment', ''); // display the layout $html = $this->_getLayout('postpayment', $vars); // append the article with cash payment information $html .= $this->_displayArticle(); } return $html; }
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'); } }
public static function getStoreAddress() { if (!isset(self::$store)) { $db = JFactory::getDbo(); $query = $db->getQuery(true); $query->select('s.*, c.country_name, c.country_isocode_2, c.country_isocode_3, z.zone_name, z.zone_code'); $query->from('#__j2store_storeprofiles AS s'); $query->where('s.state=1'); $query->order('s.store_id ASC LIMIT 1'); $query->leftJoin('#__j2store_countries AS c ON s.country_id = c.country_id'); $query->leftJoin('#__j2store_zones AS z ON s.zone_id = z.zone_id'); $db->setQuery($query); self::$store = $db->loadObject(); } return self::$store; }
/** * Calculates the per_order coupon discount for the order * and the total post-tax/shipping discount * and sets order->order_discount * * @return unknown_type */ function calculateDiscountTotals() { $this->_taxes = J2StoreHelperCart::getTaxes(); $session = JFactory::getSession(); $tax = new J2StoreTax(); JModelLegacy::addIncludePath(JPATH_SITE . '/components/com_j2store/models'); $model = JModelLegacy::getInstance('MyCart', 'J2StoreModel'); $products = $model->getDataNew(); if ($session->has('coupon', 'j2store')) { $coupon_info = J2StoreHelperCart::getCoupon($session->get('coupon', '', 'j2store')); if ($coupon_info) { $discount_total = 0; if (!$coupon_info->product) { $sub_total = J2StoreHelperCart::getSubTotal(); } else { $sub_total = 0; foreach ($products as $product) { if (in_array($product['product_id'], $coupon_info->product)) { $sub_total += $product['total']; } } } if ($coupon_info->value_type == 'F') { $coupon_info->value = min($coupon_info->value, $sub_total); } //maximum value restriction. If set then we need to check if ($coupon_info->value_type == 'P' && !empty($coupon_info->max_value) && (double) $coupon_info->max_value > 0) { //calculate the actual discount require_once JPATH_SITE . '/components/com_j2store/models/mycart.php'; $cart_model = new J2StoreModelMyCart(); $actual_discount = $cart_model->getDiscountTotal(); //is the actual discount greater than the max value if ($actual_discount > 0 && $actual_discount > (double) $coupon_info->max_value) { //set the coupon to be of fixed value $coupon_info->value = (double) $coupon_info->max_value; $coupon_info->value_type = 'F'; } } foreach ($products as $product) { $discount = 0; if (!$coupon_info->product) { $status = true; } else { if (in_array($product['product_id'], $coupon_info->product)) { $status = true; } else { $status = false; } } if ($status) { if ($coupon_info->value_type == 'F') { $discount = $coupon_info->value * ($product['total'] / $sub_total); } elseif ($coupon_info->value_type == 'P') { $discount = $product['total'] / 100 * $coupon_info->value; } if ($product['tax_profile_id']) { $tax_rates = $tax->getRateArray($product['total'] - ($product['total'] - $discount), $product['tax_profile_id']); foreach ($tax_rates as $tax_rate) { // if ($tax_rate['value_type'] == 'P') { $this->_taxes[$tax_rate['taxrate_id']] -= $tax_rate['amount']; // } } } } $discount_total += $discount; } } } // store the total amount of the discount //set the total as equal to the order_subtotal + order_tax if its greater than the sum of the two $this->order_discount = $discount_total > $this->order_subtotal + $this->order_tax ? $this->order_subtotal + $this->order_tax : $discount_total; }
if ($item->special_price > 0.0) { echo '</strike>'; } ?> </span> <!--special price--> <?php if ($item->special_price > 0.0) { ?> <span id="product_special_price_<?php echo $item->product_id; ?> " class="product_special_price"> <?php echo J2StoreHelperCart::dispayPriceWithTax($item->special_price, $item->sp_tax, $this->params->get('price_display_options', 1)); ?> </span> <?php } ?> <?php } ?> <!-- sku --> <?php if ($this->params->get('show_sku_field', 0)) { ?>
/** * Processes the payment form * and returns HTML to be displayed to the user * generally with a success/failed message * * @param $data array form post data * @return string HTML to display */ function _postPayment($data) { // Process the payment $app = JFactory::getApplication(); $vars = new JObject(); $html = ''; $orderpayment_id = $app->input->getInt('orderpayment_id'); // load the orderpayment record and set some values JTable::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_j2store/tables'); $orderpayment = JTable::getInstance('Orders', 'Table'); $orderpayment->load($orderpayment_id); if ($orderpayment->id == $orderpayment_id) { $bank_information = stripslashes($_POST['moneyorder_information']); //we have to save the bank information in the customer note because that is the only field availale to display now //TODO: Trigger a plugin event so that you can show custom info depending on the payment plugin. //get the customer note. We dont want to overwrite it. if (JString::strlen($bank_information) > 5) { $customer_note = $orderpayment->customer_note; $html = '<br />'; $html .= '<strong>' . JText::_('J2STORE_MONEYORDER_INSTRUCTIONS') . '</strong>'; $html .= '<br />'; $html .= $bank_information; $orderpayment->customer_note = $customer_note . $html; } $payment_status = $this->getPaymentStatus($this->params->get('payment_status', 4)); $orderpayment->transaction_status = $payment_status; $orderpayment->order_state = $payment_status; $orderpayment->order_state_id = $this->params->get('payment_status', 4); // DEFAULT: PENDING // save the orderpayment if ($orderpayment->save()) { JLoader::register('J2StoreHelperCart', JPATH_SITE . '/components/com_j2store/helpers/cart.php'); // remove items from cart J2StoreHelperCart::removeOrderItems($orderpayment->id); } else { $errors[] = $orderpayment->getError(); } // let us inform the user that the order is successful require_once JPATH_SITE . '/components/com_j2store/helpers/orders.php'; J2StoreOrdersHelper::sendUserEmail($orderpayment->user_id, $orderpayment->order_id, $orderpayment->transaction_status, $orderpayment->order_state, $orderpayment->order_state_id); $vars->onafterpayment_text = $this->params->get('onafterpayment', ''); // display the layout $html = $this->_getLayout('postpayment', $vars); // append the article with moneyorder payment information $html .= $this->_displayArticle(); } return $html; }
/** * Proceeds the simple payment * * @param string $resp * @param array $submitted_values * @return object Message object * @access protected */ function _evaluateSimplePaymentResponse($resp, $submitted_values) { $object = new JObject(); $object->message = ''; $html = ''; $errors = array(); $return = array(); $payment_status = JText::_('J2STORE_INCOMPLETE'); $user = JFactory::getUser(); $transaction_details = $this->_getFormattedTransactionDetails($resp); $this->_log($transaction_details, 'Payment Gateway Response'); // Evaluate a typical response from sage pay $this->_log($resp['Status']); switch ($resp['Status']) { case 'OK': // Approved $payment_status = JText::_('J2STORE_COMPLETED'); break; case 'MALFORMED': case 'INVALID': case 'NOTAUTHED': case 'REJECTED': case 'ERROR': // Declined $payment_status = JText::_('J2STORE_DECLINED'); $errors[] = $resp['StatusDetail']; break; default: // Error $payment_status = JText::_('J2STORE_ERROR'); $order_status = JText::_('J2STORE_INCOMPLETE'); $errors[] = $this->params->get('onerrorpayment', ' '); break; } // ======================= // verify & create payment // ======================= $orderpayment_id = $this->_getOrderPaymentId($submitted_values['VendorTxCode']); // check that payment amount is correct for order_id JTable::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_j2store/tables'); $orderpayment = JTable::getInstance('Orders', 'Table'); $orderpayment->load($orderpayment_id); if (empty($orderpayment->order_id)) { // TODO fail } $transaction_id = isset($resp['VPSTxId']) ? $resp['VPSTxId'] : ''; $orderpayment->transaction_details = $transaction_details; $orderpayment->transaction_id = $transaction_id; $orderpayment->transaction_status = $payment_status; //set a default status to it $orderpayment->order_state = JText::_('J2STORE_PENDING'); // PENDING $orderpayment->order_state_id = 4; // PENDING // set the order's new status and update quantities if necessary if (count($errors)) { // if an error occurred $orderpayment->order_state = trim(JText::_('J2STORE_FAILED')); // FAILED $orderpayment->order_state_id = 3; // FAILED } else { $orderpayment->order_state = trim(JText::_('J2STORE_CONFIRMED')); // Payment received and CONFIRMED $orderpayment->order_state_id = 1; // CONFIRMED JLoader::register('J2StoreHelperCart', JPATH_SITE . '/components/com_j2store/helpers/cart.php'); // remove items from cart J2StoreHelperCart::removeOrderItems($orderpayment->id); //$this->setOrderPaymentReceived( $orderpayment->order_id ); } // save the order if (!$orderpayment->save()) { $errors[] = $orderpayment->getError(); } if (empty($errors)) { // let us inform the user that the payment is successful require_once JPATH_SITE . '/components/com_j2store/helpers/orders.php'; J2StoreOrdersHelper::sendUserEmail($orderpayment->user_id, $orderpayment->order_id, $payment_status, $orderpayment->order_state, $orderpayment->order_state_id); $return['success'] = JText::_($this->params->get('onafterpayment', '')); $return['redirect'] = JRoute::_('index.php?option=com_j2store&view=checkout&task=confirmPayment&orderpayment_type=' . $this->_element . '&paction=display'); } else { $error = count($errors) ? implode("\n", $errors) : ''; $this->_sendErrorEmails($error, $transaction_details); $this->_log($error, 'Transaction Errors'); $return['error'] = $error; } return $return; // =================== // end custom code // =================== }
/** * * @param $element * @param $values */ function onJ2StoreGetShippingRates($element, $order) { // Check if this is the right plugin if (!$this->_isMe($element)) { return null; } $vars = array(); $this->includeJ2StoreTables(); $this->includeCustomTables(); $this->includeCustomModel('ShippingMethods'); $this->includeCustomModel('ShippingRates'); //set the address $order->setAddress(); $geozones_taxes = array(); // $geozones_taxes = $order->getBillingGeoZones(); $geozones = $order->getShippingGeoZones(); $gz_array = array(); foreach ($geozones as $geozone) { $gz_array[] = $geozone->geozone_id; } if (!isset($order->order_subtotal)) { $subtotal = J2StoreHelperCart::getSubTotal(); } else { $subtotal = $order->order_subtotal; } $rates = array(); $model = JModelLegacy::getInstance('ShippingMethods', 'J2StoreModel'); $model->setState('filter_enabled', '1'); $model->setState('filter_subtotal', $subtotal); if ($methods = $model->getList()) { foreach ($methods as $method) { //check if there is an override if ($method->address_override == 'store') { //there is an override. //so set the shipping address to store and get the geozones afresh $order->setAddress('store'); } else { $order->setAddress(); } $geozones = $order->getShippingGeoZones(); $gz_array = array(); foreach ($geozones as $geozone) { $gz_array[] = $geozone->geozone_id; } // filter the list of methods according to geozone $ratemodel = JModelLegacy::getInstance('ShippingRates', 'J2StoreModel'); $ratemodel->setState('filter_shippingmethod', $method->shipping_method_id); $ratemodel->setState('filter_geozones', $gz_array); if ($ratesexist = $ratemodel->getList()) { $total = $this->getTotal($method->shipping_method_id, $geozones, $order->getItems(), $geozones_taxes); if ($total) { $total->shipping_method_type = $method->shipping_method_type; $rates[] = $total; } } } } $i = 0; foreach ($rates as $rate) { $vars[$i]['element'] = $this->_element; $vars[$i]['name'] = addslashes(JText::_($rate->shipping_method_name)); $vars[$i]['type'] = $rate->shipping_method_type; $vars[$i]['code'] = $rate->shipping_rate_id; $vars[$i]['price'] = $rate->shipping_rate_price; $vars[$i]['tax'] = round($rate->shipping_tax_total, 2); $vars[$i]['extra'] = $rate->shipping_rate_handling; $vars[$i]['total'] = $rate->shipping_rate_price + $rate->shipping_rate_handling + round($rate->shipping_tax_total, 2); $i++; } //print_r($vars); return $vars; }
public function getStoreAddress() { require_once JPATH_SITE . '/components/com_j2store/helpers/cart.php'; return J2StoreHelperCart::getStoreAddress(); }
public function getDiscountTotal() { $app = JFactory::getApplication(); $session = JFactory::getSession(); $discount_total = 0; if ($session->has('coupon', 'j2store')) { $coupon_info = J2StoreHelperCart::getCoupon($session->get('coupon', '', 'j2store')); if ($coupon_info) { $products = $this->getDataNew(); if (!$coupon_info->product) { $sub_total = J2StoreHelperCart::getSubTotal(); } else { $sub_total = 0; foreach ($products as $product) { if (in_array($product['product_id'], $coupon_info->product)) { $sub_total += $product['total']; } } } if ($coupon_info->value_type == 'F') { $coupon_info->value = min($coupon_info->value, $sub_total); } $product_array2 = array(); foreach ($products as $product) { $discount = 0; if (!$coupon_info->product) { $status = true; } else { if (in_array($product['product_id'], $coupon_info->product)) { $status = true; } else { $status = false; } } if ($status) { if ($coupon_info->value_type == 'F') { $discount = $coupon_info->value * ($product['total'] / $sub_total); } elseif ($coupon_info->value_type == 'P') { $discount = $product['total'] / 100 * $coupon_info->value; } } $discount_total += $discount; } if ($coupon_info->free_shipping && $session->has('shipping_values', 'j2store')) { $shipping = $session->get('shipping_values', array(), 'j2store'); $shipping_cost = $shipping['shipping_price'] + $shipping['shipping_extra'] + $shipping['shipping_tax']; $discount_total += $shipping_cost; } } } return $discount_total; }
/** * Method to getItem * @params type int id * @result products */ public function getItem() { $id = $this->getId(); $product = J2StoreHelperCart::getItemInfo($id); //set the correct quantity if (isset($product->min_sale_qty) && $product->min_sale_qty > 1 && J2STORE_PRO == 1) { $product->product_quantity = (int) $product->min_sale_qty; $product->item_minimum_notice = JText::sprintf('J2STORE_MINIMUM_QUANTITY_NOTIFICATION', $product->product_name, (int) $product->min_sale_qty); } else { $product->product_quantity = 1; } //include the model file path JModelLegacy::addIncludePath(JPATH_SITE . '/components/com_j2store/models'); //create obj for cartmodel class $cart_model = JModelLegacy::getInstance('Mycart', 'J2StoreModel'); //now get the productoptions based on the id $attributes = $cart_model->getProductOptions($id); //let calcuate the product option based on the stock if (count($attributes) && $product->manage_stock == 1 && J2STORE_PRO == 1) { //get unavailable attribute options $attributes = $cart_model->processAttributeOptions($attributes, $product); } //assign the attributes $product->attributes = $attributes; //assign th prices $product->prices = J2StorePrices::getPrice($id, $product->product_quantity); if (J2STORE_PRO == 1 && $product->manage_stock == 1) { JModelLegacy::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_j2store/models'); $qtyModel = JModelLegacy::getInstance('ProductQuantities', 'J2StoreModel'); $qtyModel->setState('filter_product', $product->product_id); $qtyModel->setState('filter_productid', $product->product_id); $product->option_stock = $qtyModel->getList(); $product->product_stock = $qtyModel->getQuantityTotal(); } else { $product->product_stock = 99; } $product->product = $product; $product->inventory = J2StoreInventory::isAllowed($product); //get all tags if (version_compare(JVERSION, '3.0', 'ge')) { $product->product_tags = $this->getProductTags($id); } $this->executePlugins($product); return $product; }
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(); }
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); }
/** * 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; }
/** * This method occurs after payment is attempted, * and fires the onPostPayment plugin event * * @return unknown_type */ function confirmPayment() { $app = JFactory::getApplication(); $orderpayment_type = $app->input->getString('orderpayment_type'); // Get post values $values = $app->input->getArray($_POST); //backward compatibility for payment plugins foreach ($values as $name => $value) { $app->input->set($name, $value); } //set the guest mail to null if it is present //check if it was a guest checkout $account = $this->session->get('account', 'register', 'j2store'); // get the order_id from the session set by the prePayment $orderpayment_id = (int) $app->getUserState('j2store.orderpayment_id'); if ($account != 'guest') { $order_link = 'index.php?option=com_j2store&view=orders&task=view&id=' . $orderpayment_id; } else { $guest_token = $app->getUserState('j2store.order_token'); $order_link = 'index.php?option=com_j2store&view=orders&task=view'; //assign to another session variable, for security reasons if ($this->session->has('guest', 'j2store')) { $guest = $this->session->get('guest', array(), 'j2store'); $this->session->set('guest_order_email', $guest['billing']['email']); $this->session->set('guest_order_token', $guest_token); } } $dispatcher = JDispatcher::getInstance(); JPluginHelper::importPlugin('j2store'); $html = ""; $order = $this->_order; $order->load(array('id' => $orderpayment_id)); //save the coupon to the order_coupons table for tracking and unset session. if ($this->session->has('coupon', 'j2store')) { $db = JFactory::getDbo(); $query = $db->getQuery(true); $query->select('*')->from('#__j2store_coupons')->where('coupon_code=' . $db->q($this->session->get('coupon', '', 'j2store')))->where('state=1'); $query->where("((valid_from = '0000-00-00' OR valid_from < NOW()) AND (valid_to = '0000-00-00' OR valid_to > NOW()))"); $db->setQuery($query); $coupon_info = $db->loadObject(); if ($coupon_info) { $order_coupons = JTable::getInstance('OrderCoupons', 'Table'); $order_coupons->set('coupon_id', $coupon_info->coupon_id); $order_coupons->set('coupon_code', $coupon_info->coupon_code); $order_coupons->set('orderpayment_id', $orderpayment_id); $order_coupons->set('order_id', $order->order_id); $order_coupons->set('customer_id', JFactory::getUser()->id); $order_coupons->set('customer_email', $order->user_email); $order_coupons->set('amount', $order->order_discount); $order_coupons->set('created_date', JFactory::getDate()->toSql()); $order_coupons->store(); } } // free product? set the state to confirmed and save the order. if (!empty($orderpayment_id) && (double) $order->order_total == (double) '0.00') { $order->order_state = trim(JText::_('CONFIRMED')); $order->order_state_id = '1'; // PAYMENT RECEIVED. if ($order->save()) { // remove items from cart J2StoreHelperCart::removeOrderItems($order->id); } //send email require_once JPATH_SITE . '/components/com_j2store/helpers/orders.php'; J2StoreOrdersHelper::sendUserEmail($order->user_id, $order->order_id, $order->transaction_status, $order->order_state, $order->order_state_id); } else { // get the payment results from the payment plugin $results = $dispatcher->trigger("onJ2StorePostPayment", array($orderpayment_type, $values)); // Display whatever comes back from Payment Plugin for the onPrePayment for ($i = 0; $i < count($results); $i++) { $html .= $results[$i]; } // re-load the order in case the payment plugin updated it $order->load(array('id' => $orderpayment_id)); } // $order_id would be empty on posts back from Paypal, for example if (isset($orderpayment_id)) { //unset a few things from the session. $this->session->clear('shipping_method', 'j2store'); $this->session->clear('shipping_methods', 'j2store'); $this->session->clear('payment_method', 'j2store'); $this->session->clear('payment_methods', 'j2store'); $this->session->clear('payment_values', 'j2store'); $this->session->clear('guest', 'j2store'); $this->session->clear('customer_note', 'j2store'); //clear the session $this->session->clear('coupon', 'j2store'); //trigger onAfterOrder plugin event $results = $dispatcher->trigger("onJ2StoreAfterPayment", array($order)); foreach ($results as $result) { $html .= $result; } // Set display $view = $this->getView('checkout', 'html'); $view->setLayout('postpayment'); $view->set('_doTask', true); $params = $params = JComponentHelper::getParams('com_j2store'); if ($params->get('show_postpayment_orderlink', 1)) { $view->assign('order_link', $order_link); } else { $view->assign('order_link', ''); } $view->assign('plugin_html', $html); // Get and Set Model $model = $this->getModel('checkout'); $view->setModel($model, true); $view->display(); } return; }