예제 #1
0
 function checkout()
 {
     /*
     $savedGET = $_GET; 
     $savedPOST = $_POST; 
     $savedREQUEST = $_REQUEST; 
     */
     // before we do anything, let's check captcha:
     include JPATH_ROOT . DS . 'components' . DS . 'com_onepage' . DS . 'config' . DS . 'onepage.cfg.php';
     if (!class_exists('OPCLang')) {
         require JPATH_ROOT . DIRECTORY_SEPARATOR . 'components' . DIRECTORY_SEPARATOR . 'com_onepage' . DIRECTORY_SEPARATOR . 'helpers' . DIRECTORY_SEPARATOR . 'language.php';
     }
     OPCLang::loadLang();
     //mobile handling:
     if (!defined('OPC_DETECTED_DEVICE')) {
         if (class_exists('OPCplugin')) {
             OPCplugin::detectMobile();
         }
     }
     if (!isset($opc_memory)) {
         $opc_memory = '128M';
     }
     ini_set('memory_limit', $opc_memory);
     ini_set('error_reporting', 0);
     // disable error reporting for ajax:
     error_reporting(0);
     $logged = false;
     if (JFactory::getUser()->guest) {
     } else {
         $logged = true;
     }
     include JPATH_ROOT . DS . 'components' . DS . 'com_onepage' . DS . 'config' . DS . 'onepage.cfg.php';
     if (!empty($enable_captcha_logged) && $logged || !empty($enable_captcha_unlogged) && !$logged) {
         $this->checkOPCCaptcha();
     }
     if (!class_exists('VmConfig')) {
         require JPATH_ADMINISTRATOR . DS . 'components' . DS . 'com_virtuemart' . DS . 'helpers' . DS . 'config.php';
     }
     VmConfig::loadConfig();
     // since vm2.0.21a we need to load the language files here
     OPCLang::loadLang();
     $this->prepareFields();
     // fedex multibox fix:
     // register user first:
     $reg = JRequest::getVar('register_account');
     if (empty($reg)) {
         $reg = false;
     } else {
         $reg = true;
     }
     // ENABLE ONLY BUSINESS REGISTRATION WHEN REGISTER_ACCOUNT IS SET AS BUSINESS FIELD
     require_once JPATH_ROOT . DS . 'components' . DS . 'com_onepage' . DS . 'helpers' . DS . 'mini.php';
     $is_business = JRequest::getVar('opc_is_business', 0);
     // we need to alter shopper group for business when set to:
     $is_business = JRequest::getVar('opc_is_business', 0);
     if (!empty($business_fields)) {
         if (!$is_business) {
             // manage required business fields when not business selected:
             foreach ($business_fields as $fn) {
                 /*
                 	$x1 = JRequest::getVar($fn); 
                 	if (empty($x1))
                 	JRequest::setVar($fn, '_'); 
                 
                 	$x1 = JRequest::getVar('shipto_'.$fn); 
                 	if (empty($x1))
                 	JRequest::setVar('shipto_'.$fn, '_'); 
                 */
             }
         }
     }
     if ($reg) {
         if (!empty($business_fields)) {
             if (in_array('register_account', $business_fields)) {
                 if (empty($is_business)) {
                     $reg = false;
                 }
             }
         }
     }
     //if (!class_exists('VirtueMartControllerUser'))
     //require_once(JPATH_SITE.DS.'components'.DS.'com_virtuemart'.DS.'controllers'.DS.'user.php');
     //$userC = new VirtueMartControllerUser();
     $cart = VirtueMartCart::getCart(false);
     $mainframe = Jfactory::getApplication();
     $virtuemart_currency_id = $mainframe->getUserStateFromRequest("virtuemart_currency_id", 'virtuemart_currency_id', JRequest::getInt('virtuemart_currency_id'));
     $cart->paymentCurrency = $virtuemart_currency_id;
     require_once JPATH_SITE . DS . 'components' . DS . 'com_onepage' . DS . 'helpers' . DS . 'shoppergroups.php';
     OPCShopperGroups::setShopperGroupsController($cart);
     if (method_exists($cart, 'prepareCartData')) {
         $cart->prepareCartData(false);
     }
     if (!isset($cart->vendorId)) {
         $cart->vendorId = 1;
     }
     $payment_id = $cart->virtuemart_paymentmethod_id = JRequest::getInt('virtuemart_paymentmethod_id', '');
     $cart->virtuemart_shipmentmethod_id = JRequest::getInt('virtuemart_shipmentmethod_id', '');
     $coupon = JRequest::getVar('opc_coupon_code_returned', '');
     if (!empty($coupon) && empty($cart->couponCode)) {
         $cart->couponCode = $coupon;
     }
     $this->runExt($cart);
     if (method_exists($cart, 'prepareCartProducts')) {
         $cart->prepareCartProducts();
     }
     $this->setCartAddress($cart);
     $this->setExtAddress($cart, false);
     $order_language = JFactory::getLanguage()->getTag();
     JRequest::setVar('order_language', $order_language);
     // k2 mod with recaptcha enabled
     $session = JFactory::getSession();
     $orig = $session->get('socialConnectData');
     $session->set('socialConnectData', true);
     // end p1 k2 mod with recaptcha enabled
     //$this->setShopperGroups($cart);
     $data = JRequest::get('post');
     $data['quite'] = true;
     //suppress messages from thsi function
     $this->saveData($cart, $reg, false, $data);
     if (!empty($allow_sg_update)) {
         $this->storeShopperGroup($data, true);
     }
     $userModel = OPCmini::getModel('user');
     if (method_exists($userModel, 'getCurrentUser')) {
         $user = $userModel->getCurrentUser();
         self::$shopper_groups = $user->shopper_groups;
     }
     // k2 mod with recaptcha enabled
     if (empty($orig)) {
         $session->clear('socialConnectData');
     } else {
         $session->set('socialConnectData', $orig);
     }
     // end p2 k2 mod with recaptcha enabled
     if (!class_exists('VirtueMartControllerCartOpc')) {
         require_once JPATH_SITE . DS . 'components' . DS . 'com_onepage' . DS . 'overrides' . DS . 'cartcontroller.php';
     }
     $cartcontroller = new VirtueMartControllerCartOpc();
     $po = JRequest::getVar('socialNumber', '');
     if (method_exists($cartcontroller, 'setshipment')) {
         $cartcontroller->setshipment($cart);
     }
     // fix fedex multibox
     $saved_bt = $cart->BT;
     if (isset($_SESSION['load_fedex_prices_from_session'])) {
         unset($_SESSION['load_fedex_prices_from_session']);
     }
     if (method_exists($cartcontroller, 'setpayment')) {
         $cartcontroller->setpayment($cart);
     }
     if ($cart->BT != $saved_bt) {
         if (empty($cart->ST) || $cart->STsameAsBT) {
             $cart->STsameAsBT = 0;
             $cart->ST = $saved_bt;
             $text = JText::_('COM_ONEPAGE_USER_ENTERED_ADDRESS');
             if ($text == 'COM_ONEPAGE_USER_ENTERED_ADDRESS') {
                 $text = 'User Entered Address (Ship To)';
             }
             $cart->ST['address_type_name'] = $text;
             $cart->BT['address_type_name'] = JText::_('COM_ONEPAGE_ADDRESS_HAD_CHANGED_NAME');
             //$cart->BT = $saved_bt;
         } else {
             if ($cart->ST != $saved_bt) {
                 $address_changed = JText::_('COM_ONEPAGE_ADDRESS_HAD_CHANGED');
                 $mainframe = JFactory::getApplication();
                 $mainframe->redirect(JRoute::_('index.php?option=com_virtuemart&view=cart'), OPCLang::_('COM_ONEPAGE_ADDRESS_HAD_CHANGED'));
                 return;
             } else {
                 // $cart->BT = $saved_bt;
             }
         }
     }
     // security:
     JRequest::setVar('html', '');
     $post = JRequest::get('post');
     if (empty($cart->BT)) {
     }
     // fix the customer comment
     // $cart->customer_comment = JRequest::getVar('customer_comment', $cart->customer_comment);
     $cc = JRequest::getVar('customer_comment', '');
     $cc2 = JRequest::getVar('customer_note', '');
     if (empty($cart->customer_comment)) {
         $cart->customer_comment = $cc2 . $cc;
     } else {
         $cart->customer_comment = $cc2 . $cc;
     }
     JRequest::setVar('customer_comment', $cart->customer_comment);
     JRequest::setVar('customer_note', $cart->customer_comment);
     if (defined('VM_VERSION') && VM_VERSION >= 3) {
         $cart->BT['customer_note'] = $cart->customer_comment;
     }
     $OPCcheckout = new OPCcheckout($cart);
     $loader = new OPCloader();
     OPCcheckout::$current_cart =& $cart;
     $OPCcheckout->checkoutData(false);
     if ($cart->_dataValidated) {
         $cart->_confirmDone = true;
         $order = null;
         $output = $OPCcheckout->confirmedOrder();
         //$cart, $this, $order);
         /*
         jimport( 'joomla.plugin.helper' );
         $plugin = JPluginHelper::getPlugin('vmpayment', 'opctracking');
         if (!empty($plugin))
         {
            $opctracking = true; 
         }
         else 
         {
            $opctracking = false; 
         }
         */
         require_once JPATH_SITE . DS . 'components' . DS . 'com_onepage' . DS . 'helpers' . DS . 'config.php';
         $utm_p_load = false;
         $default = array();
         $utm_p = OPCConfig::getValue('opc_config', 'utm_payments', 0, $default, false, false);
         if (!empty($payment_id)) {
             if (in_array($payment_id, $utm_p)) {
                 $utm_p_load = true;
             }
         }
         if ($utm_p_load) {
             $output = str_replace('&view=pluginresponse', '&utm_nooverride=1&view=pluginresponse', $output);
             $output = str_replace('&view=pluginresponse', '&utm_nooverride=1&view=pluginresponse', $output);
         }
         require_once JPATH_SITE . DS . 'components' . DS . 'com_onepage' . DS . 'helpers' . DS . 'removemsgs.php';
         OPCremoveMsgs::removeMsgs($cart);
         $order =& OPCcheckout::$new_order;
         $session = JFactory::getSession();
         if (!empty($order)) {
             if ($order['details']['BT']->order_total <= 0) {
                 $dispatcher = JDispatcher::getInstance();
                 $returnValues = $dispatcher->trigger('registerOrderAttempt', array(&$order));
                 $cart->emptyCart();
             }
         }
     } else {
         $mainframe = JFactory::getApplication();
         $mainframe->redirect(JRoute::_('index.php?option=com_virtuemart&view=cart'), 'Captcha: ' . OPCLang::_('COM_VIRTUEMART_CART_CHECKOUT_DATA_NOT_VALID'));
     }
     // some extensions somehow reset the language, and we need to set it to the proper one:
     $lang = JFactory::getLanguage();
     $tag = $lang->getTag();
     $filename = 'com_virtuemart';
     $lang->load($filename, JPATH_ADMINISTRATOR, $tag, true);
     $lang->load($filename, JPATH_SITE, $tag, true);
     //$post = JRequest::get('post');
     $mainframe = JFactory::getApplication();
     $pathway = $mainframe->getPathway();
     $document = JFactory::getDocument();
     //  $html = JRequest::getVar('html', OPCLang::_('COM_VIRTUEMART_ORDER_PROCESSED'), 'post', 'STRING', JREQUEST_ALLOWRAW);
     $document->setTitle(OPCLang::_('COM_VIRTUEMART_CART_THANKYOU'));
     $cart->setCartIntoSession();
     // now the plugins should have already loaded the redirect html
     // we can safely
     $virtuemart_order_id = $cart->virtuemart_order_id;
     JRequest::setVar('view', 'cart');
     $_REQUEST['view'] = 'cart';
     $_POST['view'] = 'cart';
     $_GET['view'] = 'cart';
     $view = $this->getView('cart', 'html');
     $currencyDisplay = CurrencyDisplay::getInstance($cart->pricesCurrency);
     $view->currencyDisplay = $currencyDisplay;
     $view->addTemplatePath(JPATH_VM_SITE . DS . 'views' . DS . 'cart' . DS . 'tmpl' . DS);
     $view->cart = $cart;
     $display_title = JRequest::getVar('display_title', true);
     $view->display_title = $display_title;
     $view->setLayout('order_done');
     $view->assignRef('html', $output);
     // commented for 2.0.22a
     //JRequest::setVar('html', $output);
     //$view->html = $output;
     // Display it all
     ob_start();
     $view->display();
     $html1 = ob_get_clean();
     $items = $pathway->getPathwayNames();
     $skipp = false;
     foreach ($items as $i) {
         if ($i == OPCLang::_('COM_VIRTUEMART_CART_THANKYOU')) {
             $skipp = true;
         }
     }
     if (!$skipp) {
         $pathway->addItem(OPCLang::_('COM_VIRTUEMART_CART_THANKYOU'));
     }
     if (empty($html1)) {
         $html1 = $output;
     }
     JRequest::setVar('view', 'opccart');
     JRequest::setVar('contoller', 'opccart');
     $html2 = '';
     if (!empty($append_details)) {
         // ok, lets try to alter it with the order details
         JRequest::setVar('order_pass', $order['details']['BT']->order_pass);
         JRequest::setVar('order_number', $order['details']['BT']->order_number);
         JRequest::setVar('virtuemart_order_id', $order['details']['BT']->virtuemart_order_id);
         //JRequest::setVar('tmpl', 'component');
         $html2 = $this->getVMView('orders', array(), 'orders', 'details', 'html');
     }
     $allhtml = $html1 . $html2;
     $this->runExtAfter($allhtml);
     echo $allhtml;
     JRequest::setVar('html', '');
     JRequest::setVar('html', $allhtml);
     JRequest::setVar('view', 'cart');
     $_REQUEST['view'] = 'cart';
     $_POST['view'] = 'cart';
     $_GET['view'] = 'cart';
     if (!empty($theme_fix1)) {
         JRequest::setVar('layout', 'order_done');
     }
     /*
     	  	$_GET = $savedGET; 
     	    $_POST = $savedPOST; 
     	    $_REQUEST = $savedREQUEST; 
     */
     return;
 }
예제 #2
0
 private static function renderMail($viewName, $recipient, $vars = array(), $controllerName = NULL, $noVendorMail = FALSE, $useDefault = true)
 {
     if (!class_exists('VirtueMartControllerVirtuemart')) {
         require JPATH_VM_SITE . DS . 'controllers' . DS . 'virtuemart.php';
     }
     $controller = new VirtueMartControllerVirtuemart();
     $controller->addViewPath(JPATH_VM_SITE . DS . 'views');
     $view = $controller->getView($viewName, 'html');
     if (!$controllerName) {
         $controllerName = $viewName;
     }
     $controllerClassName = 'VirtueMartController' . ucfirst($controllerName);
     if (!class_exists($controllerClassName)) {
         require JPATH_VM_SITE . DS . 'controllers' . DS . $controllerName . '.php';
     }
     $view->addTemplatePath(JPATH_VM_SITE . '/views/' . $viewName . '/tmpl');
     $vmtemplate = VmConfig::get('vmtemplate', 'default');
     if ($vmtemplate == 'default') {
         if (JVM_VERSION >= 2) {
             $q = 'SELECT `template` FROM `#__template_styles` WHERE `client_id`="0" AND `home`="1"';
         } else {
             $q = 'SELECT `template` FROM `#__templates_menu` WHERE `client_id`="0" AND `menuid`="0"';
         }
         $db = JFactory::getDbo();
         $db->setQuery($q);
         $template = $db->loadResult();
     } else {
         $template = $vmtemplate;
     }
     if ($template) {
         $view->addTemplatePath(JPATH_ROOT . DS . 'templates' . DS . $template . DS . 'html' . DS . 'com_virtuemart' . DS . $viewName);
     }
     foreach ($vars as $key => $val) {
         $view->{$key} = $val;
     }
     $user = FALSE;
     $user = OPCcheckout::sendVmMail($view, $recipient, $noVendorMail);
 }