예제 #1
0
 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);
     }
 }
예제 #2
0
 private function getSubCatFeaturedProducts()
 {
     $cache = $this->application->getCache();
     $namespace = 'subcategory_featured_' . $this->application->getLocaleCode();
     $id = $this->getCategory()->getID();
     $key = array($namespace, $id);
     if ($products = $cache->get($key)) {
         return $products;
     }
     $count = $this->config->get('FEATURED_COUNT');
     if ('GRID' == $this->getListLayout()) {
         $row = $this->config->get('LAYOUT_GRID_COLUMNS');
         $count = ceil($count / $row) * $row;
     }
     $selFilter = new ARSelectFilter();
     if (!$this->config->get('FEATURED_RANDOM')) {
         $selFilter->mergeCondition(new EqualsCond(new ARFieldHandle('Product', 'isFeatured'), true));
     } else {
         $selFilter->setOrder(new ARExpressionHandle('Product.isFeatured=1'), 'DESC');
     }
     $featuredFilter = new ProductFilter($this->getCategory(), $selFilter);
     $featuredFilter->includeSubcategories();
     $selFilter->setOrder(new ARExpressionHandle('RAND()'));
     $selFilter->setLimit($count);
     $ids = ActiveRecord::getRecordSetFields('Product', $featuredFilter->getSelectFilter(), array('Product.ID'), array('Category', 'Manufacturer'));
     $rand = array();
     foreach ($ids as $id) {
         $rand[] = $id['ID'];
     }
     $featuredFilter = new ProductFilter(Category::getRootNode(), select(in('Product.ID', $rand)));
     $featuredFilter->includeSubcategories();
     $cache->set($key, $this->getProductsArray($featuredFilter), time() + 1800);
     return $cache->get($key);
 }
예제 #3
0
파일: Category.php 프로젝트: saiber/www
 /**
  * Gets a list of products assigned to this node
  *
  * @param bool $loadReferencedRecords
  * @return array
  */
 public function getProductArray(ProductFilter $productFilter, $loadReferencedRecords = false)
 {
     return ActiveRecordModel::getRecordSetArray('Product', $productFilter->getSelectFilter(), $loadReferencedRecords);
 }
예제 #4
0
파일: ProductFeed.php 프로젝트: saiber/www
 public function __construct(ProductFilter $filter)
 {
     $this->productFilter = $filter;
     parent::__construct($filter->getSelectFilter(), 'Product', array('Category', 'ProductImage', 'Manufacturer'));
 }