Exemplo n.º 1
0
 public function getCondition()
 {
     $from = new EqualsOrMoreCond(new ARFieldHandle('ProductPrice', 'price'), $this->priceFrom);
     $to = new EqualsOrLessCond(new ARFieldHandle('ProductPrice', 'price'), $this->priceTo);
     $from->addAND($to);
     return $from;
 }
Exemplo n.º 2
0
 public function getProductCondition($includeSubcategories = false)
 {
     if ($includeSubcategories) {
         if (!$this->isRoot()) {
             $cond = new EqualsOrMoreCond(new ARFieldHandle('Category', 'lft'), $this->lft->get());
             $cond->addAND(new EqualsOrLessCond(new ARFieldHandle('Category', 'rgt'), $this->rgt->get()));
             if ($this->hasProductsAsSecondaryCategory()) {
                 $cond->addOr(new INCond(new ARFieldHandle('Product', 'ID'), 'SELECT ProductCategory.productID FROM ProductCategory LEFT JOIN Category ON ProductCategory.categoryID=Category.ID WHERE Category.lft>=' . $this->lft->get() . ' AND Category.rgt<=' . $this->rgt->get()));
             }
         } else {
             $cond = new IsNotNullCond(new ARFieldHandle('Product', 'categoryID'));
         }
     } else {
         $cond = new EqualsCond(new ARFieldHandle('Product', 'categoryID'), $this->getID());
         if ($this->hasProductsAsSecondaryCategory()) {
             $cond->addOr(new INCond(new ARFieldHandle('Product', 'ID'), 'SELECT ProductCategory.productID FROM ProductCategory WHERE ProductCategory.categoryID=' . $this->getID()));
         }
     }
     return $cond;
 }
Exemplo n.º 3
0
 /**
  *  Narrow search results by categories
  */
 private function getSubcategoriesBySearchQuery(ARSelectFilter $selectFilter, $subCategories)
 {
     if (count($subCategories) > 0) {
         $case = new ARCaseHandle();
         $index = array();
         foreach ($subCategories as $key => $cat) {
             if (Category::ROOT_ID == $cat['ID']) {
                 continue;
             }
             $cond = new EqualsOrMoreCond(new ARFieldHandle('Category', 'lft'), $cat['lft']);
             $cond->addAND(new EqualsOrLessCond(new ARFieldHandle('Category', 'rgt'), $cat['rgt']));
             $case->addCondition($cond, new ARExpressionHandle($cat['ID']));
             $index[$cat['ID']] = $key;
         }
         $query = new ARSelectQueryBuilder();
         $query->includeTable('Product');
         $filter = clone $selectFilter;
         $filter->setLimit(0);
         $filter->resetOrder();
         $filter->setOrder(new ARExpressionHandle('cnt'), 'DESC');
         $filter->setGrouping(new ARExpressionHandle('ID'));
         foreach ($this->filters as $f) {
             $f->defineJoin($filter);
         }
         $query->setFilter($filter);
         $query->addField($case->toString(), null, 'ID');
         $query->addField('COUNT(*)', null, 'cnt');
         $query->joinTable('Category', 'Product', 'ID', 'categoryID');
         $query->joinTable('ProductPrice', 'Product', 'productID AND (ProductPrice.currencyID = "' . $this->application->getDefaultCurrencyCode() . '")', 'ID');
         $count = $query->getPreparedStatement(ActiveRecord::getDBConnection())->executeQuery();
         $categoryNarrow = array();
         foreach ($count as $cat) {
             if (!isset($index[$cat['ID']])) {
                 continue;
             }
             $data = $subCategories[$index[$cat['ID']]];
             $data['searchCount'] = $cat['cnt'];
             $categoryNarrow[] = $data;
         }
         return $categoryNarrow;
     }
 }
Exemplo n.º 4
0
 private function getTabCounts($categoryId)
 {
     ClassLoader::import('application.model.category.*');
     ClassLoader::import('application.model.filter.*');
     ClassLoader::import('application.model.product.*');
     $category = Category::getInstanceByID($categoryId, Category::LOAD_DATA);
     $reviewCond = new EqualsOrMoreCond(new ARFieldHandle('Category', 'lft'), $category->lft->get());
     $reviewCond->addAND(new EqualsOrLessCond(new ARFieldHandle('Category', 'rgt'), $category->rgt->get()));
     return array('tabProducts' => $category->totalProductCount->get(), 'tabFilters' => $this->getFilterCount($category), 'tabFields' => $this->getSpecFieldCount($category), 'tabImages' => $this->getCategoryImageCount($category), 'tabOptions' => $category->getOptions()->getTotalRecordCount(), 'tabRatingCategories' => ProductRatingType::getCategoryRatingTypes($category)->size(), 'tabReviews' => ActiveRecordModel::getRecordCount('ProductReview', new ARSelectFilter($reviewCond), array('Category', 'Product')), 'tabProductLists' => $category->getRelatedRecordCount('ProductList'));
 }
Exemplo n.º 5
0
 protected function getSelectFilter()
 {
     $id = $this->getID();
     if ($this->isCategory()) {
         $owner = Category::getInstanceByID($id, Category::LOAD_DATA);
         $cond = new EqualsOrMoreCond(new ARFieldHandle('Category', 'lft'), $owner->lft->get());
         $cond->addAND(new EqualsOrLessCond(new ARFieldHandle('Category', 'rgt'), $owner->rgt->get()));
     } else {
         $cond = new EqualsCond(new ARFieldHandle('ProductReview', 'productID'), $id);
     }
     return new ARSelectFilter($cond);
 }