12 class Collection extends \Magento\Sales\Model\ResourceModel\Report\Collection\AbstractCollection
34 'daily' =>
'sales_bestsellers_aggregated_daily',
35 'monthly' =>
'sales_bestsellers_aggregated_monthly',
36 'yearly' =>
'sales_bestsellers_aggregated_yearly',
77 return $this->tableForPeriod[$period];
89 if (!$this->_selectedColumns) {
93 $this->_selectedColumns = [
94 'period' => sprintf(
'MAX(%s)',
$connection->getDateFormatSql(
'period',
'%Y-%m-%d')),
96 'product_id' =>
'product_id',
97 'product_name' =>
'MAX(product_name)',
98 'product_price' =>
'MAX(product_price)',
100 if (
'year' == $this->_period) {
101 $this->_selectedColumns[
'period'] =
$connection->getDateFormatSql(
'period',
'%Y');
102 }
elseif (
'month' == $this->_period) {
103 $this->_selectedColumns[
'period'] =
$connection->getDateFormatSql(
'period',
'%Y-%m');
154 if (!$this->_period) {
157 if ($this->_from || $this->_to) {
159 $select->from($mainTable, $cols);
162 $select->from($mainTable, $cols);
177 if (
'year' == $this->_period) {
180 }
elseif (
'month' == $this->_period) {
188 $select->group([
'period',
'product_id']);
190 $select->where(
'rating_pos <= ?', $this->_ratingLimit);
216 if (!is_array($storeIds)) {
217 $storeIds = [$storeIds];
222 ) && $currentStoreIds != \
Magento\Store\Model\Store::DEFAULT_STORE_ID && $currentStoreIds != [
223 \
Magento\Store\Model\Store::DEFAULT_STORE_ID
226 if (!is_array($currentStoreIds)) {
227 $currentStoreIds = [$currentStoreIds];
229 $this->_storesIds = array_intersect($currentStoreIds, $storeIds);
231 $this->_storesIds = $storeIds;
248 parent::_beforeLoad();
252 if ($this->_period) {
256 $periodFrom = $this->_from !==
null ? new \DateTime($this->_from) :
null;
257 $periodTo = $this->_to !==
null ? new \DateTime($this->_to) :
null;
258 if (
'year' == $this->_period) {
261 if ($periodFrom->format(
'm') != 1 || $periodFrom->format(
'd') != 1) {
262 $dtFrom = clone $periodFrom;
264 $dtTo = clone $periodFrom;
265 $dtTo->setDate($dtTo->format(
'Y'), 12, 31);
266 if (!$periodTo || $dtTo < $periodTo) {
268 $dtFrom->format(
'Y-m-d'),
269 $dtTo->format(
'Y-m-d')
273 $this->_from = clone $periodFrom;
274 $this->_from->modify(
'+1 year');
275 $this->_from->setDate($this->_from->format(
'Y'), 1, 1);
276 $this->_from = $this->_from->format(
'Y-m-d');
283 if ($periodTo->format(
'm') != 12 || $periodTo->format(
'd') != 31) {
284 $dtFrom = clone $periodTo;
285 $dtFrom->setDate($dtFrom->format(
'Y'), 1, 1);
287 $dtTo = clone $periodTo;
288 if (!$periodFrom || $dtFrom > $periodFrom) {
290 $dtFrom->format(
'Y-m-d'),
291 $dtTo->format(
'Y-m-d')
295 $this->_to = clone $periodTo;
296 $this->_to->modify(
'-1 year');
297 $this->_to->setDate($this->_to->format(
'Y'), 12, 31);
298 $this->_to = $this->_to->format(
'Y-m-d');
303 if ($periodFrom && $periodTo) {
305 if ($periodTo->format(
'Y') == $periodFrom->format(
'Y')) {
306 $dtFrom = clone $periodFrom;
307 $dtTo = clone $periodTo;
309 $dtFrom->format(
'Y-m-d'),
310 $dtTo->format(
'Y-m-d')
316 }
elseif (
'month' == $this->_period) {
319 if ($periodFrom->format(
'd') != 1) {
320 $dtFrom = clone $periodFrom;
322 $dtTo = clone $periodFrom;
323 $dtTo->modify(
'+1 month');
324 $dtTo->setDate($dtTo->format(
'Y'), $dtTo->format(
'm'), 1);
325 $dtTo->modify(
'-1 day');
326 if (!$periodTo || $dtTo < $periodTo) {
328 $dtFrom->format(
'Y-m-d'),
329 $dtTo->format(
'Y-m-d')
333 $this->_from = clone $periodFrom;
334 $this->_from->modify(
'+1 month');
335 $this->_from->setDate($this->_from->format(
'Y'), $this->_from->format(
'm'), 1);
336 $this->_from = $this->_from->format(
'Y-m-d');
343 if ($periodTo->format(
'd') != $periodTo->format(
't')) {
344 $dtFrom = clone $periodTo;
345 $dtFrom->setDate($dtFrom->format(
'Y'), $dtFrom->format(
'm'), 1);
347 $dtTo = clone $periodTo;
348 if (!$periodFrom || $dtFrom > $periodFrom) {
350 $dtFrom->format(
'Y-m-d'),
351 $dtTo->format(
'Y-m-d')
355 $this->_to = clone $periodTo;
356 $this->_to->setDate($this->_to->format(
'Y'), $this->_to->format(
'm'), 1);
357 $this->_to->modify(
'-1 day');
358 $this->_to = $this->_to->format(
'Y-m-d');
363 if ($periodFrom && $periodTo) {
365 if ($periodTo->format(
'Y') == $periodFrom->format(
'Y') &&
366 $periodTo->format(
'm') == $periodFrom->format(
'm')
368 $dtFrom = clone $periodFrom;
369 $dtTo = clone $periodTo;
371 $dtFrom->format(
'Y-m-d'),
372 $dtTo->format(
'Y-m-d')
386 $unionParts[] =
'(' . $cloneSelect .
')';
387 foreach ($selectUnions as $union) {
388 $unionParts[] =
'(' . $union .
')';
elseif(isset( $params[ 'redirect_parent']))
addStoreRestrictions($storeIds)
getTableByAggregationPeriod($period)
_makeBoundarySelect($from, $to)
_applyStoresFilterToSelect(\Magento\Framework\DB\Select $select)
__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\ResourceModel\Report $resource, \Magento\Framework\DB\Adapter\AdapterInterface $connection=null)