Esempio n. 1
0
 public function init()
 {
     $date = new Axis_Date();
     $todayDate = $date->toString();
     $date = $date->addDay(-1)->toString('YYYY-MM-dd');
     $mailCount = Axis::single('contacts/message')->select()->where('created_at > ?', $date)->count();
     $orderTotal = (double) Axis::single('sales/order')->select('SUM(order_total)')->where('date_purchased_on > ?', $date)->fetchOne();
     $orderTotal = Axis::single('locale/currency')->getCurrency(Axis::config()->locale->main->currency)->toCurrency($orderTotal ? $orderTotal : 0);
     $orderCount = Axis::single('sales/order')->select()->where('date_purchased_on > ?', $date)->count();
     $userId = Zend_Auth::getInstance()->getIdentity();
     $this->setFromArray(array('today_date' => $todayDate, 'mail_count' => $mailCount, 'order_total' => $orderTotal, 'order_count' => $orderCount, 'user_info' => Axis::single('admin/user')->find($userId)->current()));
     return true;
 }
Esempio n. 2
0
 /**
  * Retrieve the list of product ids
  * which prices are depends on current discount
  *
  * @return array
  */
 public function getApplicableProducts()
 {
     $model = Axis::model('discount/eav');
     $conditions = $model->select('*')->where('discount_id = ?', $this->id)->fetchAll();
     $mProduct = Axis::model('catalog/product');
     $select = $mProduct->select('*')->distinct();
     if (!count($conditions)) {
         return $select->fetchCol();
     }
     $filters = array();
     $joinCategory = false;
     foreach ($conditions as $condition) {
         $filters[$condition['entity']][] = $condition['value'];
         if (in_array($condition['entity'], array('site', 'category'))) {
             $joinCategory = true;
         }
     }
     if ($joinCategory) {
         $select->joinInner('catalog_product_category', 'cpc.product_id = cp.id');
     }
     foreach ($filters as $key => $values) {
         switch ($key) {
             case 'manufacture':
                 $select->where('cp.manufacturer_id IN (?)', $values);
                 break;
             case 'site':
                 $select->joinInner('catalog_category', 'cc.id = cpc.category_id')->where('cc.site_id IN (?)', $values);
                 break;
             case 'category':
                 $select->where('cpc.category_id IN (?)', $values);
                 break;
             case 'optionId':
                 $where = array();
                 foreach ($values as $optionId) {
                     $value = $filters['option[' . $optionId . ']'][0];
                     $select->joinInner(array("cpa{$optionId}" => 'catalog_product_attribute'), "cpa{$optionId}.product_id = cp.id");
                     $where[] = "(cpa{$optionId}.option_id = {$optionId}" . " AND cpa{$optionId}.option_value_id = {$value})";
                 }
                 $select->where(implode(' OR ', $where));
                 break;
             default:
                 // price and date filters
                 if (0 === strpos($key, 'option') || false === strpos($key, '_')) {
                     continue;
                 }
                 $mapping = array('equals' => '=', 'greate' => '>=', 'less' => '<=', 'date' => 'created_on', 'price' => 'price');
                 list($attribute, $comparator) = explode('_', $key);
                 foreach ($values as $value) {
                     if ('date' === $attribute) {
                         $date = new Axis_Date($value);
                         $value = $date->toString('yyyy-MM-dd', 'iso');
                     }
                     $select->where("cp.{$mapping[$attribute]} {$mapping[$comparator]} ?", $value);
                 }
                 break;
         }
     }
     return $select->fetchAssoc();
 }