Ejemplo n.º 1
0
		function getProducts($onlyPublished=true){		
	
			$app = &JFactory::getApplication() ;
			
			$groupBy = '';
	
			//administrative variables to organize the joining of tables
			$joinCategory 	= true ;
			$joinMf 		= true ;
			$joinPrice 		= true ;
			$joinCustom		= false ;
			$joinLang = true; // test fix Patrick
	
			$where = array();
	
			if($onlyPublished){
				$where[] = ' p.`published`="1" ';
			}
		
			if($app->isSite() && !$this->ShowProductsInStock ){
				$where[] = ' p.`product_in_stock`>"0" ';
			}				
			
			if($this->source == 'filter'){
				$virtuemart_category_id = '';
				if(is_array($this->category_id) && !empty($this->category_id))
				{
					$virtuemart_category_id = implode(",", $this->category_id);
				}
				else
				{
					$virtuemart_category_id = intval($this->category_id);
				}
				
				$joinCategory = true ;
				$where[] = ' `#__virtuemart_product_categories`.`virtuemart_category_id` in ('.$virtuemart_category_id.')';
				
			} 
			else if($this->source == 'specific')
			{
				
				if(!empty($this->specific_product_ids) && $this->specific_product_ids!='')
				{
					$where[] = ' p.`virtuemart_product_id` in ('.$this->specific_product_ids.') ';
				}
			}
	
			
			$joinShopper = false;
			if ($app->isSite()) {
				if(!class_exists('VirtueMartModelUser')) require(JPATH_VM_ADMINISTRATOR.DS.'models'.DS.'user.php');
				$usermodel = new VirtueMartModelUser();
				$currentVMuser = $usermodel->getUser();
				$virtuemart_shoppergroup_ids =  $currentVMuser->shopper_groups;
	
				if(is_array($virtuemart_shoppergroup_ids)){
					foreach ($virtuemart_shoppergroup_ids as $key => $virtuemart_shoppergroup_id){
						$where[] .= '(s.`virtuemart_shoppergroup_id`= "' . (int) $virtuemart_shoppergroup_id . '" OR' . ' ISNULL(s.`virtuemart_shoppergroup_id`) )';
					}
					$joinShopper = true;
				}
			}
	
			if($this->featuredProducts=='yes')
			{
				$where[] = ' p.`product_special`="1" ';
			}
			
			$limit = $this->NumberOfProducts;
			if($limit>0) {
				$limit = "LIMIT $limit";
			} else {
				$limit = "";
			}
			// special  orders case
			switch ($this->SortMethod) {
			
				case 'random':
					$orderBy = "\n ORDER BY RAND() ";
					break;
				case 'newest':
					$orderBy = "\n ORDER BY p.created_on DESC ";
					break;
				case 'oldest':
					$orderBy = "\n ORDER BY p.created_on ASC";
					break;
				case 'ordering':
					$orderBy = ' ORDER BY `#__virtuemart_product_categories`.`ordering` ';
					$joinCategory = true ;
					break;
				case 'product_price':
					//$filters[] = 'p.`virtuemart_product_id` = p.`virtuemart_product_id`';
					$orderBy = ' ORDER BY pp.`product_price` ';
					$joinPrice = true ;
					break;
				default:
					$orderBy = "\n ORDER BY p.cdate DESC ";
					break;
			}
			
			$orderBy .= $limit;
	
			
			
			if($joinLang){
				$select = ' *, p.`product_in_stock`,l.`virtuemart_product_id` as virtuemart_product_id FROM `#__virtuemart_products_'.VMLANG.'` as l';
				$joinedTables = ' JOIN `#__virtuemart_products` AS p using (`virtuemart_product_id`)';
			} else {
				$select = ' * FROM `#__virtuemart_products` as p';
				$joinedTables = '';
			}
	
			if ($joinCategory == true) {
				$joinedTables .= ' LEFT JOIN `#__virtuemart_product_categories` ON p.`virtuemart_product_id` = `#__virtuemart_product_categories`.`virtuemart_product_id`
				 LEFT JOIN `#__virtuemart_categories_'.VMLANG.'` as c ON c.`virtuemart_category_id` = `#__virtuemart_product_categories`.`virtuemart_category_id` 
				 INNER JOIN `#__virtuemart_categories` as vca ON vca.`virtuemart_category_id` = c.`virtuemart_category_id`
				 ';
				 
				 $where[] = ' vca.`published`= 1 ';
			}
			
			if ($joinMf == true) {
				$joinedTables .= ' LEFT JOIN `#__virtuemart_product_manufacturers` ON p.`virtuemart_product_id` = `#__virtuemart_product_manufacturers`.`virtuemart_product_id`
				 LEFT JOIN `#__virtuemart_manufacturers_'.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 ($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(count($where)>0){
				$whereString = ' WHERE ('.implode(' AND ', $where ).') ';
			} else {
				$whereString = '';
			}
			
			$products = $this->excuteSql($select, $joinedTables, $whereString, $groupBy, $orderBy);
	
			return $products;
	
		}
Ejemplo n.º 2
0
 function OPCstoreAddress(&$cart, $data, $user_id = 0)
 {
     $x = JRequest::getVar('ship_to_info_id', '');
     if (!empty($x) && is_numeric($x)) {
         $data['shipto_virtuemart_userinfo_id'] = (int) $x;
     }
     $data['shipto_virtuemart_userinfo_id'] = (int) $data['shipto_virtuemart_userinfo_id'];
     //$user =JFactory::getUser();
     $this->addModelPath(JPATH_VM_ADMINISTRATOR . DS . 'models');
     require_once JPATH_ROOT . DS . 'components' . DS . 'com_onepage' . DS . 'helpers' . DS . 'mini.php';
     $userModel = OPCmini::getModel('user');
     $user = JFactory::getUser();
     $userinfo = $userModel->getTable('userinfos');
     if ($data['address_type'] == 'BT') {
         $userfielddata = VirtueMartModelUser::_prepareUserFields($data, 'BT');
         if (!$userinfo->bindChecknStore($userfielddata)) {
             vmError('storeAddress ' . $userinfo->getError());
         }
     }
     // Check for fields with the the 'shipto_' prefix; that means a (new) shipto address.
     $shiptonew = JRequest::getVar('opc_st_changed_new', false);
     $shiptologged = JRequest::getVar('shipto_logged');
     // shipto_logged
     // special case when using sinel ST address:
     $skipc = false;
     $shipto_logged = JRequest::getVar('shipto_logged', null);
     $shipto_logged = (int) $shipto_logged;
     if (!empty($shipto_logged)) {
         $q = 'select address_type from #__virtuemart_userinfos where virtuemart_userinfo_id = ' . $data['shipto_virtuemart_userinfo_id'] . ' limit 0,1';
         $db = JFactory::getDBO();
         $db->setQuery($q);
         $res2 = $db->loadResult();
         if (!empty($res2) && $res2 != 'bt') {
             $data['shipto_virtuemart_userinfo_id'] = $shipto_logged;
             $skipc = true;
         }
     } else {
         if (!$skipc) {
             $q = 'select address_type from #__virtuemart_userinfos where virtuemart_userinfo_id = ' . $data['shipto_virtuemart_userinfo_id'] . ' limit 0,1';
             $db = JFactory::getDBO();
             $db->setQuery($q);
             $res = $db->loadResult();
             if (empty($res)) {
                 // non existent update to ST
                 unset($data['shipto_virtuemart_userinfo_id']);
                 $data['shipto_virtuemart_userinfo_id'] = 0;
             }
             if (strtolower($res) == 'bt') {
                 // trying to update ST with improper ID
                 $data['shipto_virtuemart_userinfo_id'] = 0;
             }
         }
     }
     if (isset($data['shipto_virtuemart_userinfo_id'])) {
         $dataST = array();
         $_pattern = '/^shipto_/';
         foreach ($data as $_k => $_v) {
             if (preg_match($_pattern, $_k)) {
                 $_new = preg_replace($_pattern, '', $_k);
                 $dataST[$_new] = $_v;
             }
         }
         $userinfo = $userModel->getTable('userinfos');
         if (isset($dataST['virtuemart_userinfo_id']) and $dataST['virtuemart_userinfo_id'] != 0) {
             require_once JPATH_ROOT . DS . 'components' . DS . 'com_onepage' . DS . 'helpers' . DS . 'mini.php';
             if (!OPCmini::isSuperVendor()) {
                 $userinfo->load($dataST['virtuemart_userinfo_id']);
             }
         }
         if (empty($userinfo->virtuemart_user_id)) {
             require_once JPATH_ROOT . DS . 'components' . DS . 'com_onepage' . DS . 'helpers' . DS . 'mini.php';
             if (!OPCmini::isSuperVendor()) {
                 $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;
                 }
             }
         } else {
             if ($userinfo->virtuemart_user_id != $user->id) {
                 return;
             }
         }
         $dataST['address_type'] = 'ST';
         $userfielddata = VirtueMartModelUser::_prepareUserFields($dataST, 'ST');
         if (!$userinfo->bindChecknStore($userfielddata)) {
             vmError($userinfo->getError());
         }
         if (!empty($userinfo->virtuemart_userinfo_id)) {
             $shipto = JRequest::setVar('shipto', (int) $userinfo->virtuemart_userinfo_id);
             $cart->selected_shipto = $userinfo->virtuemart_userinfo_id;
             $cart->STsameAsBT = 0;
         }
     }
     return $userinfo->virtuemart_userinfo_id;
 }
Ejemplo n.º 3
0
 public static function getModel($model)
 {
     // make sure VM is loaded:
     if (!class_exists('VmConfig')) {
         require JPATH_ADMINISTRATOR . DS . 'components' . DS . 'com_virtuemart' . DS . 'helpers' . DS . 'config.php';
         VmConfig::loadConfig();
     }
     if (empty(OPCmini::$modelCache)) {
         OPCmini::$modelCache = array();
     }
     if (!empty(OPCmini::$modelCache[$model])) {
         return OPCmini::$modelCache[$model];
     }
     if (!class_exists('VirtueMartModel' . ucfirst($model))) {
         require JPATH_VM_ADMINISTRATOR . DS . 'models' . DS . strtolower($model) . '.php';
     }
     if (method_exists('VmModel', 'getModel')) {
         $Omodel = VmModel::getModel($model);
         OPCmini::$modelCache[$model] = $Omodel;
         return $Omodel;
     } else {
         // this section loads models for VM2.0.0 to VM2.0.4
         $class = 'VirtueMartModel' . ucfirst($model);
         if (class_exists($class)) {
             if ($class == 'VirtueMartModelUser') {
                 //require_once(JPATH_SITE.DS.'components'.DS.'com_onepage'.DS.'overrides'.DS.'user.php');
                 //$class .= 'Override';
                 $Omodel = new VirtueMartModelUser();
                 return $Omodel;
                 $Omodel->setMainTable('virtuemart_vmusers');
             }
             $Omodel = new $class();
             OPCmini::$modelCache[$model] = $Omodel;
             return $Omodel;
         } else {
             echo 'Class not found: ' . $class;
             $app = JFactory::getApplication()->close();
         }
     }
     echo 'Model not found: ' . $model;
     $app = JFactory::getApplication()->close();
     //return new ${'VirtueMartModel'.ucfirst($model)}();
 }
Ejemplo n.º 4
0
    /**
     *
     * Returns the product ids after running the filtering sql queries
     * Overriddes the function defined in the com_virtuemart/models/product.php.
     * @param 	boolen	$onlyPublished only the published products
     * @param 	string	$group	indicates some predefined groups
     * @param 	Int $nbrReturnProducts
     * @since	1.0
     * @todo	Avoid joins if only 1 filter is selected. Just get the product id from it's table
     */
    function sortSearchListQuery($onlyPublished = true, $vmcats = false, $group = false, $nbrReturnProducts = false)
    {
        $app = JFactory::getApplication();
        $jinput = $app->input;
        $db = JFactory::getDbo();
        $query = $db->getQuery(true);
        $where = array();
        //create the JRegistry with the module's params
        $module = JModuleHelper::getModule('mod_cf_filtering');
        //echo JModuleHelper::renderModule($module);
        $moduleParams = new JRegistry();
        $moduleParams->loadString($module->params);
        $resetType = $moduleParams->get('reset_results', 0);
        if ($jinput->get('reset', 0, 'int') == 1 && $resetType == 0) {
            return;
        }
        $query->select('p.virtuemart_product_id');
        $query->from('#__virtuemart_products AS p');
        //joins initialization
        $join_prodcat = false;
        $join_prodlang = false;
        $joinCategory = false;
        $join_prodmnf = false;
        $joinMf = false;
        $joinPrice = false;
        //----generate categories filter query---//
        $vm_categories = $jinput->get('virtuemart_category_id', array(), 'array');
        $vm_categories = array_filter($vm_categories);
        if (count($vm_categories) > 0 && isset($vm_categories[0])) {
            JArrayHelper::toInteger($vm_categories);
            if (count($vm_categories) > 0) {
                //set the selected categories
                $this->selectedFilt = array_merge($this->selectedFilt, $vm_categories);
                $join_prodcat = true;
                $where[] = ' p_c.virtuemart_category_id IN (' . implode(',', $vm_categories) . ')';
            }
        }
        //----generate price filter query---//
        $price_from = $jinput->get('price_from', 0, 'float');
        $price_to = $jinput->get('price_to', 0, 'float');
        if (!empty($price_from) || !empty($price_to)) {
            $productIdsByPrice = $this->getProductIdsByPrice();
            if (!empty($productIdsByPrice)) {
                $where[] = ' p.virtuemart_product_id IN (' . implode(',', $productIdsByPrice) . ')';
            } else {
                return;
            }
        }
        //----generate manufacturers filter query---//
        $vm_manufacturers = $jinput->get('virtuemart_manufacturer_id', array(), 'array');
        $vm_manufacturers = array_filter($vm_manufacturers);
        if (count($vm_manufacturers) > 0 && isset($vm_manufacturers[0])) {
            JArrayHelper::toInteger($vm_manufacturers);
            if (count($vm_manufacturers) > 0) {
                //set the selected manufs
                $this->selectedFilt = array_merge($this->selectedFilt, $vm_manufacturers);
                $join_prodmnf = true;
                $where[] = ' p_m.virtuemart_manufacturer_id IN (' . implode(',', $vm_manufacturers) . ')';
            }
        }
        //-----generate Custom fields filter---//
        //get the published filters
        $customFilters = $this->published_cf;
        $cfilter_found = false;
        if (!empty($customFilters)) {
            foreach ($customFilters as $cfid) {
                $cf_name = 'custom_f_' . $cfid->vm_custom_id;
                $selected_cf = $jinput->get($cf_name, array(), 'array');
                $selected_cf = array_filter($selected_cf);
                //get the values of each cf and create the queries
                if (count($selected_cf) > 0 && !(count($selected_cf) == 1 && isset($selected_cf[0]) && $selected_cf[0] == '')) {
                    //if there is cf and is other than a blank(+ //urlencoded)
                    //set the selected cfs
                    $this->selectedFilt = array_merge($this->selectedFilt, $selected_cf);
                    $cfilter_found = true;
                    $custom_search = array();
                    $query->innerJoin('`#__virtuemart_product_customfields` AS ' . $cf_name . ' ON ' . $cf_name . '.virtuemart_product_id=p.virtuemart_product_id');
                    foreach ($selected_cf as $cf_val) {
                        $cf_value = $this->cfHex2bin($cf_val);
                        if (isset($cf_value)) {
                            $custom_search[] = "(" . $cf_name . '.custom_value = ' . $db->Quote($cf_value, true) . ' AND ' . $cf_name . '.virtuemart_custom_id=' . $cfid->vm_custom_id . ")";
                        }
                    }
                    if ($custom_search) {
                        $where[] = " (" . implode(' OR ', $custom_search) . ") ";
                    }
                }
            }
        }
        //display products in specific shoppers
        if (!class_exists('VirtueMartModelUser')) {
            require JPATH_VM_ADMINISTRATOR . DS . 'models' . DS . 'user.php';
        }
        $usermodel = new VirtueMartModelUser();
        $currentVMuser = $usermodel->getUser();
        $virtuemart_shoppergroup_ids = (array) $currentVMuser->shopper_groups;
        if (is_array($virtuemart_shoppergroup_ids)) {
            foreach ($virtuemart_shoppergroup_ids as $key => $virtuemart_shoppergroup_id) {
                $where[] .= '(s.`virtuemart_shoppergroup_id`= "' . (int) $virtuemart_shoppergroup_id . '" OR' . ' (s.`virtuemart_shoppergroup_id`) IS NULL )';
            }
            $joinShopper = true;
        }
        //--general--//
        if ($onlyPublished) {
            $where[] = ' `p`.`published`=1';
        }
        if (!VmConfig::get('use_as_catalog', 0) && VmConfig::get('stockhandle', 'none') == 'disableit') {
            $where[] = ' p.product_in_stock>"0" ';
        }
        //ordering
        $groupBy = '';
        //First setup the variables for filtering
        $filter_order = $jinput->get('orderby', VmConfig::get('browse_orderby_field', 'p.virtuemart_product_id'), 'string');
        $filter_order_Dir = strtoupper($jinput->get('order', 'DESC', 'cmd'));
        //sanitize Direction in case of invalid input
        if ($filter_order_Dir != 'ASC' && $filter_order_Dir != 'DESC') {
            $filter_order_Dir = 'DESC';
        }
        // special  orders case
        switch ($filter_order) {
            case 'product_name':
                $orderBy = 'l.product_name';
                $join_prodlang = true;
                break;
            case 'product_special':
                $orderBy = ' p.`product_special`="1" ';
                break;
            case 'category_name':
                $orderBy = 'c.`category_name`';
                $join_prodcat = true;
                $joinCategory = true;
                break;
            case 'category_description':
                $orderBy = 'c.`category_description`';
                $join_prodcat = true;
                $joinCategory = true;
                break;
            case 'mf_name':
                $orderBy = 'm.`mf_name`';
                $join_prodmnf = true;
                $joinMf = true;
                break;
            case 'ordering':
                $orderBy = 'p_c.`ordering`';
                $join_prodcat = true;
                $joinCategory = true;
                break;
            case 'product_price':
                $orderBy = 'pp.`product_price`';
                $joinPrice = true;
                break;
            case 'created_on':
                $orderBy = 'p.`created_on`';
                break;
            default:
                if (!empty($filter_order)) {
                    $orderBy = $filter_order;
                } else {
                    $filter_order_Dir = '';
                    $orderBy = '';
                }
                break;
        }
        //set the joins
        $query->innerJoin('#__virtuemart_products_' . VMLANG . ' AS l ON p.virtuemart_product_id=l.virtuemart_product_id');
        if ($join_prodcat) {
            $query->innerJoin('#__virtuemart_product_categories AS p_c ON p_c.virtuemart_product_id=p.virtuemart_product_id');
        }
        if ($joinCategory) {
            $query->leftJoin('#__virtuemart_categories_' . VMLANG . ' as c ON c.`virtuemart_category_id` = p_c.`virtuemart_category_id`');
        }
        if ($joinShopper) {
            $query->leftJoin('`#__virtuemart_product_shoppergroups` ON p.`virtuemart_product_id` = `#__virtuemart_product_shoppergroups`.`virtuemart_product_id`
			 LEFT JOIN `#__virtuemart_shoppergroups` as s ON s.`virtuemart_shoppergroup_id` = `#__virtuemart_product_shoppergroups`.`virtuemart_shoppergroup_id`');
        }
        if ($join_prodmnf) {
            $query->innerJoin('#__virtuemart_product_manufacturers  AS p_m ON p_m.virtuemart_product_id=p.virtuemart_product_id');
        }
        if ($joinMf) {
            $query->leftJoin('#__virtuemart_manufacturers_' . VMLANG . ' as m ON m.`virtuemart_manufacturer_id` = p_m.`virtuemart_manufacturer_id`');
        }
        if ($joinPrice) {
            $query->leftJoin('`#__virtuemart_product_prices` as pp ON p.`virtuemart_product_id` = pp.`virtuemart_product_id` ');
        }
        // List state information
        $limit = $this->getState('list.limit', 5);
        $limitstart = $this->getState('list.limitstart', 0);
        $query->order($db->escape($orderBy . ' ' . $filter_order_Dir));
        if (count($where) > 0) {
            $query->where(implode(' AND ', $where));
        }
        $db->setQuery($query, $limitstart, $limit);
        //print_r((string)$query);
        $product_ids = $db->loadColumn();
        $app->setUserState("com_customfilters.product_ids", $product_ids);
        $this->total = $this->_getListCount($query);
        if ($product_ids) {
            $product_ids = array_unique($product_ids);
        }
        return $product_ids;
        return;
    }