Esempio n. 1
0
 public function getCondition()
 {
     // analyze search query
     // find exact phrases first
     $query = $this->query;
     preg_match_all('/"(.*)"/sU', $query, $matches);
     $phrases = array();
     if ($matches[1]) {
         $phrases = $matches[1];
     }
     $query = $this->getCleanedQuery($query);
     $phrases = array_merge($phrases, explode(' ', $query));
     $searchFields = array('name', 'keywords', 'shortDescription', 'longDescription', 'sku');
     $conditions = array();
     foreach ($phrases as $phrase) {
         $searchCond = null;
         foreach ($searchFields as $field) {
             $cond = new LikeCond(new ARFieldHandle('Product', $field), '%' . $phrase . '%');
             if (!$searchCond) {
                 $searchCond = $cond;
             } else {
                 $searchCond->addOr($cond);
             }
         }
         $conditions[] = $searchCond;
     }
     $condition = new AndChainCondition($conditions);
     $vc = new IsNotNullCond(f('Product.parentID'));
     $vc->addAND(new LikeCond(new ARExpressionHandle('(SELECT name FROM Product as searchvar WHERE Product.parentID=searchvar.ID)'), '%' . $phrase . '%'));
     ActiveRecordModel::getApplication()->variationCond = $vc;
     ActiveRecordModel::getApplication()->processInstancePlugins('searchFilter', $condition);
     return $condition;
 }
Esempio n. 2
0
 public function getSelectFilter($disableFilters = false)
 {
     $selectFilter = $this->category->getProductsFilter($this, false);
     $selectFilter->merge($this->productFilter);
     $cond = null;
     if ($disableFilters == false) {
         $list = array();
         // group filters by class
         foreach ($this->filters as $filter) {
             $id = $filter instanceof SpecificationFilterInterface ? $filter->getFilterGroup()->getID() : '';
             $list[get_class($filter) . '_' . $id][] = $filter->getCondition();
             $filter->defineJoin($selectFilter);
         }
         // convert filter group to OrChainCondition
         foreach ($list as &$filterGroup) {
             $filterGroup = new OrChainCondition($filterGroup);
         }
         if ($fCond = $selectFilter->getCondition()) {
             $list[] = $fCond;
         }
         $selectFilter->setCondition(new AndChainCondition($list));
         // all merged with and
     }
     if (!empty(ActiveRecordModel::getApplication()->variationCond)) {
         $c = ActiveRecordModel::getApplication()->variationCond;
         $c->addAND(eq(f('Product.isEnabled'), true));
         $noOrphans = new IsNotNullCond(f('Product.categoryID'));
         $orphanVariations = new IsNotNullCond(f('Product.parentID'));
         $orphanVariations->addAND(new IsNotNullCond(new ARExpressionHandle('(SELECT categoryID FROM Product AS par WHERE par.ID=Product.parentID)')));
         $noOrphans->addOr($orphanVariations);
         $c->addAND($noOrphans);
         //$c->addAND(gt(f('Product.stockCount'), 0));
         $conds = array($selectFilter->getCondition(), $c);
         $selectFilter->setCondition(new OrChainCondition($conds));
         $selectFilter->setOrder(new ARExpressionHandle('(Product.parentID IS NULL)'), 'DESC');
         //var_dump($selectFilter->createString());
     }
     ActiveRecordModel::getApplication()->processInstancePlugins('finalProductFilter', $selectFilter);
     return $selectFilter;
 }