public function getSelectFilter() { $selectFilter = new ARSelectFilter(); $this->application->processInstancePlugins('productFilter', $selectFilter); $order = $this->request->get('sort'); $defOrder = strtolower($this->config->get('SORT_ORDER')); if (!$order) { $order = $defOrder; } $this->applySortOrder($selectFilter, $order); // setup ProductFilter $productFilter = new ProductFilter($this->getCategory(), $selectFilter); if ($this->config->get('INCLUDE_SUBCATEGORY_PRODUCTS')) { $productFilter->includeSubcategories(); } $this->productFilter = $productFilter; foreach ($this->filters as $filter) { $productFilter->applyFilter($filter); if ($filter instanceof SearchFilter) { $productFilter->includeSubcategories(); $searchQuery = $filter->getKeywords(); } } if ($this->getCategory()->isRoot() && $this->filters || $this->filters || $this->request->get('includeSub')) { $productFilter->includeSubcategories(); } return $productFilter; }
public function bestsellingProductsBlock() { ClassLoader::import('application.model.product.ProductFilter'); $cache = $this->application->getCache(); $key = array('bestsellers', $this->getCategory()->getID() . '_' . $days); if (!$cache->get($key)) { $category = $this->getCategory(); $filter = new ProductFilter($category, new ARSelectFilter()); $filter->includeSubcategories(); $filter->setEnabledOnly(); $selectFilter = $filter->getSelectFilter(); $selectFilter->setLimit($this->config->get('BESTSELLING_ITEMS_COUNT')); $selectFilter->setOrder(new ARExpressionHandle('cnt'), 'DESC'); $q = new ARSelectQueryBuilder(); $q->includeTable('Product'); $q->joinTable('Category', 'Product', 'ID', 'categoryID'); $q->addField('Product.ID'); $q->addField(new ARExpressionHandle('(SELECT SUM(count) FROM OrderedItem LEFT JOIN CustomerOrder ON OrderedItem.customerOrderID=CustomerOrder.ID WHERE productID=Product.ID AND CustomerOrder.isPaid=1 AND CustomerOrder.dateCompleted > "' . ARSerializableDateTime::createFromTimeStamp(strtotime('-' . $this->config->get('BESTSELLING_ITEMS_DAYS') . ' days')) . '")'), null, 'cnt'); $q->setFilter($selectFilter); $cache->set($key, ActiveRecord::getDataByQuery($q)); } $products = $cache->get($key); if (!$products) { return; } $ids = array(); foreach ($products as $id) { $ids[] = $id['ID']; } $products = ActiveRecord::getRecordSetArray('Product', select(IN('Product.ID', $ids)), array('DefaultImage' => 'ProductImage')); ProductPrice::loadPricesForRecordSetArray($products); if ($products) { return new BlockResponse('products', $products); } }
private function getFeaturedMainCategoryProducts(&$categories) { $cache = $this->application->getCache(); $namespace = 'category_featured'; $products = array(); foreach ((array) $categories as $category) { $key = array($namespace, $category['ID']); if ($product = $cache->get($key)) { $products[] = $product; continue; } $cat = Category::getInstanceByID($category['ID'], Category::LOAD_DATA); $pf = new ProductFilter($cat, new ARSelectFilter()); $pf->includeSubcategories(); $f = $cat->getProductsFilter($pf); $f->mergeCondition(new EqualsCond(new ARFieldHandle('Product', 'isFeatured'), true)); $f->setLimit(1); $f->setOrder(new ARExpressionHandle('RAND()')); $product = array_pop(ActiveRecordModel::getRecordSetArray('Product', $f, array('ProductImage', 'Category', 'Manufacturer'))); if (!$product) { $product = array('ID' => 0); } $cache->set($key, $product, 1800); $products[] = $product; } ProductPrice::loadPricesForRecordSetArray($products); foreach ($products as $key => $product) { $categories[$key]['featuredProduct'] = $product; } }