public function testSetIsSubtotals()
 {
     $this->collection->setIsSubTotals(true);
     $this->assertTrue($this->collection->isSubTotals());
     $this->collection->setIsSubTotals(false);
     $this->assertFalse($this->collection->isSubTotals());
 }
Example #2
0
 /**
  * Add price rule filter
  *
  * @param \Magento\Reports\Model\Resource\Report\Collection\AbstractCollection $collection
  * @param \Magento\Framework\Object $filterData
  * @return \Magento\Reports\Block\Adminhtml\Grid\AbstractGrid
  */
 protected function _addCustomFilter($collection, $filterData)
 {
     if ($filterData->getPriceRuleType()) {
         $rulesList = $filterData->getData('rules_list');
         if (isset($rulesList[0])) {
             $rulesIds = explode(',', $rulesList[0]);
             $collection->addRuleFilter($rulesIds);
         }
     }
     return parent::_addCustomFilter($filterData, $collection);
 }
 /**
  * @param \Magento\Framework\Data\Collection\EntityFactory $entityFactory
  * @param \Psr\Log\LoggerInterface $logger
  * @param \Magento\Framework\Data\Collection\Db\FetchStrategyInterface $fetchStrategy
  * @param \Magento\Framework\Event\ManagerInterface $eventManager
  * @param \Magento\Sales\Model\Resource\Report $resource
  * @param null $connection
  */
 public function __construct(\Magento\Framework\Data\Collection\EntityFactory $entityFactory, \Psr\Log\LoggerInterface $logger, \Magento\Framework\Data\Collection\Db\FetchStrategyInterface $fetchStrategy, \Magento\Framework\Event\ManagerInterface $eventManager, \Magento\Sales\Model\Resource\Report $resource, $connection = null)
 {
     parent::__construct($entityFactory, $logger, $fetchStrategy, $eventManager, $connection, $resource);
     $this->setModel('Magento\\Reports\\Model\\Item');
 }
Example #4
0
 /**
  * Add order status filter
  *
  * @param \Magento\Reports\Model\Resource\Report\Collection\AbstractCollection $collection
  * @param \Magento\Framework\Object $filterData
  * @return $this
  */
 protected function _addOrderStatusFilter($collection, $filterData)
 {
     $collection->addOrderStatusFilter($filterData->getData('order_statuses'));
     return $this;
 }
Example #5
0
 /**
  * Re-declare parent method for applying filters after parent method, but before adding unions and calculating
  * totals
  *
  * @return $this|\Magento\Framework\Model\Resource\Db\Collection\AbstractCollection
  */
 protected function _beforeLoad()
 {
     parent::_beforeLoad();
     $this->_applyStoresFilter();
     if ($this->_period) {
         $selectUnions = array();
         // apply date boundaries (before calling $this->_applyDateRangeFilter())
         $dtFormat = \Magento\Framework\Stdlib\DateTime::DATE_INTERNAL_FORMAT;
         $periodFrom = !is_null($this->_from) ? new \Magento\Framework\Stdlib\DateTime\Date($this->_from, $dtFormat) : null;
         $periodTo = !is_null($this->_to) ? new \Magento\Framework\Stdlib\DateTime\Date($this->_to, $dtFormat) : null;
         if ('year' == $this->_period) {
             if ($periodFrom) {
                 // not the first day of the year
                 if ($periodFrom->toValue(\Zend_Date::MONTH) != 1 || $periodFrom->toValue(\Zend_Date::DAY) != 1) {
                     $dtFrom = $periodFrom->getDate();
                     // last day of the year
                     $dtTo = $periodFrom->getDate()->setMonth(12)->setDay(31);
                     if (!$periodTo || $dtTo->isEarlier($periodTo)) {
                         $selectUnions[] = $this->_makeBoundarySelect($dtFrom->toString($dtFormat), $dtTo->toString($dtFormat));
                         // first day of the next year
                         $this->_from = $periodFrom->getDate()->addYear(1)->setMonth(1)->setDay(1)->toString($dtFormat);
                     }
                 }
             }
             if ($periodTo) {
                 // not the last day of the year
                 if ($periodTo->toValue(\Zend_Date::MONTH) != 12 || $periodTo->toValue(\Zend_Date::DAY) != 31) {
                     $dtFrom = $periodTo->getDate()->setMonth(1)->setDay(1);
                     // first day of the year
                     $dtTo = $periodTo->getDate();
                     if (!$periodFrom || $dtFrom->isLater($periodFrom)) {
                         $selectUnions[] = $this->_makeBoundarySelect($dtFrom->toString($dtFormat), $dtTo->toString($dtFormat));
                         // last day of the previous year
                         $this->_to = $periodTo->getDate()->subYear(1)->setMonth(12)->setDay(31)->toString($dtFormat);
                     }
                 }
             }
             if ($periodFrom && $periodTo) {
                 // the same year
                 if ($periodFrom->toValue(\Zend_Date::YEAR) == $periodTo->toValue(\Zend_Date::YEAR)) {
                     $dtFrom = $periodFrom->getDate();
                     $dtTo = $periodTo->getDate();
                     $selectUnions[] = $this->_makeBoundarySelect($dtFrom->toString($dtFormat), $dtTo->toString($dtFormat));
                     $this->getSelect()->where('1<>1');
                 }
             }
         } elseif ('month' == $this->_period) {
             if ($periodFrom) {
                 // not the first day of the month
                 if ($periodFrom->toValue(\Zend_Date::DAY) != 1) {
                     $dtFrom = $periodFrom->getDate();
                     // last day of the month
                     $dtTo = $periodFrom->getDate()->addMonth(1)->setDay(1)->subDay(1);
                     if (!$periodTo || $dtTo->isEarlier($periodTo)) {
                         $selectUnions[] = $this->_makeBoundarySelect($dtFrom->toString($dtFormat), $dtTo->toString($dtFormat));
                         // first day of the next month
                         $this->_from = $periodFrom->getDate()->addMonth(1)->setDay(1)->toString($dtFormat);
                     }
                 }
             }
             if ($periodTo) {
                 // not the last day of the month
                 if ($periodTo->toValue(\Zend_Date::DAY) != $periodTo->toValue(\Zend_Date::MONTH_DAYS)) {
                     $dtFrom = $periodTo->getDate()->setDay(1);
                     // first day of the month
                     $dtTo = $periodTo->getDate();
                     if (!$periodFrom || $dtFrom->isLater($periodFrom)) {
                         $selectUnions[] = $this->_makeBoundarySelect($dtFrom->toString($dtFormat), $dtTo->toString($dtFormat));
                         // last day of the previous month
                         $this->_to = $periodTo->getDate()->setDay(1)->subDay(1)->toString($dtFormat);
                     }
                 }
             }
             if ($periodFrom && $periodTo) {
                 // the same month
                 if ($periodFrom->toValue(\Zend_Date::YEAR) == $periodTo->toValue(\Zend_Date::YEAR) && $periodFrom->toValue(\Zend_Date::MONTH) == $periodTo->toValue(\Zend_Date::MONTH)) {
                     $dtFrom = $periodFrom->getDate();
                     $dtTo = $periodTo->getDate();
                     $selectUnions[] = $this->_makeBoundarySelect($dtFrom->toString($dtFormat), $dtTo->toString($dtFormat));
                     $this->getSelect()->where('1<>1');
                 }
             }
         }
         $this->_applyDateRangeFilter();
         // add unions to select
         if ($selectUnions) {
             $unionParts = array();
             $cloneSelect = clone $this->getSelect();
             $unionParts[] = '(' . $cloneSelect . ')';
             foreach ($selectUnions as $union) {
                 $unionParts[] = '(' . $union . ')';
             }
             $this->getSelect()->reset()->union($unionParts, \Zend_Db_Select::SQL_UNION_ALL);
         }
         if ($this->isTotals()) {
             // calculate total
             $cloneSelect = clone $this->getSelect();
             $this->getSelect()->reset()->from($cloneSelect, $this->getAggregatedColumns());
         } else {
             // add sorting
             $this->getSelect()->order(array('period ASC', 'views_num DESC'));
         }
     }
     return $this;
 }