protected function _prepareCollection() { if (!Mage::helper('core')->isModuleEnabled('Mage_Reports')) { return $this; } $collection = Mage::getResourceModel('reports/order_collection')->addItemCountExpr()->joinCustomerName('customer')->orderByCreatedAt(); if ($this->getParam('store') || $this->getParam('website') || $this->getParam('group')) { if ($this->getParam('store')) { $collection->addAttributeToFilter('store_id', $this->getParam('store')); } else { if ($this->getParam('website')) { $storeIds = Mage::app()->getWebsite($this->getParam('website'))->getStoreIds(); $collection->addAttributeToFilter('store_id', array('in' => $storeIds)); } else { if ($this->getParam('group')) { $storeIds = Mage::app()->getGroup($this->getParam('group'))->getStoreIds(); $collection->addAttributeToFilter('store_id', array('in' => $storeIds)); } } } $collection->addRevenueToSelect(); } else { $collection->addRevenueToSelect(true); } $this->setCollection($collection); return parent::_prepareCollection(); }
protected function _prepareCollection() { $collection = Mage::getModel('compta_invoice/invoice')->getCollection()->addFieldToFilter('adjusted', 0)->addFieldToSelect('*'); $collection->getSelect()->joinLeft('compta_customer', 'compta_customer.customer_id = main_table.customer_id'); $this->setCollection($collection); return parent::_prepareCollection(); }
protected function _prepareCollection() { //TODO: add full name logic $collection = Mage::getResourceModel('reports/order_collection')->addItemCountExpr()->addExpressionAttributeToSelect('customer', "IFNULL(CONCAT({{customer_firstname}},' ',{{customer_lastname}}), '{$this->__('Guest')}')", array('customer_firstname', 'customer_lastname'))->setOrder('created_at'); if ($this->getParam('store') || $this->getParam('website') || $this->getParam('group')) { if ($this->getParam('store')) { $collection->addAttributeToFilter('store_id', $this->getParam('store')); } else { if ($this->getParam('website')) { $storeIds = Mage::app()->getWebsite($this->getParam('website'))->getStoreIds(); $collection->addAttributeToFilter('store_id', array('in' => $storeIds)); } else { if ($this->getParam('group')) { $storeIds = Mage::app()->getGroup($this->getParam('group'))->getStoreIds(); $collection->addAttributeToFilter('store_id', array('in' => $storeIds)); } } } $collection->addExpressionAttributeToSelect('revenue', '({{base_grand_total}})', array('base_grand_total')); } else { $collection->addExpressionAttributeToSelect('revenue', '({{base_grand_total}}*{{base_to_global_rate}})', array('base_grand_total', 'base_to_global_rate')); } $this->setCollection($collection); return parent::_prepareCollection(); }
protected function _prepareCollection() { $collection = Mage::getResourceModel('affiliateplus/account_collection'); if ($storeId = $this->getRequest()->getParam('store')) { $collection->setStoreId($storeId); } $this->setCollection($collection); return parent::_prepareCollection(); }
protected function _prepareCollection() { $collection = Mage::getResourceModel('affiliateplus/transaction_collection'); $collection->setModel('adminhtml/report_item'); $itemTable = $collection->getTable('sales/order_item'); $collection->getSelect()->join(array('i' => $itemTable), 'main_table.order_id = i.order_id AND FIND_IN_SET(i.product_id, main_table.order_item_ids)', array('name', 'product_id', 'product_type', 'sku', 'base_price', 'num_order_placed' => 'SUM(i.qty_ordered)'))->where('type = 3')->group('product_id')->order('num_order_placed DESC')->order('base_price DESC'); $this->setCollection($collection); return parent::_prepareCollection(); }
protected function _prepareCollection() { $collection = Mage::getResourceModel('affiliateplus/action_collection'); $collection->getSelect()->reset(Zend_Db_Select::COLUMNS)->columns(array('referer' => 'domain', 'clicks' => 'SUM(totals)', 'uniques' => 'SUM(is_unique)'))->group('referer')->order('clicks DESC'); if ($storeId = $this->getRequest()->getParam('store')) { $collection->addFieldToFilter('store_id', $storeId); } $this->setCollection($collection); return parent::_prepareCollection(); }
/** * Loads the necessary live user data * from the specified Piwik instance. * * @return Faett_Piwik_Block_Adminhtml_Dashboard_Tab_Live_User The instance */ protected function _prepareCollection() { // initialize the Piwik service $service = Faett_Piwik_Service::create(); // load the live user data $collection = $service->call('Live.getLastVisits'); // set the data $this->setCollection($collection); // call the method of the parent class return parent::_prepareCollection(); }
protected function _prepareCollection() { $collection = Mage::getResourceModel('affiliateplus/account_collection'); $transactionTable = $collection->getTable('affiliateplus/transaction'); $collection->getSelect()->joinLeft(array('ts' => $transactionTable), 'main_table.account_id = ts.account_id AND ts.type = 3', array('amount' => 'SUM(ts.total_amount)', 'num_order_placed' => 'COUNT(ts.transaction_id)'))->where('ts.status = 1')->group('ts.account_id')->order('amount DESC'); if ($storeId = $this->getRequest()->getParam('store')) { $collection->setStoreId($storeId); $collection->getSelect()->where("ts.store_id = {$storeId}"); } $this->setCollection($collection); return parent::_prepareCollection(); }
protected function _prepareCollection() { if ($this->getParam('website')) { $storeIds = Mage::app()->getWebsite($this->getParam('website'))->getStoreIds(); $storeId = array_pop($storeIds); } else { if ($this->getParam('group')) { $storeIds = Mage::app()->getGroup($this->getParam('group'))->getStoreIds(); $storeId = array_pop($storeIds); } else { $storeId = (int) $this->getParam('store'); } } $collection = Mage::getResourceModel('reports/product_collection')->addAttributeToSelect('*')->addViewsCount()->setStoreId($storeId)->addStoreFilter($storeId); $this->setCollection($collection); return parent::_prepareCollection(); }
protected function _prepareCollection() { if ($this->getParam('website')) { $storeIds = Mage::app()->getWebsite($this->getParam('website'))->getStoreIds(); $storeId = array_pop($storeIds); } else { if ($this->getParam('group')) { $storeIds = Mage::app()->getGroup($this->getParam('group'))->getStoreIds(); $storeId = array_pop($storeIds); } else { $storeId = (int) $this->getParam('store'); } } $collection = Mage::getResourceModel('sales/report_bestsellers_collection')->setModel('catalog/product')->addStoreFilter($storeId); $this->setCollection($collection); return parent::_prepareCollection(); }
protected function _prepareCollection() { if ($this->getParam('website')) { $storeIds = Mage::app()->getWebsite($this->getParam('website'))->getStoreIds(); $storeId = array_pop($storeIds); } else { if ($this->getParam('group')) { $storeIds = Mage::app()->getGroup($this->getParam('group'))->getStoreIds(); $storeId = array_pop($storeIds); } else { $storeId = (int) $this->getParam('store'); } } $collection = Mage::getResourceModel('reports/product_collection')->addOrderedQty()->addAttributeToSelect(array('name', 'price'))->setStoreId($storeId)->addStoreFilter($storeId)->setOrder('ordered_qty', 'desc'); $this->setCollection($collection); return parent::_prepareCollection(); }
protected function _prepareCollection() { $this->_collection = Mage::getModel('catalogsearch/query')->getResourceCollection(); $this->_collection->setRecentQueryFilter(); if ($this->getRequest()->getParam('store')) { $this->_collection->addFieldToFilter('store_id', $this->getRequest()->getParam('store')); } else { if ($this->getRequest()->getParam('website')) { $storeIds = Mage::app()->getWebsite($this->getRequest()->getParam('website'))->getStoreIds(); $this->_collection->addFieldToFilter('store_id', array('in' => $storeIds)); } else { if ($this->getRequest()->getParam('group')) { $storeIds = Mage::app()->getGroup($this->getRequest()->getParam('group'))->getStoreIds(); $this->_collection->addFieldToFilter('store_id', array('in' => $storeIds)); } } } $this->setCollection($this->_collection); return parent::_prepareCollection(); }
protected function _prepareCollection() { $this->_collection = Mage::getModel('catalogsearch/query')->getResourceCollection(); if ($this->getRequest()->getParam('store')) { $storeIds = $this->getRequest()->getParam('store'); } else { if ($this->getRequest()->getParam('website')) { $storeIds = Mage::app()->getWebsite($this->getRequest()->getParam('website'))->getStoreIds(); } else { if ($this->getRequest()->getParam('group')) { $storeIds = Mage::app()->getGroup($this->getRequest()->getParam('group'))->getStoreIds(); } else { $storeIds = ''; } } } $this->_collection->setPopularQueryFilter($storeIds); $this->setCollection($this->_collection); return parent::_prepareCollection(); }
protected function _prepareCollection() { if (!Mage::helper('Mage_Core_Helper_Data')->isModuleEnabled('Mage_Sales')) { return $this; } if ($this->getParam('website')) { $storeIds = Mage::app()->getWebsite($this->getParam('website'))->getStoreIds(); $storeId = array_pop($storeIds); } else { if ($this->getParam('group')) { $storeIds = Mage::app()->getGroup($this->getParam('group'))->getStoreIds(); $storeId = array_pop($storeIds); } else { $storeId = (int) $this->getParam('store'); } } $collection = Mage::getResourceModel('Mage_Sales_Model_Resource_Report_Bestsellers_Collection')->setModel('Mage_Catalog_Model_Product')->addStoreFilter($storeId); $this->setCollection($collection); return parent::_prepareCollection(); }
protected function _prepareCollection() { $collection = new Varien_Data_Collection(); $monthsTrad = array('January' => 'Janvier', 'February' => 'Février', 'March' => 'Mars', 'April' => 'Avril', 'May' => 'Mai', 'June' => 'Juin', 'July' => 'Juillet', 'August' => 'Août', 'September' => 'Septembre', 'October' => 'Octobre', 'November' => 'Novembre', 'December' => 'Décembre'); for ($m = 0; $m < 5; $m++) { $object = new Varien_Object(); $collectionInvoices = Mage::getModel('compta_invoice/invoice')->getCollection()->addFieldToFilter('adjusted', 1)->addFieldToFilter('payment_date', array('like' => date("Y-m", strtotime("-{$m} month")) . "-%")); $total = 0; foreach ($collectionInvoices as $invoice) { $total += $invoice->getAmount(); } $object->setData('month', $monthsTrad[date("F", strtotime("-{$m} month"))] . ' ' . date("Y", strtotime("-{$m} month"))); $object->setData('amount', $total); $object->setData('amount_net', Mage::helper('compta_invoice')->toNet($total)); $collection->addItem($object); unset($object); } $this->setCollection($collection); return parent::_prepareCollection(); }
protected function _prepareCollection() { $collection = Mage::getResourceModel('reports/customer_collection')->addCustomerName(); $storeFilter = 0; if ($this->getParam('store')) { $collection->addAttributeToFilter('store_id', $this->getParam('store')); $storeFilter = 1; } else { if ($this->getParam('website')) { $storeIds = Mage::app()->getWebsite($this->getParam('website'))->getStoreIds(); $collection->addAttributeToFilter('store_id', array('in' => $storeIds)); } else { if ($this->getParam('group')) { $storeIds = Mage::app()->getGroup($this->getParam('group'))->getStoreIds(); $collection->addAttributeToFilter('store_id', array('in' => $storeIds)); } } } $collection->addOrdersStatistics($storeFilter)->orderByCustomerRegistration(); $this->setCollection($collection); return parent::_prepareCollection(); }
protected function _prepareCollection() { if (!Mage::helper('Mage_Core_Helper_Data')->isModuleEnabled('Mage_CatalogSearch')) { return parent::_prepareCollection(); } $this->_collection = Mage::getModel('Mage_CatalogSearch_Model_Query')->getResourceCollection(); $this->_collection->setRecentQueryFilter(); if ($this->getRequest()->getParam('store')) { $this->_collection->addFieldToFilter('store_id', $this->getRequest()->getParam('store')); } else { if ($this->getRequest()->getParam('website')) { $storeIds = Mage::app()->getWebsite($this->getRequest()->getParam('website'))->getStoreIds(); $this->_collection->addFieldToFilter('store_id', array('in' => $storeIds)); } else { if ($this->getRequest()->getParam('group')) { $storeIds = Mage::app()->getGroup($this->getRequest()->getParam('group'))->getStoreIds(); $this->_collection->addFieldToFilter('store_id', array('in' => $storeIds)); } } } $this->setCollection($this->_collection); return parent::_prepareCollection(); }
protected function _prepareCollection() { $collection = Mage::getResourceModel('reports/order_collection'); /* @var $collection Mage_Reports_Model_Mysql4_Order_Collection */ $collection->groupByCustomer()->addOrdersCount()->joinCustomerName(); $storeFilter = 0; if ($this->getParam('store')) { $collection->addAttributeToFilter('store_id', $this->getParam('store')); $storeFilter = 1; } else { if ($this->getParam('website')) { $storeIds = Mage::app()->getWebsite($this->getParam('website'))->getStoreIds(); $collection->addAttributeToFilter('store_id', array('in' => $storeIds)); } else { if ($this->getParam('group')) { $storeIds = Mage::app()->getGroup($this->getParam('group'))->getStoreIds(); $collection->addAttributeToFilter('store_id', array('in' => $storeIds)); } } } $collection->addSumAvgTotals($storeFilter)->orderByTotalAmount(); $this->setCollection($collection); return parent::_prepareCollection(); }
protected function _prepareCollection() { $this->_collection = Mage::getModel('catalog/product')->getCollection()->addAttributetoSelect('name')->addAttributetoSelect('creator_id')->addAttributetoFilter('creator_id', array('notnull' => true)); $this->setCollection($this->_collection); return parent::_prepareCollection(); }
protected function _prepareCollection() { $collection = new Varien_Data_Collection(); $monthsTrad = array('1' => 'Janvier', '2' => 'Février', '3' => 'Mars', '4' => 'Avril', '5' => 'Mai', '6' => 'Juin', '7' => 'Juillet', '8' => 'Août', '9' => 'Septembre', '10' => 'Octobre', '11' => 'Novembre', '12' => 'Décembre'); $tab = array(); $calendarCollection = Mage::getModel('compta_calendar/calendar')->getCollection(); foreach ($calendarCollection as $calendar) { $dateValues = Mage::helper('core')->jsonDecode($calendar->getValues()); foreach ($dateValues as $day => $nhour) { $customer = Mage::getModel('compta_customer/customer')->load($calendar->getCustomerId()); $delayPaiement = $customer->getPaiementDelay(); $yyyy_mm = substr($day, 0, 7); if (!isset($tab[$yyyy_mm][$calendar->getCustomerId()]['nbhour'])) { $tab[$yyyy_mm][$calendar->getCustomerId()]['nbhour'] = 0; } $tab[$yyyy_mm][$calendar->getCustomerId()]['nbhour'] += $nhour; $tab[$yyyy_mm][$calendar->getCustomerId()]['delay'] = $delayPaiement; } } $prevision = array(); foreach ($tab as $monthYYYYmm => $customerId) { foreach ($customerId as $cId => $data) { $addDay = $data['delay'] ? $data['delay'] : "0"; $nextMonthDate = date('Y-m', strtotime("+1 months +{$addDay} days", strtotime($monthYYYYmm . '-01'))); $customer = Mage::getModel('compta_customer/customer')->load($calendar->getCustomerId()); if (!isset($prevision[$nextMonthDate])) { $prevision[$nextMonthDate] = 0; } $prevision[$nextMonthDate] += $customer->getThm() * $data['nbhour']; } } $currentMonth = (int) date('m'); for ($m = $currentMonth; $m <= $currentMonth + 5; $m++) { $findMe = date('Y') . '-' . sprintf("%'.02d", $m); $object = new Varien_Object(); if (!isset($prevision[$findMe])) { $total = 0; } else { $total = $prevision[$findMe]; } $object->setData('month', $monthsTrad[$m]); $object->setData('amount', $total); $object->setData('amount_net', Mage::helper('compta_invoice')->toNet($total)); $collection->addItem($object); unset($object); } $this->setCollection($collection); return parent::_prepareCollection(); }
/** * Prepare collection * * Extend collection with joins to other resources. * * @return Mage_Adminhtml_Block_Widget_Grid */ protected function _prepareCollection() { $collection = Mage::getResourceModel($this->_getCollectionClass()); $this->setCollection($collection); return parent::_prepareCollection(); }