/** * Take a data array and save any address info found in the array. * * @author unknown, oscar, max milbers * @param array $data (Posted) user data * @param sting $_table Table name to write to, null (default) not to write to the database * @param boolean $_cart Attention, this was deleted, the address to cart is now done in the controller (True to write to the session (cart)) * @return boolean True if the save was successful, false otherwise. */ function storeAddress(&$data) { $user = JFactory::getUser(); $userinfo = $this->getTable('userinfos'); $manager = ($user->authorise('core.admin', 'com_virtuemart') or $user->authorise('core.manage', 'com_virtuemart')); if ($data['address_type'] == 'BT') { if (isset($data['virtuemart_userinfo_id']) and $data['virtuemart_userinfo_id'] != 0) { if (!$manager) { $userinfo->load($data['virtuemart_userinfo_id']); if ($userinfo->virtuemart_user_id != $user->id) { vmError('Hacking attempt as admin?', 'Hacking attempt storeAddress'); return false; } } } else { if (!$manager) { $userId = $user->id; } else { $userId = (int) $data['virtuemart_user_id']; } $q = 'SELECT `virtuemart_userinfo_id` FROM #__virtuemart_userinfos WHERE `virtuemart_user_id` = ' . $userId . ' AND `address_type` = "BT"'; $db = JFactory::getDbo(); $db->setQuery($q); $total = $db->loadColumn(); if (count($total) > 0) { $data['virtuemart_userinfo_id'] = (int) $total[0]; } else { $data['virtuemart_userinfo_id'] = 0; //md5(uniqid($this->virtuemart_user_id)); } $userinfo->load($data['virtuemart_userinfo_id']); //unset($data['virtuemart_userinfo_id']); } $data = (array) $data; if (!$this->validateUserData($data, 'BT')) { return false; } $userInfoData = self::_prepareUserFields($data, 'BT', $userinfo); //vmdebug('model user storeAddress',$data); if (!$userinfo->bindChecknStore($userInfoData)) { vmError('storeAddress ' . $userinfo->getError()); } } // Check for fields with the the 'shipto_' prefix; that means a (new) shipto address. if ($data['address_type'] == 'ST' or isset($data['shipto_address_type_name'])) { $dataST = array(); $_pattern = '/^shipto_/'; foreach ($data as $_k => $_v) { if (preg_match($_pattern, $_k)) { $_new = preg_replace($_pattern, '', $_k); $dataST[$_new] = $_v; } } $userinfo = $this->getTable('userinfos'); if (isset($dataST['virtuemart_userinfo_id']) and $dataST['virtuemart_userinfo_id'] != 0) { $dataST['virtuemart_userinfo_id'] = (int) $dataST['virtuemart_userinfo_id']; if (!$manager) { $userinfo->load($dataST['virtuemart_userinfo_id']); $user = JFactory::getUser(); if ($userinfo->virtuemart_user_id != $user->id) { vmError('Hacking attempt as admin?', 'Hacking attempt store address'); return false; } } } if (empty($userinfo->virtuemart_user_id)) { if (!$manager) { $dataST['virtuemart_user_id'] = $user->id; } else { if (isset($data['virtuemart_user_id'])) { $dataST['virtuemart_user_id'] = (int) $data['virtuemart_user_id']; } else { //Disadvantage is that admins should not change the ST address in the FE (what should never happen anyway.) $dataST['virtuemart_user_id'] = $user->id; } } } if (!is_array($dataST)) { $dataST = (array) $dataST; } if (!$this->validateUserData($dataST, 'ST')) { return false; } $dataST['address_type'] = 'ST'; $userfielddata = self::_prepareUserFields($dataST, 'ST', $userinfo); if (!$userinfo->bindChecknStore($userfielddata)) { vmError($userinfo->getError()); } $app = JFactory::getApplication(); if ($app->isSite()) { if (!class_exists('VirtueMartCart')) { require JPATH_VM_SITE . DS . 'helpers' . DS . 'cart.php'; } $cart = VirtuemartCart::getCart(); if ($cart) { $cart->selected_shipto = $userinfo->virtuemart_userinfo_id; } } } return $userinfo->virtuemart_userinfo_id; }
* @link http://www.virtuemart.net * @copyright Copyright (c) 2014 VirtueMart Team. All rights reserved. * @license http://www.gnu.org/copyleft/gpl.html GNU/GPL2, see LICENSE.php * @version $Id: cart.php 7682 2014-02-26 17:07:20Z Milbo $ */ defined('_JEXEC') or die('Restricted access'); $_prefix = $viewData['prefix']; $field = $viewData['field']; $tos = $field['value']; $app = JFactory::getApplication(); if ($app->isSite()) { vmJsApi::popup('#full-tos', '#terms-of-service'); if (!class_exists('VirtueMartCart')) { require VMPATH_SITE . DS . 'helpers' . DS . 'cart.php'; } $cart = VirtuemartCart::getCart(); $cart->prepareVendor(); if (empty($tos) and !VmConfig::get('agree_to_tos_onorder', true)) { if (is_array($cart->BT) and !empty($cart->BT['tos'])) { $tos = $cart->BT['tos']; } } } if (!class_exists('VmHtml')) { require VMPATH_ADMIN . DS . 'helpers' . DS . 'html.php'; } echo VmHtml::checkbox($_prefix . $field['name'], $tos, 1, 0, 'class="terms-of-service required"', 'tos'); if (VmConfig::get('oncheckout_show_legal_info', 1) and $app->isSite()) { ?> <div class="terms-of-service"> <label for="tos">
public function customizeFieldsPerOPCConfig(&$userFields) { if (empty($userFields)) { return; } if (count($userFields['fields']) === 0) { // no fields found return ''; } require_once JPATH_ROOT . DS . 'components' . DS . 'com_onepage' . DS . 'helpers' . DS . 'userfields.php'; include JPATH_ROOT . DS . 'components' . DS . 'com_onepage' . DS . 'config' . DS . 'onepage.cfg.php'; /* $newf = array(); $newf['fields'] = array(); if (isset($userFields['fields']['name'])) $newf['fields']['name'] = $userFields['fields']['name']; */ $user = JFactory::getUser(); $user_id = $user->get('id'); if (empty($user_id)) { if (isset($userFields['fields']['password'])) { if (VM_REGISTRATION_TYPE == 'OPTIONAL_REGISTRATION') { $ra = array(); $ra['formcode'] = '<input type="checkbox" autocomplete="off" id="register_account" name="register_account" value="1" class="inputbox checkbox inline" onchange="Onepage.showFields( this.checked, new Array('; if (empty($op_usernameisemail)) { $ra['formcode'] .= '\'username\', \'password\', \'password2\', \'opc_password\''; } else { $ra['formcode'] .= '\'password\', \'password2\', \'opc_password\''; } $ra['formcode'] .= ') );" '; if (empty($op_create_account_unchecked)) { $ra['formcode'] .= ' checked="checked" '; } $ra['formcode'] .= '/>'; $ra['name'] = 'register_account'; $ra['title'] = OPCLang::_('COM_VIRTUEMART_ORDER_REGISTER'); $ra['required'] = false; $ra['type'] = 'checkbox'; $ra['readonly'] = false; $ra['hidden'] = false; $ra['description'] = ''; $userFields['fields']['register_account'] = $ra; } } } if (!class_exists('VirtueMartCart')) { require JPATH_VM_SITE . DS . 'helpers' . DS . 'cart.php'; } $cart = VirtuemartCart::getCart(); require_once JPATH_ROOT . DS . 'components' . DS . 'com_onepage' . DS . 'helpers' . DS . 'userfields.php'; OPCUserFields::getUserFields($userFields, $this, $cart); $user = JFactory::getUser(); $uid = $user->get('id'); $guest = $user->get('guest'); if (empty($guest) || !empty($uid)) { $arr = array('password', 'opc_password', 'password2', 'opc_password2', 'username', 'virtuemart_state_id', 'shipto_virtuemart_state_id'); foreach ($userFields['fields'] as $key => $f) { if (in_array($key, $arr)) { $userFields['fields'][$key]['formcode'] = str_replace('required', 'notrequired', $f['formcode']); $userFields['fields'][$key]['required'] = false; } if ($key == 'virtuemart_state_id') { } } } }
public static function loadOPCcartView() { include JPATH_ROOT . DIRECTORY_SEPARATOR . 'components' . DIRECTORY_SEPARATOR . 'com_onepage' . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . 'onepage.cfg.php'; $task = JRequest::getWord('task'); $option = JRequest::getWord('option'); $view = JRequest::getWord('view'); $layout = JRequest::getVar('layout', ''); $controller = JRequest::getWord('controller', JRequest::getWord('view', 'virtuemart')); if ($view == 'cart2') { $view = 'opc'; $_POST['view'] = 'opc'; $_GET['view'] = 'opc'; $_REQUEST['view'] = 'opc'; $controller = 'opc'; JRequest::setVar('view', 'opc'); JRequest::setVar('task', 'cart'); } if ($view == 'cart' || $view == 'opc' || $view == 'user' && $task == 'editaddresscheckout' || $task == 'pluginUserPaymentCancel' || $task == 'editaddresscart') { if (!defined('JPATH_VM_SITE')) { if (!class_exists('VmConfig')) { require JPATH_ADMINISTRATOR . DIRECTORY_SEPARATOR . 'components' . DIRECTORY_SEPARATOR . 'com_virtuemart' . DIRECTORY_SEPARATOR . 'helpers' . DIRECTORY_SEPARATOR . 'config.php'; } VmConfig::loadConfig(); } // require_once(dirname(__FILE__) . DS . 'loader.php'); //overrides'.DIRECTORY_SEPARATOR.'vmplugin.php'); if (!class_exists('VirtueMartViewCart')) { if (!empty($opc_memory)) { ini_set('memory_limit', $opc_memory); } else { ini_set('memory_limit', '128M'); } // we must disable chosen as it causes lot's of troubles: require_once JPATH_OPC . DIRECTORY_SEPARATOR . 'overrides' . DIRECTORY_SEPARATOR . 'virtuemart.cart.view.html.php'; } else { // opc will not load because some other extension is using cart view override return false; } if ($view == 'user') { if (!class_exists('VirtueMartViewUser')) { require JPATH_OPC . DIRECTORY_SEPARATOR . 'overrides' . DIRECTORY_SEPARATOR . 'virtuemart.user.view.html.php'; } JRequest::setVar('layout', 'default'); JRequest::setVar('view', 'cart'); } unset($_POST['checkout']); unset($_GET['checkout']); unset($_REQUEST['checkout']); unset($_POST['confirm']); unset($_GET['confirm']); unset($_REQUEST['confirm']); if (!class_exists('VirtueMartCart')) { require JPATH_SITE . DIRECTORY_SEPARATOR . 'components' . DIRECTORY_SEPARATOR . 'com_virtuemart' . DIRECTORY_SEPARATOR . 'helpers' . DIRECTORY_SEPARATOR . 'cart.php'; } $cart = VirtuemartCart::getCart(); $cart->_redirect = false; $cart->_redirect_disabled = true; //include_once(JPATH_OPC.DIRECTORY_SEPARATOR.'overrides'.DIRECTORY_SEPARATOR.'cart.php'); } else { return false; } if ($controller === 'opc') { if (strpos($controller, '..') !== false) { die('?'); } require_once JPATH_SITE . DIRECTORY_SEPARATOR . 'components' . DIRECTORY_SEPARATOR . 'com_onepage' . DIRECTORY_SEPARATOR . 'controllers' . DIRECTORY_SEPARATOR . 'opc.php'; // fix 206 bug here: /* if (!class_exists('VmFilter')) require_once(JPATH_SITE.DIRECTORY_SEPARATOR.'components'.DIRECTORY_SEPARATOR.'com_onepage'.DIRECTORY_SEPARATOR.'overrides'.DIRECTORY_SEPARATOR.'vmfilter.php'); */ } // proceed return true; }
function opcregister() { if (!class_exists('OPCLang')) { require JPATH_ROOT . DIRECTORY_SEPARATOR . 'components' . DIRECTORY_SEPARATOR . 'com_onepage' . DIRECTORY_SEPARATOR . 'helpers' . DIRECTORY_SEPARATOR . 'language.php'; } OPCLang::loadLang(); $this->checkVM2Captcha('index.php?option=com_virtuemart&view=user'); 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 . 'loader.php'; $msg = ''; //$this->saveData(false,true); if (!class_exists('VmConfig')) { require JPATH_ADMINISTRATOR . DS . 'components' . DS . 'com_virtuemart' . DS . 'helpers' . DS . 'config.php'; } VmConfig::loadConfig(); $data = JRequest::get('post'); $userinfo_id = (int) JRequest::getInt('virtuemart_userinfo_id', 0); $data['address_type'] = JRequest::getWord('addrtype', JRequest::getWord('address_type', 'BT')); if ($data['address_type'] == 'BT') { $prefix = ''; $data['shipto_virtuemart_userinfo_id'] = null; } else { $prefix = 'shipto_'; $data['shipto_virtuemart_userinfo_id'] = $userinfo_id; } $data['quite'] = false; $adminmode = false; // logged in users if (!empty($userinfo_id)) { $q = 'select * from #__virtuemart_userinfos where virtuemart_userinfo_id = ' . $userinfo_id . ' limit 0,1'; $db = JFactory::getDBO(); $db->setQuery($q); $res = $db->loadAssoc(); // if user is already registered: $user = JFactory::getUser(); $uidc = (int) $user->get('id'); $data['virtuemart_user_id'] = $uidc; if (!empty($res)) { $address_type = $res['address_type']; $uid = (int) $res['virtuemart_user_id']; if (!empty($uid)) { // 1st security, user ids must match if ($uid != $uidc) { require_once JPATH_ROOT . DS . 'components' . DS . 'com_onepage' . DS . 'helpers' . DS . 'mini.php'; if (!OPCmini::isSuperVendor()) { $msg = 'OPC: Access Denied'; return $this->returnTerminate($msg); } else { $adminmode = true; } } JRequest::setVar('virtuemart_user_id', $uid); $data['virtuemart_user_id'] = $uid; } } if (!$adminmode) { if (empty($data['user_id'])) { $data['user_id'] = $uidc; $data['virtuemart_user_id'] = $uidc; $data[$prefix . 'user_id'] = $uidc; $data[$prefix . 'virtuemart_user_id'] = $uidc; } $username = $user->get('username'); $email = $user->get('email'); if (empty($data['username']) && !empty($username)) { $data['username'] = $username; $data[$prefix . 'username'] = $username; } else { if (empty($data['username']) && !empty($email)) { $data['username'] = $email; $data[$prefix . 'username'] = $email; } } if (empty($data[$prefix . 'email'])) { $data[$prefix . 'email'] = $email; } $doUpdate = true; } // address name override: if (empty($data[$prefix . 'name'])) { if (!empty($res)) { $data[$prefix . 'name'] = $res['address_type_name']; } else { $data[$prefix . 'name'] = ''; } if (!empty($data[$prefix . 'first_name'])) { $data['name'] .= $data[$prefix . 'first_name']; } if (!empty($data[$prefix . 'last_name'])) { $data[$prefix . 'name'] .= $data[$prefix . 'last_name']; } } // end of logged in user OPCloader::setRegType(); //NO_REGISTRATION, NORMAL_REGISTRATION, SILENT_REGISTRATION, OPTIONAL_REGISTRATION if (VM_REGISTRATION_TYPE == 'NO_REGISTRATION') { $register = false; } else { if (VM_REGISTRATION_TYPE == 'NORMAL_REGISTRATION') { $register = true; } else { if (VM_REGISTRATION_TYPE == 'SILENT_REGISTRATION') { $register = true; } else { if (VM_REGISTRATION_TYPE == 'OPTIONAL_REGISTRATION') { $register = JRequest::getVar('register_account', false); } } } } $mainframe = JFactory::getApplication(); $msg = ''; $userModel = OPCmini::getModel('user'); if ($user->guest != 1 || $register) { self::getVendorDataStored($data); } // update address of already registered user /* if (!empty($doUpdate)) { $this->userStoreAddress($userModel, $data); return $this->returnTerminate(''); } */ } $cart = VirtuemartCart::getCart(); 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); } $this->prepareFields(); $this->setCartAddress($cart); $this->setExtAddress($cart, false); // k2 mod with recaptcha enabled $session = JFactory::getSession(); $orig = $session->get('socialConnectData'); $session->set('socialConnectData', true); // end p1 k2 mod with recaptcha enabled $data = JRequest::get('post'); $reg = JRequest::getVar('register_account'); if (empty($reg)) { $reg = false; } else { $reg = true; } if (!isset($data['address_type'])) { $data['address_type'] = 'BT'; } if ($data['address_type'] == 'ST') { if (!isset($data['ship_to_info_id'])) { $data['ship_to_info_id'] = 'new'; } // opc hack: $data['sa'] = 'adresaina'; $suid = JRequest::getVar('shipto_virtuemart_userinfo_id', JRequest::getVar('virtuemart_userinfo_id')); if (empty($suid)) { $data['opc_st_changed_new'] = true; } JRequest::setVar('opc_st_changed_new', true); JRequest::setVar('sa', 'adresaina'); } $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 return $this->returnTerminate($msg); }
public static function addtocartaslink(&$ref) { $c = get_class($ref->cart); if ($c != 'VirtuemartCart') { $ref->cart = VirtuemartCart::getCart(); } include JPATH_ROOT . DS . 'components' . DS . 'com_onepage' . DS . 'config' . DS . 'onepage.cfg.php'; $rememberhtml = ''; $rp = JRequest::getVar('randomproduct', 0); if (!empty($rp)) { if (OPCloader::checkOPCSecret()) { $opc_link_type = 1; $q = 'select virtuemart_product_id from #__virtuemart_products where published=1 limit 1'; $db = JFactory::getDBO(); $db->setQuery($q); $temp_id = $db->loadResult(); JRequest::setVar('add_id', $temp_id); } } if (empty($opc_link_type)) { return; } $p_id = JRequest::getVar('add_id', ''); if (empty($p_id)) { return; } if (!isset($ref->cart->order_number)) { $ref->cart->order_number = ''; } if (!empty($p_id)) { $qq = array(); if (is_array($p_id)) { foreach ($p_id as $i => $item) { if (!is_numeric($p_id[$i])) { break; } $q = JRequest::getVar('qadd_' . $p_id[$i], 1); if (!is_numeric($q)) { break; } $rememberhtml .= '<input type="hidden" name="qadd_' . $p_id[$i] . '" value="' . $q . '" />'; $rememberhtml .= '<input type="hidden" name="add_id[' . $i . ']" value="' . $p_id[$i] . '" />'; $q = (double) $q; $qq[$p_id[$i]] = $q; } } else { // you can use /index.php?option=com_virtuemart&page=shop.cart&add_id=10&quadd=1; // to add two products (ids: 10 and 11) of two quantity each (quadd_11=2 for product id 11 set quantity 2) // OR /index.php?option=com_virtuemart&page=shop.cart&add_id[]=10&quadd_10=2&add_id[]=11&qadd_11=2 $q = JRequest::getVar('qadd_' . $p_id, 1); $rememberhtml .= '<input type="hidden" name="qadd_' . $p_id . '" value="' . $q . '" />'; $rememberhtml .= '<input type="hidden" name="add_id" value="' . $p_id . '" />'; $q = (double) $q; $q2 = JRequest::getVar('qadd', 1); //$rememberhtml .= '<input type="hidden" name="qadd" value="'.$q2.'" />'; if (!is_numeric($p_id)) { return; } $qq[$p_id] = $q; $a = array(); $a[$p_id] = $p_id; $p_id = $a; } } else { return; } $post = JRequest::get('default'); /* if (!class_exists('VirtueMartModelProduct')) require(JPATH_VM_ADMINISTRATOR . DS . 'models' . DS . 'product.php'); */ require_once JPATH_ROOT . DS . 'components' . DS . 'com_onepage' . DS . 'helpers' . DS . 'mini.php'; $productClass = OPCmini::getModel('product'); //new VirtueMartModelProduct(); //$virtuemart_product_ids = JRequest::getVar('virtuemart_product_id', array(), 'default', 'array'); //is sanitized then $newp = array(); $rr2 = array(); foreach ($p_id as $pid) { $newp[$pid] = $pid; $product = $productClass->getProductSingle($pid, true, true, true); $rr = OPCAddToCartAsLink::getProductCustomsFieldCart($product); $rr2[] = $rr; } if ($opc_link_type == 2 || $opc_link_type == 1) { if (!empty($ref->cart->products)) { $p = $ref->cart->products; foreach ($p as $key => $pr) { $id = $pr->virtuemart_product_id; // delete cart content if ($opc_link_type == 1) { if (isset($ref->cart->products[$key])) { $ref->cart->removeProductCart($key); } else { if (isset($ref->cart->product[$id])) { $ref->cart->removeProductCart($id); } } continue; } // do not increment quantity: if ($opc_link_type == 2) { if (in_array($id, $newp)) { return; } } } } } $virtuemart_product_ids = JRequest::setVar('virtuemart_product_id', $newp); //is sanitized then $virtuemart_product_ids = JRequest::setVar('quantity', $qq); //is sanitized then if (!empty($rr2)) { foreach ($rr2 as $rr1) { foreach ($rr1 as $post) { $x = JRequest::getVar($post['name']); if (empty($x)) { $test = array(); if (strpos($post['name'], ']') !== false) { $post['name'] = parse_str($post['name'] . '=' . $post['value'], $test); $firstkey = 0; if (!empty($test)) { foreach ($test as $key => $val) { $firstkey = $key; break; } } $name = $firstkey; $value = $test[$name]; JRequest::setVar($name, $value); } else { JRequest::setVar($post['name'], $post['value']); } } } } } if (!empty($opc_auto_coupon)) { $ref->cart->couponCode = $opc_auto_coupon; } $ref->cart->add(); JRequest::setVar('virtuemart_product_id', ''); JRequest::setVar('add_id', ''); JRequest::setVar('opc_adc', 1); //$quantityPost = (int) $post['quantity'][$p_key]; return $rememberhtml; }