/** * Bind the post data to the JUser object and the VM tables, then saves it * It is used to register new users * This function can also change already registered users, this is important when a registered user changes his email within the checkout. * * @author Max Milbers * @author Oscar van Eijk * @return boolean True is the save was successful, false otherwise. */ public static function storeVM25(&$data, $checkToken = TRUE, &$userModel, $opc_no_activation = false, &$opc) { $message = ''; $user = ''; $newId = 0; if ($checkToken) { JRequest::checkToken() or jexit('Invalid Token, while trying to save user'); } $mainframe = JFactory::getApplication(); if (empty($data)) { vmError('Developer notice, no data to store for user'); return false; } //To find out, if we have to register a new user, we take a look on the id of the usermodel object. //The constructor sets automatically the right id. $user = JFactory::getUser(); $user_id = $user->id; $new = $user->id < 1; if (empty($user_id)) { $user = new JUser(); //thealmega http://forum.virtuemart.net/index.php?topic=99755.msg393758#msg393758 } else { $user = JFactory::getUser($user_id); } $gid = $user->get('gid'); // Save original gid // Preformat and control user datas by plugin JPluginHelper::importPlugin('vmuserfield'); $dispatcher = JDispatcher::getInstance(); $valid = true; $dispatcher->trigger('plgVmOnBeforeUserfieldDataSave', array(&$valid, $user_id, &$data, $user)); // $valid must be false if plugin detect an error if ($valid == false) { return false; } // Before I used this "if($cart && !$new)" // This construction is necessary, because this function is used to register a new JUser, so we need all the JUser data in $data. // On the other hand this function is also used just for updating JUser data, like the email for the BT address. In this case the // name, username, password and so on is already stored in the JUser and dont need to be entered again. if (empty($data['email'])) { $email = $user->get('email'); if (!empty($email)) { $data['email'] = $email; } } $data['email'] = str_replace(array('\'', '"', ',', '%', '*', '/', '\\', '?', '^', '`', '{', '}', '|', '~'), array(''), $data['email']); unset($data['isRoot']); unset($data['groups']); unset($data['_authGroups']); //This is important, when a user changes his email address from the cart, //that means using view user layout edit_address (which is called from the cart) $user->set('email', $data['email']); if (empty($data['name'])) { $name = $user->get('name'); if (!empty($name)) { $data['name'] = $name; } } if (empty($data['name'])) { $data['name'] = ''; if (!empty($data['first_name'])) { $data['name'] = $data['first_name']; } if ($data['name'] == '_') { $data['name'] = ''; } if (!empty($data['last_name'])) { $data['name'] = $data['last_name']; } if ($data['name'] == '_') { $data['name'] = ''; } if (empty($data['name'])) { $data['name'] = $data['username']; } if ($data['name'] == '_') { $data['name'] = ''; } if (empty($data['name'])) { $data['name'] = $data['email']; } } if (empty($data['username'])) { $username = $user->get('username'); if (!empty($username)) { $data['username'] = $username; } else { $data['username'] = JRequest::getVar('username', '', 'post', 'username'); if (empty($data['username'])) { $data['username'] = $data['email']; } } } if (empty($data['password'])) { $data['password'] = JRequest::getVar('password', '', 'post', 'string', JREQUEST_ALLOWRAW); } if (empty($data['password2'])) { $data['password2'] = JRequest::getVar('password2', '', 'post', 'string', JREQUEST_ALLOWRAW); } if (!$new && !empty($data['password']) && empty($data['password2'])) { unset($data['password']); unset($data['password2']); } $usersConfig = JComponentHelper::getParams('com_users'); $usernamechange = $usersConfig->get('change_login_name', true); if (!$new) { if (empty($usernamechange)) { $data['username'] = $user->get('username'); } } if (!$user->authorise('core.admin', 'com_virtuemart')) { $whiteDataToBind = array(); $whiteDataToBind['name'] = $data['name']; $whiteDataToBind['username'] = $data['username']; $whiteDataToBind['email'] = $data['email']; if (isset($data['password'])) { $whiteDataToBind['password'] = $data['password']; } if (isset($data['password2'])) { $whiteDataToBind['password2'] = $data['password2']; } } else { $whiteDataToBind = $data; } // Bind Joomla userdata if (!$user->bind($whiteDataToBind)) { foreach ($user->getErrors() as $error) { // vmError('user bind '.$error); vmError('user bind ' . $error, JText::sprintf('COM_VIRTUEMART_USER_STORE_ERROR', $error)); } $message = 'Couldnt bind data to joomla user'; } if ($new) { // If user registration is not allowed, show 403 not authorized. // But it is possible for admins and storeadmins to save /* JPluginHelper::importPlugin('user'); JPluginHelper::importPlugin('system'); $dispatcher = JDispatcher::getInstance(); $valid = true ; $dispatcher->trigger('onAfterStoreUser',array($user,true,true,'' )); */ if (!defined('VM_VERSION') || VM_VERSION < 3) { if (!class_exists('Permissions')) { require JPATH_VM_ADMINISTRATOR . DS . 'helpers' . DS . 'permissions.php'; } if (!Permissions::getInstance()->check("admin,storeadmin") && $usersConfig->get('allowUserRegistration') == '0') { VmConfig::loadJLang('com_virtuemart'); //JError::raiseError( 403, JText::_('COM_VIRTUEMART_ACCESS_FORBIDDEN')); $data['virtuemart_user_id'] = 0; unset($data['username']); unset($data['password']); unset($data['password2']); $user = new JUser(); $userModel->_id = 0; //$userModel->saveUserData($data); $opc->userStoreAddress($userModel, $data); return false; } $authorize = JFactory::getACL(); } else { $authorize = JFactory::getUser(); if (!($authorize->authorise('core.admin', 'com_virtuemart') or $authorize->authorise('core.manage', 'com_virtuemart')) and $usersConfig->get('allowUserRegistration') == '0') { VmConfig::loadJLang('com_virtuemart'); vmError(vmText::_('COM_VIRTUEMART_ACCESS_FORBIDDEN')); $data['virtuemart_user_id'] = 0; unset($data['username']); unset($data['password']); unset($data['password2']); $user = new JUser(); $userModel->_id = 0; //$userModel->saveUserData($data); $opc->userStoreAddress($userModel, $data); return false; } } // Initialize new usertype setting $newUsertype = $usersConfig->get('new_usertype'); if (!$newUsertype) { if (JVM_VERSION === 1) { $newUsertype = 'Registered'; } else { $newUsertype = 2; } } // Set some initial user values $user->set('usertype', $newUsertype); if (JVM_VERSION === 1) { $user->set('gid', $authorize->get_group_id('', $newUsertype, 'ARO')); } else { $user->groups[] = $newUsertype; } $date = JFactory::getDate(); if (method_exists($date, 'toMySQL')) { $user->set('registerDate', $date->toMySQL()); } else { $user->set('registerDate', $date->toSQL()); } // If user activation is turned on, we need to set the activation information $useractivation = $usersConfig->get('useractivation'); if (!empty($opc_no_activation)) { $useractivation = false; } $doUserActivation = false; if (JVM_VERSION === 1) { if ($useractivation == '1') { $doUserActivation = true; } } else { if ($useractivation == '1' or $useractivation == '2') { $doUserActivation = true; } } vmdebug('user', $useractivation, $doUserActivation); if ($doUserActivation) { jimport('joomla.user.helper'); if (method_exists('JApplication', 'getHash')) { $user->set('activation', JApplication::getHash(JUserHelper::genRandomPassword())); } else { $user->set('activation', JUtility::getHash(JUserHelper::genRandomPassword())); } //$user->set('activation', JUtility::getHash( JUserHelper::genRandomPassword()) ); $user->set('block', '1'); //$user->set('lastvisitDate', '0000-00-00 00:00:00'); } } $option = JRequest::getCmd('option'); // If an exising superadmin gets a new group, make sure enough admins are left... if (!$new && $user->get('gid') != $gid && $gid == __SUPER_ADMIN_GID) { if (method_exists($userModel, 'getSuperAdminCount')) { if ($userModel->getSuperAdminCount() <= 1) { vmError(JText::_('COM_VIRTUEMART_USER_ERR_ONLYSUPERADMIN')); return false; } } } if (isset($data['language'])) { $user->setParam('language', $data['language']); } else { if (isset($data['order_language'])) { $user->setParam('language', $data['order_language']); } } // Save the JUser object $regfail = false; if (!$user->save()) { vmError(JText::_($user->getError()), JText::_($user->getError())); $regfail = true; } //vmdebug('my user, why logged in? ',$user); if (!$regfail) { $newId = $user->get('id'); } else { $newId = 0; } $data['virtuemart_user_id'] = $newId; //We need this in that case, because data is bound to table later $regid = $user->get('id'); if (!empty($regid)) { $GLOBALS['opc_new_user'] = $user->get('id'); } else { $GLOBALS['opc_new_user'] = $newId; } //$this->setUserId($newId); $userModel->_id = $newId; $userModel->_data = null; //Save the VM user stuff if (!empty($data['quite'])) { $msgqx1 = JFactory::getApplication()->get('messageQueue', array()); $msgqx2 = JFactory::getApplication()->get('_messageQueue', array()); } if (!empty($newId)) { include JPATH_SITE . DS . 'components' . DS . 'com_onepage' . DS . 'config' . DS . 'onepage.cfg.php'; if ($new || $allow_sg_update) { $userdata = $userModel->saveUserData($data); $groups = array(); if (method_exists($userModel, 'getCurrentUser')) { $user2 = $userModel->getCurrentUser(); $groups = $user2->shopper_groups; } $shoppergroupmodel = VmModel::getModel('ShopperGroup'); $default = $shoppergroupmodel->getDefault(0); if (!empty($default)) { $default_id = $default->virtuemart_shoppergroup_id; } else { $default_id = 1; } $default1 = $shoppergroupmodel->getDefault(1); if (!empty($default1)) { $default1 = $default1->virtuemart_shoppergroup_id; } else { $default1 = 2; } require_once JPATH_SITE . DS . 'components' . DS . 'com_onepage' . DS . 'helpers' . DS . 'shoppergroups.php'; OPCShopperGroups::getSetShopperGroup(false); $session = JFactory::getSession(); $ids = $session->get('vm_shoppergroups_add', array(), 'vm'); if (!empty($groups)) { $ids = array_merge($ids, $groups); } $remove = $session->get('vm_shoppergroups_remove', array(), 'vm'); if (!empty($remove)) { foreach ($remove as $sr) { foreach ($ids as $key => $sg) { if ($sg == $sr) { unset($ids[$key]); } } } } if (!empty($ids)) { foreach ($ids as $key => $sg) { if ($sg == $default) { unset($ids[$key]); } if (empty($sg)) { unset($ids[$key]); } if ($sg == $default1) { unset($ids[$key]); } } } if (empty($data['virtuemart_shoppergroup_id']) or $data['virtuemart_shoppergroup_id'] == $default->virtuemart_shoppergroup_id) { $data['virtuemart_shoppergroup_id'] = array(); } if (!empty($ids)) { $ids = array_unique($ids); //stAn, opc 250: $data['virtuemart_shoppergroup_id'] = $sg; $data['virtuemart_shoppergroup_id'] = $ids; // Bind the form fields to the table $db = JFactory::getDBO(); if (!empty($ids)) { foreach ($ids as $ssg) { $q = 'select * from #__virtuemart_vmuser_shoppergroups where virtuemart_user_id = ' . (int) $newId . ' and virtuemart_shoppergroup_id = ' . (int) $ssg . ' limit 0,1'; $db->setQuery($q); $res = $db->loadAssocList(); if (empty($res)) { $q = "insert into `#__virtuemart_vmuser_shoppergroups` (id, virtuemart_user_id, virtuemart_shoppergroup_id) values (NULL, " . (int) $newId . ", " . (int) $ssg . ")"; $db->setQuery($q); $db->query(); } } } } } } //$userAddress = $userModel->storeAddress($data); $userAddress = $opc->userStoreAddress($userModel, $data); if (!empty($data['quite'])) { $x = JFactory::getApplication()->set('messageQueue', $msgqx1); $x = JFactory::getApplication()->set('_messageQueue', $msgqx2); } if (empty($userdata) || empty($userAddress)) { // we will not show the error because if we display only register fields, but an account field is marked as required, it still gives an error if (empty($data['quite'])) { vmError('COM_VIRTUEMART_NOT_ABLE_TO_SAVE_USER_DATA'); } // vmError(Jtext::_('COM_VIRTUEMART_NOT_ABLE_TO_SAVE_USERINFO_DATA')); } if (!$regfail) { if ($new) { // make sure that VM has proper user: if (!empty($newId)) { //JFactory::getUser()->load($newId); if (!class_exists('VirtueMartViewUser')) { require_once JPATH_SITE . DS . 'components' . DS . 'com_onepage' . DS . 'overrides' . DS . 'virtuemart.user.registration.view.html.php'; } OPCUser::sendRegistrationEmail($user, $user->password_clear, $doUserActivation, $data); } if ($doUserActivation) { vmInfo('COM_VIRTUEMART_REG_COMPLETE_ACTIVATE'); } else { //vmInfo('COM_VIRTUEMART_REG_COMPLETE'); $user->set('activation', ''); $user->set('block', '0'); $user->set('guest', '0'); } } } //The extra check for isset vendor_name prevents storing of the vendor if there is no form (edit address cart) // stAn, let's not alter vendor /* if((int)$data['user_is_vendor']==1 and isset($data['vendor_name'])){ vmdebug('vendor recognised '.$data['virtuemart_vendor_id']); if($userModel->storeVendorData($data)){ if ($new) { if ($doUserActivation ) { vmInfo('COM_VIRTUEMART_REG_VENDOR_COMPLETE_ACTIVATE'); } else { vmInfo('COM_VIRTUEMART_REG_VENDOR_COMPLETE'); } } else { vmInfo('COM_VIRTUEMART_VENDOR_DATA_STORED'); } } } */ return array('user' => $user, 'password' => $data['password'], 'message' => $message, 'newId' => $newId, 'success' => !$regfail); }
public static function setShopperGroupsController($cart = null) { // we need to alter shopper group for business when set to: $is_business = JRequest::getVar('opc_is_business', 0); $remove = array(); //require_once(JPATH_OPC.DS.'helpers'.DS.'loader.php'); OPCShopperGroups::getSetShopperGroup(); if (!class_exists('VirtueMartModelShopperGroup')) { if (file_exists(JPATH_VM_ADMINISTRATOR . DS . 'models' . DS . 'shoppergroup.php')) { require JPATH_VM_ADMINISTRATOR . DS . 'models' . DS . 'shoppergroup.php'; } else { return; } } if (!method_exists('VirtueMartModelShopperGroup', 'appendShopperGroups')) { return 1; } include JPATH_ROOT . DS . 'components' . DS . 'com_onepage' . DS . 'config' . DS . 'onepage.cfg.php'; if (!empty($business_shopper_group) || !empty($visitor_shopper_group)) { if (class_exists('VirtueMartModelShopperGroup')) { $shoppergroupmodel = new VirtueMartModelShopperGroup(); if (method_exists($shoppergroupmodel, 'removeSessionSgrps')) { if (method_exists($shoppergroupmodel, 'appendShopperGroups')) { if (!empty($is_business)) { // we will differenciate between default and anonymous shopper group // default is used for non-logged users // anononymous is used for logged in users as guests OPCShopperGroups::setShopperGroups($business_shopper_group); $remove[] = $visitor_shopper_group; // function appendShopperGroups(&$shopperGroups,$user,$onlyPublished = FALSE,$vendorId=1){ // remove previous: /* $session = JFactory::getSession(); $shoppergroup_ids = $session->get('vm_shoppergroups_add',array(),'vm'); $shoppergroupmodel->removeSessionSgrps($shoppergroup_ids); $new_shoppergroups = array(); $new_shoppergroups[] = $business_shopper_group; $shoppergroup_ids = $session->set('vm_shoppergroups_add',$new_shoppergroups,'vm'); $shoppergroupmodel->appendShopperGroups($new_shoppergroups, null); JRequest::setVar('virtuemart_shoppergroup_id', $new_shoppergroups, 'post'); */ //appendShopperGroups } else { OPCShopperGroups::setShopperGroups($visitor_shopper_group); $remove[] = $business_shopper_group; /* $shoppergroupmodel = new VirtueMartModelShopperGroup(); // function appendShopperGroups(&$shopperGroups,$user,$onlyPublished = FALSE,$vendorId=1){ // remove previous: $session = JFactory::getSession(); $shoppergroup_ids = $session->get('vm_shoppergroups_add',array(),'vm'); $shoppergroupmodel->removeSessionSgrps($shoppergroup_ids); $new_shoppergroups = array(); $new_shoppergroups[] = $visitor_shopper_group; $shoppergroup_ids = $session->set('vm_shoppergroups_add',$new_shoppergroups,'vm'); $shoppergroupmodel->appendShopperGroups($new_shoppergroups, null); JRequest::setVar('virtuemart_shoppergroup_id', $new_shoppergroups, 'post'); */ } } } } } // EU VAT shopper group: if (!empty($euvat_shopper_group)) { $removeu = true; $session = JFactory::getSession(); $vatids = $session->get('opc_vat', array()); if (!is_array($vatids)) { $vatids = @unserialize($vatids); } //BIT vat checker: if (!empty($vatids['field'])) { $euvat = JRequest::getVar($vatids['field'], ''); $euvat = preg_replace("/[^a-zA-Z0-9]/", "", $euvat); $euvat = strtoupper($euvat); if (!empty($cart)) { $address = $cart->ST == 0 ? $cart->BT : $cart->ST; $country = $address['virtuemart_country_id']; } else { $country = JRequest::getVar('virtuemart_country_id'); } $vathash = $country . '_' . $euvat; $home = 'NL'; if (!class_exists('ShopFunctions')) { require JPATH_VM_ADMINISTRATOR . DS . 'helpers' . DS . 'shopfunctions.php'; } $country_2_code = shopFunctions::getCountryByID($country, 'country_2_code'); $home = explode(',', $home_vat_countries); $list = array(); if (is_array($home)) { foreach ($home as $k => $v) { $list[] = strtoupper(trim($v)); } } else { $list[] = $v; } if (!in_array($country_2_code, $list)) { if (!empty($euvat)) { $euvat = strtoupper($euvat); if (!empty($vatids[$vathash])) { //change OPC VAT shopper group: OPCShopperGroups::setShopperGroups($euvat_shopper_group); $removeu = false; } } } } if ($removeu) { $remove[] = $euvat_shopper_group; } } OPCShopperGroups::setShopperGroups(-1, $remove); if (class_exists('calculationHelper')) { calculationHelper::$_instance = null; } $session = JFactory::getSession(); $shoppergroup_ids = $session->get('vm_shoppergroups_add', array(), 'vm'); }
static function getSetShopperGroup($debug = false) { require_once JPATH_SITE . DS . 'components' . DS . 'com_onepage' . DS . 'helpers' . DS . 'shoppergroups.php'; return OPCShopperGroups::getSetShopperGroup($debug); }
function opc() { if (!class_exists('VmConfig')) { require JPATH_ADMINISTRATOR . DS . 'components' . DS . 'com_virtuemart' . DS . 'helpers' . DS . 'config.php'; } VmConfig::loadConfig(); require_once JPATH_OPC . DS . 'helpers' . DS . 'loader.php'; OPCloader::$debugMsg = ''; //mobile handling: if (!defined('OPC_DETECTED_DEVICE')) { if (class_exists('OPCplugin')) { OPCplugin::detectMobile(); } } if (!class_exists('OPCLang')) { require JPATH_ROOT . DIRECTORY_SEPARATOR . 'components' . DIRECTORY_SEPARATOR . 'com_onepage' . DIRECTORY_SEPARATOR . 'helpers' . DIRECTORY_SEPARATOR . 'language.php'; } OPCLang::loadLang(); require_once JPATH_ROOT . DS . 'components' . DS . 'com_onepage' . DS . 'helpers' . DS . 'mini.php'; require_once JPATH_SITE . DS . 'components' . DS . 'com_onepage' . DS . 'helpers' . DS . 'shoppergroups.php'; //$this->setShopperGroups(); $userModel = OPCmini::getModel('user'); $cmd = JRequest::getVar('cmd', ''); if ($cmd === 'checkbitvat') { $checkvat = $this->checkBitVat(); } if ($cmd === 'checkvatopc') { $checkvat = $this->checkOPCVat(); } OPCShopperGroups::setShopperGroupsController(); if (method_exists($userModel, 'getCurrentUser')) { $user = $userModel->getCurrentUser(); self::$shopper_groups = $user->shopper_groups; if (!empty($user->virtuemart_shipmentmethod_id)) { $user->virtuemart_shipmentmethod_id = 0; $user->virtuemart_paymentmethod_id = 0; } } $session = JFactory::getSession(); $b = $session->set('eurobnk', null, 'vm'); if (empty($euvat_shopper_group)) { jimport('joomla.html.parameter'); if (class_exists('plgSystemBit_vm_change_shoppergroup')) { $session = JFactory::getSession(); $sg = $session->get('vm_shoppergroups_add', array(), 'vm'); $dispatcher = JDispatcher::getInstance(); JPluginHelper::importPlugin('system', 'plgSystemBit_vm_change_shoppergroup', true, $dispatcher); // very important $document = JFactory::getDocument(); JRequest::setVar('format_override', 'html'); $_REQUEST['view'] = 'cart'; $_REQUEST['option'] = 'com_virtuemart'; $doctype = $document->getType(); $dispatcher->trigger('onAfterRender'); JRequest::setVar('format_override', 'raw'); $sg = $session->get('vm_shoppergroups_add', array(), 'vm'); } } JResponse::setBody(''); // security: JRequest::setVar('virtuemart_shoppergroup_id', null, 'post'); if (!class_exists('VmConfig')) { require JPATH_ADMINISTRATOR . DS . 'components' . DS . 'com_virtuemart' . DS . 'helpers' . DS . 'config.php'; } VmConfig::loadConfig(true); // since vm2.0.21a we need to load the language files here if (method_exists('VmConfig', 'loadJLang')) { $lang = JFactory::getLanguage(); $extension = 'com_virtuemart'; $lang->load($extension); // when AJAX it needs to be loaded manually here >> in case you are outside virtuemart !!! VmConfig::loadJLang('com_virtuemart_orders', true); VmConfig::loadJLang('com_virtuemart_shoppers', true); } /// load shipping here $vars = JRequest::get('post'); // custom tag test $cmd = JRequest::getVar('cmd', 'get_shipping'); $doc = JFactory::getDocument(); $type = get_class($doc); if ($type == 'JDocumentRAW') { //C:\Documents and Settings\Rupos\Local Settings\Temp\scp02371\srv\www\clients\client1\web90\web\vm2\components\com_onepage\overrides\ //require_once(JPATH_SITE.DS.'components'.DS.'com_onepage'.DS.'overrides'.DS.'opchtml.php'); //JFactory::$instance = new JDocumentOpchtml(); //JFactory::$document = new JDocumentOpchtml(); } /* $doc->addCustomTag = create_function('$string', 'return;'); $doc->addCustomTag( '<!-- This is a comment. -->' ); */ $c = JRequest::getVar('virtuemart_currency_id', 0); JRequest::setVar('virtuemart_currency_id', (int) JRequest::getVar('virtuemart_currency_id')); /* to test the currency: */ $mainframe = Jfactory::getApplication(); $virtuemart_currency_id = $mainframe->getUserStateFromRequest("virtuemart_currency_id", 'virtuemart_currency_id', JRequest::getInt('virtuemart_currency_id')); // end custom tag test $view = $this->getView('cart', 'html'); $cmd = JRequest::getCmd('cmd', 'get_shipping'); $return = array(); $return['cmd'] = $cmd; if (!empty($checkvat)) { $return['checkvat'] = $checkvat; } $db = JFactory::getDBO(); $username = JRequest::getVar('username', ''); $user = JFactory::getUser(); $un = $user->get('username'); if ($un == $username) { // do not complain if entering the same username of already registered $return['username_exists'] = false; } else { if (!empty($username)) { $q = "select username from #__users where username = '******' limit 0,1"; $db->setQuery($q); $r = $db->loadResult(); if (!empty($r)) { $return['username_exists'] = true; } else { $return['username_exists'] = false; } } } if ($cmd === 'checkemail') { $email = JRequest::getVar('email', ''); $return['email'] = $email; $user = JFactory::getUser(); $ue = $user->get('email'); if ($email == $ue) { // do not complain if user is logged in and enters the same email address $return['email_exists'] = false; } else { if (!empty($email)) { $q = "select email from #__users where username = '******' or email = '" . $db->getEscaped($email) . "' limit 0,1"; $db->setQuery($q); $r = $db->loadResult(); if (!empty($r)) { $return['email_exists'] = true; } else { $return['email_exists'] = false; } } } } if ($cmd === 'get_klarna_address') { if (file_exists(JPATH_SITE . DS . 'plugins' . DS . 'vmpayment' . DS . 'klarna' . DS . 'klarna' . DS . 'api' . DS . 'klarna.php')) { $klarnaaddress = $this->getKlarnaAddress(); if (!empty($klarnaaddress)) { echo json_encode(array('cmd' => 'getKlarna', 'shipping' => 'opc_do_not_update', 'klarna' => $klarnaaddress, 'totals_html' => '', 'payment' => '')); $mainframe = JFactory::getApplication(); // do not allow further processing $mainframe->close(); } } } if (!defined('JPATH_OPC')) { define('JPATH_OPC', JPATH_SITE . DS . 'components' . DS . 'com_onepage'); } require_once JPATH_OPC . DS . 'helpers' . DS . 'loader.php'; require_once JPATH_OPC . DS . 'helpers' . DS . 'ajaxhelper.php'; include JPATH_ROOT . DS . 'components' . DS . 'com_onepage' . DS . 'config' . DS . 'onepage.cfg.php'; $OPCloader = new OPCloader(); $cart = VirtueMartCart::getCart(false); $opcsavedST = $cart->ST; $opcsavedBT = $cart->BT; $stopen = JRequest::getVar('shiptoopen', 0); if ($stopen === 'false') { $stopen = 0; } if (empty($stopen)) { $sa = JRequest::getVar('sa', ''); if ($sa == 'adresaina') { $stopen = 1; } } if ($stopen) { $restoreST = false; $restoreBT = true; } else { $cart->ST = 0; $restoreST = true; $restoreBT = false; } //$virtuemart_currency_id; = $mainframe->getUserStateFromRequest( "virtuemart_currency_id", 'virtuemart_currency_id',JRequest::getInt('virtuemart_currency_id') ); $cart->paymentCurrency = $virtuemart_currency_id; if (defined('VM_VERSION') && VM_VERSION >= 3) { if (method_exists($cart, 'prepareCartProducts')) { $cart->prepareCartProducts(); } } if ($cmd === 'getST') { require_once JPATH_ROOT . DS . 'components' . DS . 'com_onepage' . DS . 'helpers' . DS . 'loggedshopper.php'; $return['sthtml'] = OPCLoggedShopper::getSTHtml($cart); } if (!isset($cart->vendorId)) { $cart->vendorId = 1; } if ($cmd == 'updateattributes') { $arr = $this->updateattributes($cart); if (!empty($arr)) { foreach ($arr as $key => $val) { $return[$key] = $val; } } } if ($cmd == 'update_product') { if (defined('VM_VERSION') && VM_VERSION >= 3) { $quantity = JRequest::getVar('quantity'); if (!is_array($quantity)) { $cart_virtuemart_product_id = JRequest::getVar('cart_virtuemart_product_id'); $arr = array($cart_virtuemart_product_id => (int) $quantity); JRequest::setVar('quantity', $arr); $x = JRequest::getVar('quantity'); } } $cart->updateProductCart(); } if ($cmd == 'delete_product') { $cart->updateProductCart(); } if ($cmd == 'removecoupon') { JRequest::setVar('coupon_code', ''); $_REQUEST['coupon_code'] = $_POST['coupon_code'] = $_GET['coupon_code'] = ''; $cart->couponCode = ''; //$this->setCoupon($cart); $deletecouponmsg = true; } $cp = 0; if (method_exists($cart, 'prepareCartProducts')) { $cart->prepareCartProducts(); } $cart->setCartIntoSession(); $stopen = JRequest::getVar('shiptoopen', false); //if (!empty($stopen)) if ($stopen === 'true' || $stopen === '1') { $stopen = true; $sa = JRequest::setVar('sa', 'adresaina'); } else { $stopen = false; } //$this->setAddress($cart, true, $stopen); $this->setAddress($cart); $BT = $cart->BT; if ($stopen) { $this->setAddress($cart, true, $stopen); $cart->BT = $BT; } else { $cart->ST = 0; } //die('h'); $this->setExtAddress($cart, false, $stopen); $zip = JRequest::getVar('shipto_zip'); // IMPORTANT: this function calls shipping if Vm's automatic enabled if (method_exists($cart, 'prepareCartData')) { $cart->prepareCartData(false); } // US and Canada fix, show no tax for no state selected if (!isset($cart->BT['virtuemart_state_id'])) { $cart->BT['virtuemart_state_id'] = ''; } if (!empty($cart->ST)) { // if the VM uses BT address instead of ST address in calculation, uncomment the following line: // $cart->BT = $cart->ST; // this only applies to the display of the checkout, not actual saving of the data if (!isset($cart->ST['virtuemart_state_id'])) { $cart->ST['virtuemart_state_id'] = ''; } } @header('Content-Type: text/html; charset=utf-8'); @header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1 @header("Expires: Sat, 26 Jul 1997 05:00:00 GMT"); // Date in the past // run vm main controlle due to compatibilty JPluginHelper::importPlugin('vmextended'); JPluginHelper::importPlugin('vmuserfield'); $dispatcher = JDispatcher::getInstance(); $_controller = 'cart'; $trigger = 'onVmSiteController'; $trigger = 'plgVmOnMainController'; $dispatcher->trigger($trigger, array($_controller)); // this function will reload the taxes on products per country // this calls api methods as well, let's disable it for now: $cart->virtuemart_shipmentmethod_id = 0; if (method_exists($cart, 'prepareCartViewData')) { $cart->prepareCartViewData(); } if (!empty($virtuemart_currency_id)) { $cart->paymentCurrency = $virtuemart_currency_id; } if ($cmd == 'process_coupon') { $cart->couponCode = JRequest::getVar('coupon_code', ''); $this->setCoupon($cart); // set coupon } $view->cart = $cart; $view->assignRef('cart', $cart); //if (($cmd != 'runpay') && ($cmd != 'refreshPayment')) // this influences the recalculation of the basket: $cmds = array('process_coupon', 'refresh-totals', 'refresh_totals', 'removecoupon', 'delete_product', 'update_product', 'checkvatopc', 'delete_product', 'update_product', 'updateattributes', 'get_shipping'); if (empty($cmd) || in_array($cmd, $cmds) || stripos($cmd, 'shipping') !== false) { $shipping = $OPCloader->getShipping($view, $cart, true); $saved_totals = OPCloader::$totals_html; } else { $shipping = 'opc_do_not_update'; OPCloader::$totals_html = ''; } $return['shipping'] = $shipping; if (empty(OPCloader::$inform_html)) { OPCloader::$inform_html = array(); } $return['inform_html'] = implode('', OPCloader::$inform_html); if (!empty($cart->couponCode)) { $db = JFactory::getDBO(); $q = "select * from #__virtuemart_coupons where coupon_code = '" . $db->getEscaped($cart->couponCode) . "' limit 0,1"; $db->setQuery($q); $res = $db->loadAssoc(); if (!empty($res)) { if ($res['percent_or_total'] == 'percent') { $cp = $res['coupon_value']; } } if (empty($cp)) { if (OPCloader::tableExists('awocoupon')) { $db = JFactory::getDBO(); $q = "select * from #__awocoupon where coupon_code = '" . $db->getEscaped($cart->couponCode) . "' and coupon_value_type = 'percent' limit 0,1"; $db->setQuery($q); $res = $db->loadAssoc(); if (!empty($res)) { $cp = $res['coupon_value']; } } } } if (!empty($cp)) { $cp = (double) $cp; if (round($cp) == $cp) { $cp = (int) $cp . ' %'; } else { $cp = number_format($cp, 2, '.', ' ') . ' %'; } } $return['couponpercent'] = $cp; // get payment html $num = 0; if ($cmd == 'runpay') { $view->cart->virtuemart_shipmentmethod_id = JRequest::getVar('shipping_rate_id', ''); } $isexpress = OPCloader::isExpress($cart); $ph2_a = $OPCloader->getPayment($view, $num, false, $isexpress); $ph2 = $ph2_a['html']; $return['payment_extra'] = $ph2_a['extra']; /* if (!empty($ph_a['extra'])) { foreach ($ph_a['extra'] as $key=>$val) { $return['payment_extra'].$val; } } */ if ($cmd == 'runpay') { $cart->virtuemart_shipmentmethod_id = null; } if (!empty(OPCloader::$totalIsZero)) { $hide_payment_if_one = true; $num = 1; $ph2 = '<input type="hidden" value="0" name="virtuemart_paymentmethod_id" id="virtuemart_paymentmethod_id_0" />'; } if (!empty($hide_payment_if_one) && $num === 1 || $isexpress) { $ph = '<div class="payment_inner_html" rel="force_hide_payments">' . $ph2; } else { $ph = '<div class="payment_inner_html" rel="force_show_payments">' . $ph2; } $ph .= '</div>'; $return['payment'] = $ph; if (isset($saved_totals)) { $return['totals_html'] = $saved_totals; } else { $return['totals_html'] = OPCloader::$totals_html; } $return['min_pov'] = OPCloader::checkPurchaseValue($cart); if (!empty($return['totals_html'])) { $session = JFactory::getSession(); /* $r = $session->get('opcuniq'); if (empty($r)) { $rand = uniqid('', true); $session->set('opcuniq', $rand); $session->set($rand, '0'); } */ $rand = uniqid('', true); $return['totals_html'] .= '<input type="hidden" name="opcuniq" value="' . $rand . '" />'; } $t = $return['shipping'] . ' ' . $return['payment']; $t = str_replace('//<![CDATA[', '', $t); $t = str_replace('//]]> ', '', $t); $t = str_replace('<![CDATA[', '', $t); $t = str_replace(']]> ', '', $t); $t = str_replace('#paymentForm', '#adminForm', $t); //$t = str_replace('jQuery(document).ready(', ' jQuery( ', $t); $js = array(); if (strpos($t, '<script') !== false) { $xa = basketHelper::strposall($t, '<script'); foreach ($xa as $st) { // end of <script tag $x1 = strpos($t, '>', $st + 1); // end of </scrip tag $x2 = strpos($t, '</scrip', $st + 1); $js1 = substr($t, $x1 + 1, $x2 - $x1 - 1); $js[] = $js1; } } $return['shipping'] .= JHtml::_('form.token'); $return['payment'] .= JHtml::_('form.token'); if (isset(VmPlugin::$ccount)) { if (!empty($opc_debug)) { $js[] = "\n" . 'op_log("Positive cache match: ' . VmPlugin::$ccount . '");'; } } if (!empty($opc_debug)) { if (defined('OPCMEMSTART')) { $mem = memory_get_usage(true); $memd = $mem - OPCMEMSTART; $memd = (double) ($memd / 1024); $memd = number_format($memd, 0, '.', ' '); if (!defined('debugmem')) { $debugmem = $mem - OPCMEMSTART; $debugmem = (double) ($debugmem / 1024); } else { $debugmem = (double) (debugmem / 1024); } $debugmem = number_format($debugmem, 0, '.', ' '); $mem = (double) ($mem / 1024); $mem = number_format($mem, 0, '.', ' '); $js[] = "\n" . 'op_log("Memory usage: ' . $memd . 'kb of ' . $mem . 'kb, debug mem: ' . $debugmem . 'kb ");'; } } $return['javascript'] = $js; $return['opcplugins'] = OPCloader::getPluginData($cart); require_once JPATH_SITE . DS . 'components' . DS . 'com_onepage' . DS . 'helpers' . DS . 'removemsgs.php'; OPCremoveMsgs::removeMsgs($cart); $x = JFactory::getApplication()->getMessageQueue(); $arr = array(); $disablarray = array('Unrecognised mathop', JText::_('COM_VIRTUEMART_CART_PLEASE_ACCEPT_TOS')); include JPATH_SITE . DS . 'components' . DS . 'com_onepage' . DS . 'helpers' . DS . 'third_party' . DS . 'third_party_disable_msgs.php'; $euvat_text = array('VMUSERFIELD_ISTRAXX_EUVATCHECKER_INVALID', 'VMUSERFIELD_ISTRAXX_EUVATCHECKER_VALID', 'VMUSERFIELD_ISTRAXX_EUVATCHECKER_INVALID_COUNTRYCODE', 'VMUSERFIELD_ISTRAXX_EUVATCHECKER_INVALID_FORMAT_REASON', 'VMUSERFIELD_ISTRAXX_EUVATCHECKER_INVALID_FORMAT', 'VMUSERFIELD_ISTRAXX_EUVATCHECKER_SERVICE_UNAVAILABLE', 'VMUSERFIELD_ISTRAXX_EUVATCHECKER_COMPANYNAME_REQUIRED'); foreach ($euvat_text as $k => $t) { $tt = JText::_($t); $euvat_text[$k] = substr($tt, 0, 20); } $euvatinfo = ''; $remove = array(); foreach ($x as $key => $val) { foreach ($euvat_text as $kx => $eutext) { // echo 'comparing '.$eutext.' with '.$val['message']."<br />\n"; if (stripos($val['message'], $eutext) !== false) { $euvatinfo .= $val['message']; $remove[] = $key; break; } } foreach ($disablarray as $msg) { if (stripos($val['message'], $msg) !== false) { $remove[] = $key; } if (stripos($val['message'], JText::_('COM_VIRTUEMART_COUPON_CODE_INVALID')) !== false) { $cart->couponCode = ''; $cart->setCartIntoSession(); } } } if (!empty($euvatinfo)) { $return['checkvat'] = $euvatinfo; } foreach ($x as $key => $val) { if (!in_array($key, $remove)) { $arr[] = $val['message']; } } $return['msgs'] = $arr; if (!empty($opc_debug)) { if (!empty(OPCloader::$debugMsg)) { $return['debug_msgs'] = OPCloader::$debugMsg; } } if (!empty($cart->couponCode)) { $return['couponcode'] = $cart->couponCode; } else { $return['couponcode'] = ''; } require_once JPATH_SITE . DS . 'components' . DS . 'com_onepage' . DS . 'helpers' . DS . 'shoppergroups.php'; OPCShopperGroups::setShopperGroupsController($cart); $upd = array('update_product', 'delete_product', 'process_coupon', 'removecoupon', 'updateattribute', 'refreshall', 'updateattributes', 'checkvatopc', 'checkvat', 'vat_info'); if (in_array($cmd, $upd) || stripos($cmd, 'shipping') !== false || !empty($ajaxify_cart)) { if ($shipping == 'opc_do_not_update') { $shipping = ''; } if (!empty($ph2_a['html'])) { $payment_html = $op_payment = '<div id="payment_html">' . $ph2_a['html'] . '</div>'; } else { $payment_html = $op_payment = '<div id="payment_html"> </div>'; } $html = $this->getCartHtml($cart, $OPCloader, $shipping, $payment_html); $return['basket'] = $html; } $cart->virtuemart_shipmentmethod_id = 0; $cart->virtuemart_paymentmethod_id = 0; $cart->setCartIntoSession(); $x = @ob_get_clean(); $x = @ob_get_clean(); $x = @ob_get_clean(); $x = @ob_get_clean(); //echo json_encode(''); echo json_encode($return); //echo $shipping; $dispatcher = JDispatcher::getInstance(); $returnValues = $dispatcher->trigger('updateAbaData', array()); if ($restoreBT) { $cart->BT = $opcsavedBT; } if ($restoreST) { $cart->ST = $opcsavedST; } $cart->setCartIntoSession(); $mainframe = JFactory::getApplication(); // do not allow further processing $mainframe->close(); die; }