Пример #1
0
 public function getChildProductIDs()
 {
     $f = new ARSelectFilter(new INCond(new ARFieldHandle('Product', 'parentID'), $this->getRecordIDs()));
     $q = new ARSelectQueryBuilder($f);
     $q->includeTable('Product');
     $q->setFilter($f);
     $q->removeFieldList();
     $q->addField('ID');
     $q->addField('parentID');
     $ids = array();
     foreach (ActiveRecordModel::getDataByQuery($q) as $row) {
         $ids[$row['parentID']][] = $row['ID'];
     }
     return $ids;
 }
Пример #2
0
 private function getPage($class, $page, ARSelectFilter $f, $fields)
 {
     $f->setLimit(self::MAX_URLS, $page * self::MAX_URLS);
     $query = new ARSelectQueryBuilder();
     $query->setFilter($f);
     $query->includeTable($class);
     foreach ($fields as $field) {
         $query->addField($field);
     }
     return ActiveRecord::fetchDataFromDB($query);
 }
Пример #3
0
 public function getCountByManufacturers($includeAppliedFilters)
 {
     $selectFilter = $this->productFilter->getSelectFilter(!$includeAppliedFilters);
     $selectFilter->removeFieldList();
     $selectFilter->setLimit(0);
     $selectFilter->setOrder(new ARExpressionHandle('cnt'), 'DESC');
     $selectFilter->setGrouping(new ARFieldHandle('Product', 'manufacturerID'));
     $selectFilter->mergeHavingCondition(new MoreThanCond(new ARExpressionHandle('cnt'), 0));
     $selectFilter->mergeHavingCondition(new NotEqualsCond(new ARFieldHandle('Manufacturer', 'name'), ''));
     $selectFilter->resetOrder();
     $selectFilter->setOrder(new ARFieldHandle('Manufacturer', 'name'));
     $query = new ARSelectQueryBuilder();
     $query->includeTable('Product');
     $query->joinTable('Manufacturer', 'Product', 'ID', 'manufacturerID');
     $query->joinTable('Category', 'Product', 'ID', 'categoryID');
     $query->addField('COUNT(Product.manufacturerID)', null, 'cnt');
     $query->addField('ID', 'Manufacturer');
     $query->addField('name', 'Manufacturer');
     $query->setFilter($selectFilter);
     ActiveRecordModel::getApplication()->processInstancePlugins('manufacturerCountQuery', $query);
     $data = ActiveRecordModel::getDataBySQL($query->getPreparedStatement(ActiveRecord::getDBConnection()));
     return $data;
 }
Пример #4
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);
     }
 }
Пример #5
0
 public function info()
 {
     ClassLoader::importNow("application.helper.getDateFromString");
     $product = Product::getInstanceById($this->request->get('id'), ActiveRecord::LOAD_DATA, array('DefaultImage' => 'ProductImage', 'Manufacturer', 'Category'));
     $thisMonth = date('m');
     $lastMonth = date('Y-m', strtotime(date('m') . '/15 -1 month'));
     $periods = array('_last_1_h' => "-1 hours | now", '_last_3_h' => "-3 hours | now", '_last_6_h' => "-6 hours | now", '_last_12_h' => "-12 hours | now", '_last_24_h' => "-24 hours | now", '_last_3_d' => "-3 days | now", '_this_week' => "w:Monday | now", '_last_week' => "w:Monday ~ -1 week | w:Monday", '_this_month' => $thisMonth . "/1 | now", '_last_month' => $lastMonth . "-1 | " . $lastMonth . "/1", '_this_year' => "January 1 | now", '_last_year' => "January 1 last year | January 1", '_overall' => "now | now");
     $purchaseStats = array();
     $prevCount = 0;
     foreach ($periods as $key => $period) {
         list($from, $to) = explode(' | ', $period);
         $cond = new EqualsCond(new ARFieldHandle('OrderedItem', 'productID'), $product->getID());
         if ('now' != $from) {
             $cond->addAND(new EqualsOrMoreCond(new ARFieldHandle('CustomerOrder', 'dateCompleted'), getDateFromString($from)));
         }
         if ('now' != $to) {
             $cond->addAnd(new EqualsOrLessCond(new ARFieldHandle('CustomerOrder', 'dateCompleted'), getDateFromString($to)));
         }
         $f = new ARSelectFilter($cond);
         $f->mergeCondition(new EqualsCond(new ARFieldHandle('CustomerOrder', 'isFinalized'), true));
         $f->removeFieldList();
         $f->addField('SUM(OrderedItem.count)');
         $query = new ARSelectQueryBuilder();
         $query->setFilter($f);
         $query->includeTable('OrderedItem');
         $query->joinTable('CustomerOrder', 'OrderedItem', 'ID', 'customerOrderID');
         if (($count = array_shift(array_shift(ActiveRecordModel::getDataBySql($query->getPreparedStatement(ActiveRecord::getDBConnection()))))) && ($count > $prevCount || '_overall' == $key)) {
             $purchaseStats[$key] = $count;
         }
         if ($count > $prevCount) {
             $prevCount = $count;
         }
     }
     $response = new ActionResponse();
     $response->set('together', $product->getProductsPurchasedTogether(10));
     $response->set('product', $product->toArray());
     $response->set('purchaseStats', $purchaseStats);
     return $response;
 }
Пример #6
0
 public function getProductCount(ProductFilter $productFilter)
 {
     $query = new ARSelectQueryBuilder();
     $query->includeTable('Product');
     $query->addField('COUNT(*) AS cnt');
     $filter = $this->getProductsFilter($productFilter);
     $filter->setLimit(0);
     $query->setFilter($filter);
     $data = ActiveRecord::getDataBySQL($query->getPreparedStatement(ActiveRecord::getDBConnection()));
     return $data[0]['cnt'];
 }
Пример #7
0
 private function getOrderArray(ARSet $orders)
 {
     $orderArray = $orders->toArray();
     $ids = array();
     foreach ($orderArray as $key => $order) {
         $ids[$order['ID']] = $key;
     }
     ClassLoader::import('application.model.order.OrderNote');
     $f = new ARSelectFilter(new INCond(new ARFieldHandle('OrderNote', 'orderID'), empty($ids) ? array(-1) : array_keys($ids)));
     $f->mergeCondition(new EqualsCond(new ARFieldHandle('OrderNote', 'isAdmin'), 1));
     $f->mergeCondition(new EqualsCond(new ARFieldHandle('OrderNote', 'isRead'), 0));
     $f->setGrouping(new ARFieldHandle('OrderNote', 'orderID'));
     $query = new ARSelectQueryBuilder();
     $query->setFilter($f);
     $query->includeTable('OrderNote');
     $query->removeFieldList();
     $query->addField('COUNT(*)', null, 'cnt');
     $query->addField('orderID');
     foreach (ActiveRecordModel::getDataBySQL($query->getPreparedStatement(ActiveRecord::getDBConnection())) as $res) {
         $orderArray[$ids[$res['orderID']]]['unreadMessageCount'] = $res['cnt'];
     }
     return $orderArray;
 }
Пример #8
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;
     }
 }
Пример #9
0
 /**
  * Updates a set of records by using ARUpdateFilter
  *
  * @param class $className
  * @param ARUpdateFilter $filter
  * @return unknown
  */
 public static function updateRecordSet($className, ARUpdateFilter $filter, $joinReferencedTables = false)
 {
     $schema = self::getSchemaInstance($className);
     $db = self::getDBConnection();
     $query = new ARSelectQueryBuilder();
     $query->includeTable($className);
     if ($joinReferencedTables) {
         //$tables = is_array($joinReferencedTables) ? array_flip($joinReferencedTables) : $joinReferencedTables;
         self::joinReferencedTables($schema, $query, $joinReferencedTables);
     }
     $query->setFilter($filter);
     $query->removeFieldList();
     $sql = preg_replace('/^SELECT[ ]*FROM/', 'UPDATE', $query->createString());
     self::getLogger()->logQuery($sql);
     return $db->executeUpdate($sql);
 }
Пример #10
0
 protected function getQuery($countSql = null)
 {
     $q = new ARSelectQueryBuilder();
     $q->includeTable($this->getMainTable());
     $f = new ARSelectFilter();
     $q->setFilter($f);
     $dateHandle = $this->dateHandle ? $this->dateHandle : $this->getDateHandle();
     $this->setDateCondition($f, $dateHandle);
     $this->prepareDateQuery($dateHandle->toString(), $this->interval, $q);
     if ($countSql) {
         $q->addField(new ARExpressionHandle($countSql), null, 'cnt');
     }
     return $q;
 }