public function actionList()
 {
     $_default_item_perpage = 10;
     if (isset($_GET['limit']) && (int) $_GET['limit'] > 0) {
         Yii::app()->session['current'] = $_GET['limit'];
         $_default_item_perpage = Yii::app()->session['current'];
     } else {
         if (isset(Yii::app()->session['current'])) {
             $_default_item_perpage = Yii::app()->session['current'];
         } else {
             Yii::app()->session['current'] = $_default_item_perpage;
         }
     }
     $criteria = new CDbCriteria();
     $criteria->addCondition('current=1 AND web=1');
     $q = Yii::app()->getRequest()->getQuery('q');
     if ($q) {
         $criteria->addCondition('`title` LIKE "%' . $q . '%" OR `code` LIKE "%' . $q . '%" OR `description_short` LIKE "%' . $q . '%"');
     }
     $criteria->order = _xls_get_sort_order();
     $item_count = Product::model()->count($criteria);
     $pages = new CPagination($item_count);
     $pages->setPageSize($_default_item_perpage);
     $pages->applyLimit($criteria);
     $model = Product::model()->findAll($criteria);
     $this->render('list', array('model' => $model, 'item_count' => $item_count, 'page_size' => $_default_item_perpage, 'items_count' => $item_count, 'pages' => $pages));
 }
示例#2
0
 /**
  * Used for general category browsing (which is really a search by category or family)
  * The URL manager passes the category request_url which we look up here
  */
 public function actionBrowse()
 {
     $strC = Yii::app()->getRequest()->getQuery('cat');
     $strB = Yii::app()->getRequest()->getQuery('brand');
     $strS = Yii::app()->getRequest()->getQuery('class_name');
     $strInv = '';
     //If we haven't passed any criteria, we just query the database
     $criteria = new CDbCriteria();
     $criteria->alias = 'Product';
     if (!empty($strC)) {
         $objCategory = Category::LoadByRequestUrl($strC);
         if ($objCategory) {
             $criteria->join = 'LEFT JOIN xlsws_product_category_assn as ProductAssn ON ProductAssn.product_id=Product.id';
             $intIdArray = array($objCategory->id);
             $intIdArray = array_merge($intIdArray, $objCategory->GetBranchPath());
             $criteria->addInCondition('category_id', $intIdArray);
             $this->pageTitle = $objCategory->PageTitle;
             $this->pageDescription = $objCategory->PageDescription;
             $this->pageImageUrl = $objCategory->CategoryImage;
             $this->breadcrumbs = $objCategory->Breadcrumbs;
             $this->pageHeader = Yii::t('category', $objCategory->label);
             $this->subcategories = $objCategory->getSubcategoryTree($this->MenuTree);
             if ($objCategory->custom_page) {
                 $this->custom_page_content = $objCategory->customPage->page;
             }
             $this->canonicalUrl = $objCategory->getCanonicalUrl();
         }
     }
     if (!empty($strB)) {
         $objFamily = Family::LoadByRequestUrl($strB);
         if ($objFamily) {
             $criteria->addCondition('family_id = :id');
             $criteria->params = array(':id' => $objFamily->id);
             $this->pageTitle = $objFamily->PageTitle;
             $this->pageHeader = $objFamily->family;
             $this->canonicalUrl = $objFamily->getCanonicalUrl();
         }
     }
     if (!empty($strS)) {
         $objClasses = Classes::LoadByRequestUrl($strS);
         if ($objClasses) {
             $criteria->addCondition('class_id = :id');
             $criteria->params = array(':id' => $objClasses->id);
             $this->pageHeader = $objClasses->class_name;
             $this->canonicalUrl = $objClasses->getCanonicalUrl();
         }
     }
     if (_xls_get_conf('INVENTORY_OUT_ALLOW_ADD') == Product::InventoryMakeDisappear) {
         $criteria->addCondition('(inventory_avail>0 OR inventoried=0)');
     }
     if (!_xls_get_conf('CHILD_SEARCH') || empty($strQ)) {
         $criteria->addCondition('Product.parent IS NULL');
     }
     if (Product::HasFeatured() && empty($strS) && empty($strB) && empty($strC)) {
         $criteria->addCondition('featured=1');
         $this->pageHeader = 'Featured Products';
     }
     $criteria->addCondition('web=1');
     $criteria->addCondition('current=1');
     $criteria->order = 'Product.' . _xls_get_sort_order();
     $productsGrid = new ProductGrid($criteria);
     $this->returnUrl = $this->canonicalUrl;
     $this->pageImageUrl = "";
     if ($strB == '*') {
         $familiesCriteria = new CDbCriteria();
         $familiesCriteria->order = 'family';
         if (CPropertyValue::ensureBoolean(Yii::app()->params['DISPLAY_EMPTY_CATEGORY']) === false) {
             $familiesCriteria->addCondition('child_count > 0');
         }
         $families = Family::model()->findAll($familiesCriteria);
         $this->render('brands', array('model' => $families));
     } else {
         $this->render('grid', array('model' => $productsGrid->getProductGrid(), 'item_count' => $productsGrid->getNumberOfRecords(), 'page_size' => Yii::app()->params['PRODUCTS_PER_PAGE'], 'items_count' => $productsGrid->getNumberOfRecords(), 'pages' => $productsGrid->getPages()));
     }
 }
示例#3
0
 /**
  * Returns a criteria that the custom page can use to display
  * a slider for the products.
  *
  * @return CDbCriteria
  */
 public function GetSliderCriteria()
 {
     $criteria = $this->getDefaultProductCriteria();
     $criteria->limit = _xls_get_conf('MAX_PRODUCTS_IN_SLIDER', 64);
     $criteria->order = _xls_get_sort_order();
     //'Product.id DESC';
     return $criteria;
 }
 /**
  * Build a weighted search query. Whole words rank higher than partial, and
  * words in titles rank higher than in descriptions, which are higher than tags
  *
  * Returns a SQL string based on our passed search string
  *
  * @param $form
  * @param null $intLimit
  * @param null $intOffset
  * @param bool $isCustomPage
  * @return mixed
  */
 protected function buildCommand($formModel, $intLimit = null, $intOffset = null, $isCustomPage = false)
 {
     $strQ = $formModel->q;
     $strInv = '';
     $intCount = 0;
     $arrBind = array(':query' => $strQ);
     if (_xls_get_conf('INVENTORY_OUT_ALLOW_ADD') == Product::InventoryMakeDisappear) {
         $strInv .= " AND (inventory_avail>0 OR inventoried=0) ";
     }
     if (!_xls_get_conf('CHILD_SEARCH')) {
         $strInv .= " AND parent IS NULL ";
     }
     //Since we have passed our AdvancedSearchForm, go through the used fields and add them to our query
     foreach ($formModel as $key => $val) {
         if (!empty($val) && $key != "q") {
             $arrBind[':' . $key] = $val;
             switch ($key) {
                 case 'startprice':
                     $strInv .= " AND sell_web >= :startprice ";
                     break;
                 case 'endprice':
                     $strInv .= " AND sell_web <= :endprice ";
                     break;
                 case 'product_size':
                     $strInv .= " AND product_size = :product_size ";
                     break;
                 case 'product_color':
                     $strInv .= " AND product_color = :product_color ";
                     break;
                 case 'tag':
                     $strInv .= " AND tag = :tag ";
                     break;
             }
         }
     }
     $arr = explode(" ", $strQ);
     $strCases = "(CASE WHEN `title` = :query THEN 10 ELSE 0 END) +";
     $strWhere = " `title` = :query OR ";
     foreach ($arr as $item) {
         $strTag = ':item' . $intCount;
         $strTag1 = ':itemL1' . $intCount;
         $strTag2 = ':itemL2' . $intCount;
         $strTag3 = ':itemL3' . $intCount;
         $arrBind[':item' . $intCount] = $item;
         $arrBind[':itemL1' . $intCount] = "%{$item}%";
         $arrBind[':itemL2' . $intCount] = "%{$item} %";
         $arrBind[':itemL3' . $intCount] = "{$item}%";
         $strCases .= "(CASE WHEN `title` = {$strTag} THEN 20 ELSE 0 END) +";
         $strCases .= "(CASE WHEN `title` LIKE {$strTag3} THEN 15 ELSE 0 END) +";
         $strCases .= "(CASE WHEN `title` LIKE {$strTag2} THEN 10 ELSE 0 END) +";
         $strCases .= "(CASE WHEN `title` LIKE {$strTag1} THEN 3 ELSE 0 END) +";
         $strCases .= "(CASE WHEN `description_long` LIKE {$strTag1} THEN 2 ELSE 0 END) +";
         $strCases .= "(CASE WHEN `tag` = {$strTag} THEN 2 ELSE 0 END) +";
         $strCases .= "(CASE WHEN `description_short` LIKE {$strTag1} THEN 1 ELSE 0 END) +";
         $strCases .= "(CASE WHEN `code` = {$strTag} THEN 1 ELSE 0 END) +";
         $strCases .= "(CASE WHEN `product_size` = {$strTag} THEN 1 ELSE 0 END) +";
         $strCases .= "(CASE WHEN `product_color` = {$strTag} THEN 1 ELSE 0 END) +";
         $strWhere .= " `title` = {$strTag} OR ";
         $strWhere .= " `title` LIKE {$strTag3} OR ";
         $strWhere .= " `title` LIKE {$strTag2} OR ";
         $strWhere .= " `title` LIKE {$strTag1} OR ";
         $strWhere .= " `description_long` LIKE {$strTag1} OR ";
         $strWhere .= " `tag` = {$strTag}  OR ";
         $strWhere .= " `description_short` LIKE {$strTag1} OR ";
         $strWhere .= " `code` = {$strTag} OR ";
         $strWhere .= " `product_size` = {$strTag} OR ";
         $strWhere .= " `product_color` = {$strTag} OR ";
         $intCount++;
     }
     $strCases = substr($strCases, 0, -1);
     //Remove last +
     $strWhere = substr($strWhere, 0, -3);
     //Remove last OR(space)
     $objCommand = Yii::app()->db->createCommand();
     $objCommand->select('t.*, (' . $strCases . ') AS relevance');
     $objCommand->leftJoin('xlsws_product_tags t2', 't2.product_id = t.id');
     $objCommand->leftJoin('xlsws_tags t3', 't2.tag_id = t3.id');
     $objCommand->from('xlsws_product t');
     $objCommand->where('(' . $strWhere . ') ' . $strInv . '	AND web=1 AND current=1');
     //If we have passed a category, append it to the search here
     if (isset($formModel['cat']) && $formModel['cat'] > 0) {
         $objCategory = Category::model()->findbyPk($formModel['cat']);
         $this->strBreadcrumbCat = Yii::t('category', $objCategory->label);
         $intIdArray = array($objCategory->id);
         $intIdArray = array_merge($intIdArray, $objCategory->GetBranchPath());
         unset($arrBind[':cat']);
         $objCommand->leftJoin('xlsws_product_category_assn t4', 't4.product_id = t.id');
         $objCommand->where(array('AND', '(' . $strWhere . ') ' . $strInv . ' AND web=1 AND current=1', array('in', 'category_id', $intIdArray)));
     }
     $orderBy = $isCustomPage ? 't.' . _xls_get_sort_order() : 'relevance DESC';
     $objCommand->group('t.id');
     $objCommand->order($orderBy);
     if (!is_null($intLimit)) {
         if ($intLimit == -1) {
             //This means we're just running a count, so we don't need all aspects of this query
             $objCommand->select(' count(DISTINCT t.id) ');
             $objCommand->group(null);
             $objCommand->order(null);
         } else {
             $objCommand->limit($intLimit, $intOffset);
         }
     }
     foreach ($arrBind as $key => $val) {
         $objCommand->bindValue($key, $val, PDO::PARAM_STR);
     }
     return $objCommand;
 }