Get bestseller collection.

@param string $from
@param string $to
@param int $limit
@param int $storeId

@return array|\Magento\Catalog\Model\ResourceModel\Product\Collection
348859
public function getBestsellerCollection($from, $to, $limit, $storeId)
    {
        //create report collection
        $reportProductCollection = $this->productSoldFactory->create()
            ->addOrderedQty($from, $to)
            ->setOrder('ordered_qty', 'desc')
            ->setStoreIds([$storeId])
            ->setPageSize($limit);

        $productsSku = $reportProductCollection->getColumnValues('order_items_sku');

        return $this->getProductsCollectionBySku($productsSku);
    }
1116993
public function getGamesByCompany($id, $offset = 0, $limit = 25)
    {
        list($offset, $limit) = $this->normalizeOffsetAndLimit($offset, $limit);

        $id = (int) $id;
        $id = max(0, $id);

        return $this->request('companies/'.$id.'/games', [
            'offset' => $offset,
            'limit' => $limit,
        ]);
    }
909763
public function range($from, $to, $condition = true) {
		$range = new Range($this, !$condition);
		$range->setFrom($from);
		$range->setTo($to);
		return $range;
	}
720028
public function limit($from, $to = '') 
    {
        $this->sql .= ' LIMIT ' . $from;
        
        if(is_numeric($to)) {
            $this->sql .= ', ' . $to;
        }
        
        return $this;
    }
565186
public function findLimited($from, $to, $arg = null, $operator = '=', $fields = array('*'))
    {
        return $this->find($arg, $operator, $fields)->limit($from, $to);
    }
1150240
public function replace($from, $to)
    {
        $values = $this->_replace($from, $to);
        return new Collection($values);
    }
237047
protected function getItems($sectionId, $limit, $offset)
    {
        // TODO Добавить в этот класс ссылку на плагин
        $plugin = Eresus_Plugin_Registry::getInstance()->load('gallery');
        /* @var Gallery_Entity_Table_Image $table */
        $table = ORM::getTable($plugin, 'Image');
        $items = $table->findInSection($sectionId, $limit, $offset);
        return $items;
    }
397190
public function resetReviews($from = null, $to = null)
    {
        $conn = $this->getConnection();
        if ($from && $to) {
            $where = [
                'created_at >= ?' => $from . ' 00:00:00',
                'created_at <= ?' => $to . ' 23:59:59',
                'review_imported is ?' => new \Zend_Db_Expr('not null')
            ];
        } else {
            $where = $conn->quoteInto(
                'review_imported is ?',
                new \Zend_Db_Expr('not null')
            );
        }
        $num = $conn->update(
            $this->getTable(Schema::EMAIL_REVIEW_TABLE),
            ['review_imported' => new \Zend_Db_Expr('null')],
            $where
        );

        return $num;
    }
985753
public function getItems($offset, $limit)
    {
        $this
            ->paginator
            ->getQuery()
            ->setFirstResult($offset)
            ->setMaxResults($limit)
        ;

        return iterator_to_array($this->paginator->getIterator());
    }
421576
private function getStore($storeId)
    {
        if (! isset($this->store)) {
            $this->store = $this->storeManager->getStore($storeId);
        }

        return $this->store;
    }
360353
public function cardSummary(string $from, string $to, $condSource = 0)
    {
        $ext = [
            'cond_source' => intval($condSource),
        ];

        return $this->query('datacube/getcardbizuininfo', $from, $to, $ext);
    }
1267243
public function getLikeCountByDate($from, $to = null): int
    {
        return Like::countByDate($this, $from, $to);
    }
83861
public function getItems($offset, $limit) {
		$this->cursor->skip($offset);
		$this->cursor->limit($limit);
		
		$data = iterator_to_array($this->cursor);

		if ($this->datagate === null) {
			return new Collection($data);
		}
		
		return $this->datagate->createCollection($data);
	}
311120
public function getMostViewedProductCollection($from, $to, $limit, $catId, $catName)
    {
        $reportProductCollection = $this->reportProductCollection->create()
            ->addViewsCount($from, $to)
            ->setPageSize($limit);

        //filter collection by category by category_id
        if ($catId) {
            $category = $this->categoryFactory->create();
            $this->categoryResource->load($category, $catId);
            if ($category->getId()) {
                $reportProductCollection->getSelect()
                    ->joinLeft(
                        ['ccpi' => $this->getTable('catalog_category_product_index')],
                        'e.entity_id = ccpi.product_id',
                        ['category_id']
                    )
                    ->where('ccpi.category_id =?', $catId);
            } else {
                $this->helper->log(
                    'Most viewed. Category id ' . $catId
                    . ' is invalid. It does not exist.'
                );
            }
        }

        //filter collection by category by category_name
        if ($catName) {
            $category = $this->categoryFactory->create()
                ->loadByAttribute('name', $catName);
            if ($category->getId()) {
                $reportProductCollection->getSelect()
                    ->joinLeft(
                        ['ccpi' => $this->getTable('catalog_category_product_index')],
                        'e.entity_id  = ccpi.product_id',
                        ['category_id']
                    )
                    ->where('ccpi.category_id =?', $category->getId());
            } else {
                $this->helper->log(
                    'Most viewed. Category name ' . $catName
                    . ' is invalid. It does not exist.'
                );
            }
        }

        return $reportProductCollection;
    }
323953
public function purchase(array $productsToBuy, array $productIds, DataBaseExporter $exporter, int $internalOrderId): int
    {
        $preOrdersCount = 0;
        $order = Order::createOrder($productsToBuy, $internalOrderId, true);

        foreach ($order->getProducts() as $product) {
            $numberOfPreOrders = 0;
            $links = [];

            foreach ($product->getCodes() as $code) {

                if ($code->isPreOrder()) {
                    $numberOfPreOrders++;
                    $preOrdersCount++;
                }

                $links[] = $code->getCodeId();
            }

            $orderedCodes = [
                'cwOrderId' => $order->getOrderId(),
                'links' => $links,
                'preOrders' => $numberOfPreOrders
            ];

            $exporter->export(null, $orderedCodes, $productIds[$product->getProductId()], $internalOrderId);
        }

        return $preOrdersCount;
    }
1288438
public function limitTo(int $from, int $until) {
		// build the limit to 
		$this->Limit = array($from, $until);
		// return self to the next method
		return $this;
	}
419369
public function findLastActiveProducts($limit = 5)
    {
        return $this->createQueryBuilder('p')
            ->select('p', 'i', 'g')
            ->distinct()
            ->leftJoin('p.image', 'i')
            ->leftJoin('p.gallery', 'g')
            ->leftJoin('p.variations', 'pv')
            ->andWhere('p.parent IS NULL')      // Limit to master products or products without variations
            ->andWhere('p.enabled = :enabled')
            ->andWhere('pv.enabled = :enabled or pv.enabled IS NULL')
            ->andWhere('p.stock != 0')
            ->andWhere('p.price != 0')
            ->andWhere('pv.stock != 0 or pv.stock IS NULL')
            ->andWhere('pv.price != 0 or pv.price IS NULL')
            ->orderBy('p.createdAt', 'DESC')
            ->setMaxResults($limit)
            ->setParameters([
                'enabled' => true,
            ])
            ->getQuery()
            ->execute();
    }