Ejemplo n.º 1
0
 /**
  * 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 function store(&$data)
 {
     $message = '';
     vRequest::vmCheckToken('Invalid Token, while trying to save user');
     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.
     $new = false;
     if (empty($this->_id) or $this->_id < 1) {
         $new = true;
         $user = new JUser();
         //thealmega http://forum.virtuemart.net/index.php?topic=99755.msg393758#msg393758
     } else {
         $cUser = JFactory::getUser();
         if (!vmAccess::manager('user.edit') and $cUser->id != $this->_id) {
             vmWarn('Insufficient permission');
             return false;
         }
         $user = JFactory::getUser($this->_id);
     }
     $gid = $user->get('gid');
     // Save original gid
     // Preformat and control user datas by plugin
     JPluginHelper::importPlugin('vmextended');
     JPluginHelper::importPlugin('vmuserfield');
     $dispatcher = JDispatcher::getInstance();
     $valid = true;
     $dispatcher->trigger('plgVmOnBeforeUserfieldDataSave', array(&$valid, $this->_id, &$data, $user));
     // $valid must be false if plugin detect an error
     if (!$valid) {
         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;
         }
     } else {
         $data['email'] = vRequest::filter($data['email'], FILTER_VALIDATE_EMAIL, FILTER_FLAG_STRIP_LOW | FILTER_FLAG_STRIP_HIGH);
     }
     //$data['email'] = str_replace(array('\'','"',',','%','*','/','\\','?','^','`','{','}','|','~'),array(''),$data['email']);
     //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;
         }
     } else {
         $data['name'] = vRequest::filter($data['name'], FILTER_SANITIZE_STRING, FILTER_FLAG_STRIP_LOW);
     }
     $data['name'] = str_replace(array('\'', '"', ',', '%', '*', '/', '\\', '?', '^', '`', '{', '}', '|', '~'), array(''), $data['name']);
     if (empty($data['username'])) {
         $username = $user->get('username');
         if (!empty($username)) {
             $data['username'] = $username;
         } else {
             $data['username'] = vRequest::filter($data['username'], FILTER_SANITIZE_STRING, FILTER_FLAG_STRIP_LOW);
         }
     }
     if (empty($data['password'])) {
         $data['password'] = vRequest::getCmd('password', '');
         if ($data['password'] != vRequest::get('password')) {
             vmError('Password contained invalid character combination.');
             return false;
         }
     }
     if (empty($data['password2'])) {
         $data['password2'] = vRequest::getCmd('password2');
         if ($data['password2'] != vRequest::get('password2')) {
             vmError('Password2 contained invalid character combination.');
             return false;
         }
     }
     if (!$new and empty($data['password2'])) {
         unset($data['password']);
         unset($data['password2']);
     }
     if (!vmAccess::manager('core')) {
         $whiteDataToBind = array();
         if (isset($data['name'])) {
             $whiteDataToBind['name'] = $data['name'];
         }
         if (isset($data['username'])) {
             $whiteDataToBind['username'] = $data['username'];
         }
         if (isset($data['email'])) {
             $whiteDataToBind['email'] = $data['email'];
         }
         if (isset($data['language'])) {
             $whiteDataToBind['language'] = $data['language'];
         }
         if (isset($data['editor'])) {
             $whiteDataToBind['editor'] = $data['editor'];
         }
         if (isset($data['password'])) {
             $whiteDataToBind['password'] = $data['password'];
         }
         if (isset($data['password2'])) {
             $whiteDataToBind['password2'] = $data['password2'];
         }
         unset($data['isRoot']);
     } else {
         $whiteDataToBind = $data;
     }
     // Bind Joomla userdata
     if (!$user->bind($whiteDataToBind)) {
         vmdebug('Couldnt bind data to joomla user');
         //array('user'=>$user,'password'=>$data['password'],'message'=>$message,'newId'=>$newId,'success'=>false);
     }
     if ($new) {
         // If user registration is not allowed, show 403 not authorized.
         // But it is possible for admins and storeadmins to save
         $usersConfig = JComponentHelper::getParams('com_users');
         $cUser = JFactory::getUser();
         if ($usersConfig->get('allowUserRegistration') == '0' and !vmAccess::manager('user')) {
             VmConfig::loadJLang('com_virtuemart');
             vmError(vmText::_('COM_VIRTUEMART_ACCESS_FORBIDDEN'));
             return;
         }
         // Initialize new usertype setting
         $newUsertype = $usersConfig->get('new_usertype');
         if (!$newUsertype) {
             $newUsertype = 2;
         }
         // Set some initial user values
         $user->set('usertype', $newUsertype);
         $user->groups[] = $newUsertype;
         $date = JFactory::getDate();
         $user->set('registerDate', $date->toSQL());
         // If user activation is turned on, we need to set the activation information
         $useractivation = $usersConfig->get('useractivation');
         $doUserActivation = false;
         if ($useractivation == '1' or $useractivation == '2') {
             $doUserActivation = true;
         }
         if ($doUserActivation) {
             jimport('joomla.user.helper');
             $user->set('activation', vRequest::getHash(JUserHelper::genRandomPassword()));
             $user->set('block', '1');
             //$user->set('lastvisitDate', '0000-00-00 00:00:00');
         }
     }
     $option = vRequest::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 ($this->getSuperAdminCount() <= 1) {
             vmError(vmText::_('COM_VIRTUEMART_USER_ERR_ONLYSUPERADMIN'));
             return false;
         }
     }
     if (isset($data['language'])) {
         $user->setParam('language', $data['language']);
     }
     // Save the JUser object
     if (!$user->save()) {
         $msg = vmText::sprintf('JLIB_APPLICATION_ERROR_SAVE_FAILED', $user->getError());
         vmError($msg, $msg);
         return false;
     } else {
         $data['name'] = $user->get('name');
         $data['username'] = $user->get('username');
         $data['email'] = $user->get('email');
         $data['language'] = $user->get('language');
         $data['editor'] = $user->get('editor');
     }
     $newId = $user->get('id');
     $data['virtuemart_user_id'] = $newId;
     //We need this in that case, because data is bound to table later
     $this->setUserId($newId);
     //Save the VM user stuff
     if (!$this->saveUserData($data) || !self::storeAddress($data)) {
         vmError('COM_VIRTUEMART_NOT_ABLE_TO_SAVE_USER_DATA');
         // 			vmError(vmText::_('COM_VIRTUEMART_NOT_ABLE_TO_SAVE_USERINFO_DATA'));
     } else {
         if ($new) {
             $user->userInfo = $data;
             $password = '';
             if ($usersConfig->get('sendpassword', 1)) {
                 $password = $user->password_clear;
             }
             //$doVendor = (boolean) $usersConfig->get('mail_to_admin', true);
             $this->sendRegistrationEmail($user, $password, $doUserActivation);
             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');
             }
         } else {
             vmInfo('COM_VIRTUEMART_USER_DATA_STORED');
         }
     }
     //The extra check for isset vendor_name prevents storing of the vendor if there is no form (edit address cart)
     if ((int) $data['user_is_vendor'] == 1 and isset($data['vendor_currency'])) {
         vmdebug('vendor recognised ' . $data['virtuemart_vendor_id']);
         if ($this->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' => true);
 }
Ejemplo n.º 2
0
 /**
  * New function for sorting, searching, filtering and pagination for product ids.
  *
  * @author Max Milbers
  */
 function sortSearchListQuery($onlyPublished = TRUE, $virtuemart_category_id = FALSE, $group = FALSE, $nbrReturnProducts = FALSE, $langFields = array())
 {
     $app = JFactory::getApplication();
     $db = JFactory::getDbo();
     //User Q.Stanley said that removing group by is increasing the speed of product listing in a bigger shop (10k products) by factor 60
     //So what was the reason for that we have it? TODO experiemental, find conditions for the need of group by
     $groupBy = ' group by p.`virtuemart_product_id` ';
     //administrative variables to organize the joining of tables
     $joinLang = false;
     $joinCategory = FALSE;
     $joinCatLang = false;
     $joinMf = FALSE;
     $joinMfLang = false;
     $joinPrice = FALSE;
     $joinCustom = FALSE;
     $joinShopper = FALSE;
     $joinChildren = FALSE;
     //$joinLang = false;
     $orderBy = ' ';
     $where = array();
     //$isSite = $app->isSite ();
     $isSite = true;
     if ($app->isAdmin() or vRequest::get('manage', false) and vmAccess::getVendorId()) {
         $isSite = false;
     }
     if (!empty($this->keyword) and $this->keyword !== '' and $group === FALSE) {
         $keyword = vRequest::filter(html_entity_decode($this->keyword, ENT_QUOTES, "UTF-8"), FILTER_SANITIZE_STRING, FILTER_FLAG_ENCODE_LOW);
         $keyword = '"%' . str_replace(array(' ', '-'), '%', $keyword) . '%"';
         //$keyword = '"%' . $db->escape ($this->keyword, TRUE) . '%"';
         vmdebug('Current search field', $this->valid_search_fields);
         foreach ($this->valid_search_fields as $searchField) {
             if ($searchField == 'category_name' || $searchField == 'category_description') {
                 $joinCatLang = true;
             } else {
                 if ($searchField == 'mf_name') {
                     $joinMfLang = true;
                 } else {
                     if ($searchField == 'product_price') {
                         $joinPrice = TRUE;
                     } else {
                         if ($searchField == 'product_name' or $searchField == 'product_s_desc' or $searchField == 'product_desc' or $searchField == 'slug') {
                             $langFields[] = $searchField;
                             //if (strpos ($searchField, '`') !== FALSE){
                             //$searchField = '`l`.'.$searchField;
                             $keywords_plural = preg_replace('/\\s+/', '%" AND ' . $searchField . ' LIKE "%', $keyword);
                             if ($app->isSite() and VmConfig::$defaultLang != VmConfig::$vmlang and !VmConfig::get('prodOnlyWLang', false)) {
                                 $filter_search[] = '`ld`.' . $searchField . ' LIKE ' . $keywords_plural;
                                 if (VmConfig::$defaultLang != VmConfig::$jDefLang) {
                                     $filter_search[] = '`ljd`.' . $searchField . ' LIKE ' . $keywords_plural;
                                 }
                             }
                             $searchField = '`l`.' . $searchField;
                             //}
                         }
                     }
                 }
             }
             if (strpos($searchField, '`') !== FALSE) {
                 $keywords_plural = preg_replace('/\\s+/', '%" AND ' . $searchField . ' LIKE "%', $keyword);
                 $filter_search[] = $searchField . ' LIKE ' . $keywords_plural;
             } else {
                 $keywords_plural = preg_replace('/\\s+/', '%" AND `' . $searchField . '` LIKE "%', $keyword);
                 $filter_search[] = '`' . $searchField . '` LIKE ' . $keywords_plural;
                 //$filter_search[] = '`' . $searchField . '` LIKE ' . $keyword;
             }
         }
         if (!empty($filter_search)) {
             $where[] = '(' . implode(' OR ', $filter_search) . ')';
         } else {
             $where[] = '`l`.product_name LIKE ' . $keyword;
             $langFields[] = 'product_name';
             //If they have no check boxes selected it will default to product name at least.
         }
     }
     // 		vmdebug('my $this->searchcustoms ',$this->searchcustoms);
     if (!empty($this->searchcustoms)) {
         $joinCustom = TRUE;
         foreach ($this->searchcustoms as $key => $searchcustom) {
             $custom_search[] = '(pf.`virtuemart_custom_id`="' . (int) $key . '" and pf.`customfield_value` like "%' . $db->escape($searchcustom, TRUE) . '%")';
         }
         $where[] = " ( " . implode(' OR ', $custom_search) . " ) ";
     }
     if ($isSite and !VmConfig::get('use_as_catalog', 0)) {
         if (VmConfig::get('stockhandle', 'none') == 'disableit_children') {
             $where[] = ' ( (p.`product_in_stock` - p.`product_ordered`) >"0" OR (children.`product_in_stock` - children.`product_ordered`) > "0") ';
             $joinChildren = TRUE;
         } else {
             if (VmConfig::get('stockhandle', 'none') == 'disableit') {
                 $where[] = ' p.`product_in_stock` - p.`product_ordered` >"0" ';
             }
         }
     }
     if ($virtuemart_category_id > 0) {
         $joinCategory = TRUE;
         $where[] = ' `pc`.`virtuemart_category_id` = ' . $virtuemart_category_id;
     } else {
         if ($isSite) {
             if (!VmConfig::get('show_uncat_parent_products', TRUE)) {
                 $joinCategory = TRUE;
                 $where[] = ' ((p.`product_parent_id` = "0" AND `pc`.`virtuemart_category_id` > "0") OR p.`product_parent_id` > "0") ';
             }
             if (!VmConfig::get('show_uncat_child_products', TRUE)) {
                 $joinCategory = TRUE;
                 $where[] = ' ((p.`product_parent_id` > "0" AND `pc`.`virtuemart_category_id` > "0") OR p.`product_parent_id` = "0") ';
             }
         }
     }
     if ($isSite and !VmConfig::get('show_unpub_cat_products', TRUE)) {
         $joinCategory = TRUE;
         $where[] = ' `c`.`published` = 1 ';
     }
     if ($this->product_parent_id) {
         $where[] = ' p.`product_parent_id` = ' . $this->product_parent_id;
     }
     if ($isSite) {
         $usermodel = VmModel::getModel('user');
         $currentVMuser = $usermodel->getCurrentUser();
         $virtuemart_shoppergroup_ids = (array) $currentVMuser->shopper_groups;
         if (is_array($virtuemart_shoppergroup_ids)) {
             $sgrgroups = array();
             foreach ($virtuemart_shoppergroup_ids as $key => $virtuemart_shoppergroup_id) {
                 $sgrgroups[] = '`ps`.`virtuemart_shoppergroup_id`= "' . (int) $virtuemart_shoppergroup_id . '" ';
             }
             $sgrgroups[] = '`ps`.`virtuemart_shoppergroup_id` IS NULL ';
             $where[] = " ( " . implode(' OR ', $sgrgroups) . " ) ";
             $joinShopper = TRUE;
         }
     }
     if ($this->virtuemart_manufacturer_id) {
         $joinMf = TRUE;
         if (is_array($this->virtuemart_manufacturer_id)) {
             $mans = array();
             foreach ($this->virtuemart_manufacturer_id as $key => $v) {
                 $mans[] = '`#__virtuemart_product_manufacturers`.`virtuemart_manufacturer_id`= "' . (int) $v . '" ';
             }
             $where[] = " ( " . implode(' OR ', $mans) . " ) ";
         } else {
             $where[] = ' `#__virtuemart_product_manufacturers`.`virtuemart_manufacturer_id` = ' . $this->virtuemart_manufacturer_id;
             //$virtuemart_manufacturer_id = $this->virtuemart_manufacturer_id;
         }
     }
     // Time filter
     if ($this->search_type != '') {
         $search_order = $db->escape(vRequest::getCmd('search_order') == 'bf' ? '<' : '>');
         switch ($this->search_type) {
             case 'parent':
                 $where[] = 'p.`product_parent_id` = "0"';
                 break;
             case 'product':
                 $where[] = 'p.`modified_on` ' . $search_order . ' "' . $db->escape(vRequest::getVar('search_date')) . '"';
                 break;
             case 'price':
                 $joinPrice = TRUE;
                 $where[] = 'pp.`modified_on` ' . $search_order . ' "' . $db->escape(vRequest::getVar('search_date')) . '"';
                 break;
             case 'withoutprice':
                 $joinPrice = TRUE;
                 $where[] = 'pp.`product_price` IS NULL';
                 break;
             case 'stockout':
                 $where[] = ' p.`product_in_stock`- p.`product_ordered` < 1';
                 break;
             case 'stocklow':
                 $where[] = 'p.`product_in_stock`- p.`product_ordered` < p.`low_stock_notification`';
                 break;
         }
     }
     //vmdebug('my filter ordering ',$this->filter_order);
     // special  orders case
     $ff_select_price = '';
     switch ($this->filter_order) {
         case '`p`.product_special':
             if ($isSite) {
                 $where[] = ' p.`product_special`="1" ';
                 // TODO Change  to  a  individual button
                 $orderBy = 'ORDER BY RAND()';
             } else {
                 $orderBy = 'ORDER BY p.`product_special`';
             }
             break;
         case 'category_name':
             $orderBy = ' ORDER BY `category_name` ';
             $joinCategory = TRUE;
             $joinCatLang = true;
             break;
         case 'category_description':
             $orderBy = ' ORDER BY `category_description` ';
             $joinCategory = TRUE;
             $joinCatLang = true;
             break;
         case 'mf_name':
         case '`l`.mf_name':
             $orderBy = ' ORDER BY `mf_name` ';
             $joinMf = TRUE;
             $joinMfLang = true;
             break;
         case 'ordering':
         case 'pc.ordering':
             $orderBy = ' ORDER BY `pc`.`ordering` ';
             $joinCategory = TRUE;
             break;
         case 'pc.ordering,product_name':
             $orderBy = ' ORDER BY `pc`.`ordering`,`product_name` ';
             $joinCategory = TRUE;
             $joinLang = true;
             break;
         case 'product_price':
             $orderBy = ' ORDER BY `product_price` ';
             $ff_select_price = ' , IF(pp.override, pp.product_override_price, pp.product_price) as product_price ';
             $joinPrice = TRUE;
             break;
         case 'created_on':
         case '`p`.created_on':
             $orderBy = ' ORDER BY p.`created_on` ';
             break;
         default:
             if (!empty($this->filter_order)) {
                 $orderBy = ' ORDER BY ' . $this->filter_order . ' ';
             } else {
                 $this->filter_order_Dir = '';
             }
             break;
     }
     //Group case from the modules
     if ($group) {
         $latest_products_days = VmConfig::get('latest_products_days', 7);
         $latest_products_orderBy = VmConfig::get('latest_products_orderBy', 'created_on');
         $groupBy = 'group by p.`virtuemart_product_id` ';
         switch ($group) {
             case 'featured':
                 $where[] = 'p.`product_special`="1" ';
                 $orderBy = 'ORDER BY RAND()';
                 break;
             case 'latest':
                 /*$date = JFactory::getDate (time () - (60 * 60 * 24 * $latest_products_days));
                 		$dateSql = $date->toSQL ();
                 		$where[] = 'p.`' . $latest_products_orderBy . '` > "' . $dateSql . '" ';*/
                 //vmdebug('product model ',$latest_products_orderBy);
                 $orderBy = 'ORDER BY p.`' . $latest_products_orderBy . '`';
                 $this->filter_order_Dir = 'DESC';
                 break;
             case 'random':
                 $orderBy = ' ORDER BY RAND() ';
                 //LIMIT 0, '.(int)$nbrReturnProducts ; //TODO set limit LIMIT 0, '.(int)$nbrReturnProducts;
                 break;
             case 'topten':
                 $orderBy = ' ORDER BY p.`product_sales` ';
                 //LIMIT 0, '.(int)$nbrReturnProducts;  //TODO set limitLIMIT 0, '.(int)$nbrReturnProducts;
                 $joinPrice = true;
                 $where[] = 'pp.`product_price`>"0.0" ';
                 $this->filter_order_Dir = 'DESC';
                 break;
             case 'recent':
                 $rSession = JFactory::getSession();
                 $rIds = $rSession->get('vmlastvisitedproductids', array(), 'vm');
                 // get recent viewed from browser session
                 return $rIds;
         }
         // 			$joinCategory 	= false ; //creates error
         // 			$joinMf 		= false ;	//creates error
         $joinPrice = TRUE;
         $this->searchplugin = FALSE;
         // 			$joinLang = false;
     }
     /*if ($onlyPublished and !empty($this->virtuemart_vendor_id) and vRequest::get('manage',false) and vmAccess::isSuperVendor()) {
     			$where[] = ' p.`virtuemart_vendor_id` = "'.$this->virtuemart_vendor_id.'" ';
     		} else {*/
     if (!empty($onlyPublished) and $isSite) {
         $where[] = ' p.`published`="1" ';
     }
     if (!empty($this->virtuemart_vendor_id)) {
         $where[] = ' p.`virtuemart_vendor_id` = "' . $this->virtuemart_vendor_id . '" ';
     }
     //}
     $joinedTables = array();
     //This option switches between showing products without the selected language or only products with language.
     if ($app->isSite() and !VmConfig::get('prodOnlyWLang', false)) {
         //Maybe we have to join the language to order by product name, description, etc,...
         $productLangFields = array('product_s_desc', 'product_desc', 'product_name', 'metadesc', 'metakey', 'slug');
         foreach ($productLangFields as $field) {
             if (strpos($orderBy, $field, 6) !== FALSE) {
                 $langFields[] = $field;
                 $orderbyLangField = $field;
                 $joinLang = true;
                 break;
             }
         }
     } else {
         $joinLang = true;
     }
     $selectLang = '';
     if ($joinLang or count($langFields) > 0) {
         if (!VmConfig::get('prodOnlyWLang', false) and VmConfig::$defaultLang != VmConfig::$vmlang and Vmconfig::$langCount > 1) {
             $this->useLback = true;
             $this->useJLback = false;
             $method = 'LEFT';
             if ($isSite) {
                 $method = 'INNER';
             }
             if (VmConfig::$defaultLang != VmConfig::$jDefLang) {
                 $joinedTables[] = ' ' . $method . ' JOIN `#__virtuemart_products_' . VmConfig::$jDefLang . '` as ljd using (`virtuemart_product_id`)';
                 $method = 'LEFT';
                 $this->useJLback = true;
             }
             $joinedTables[] = ' ' . $method . ' JOIN `#__virtuemart_products_' . VmConfig::$defaultLang . '` as ld using (`virtuemart_product_id`)';
             $joinedTables[] = ' LEFT JOIN `#__virtuemart_products_' . VmConfig::$vmlang . '` as l using (`virtuemart_product_id`)';
             $langFields = array_unique($langFields);
             if (count($langFields) > 0) {
                 foreach ($langFields as $langField) {
                     $expr2 = 'ld.' . $langField;
                     if ($this->useJLback) {
                         $expr2 = 'IFNULL(ld.' . $langField . ', ljd.' . $langField . ')';
                     }
                     $selectLang .= ', IFNULL(l.' . $langField . ',' . $expr2 . ') as ' . $langField . '';
                 }
             }
         } else {
             $this->useLback = false;
             $joinedTables[] = ' INNER JOIN `#__virtuemart_products_' . VmConfig::$vmlang . '` as l using (`virtuemart_product_id`)';
         }
     }
     $select = ' p.`virtuemart_product_id`' . $ff_select_price . $selectLang . ' FROM `#__virtuemart_products` as p ';
     if ($joinShopper == TRUE) {
         $joinedTables[] = ' LEFT JOIN `#__virtuemart_product_shoppergroups` as ps ON p.`virtuemart_product_id` = `ps`.`virtuemart_product_id` ';
         //$joinedTables[] = ' LEFT OUTER JOIN `#__virtuemart_shoppergroups` as s ON s.`virtuemart_shoppergroup_id` = `#__virtuemart_product_shoppergroups`.`virtuemart_shoppergroup_id` ';
     }
     if ($joinCategory == TRUE or $joinCatLang) {
         $joinedTables[] = ' LEFT JOIN `#__virtuemart_product_categories` as pc ON p.`virtuemart_product_id` = `pc`.`virtuemart_product_id` ';
         if ($isSite and !VmConfig::get('show_unpub_cat_products', TRUE)) {
             $joinedTables[] = ' LEFT JOIN `#__virtuemart_categories` as c ON c.`virtuemart_category_id` = `pc`.`virtuemart_category_id` ';
         }
         if ($joinCatLang) {
             $joinedTables[] = ' LEFT JOIN `#__virtuemart_categories_' . VmConfig::$vmlang . '` as cl ON cl.`virtuemart_category_id` = `pc`.`virtuemart_category_id`';
         }
     }
     if ($joinMf == TRUE or $joinMfLang) {
         $joinedTables[] = ' LEFT JOIN `#__virtuemart_product_manufacturers` ON p.`virtuemart_product_id` = `#__virtuemart_product_manufacturers`.`virtuemart_product_id` ';
         if ($joinMfLang) {
             $joinedTables[] = 'LEFT JOIN `#__virtuemart_manufacturers_' . VmConfig::$vmlang . '` as m ON m.`virtuemart_manufacturer_id` = `#__virtuemart_product_manufacturers`.`virtuemart_manufacturer_id` ';
         }
     }
     if ($joinPrice == TRUE) {
         $joinedTables[] = ' LEFT JOIN `#__virtuemart_product_prices` as pp ON p.`virtuemart_product_id` = pp.`virtuemart_product_id` ';
     }
     if ($this->searchcustoms) {
         $joinedTables[] = ' LEFT JOIN `#__virtuemart_product_customfields` as pf ON p.`virtuemart_product_id` = pf.`virtuemart_product_id` ';
     }
     if ($this->searchplugin !== 0) {
         if (!empty($PluginJoinTables)) {
             $plgName = $PluginJoinTables[0];
             $joinedTables[] = ' LEFT JOIN `#__virtuemart_product_custom_plg_' . $plgName . '` as ' . $plgName . ' ON ' . $plgName . '.`virtuemart_product_id` = p.`virtuemart_product_id` ';
         }
     }
     /*if ($joinShopper == TRUE) {
     			$joinedTables[] = ' LEFT JOIN `#__virtuemart_product_shoppergroups` ON p.`virtuemart_product_id` = `#__virtuemart_product_shoppergroups`.`virtuemart_product_id`
     			 LEFT  OUTER JOIN `#__virtuemart_shoppergroups` as s ON s.`virtuemart_shoppergroup_id` = `#__virtuemart_product_shoppergroups`.`virtuemart_shoppergroup_id`';
     		}/*/
     if ($joinChildren) {
         $joinedTables[] = ' LEFT OUTER JOIN `#__virtuemart_products` children ON p.`virtuemart_product_id` = children.`product_parent_id` ';
     }
     if ($this->searchplugin !== 0) {
         JPluginHelper::importPlugin('vmcustom');
         $dispatcher = JDispatcher::getInstance();
         $dispatcher->trigger('plgVmBeforeProductSearch', array(&$select, &$joinedTables, &$where, &$groupBy, &$orderBy, &$joinLang));
     }
     if (count($where) > 0) {
         $whereString = ' WHERE (' . implode(' AND ', $where) . ') ';
     } else {
         $whereString = '';
     }
     //vmdebug ( ' joined ? ',$select, $joinedTables, $whereString, $groupBy, $orderBy, $this->filter_order_Dir );		/* jexit();  */
     $this->orderByString = $orderBy;
     if ($this->_onlyQuery) {
         return array($select, $joinedTables, $where, $orderBy, $joinLang);
     }
     $joinedTables = " \n" . implode(" \n", $joinedTables);
     vmSetStartTime('sortSearchQuery');
     $product_ids = $this->exeSortSearchListQuery(2, $select, $joinedTables, $whereString, $groupBy, $orderBy, $this->filter_order_Dir, $nbrReturnProducts);
     vmTime('sortSearchQuery products', 'sortSearchQuery');
     //vmdebug('exeSortSearchLIstquery orderby ',$product_ids);
     return $product_ids;
 }
Ejemplo n.º 3
0
 /**
  * Get the Order By Select List
  *
  * notice by Max Milbers html tags should never be in a model. This function should be moved to a helper or simular,...
  *
  * @author Kohl Patrick, Max Milbers
  * @access public
  * @param $fieds from config Back-end
  * @return $orderByList
  * Order,order By, manufacturer and category link List to echo Out
  **/
 function getOrderByList($virtuemart_category_id = FALSE)
 {
     $getArray = vRequest::getGet(FILTER_SANITIZE_STRING);
     $fieldLink = '';
     foreach ($getArray as $key => $value) {
         $key = vRequest::filter($key, FILTER_SANITIZE_SPECIAL_CHARS, FILTER_FLAG_ENCODE_LOW);
         $value = vRequest::filter($value, FILTER_SANITIZE_SPECIAL_CHARS, FILTER_FLAG_ENCODE_LOW);
         if (is_array($value)) {
             foreach ($value as $k => $v) {
                 if ($v == '') {
                     continue;
                 }
                 $fieldLink .= '&' . urlencode($key) . '[' . urlencode($k) . ']' . '=' . urlencode($v);
             }
         } else {
             if ($key == 'dir' or $key == 'orderby') {
                 continue;
             }
             if ($value == '') {
                 continue;
             }
             $fieldLink .= '&' . urlencode($key) . '=' . urlencode($value);
         }
     }
     $fieldLink = 'index.php?' . ltrim($fieldLink, '&');
     $orderDirLink = '';
     $orderDirConf = VmConfig::get('prd_brws_orderby_dir');
     $orderDir = vRequest::getCmd('dir', $orderDirConf);
     if ($orderDir != $orderDirConf) {
         $orderDirLink .= '&dir=' . $orderDir;
         //was '&order='
     }
     $orderbyTxt = '';
     $orderby = vRequest::getString('orderby', VmConfig::get('browse_orderby_field'));
     $orderby = $this->checkFilterOrder($orderby);
     $orderbyCfg = VmConfig::get('browse_orderby_field');
     if ($orderby != $orderbyCfg) {
         $orderbyTxt = '&orderby=' . $orderby;
     }
     $manufacturerTxt = '';
     $manufacturerLink = '';
     if (VmConfig::get('show_manufacturers')) {
         $manuM = VmModel::getModel('manufacturer');
         vmSetStartTime('mcaching');
         $mlang = (!VmConfig::get('prodOnlyWLang', false) and VmConfig::$defaultLang != VmConfig::$vmlang and Vmconfig::$langCount > 1);
         if (true) {
             $cache = JFactory::getCache('com_virtuemart_cat_manus', 'callback');
             $cache->setCaching(true);
             $manufacturers = $cache->call(array('VirtueMartModelManufacturer', 'getManufacturersOfProductsInCategory'), $virtuemart_category_id, VmConfig::$vmlang, $mlang);
             vmTime('Manufacturers by Cache', 'mcaching');
         } else {
             $manufacturers = $manuM->getManufacturersOfProductsInCategory($virtuemart_category_id, VmConfig::$vmlang, $mlang);
             vmTime('Manufacturers by function', 'mcaching');
         }
         // manufacturer link list
         $manufacturerLink = '';
         $virtuemart_manufacturer_id = vRequest::getInt('virtuemart_manufacturer_id', '');
         if ($virtuemart_manufacturer_id != '') {
             $manufacturerTxt = '&virtuemart_manufacturer_id=' . $virtuemart_manufacturer_id;
         }
         if (count($manufacturers) > 0) {
             $manufacturerLink = '<div class="orderlist">';
             if ($virtuemart_manufacturer_id > 0) {
                 $allLink = str_replace($manufacturerTxt, $fieldLink, '');
                 $allLink .= '&virtuemart_manufacturer_id=0';
                 $manufacturerLink .= '<div><a title="" href="' . JRoute::_($allLink . $orderbyTxt . $orderDirLink, FALSE) . '">' . vmText::_('COM_VIRTUEMART_SEARCH_SELECT_ALL_MANUFACTURER') . '</a></div>';
             }
             if (count($manufacturers) > 1) {
                 foreach ($manufacturers as $mf) {
                     $link = JRoute::_($fieldLink . '&virtuemart_manufacturer_id=' . $mf->virtuemart_manufacturer_id . $orderbyTxt . $orderDirLink, FALSE);
                     if ($mf->virtuemart_manufacturer_id != $virtuemart_manufacturer_id) {
                         $manufacturerLink .= '<div><a title="' . $mf->mf_name . '" href="' . $link . '">' . $mf->mf_name . '</a></div>';
                     } else {
                         $currentManufacturerLink = '<div class="title">' . vmText::_('COM_VIRTUEMART_PRODUCT_DETAILS_MANUFACTURER_LBL') . '</div><div class="activeOrder">' . $mf->mf_name . '</div>';
                     }
                 }
             } elseif ($virtuemart_manufacturer_id > 0) {
                 $currentManufacturerLink = '<div class="title">' . vmText::_('COM_VIRTUEMART_PRODUCT_DETAILS_MANUFACTURER_LBL') . '</div><div class="activeOrder">' . $manufacturers[0]->mf_name . '</div>';
             } else {
                 $currentManufacturerLink = '<div class="title">' . vmText::_('COM_VIRTUEMART_PRODUCT_DETAILS_MANUFACTURER_LBL') . '</div><div class="Order"> ' . $manufacturers[0]->mf_name . '</div>';
             }
             $manufacturerLink .= '</div>';
         }
     }
     /* order by link list*/
     $orderByLink = '';
     $fields = VmConfig::get('browse_orderby_fields');
     if (count($fields) > 1) {
         $orderByLink = '<div class="orderlist">';
         foreach ($fields as $field) {
             if ($field != $orderby) {
                 $dotps = strrpos($field, '.');
                 if ($dotps !== FALSE) {
                     $prefix = substr($field, 0, $dotps + 1);
                     $fieldWithoutPrefix = substr($field, $dotps + 1);
                 } else {
                     $prefix = '';
                     $fieldWithoutPrefix = $field;
                 }
                 $text = vmText::_('COM_VIRTUEMART_' . strtoupper(str_replace(array(',', ' '), array('_', ''), $fieldWithoutPrefix)));
                 $field = explode('.', $field);
                 if (isset($field[1])) {
                     $field = $field[1];
                 } else {
                     $field = $field[0];
                 }
                 $link = JRoute::_($fieldLink . $manufacturerTxt . '&orderby=' . $field, FALSE);
                 $orderByLink .= '<div><a title="' . $text . '" href="' . $link . '">' . $text . '</a></div>';
             }
         }
         $orderByLink .= '</div>';
     }
     if ($orderDir == 'ASC') {
         $orderDir = 'DESC';
     } else {
         $orderDir = 'ASC';
     }
     if ($orderDir != $orderDirConf) {
         $orderDirLink = '&dir=' . $orderDir;
         //was '&order='
     } else {
         $orderDirLink = '';
     }
     $orderDirTxt = vmText::_('COM_VIRTUEMART_' . $orderDir);
     $link = JRoute::_($fieldLink . $orderbyTxt . $orderDirLink . $manufacturerTxt, FALSE);
     // full string list
     if ($orderby == '') {
         $orderby = $orderbyCfg;
     }
     $orderby = strtoupper($orderby);
     $dotps = strrpos($orderby, '.');
     if ($dotps !== FALSE) {
         $prefix = substr($orderby, 0, $dotps + 1);
         $orderby = substr($orderby, $dotps + 1);
     } else {
         $prefix = '';
     }
     $orderby = str_replace(',', '_', $orderby);
     $orderByList = '<div class="orderlistcontainer"><div class="title">' . vmText::_('COM_VIRTUEMART_ORDERBY') . '</div><div class="activeOrder"><a title="' . $orderDirTxt . '" href="' . $link . '">' . vmText::_('COM_VIRTUEMART_SEARCH_ORDER_' . $orderby) . ' ' . $orderDirTxt . '</a></div>';
     $orderByList .= $orderByLink . '</div>';
     $manuList = '';
     if (VmConfig::get('show_manufacturers')) {
         if (empty($currentManufacturerLink)) {
             $currentManufacturerLink = '<div class="title">' . vmText::_('COM_VIRTUEMART_PRODUCT_DETAILS_MANUFACTURER_LBL') . '</div><div class="activeOrder">' . vmText::_('COM_VIRTUEMART_SEARCH_SELECT_MANUFACTURER') . '</div>';
         }
         $manuList = ' <div class="orderlistcontainer">' . $currentManufacturerLink;
         $manuList .= $manufacturerLink . '</div><div class="clear"></div>';
     }
     return array('orderby' => $orderByList, 'manufacturer' => $manuList);
 }