-
Notifications
You must be signed in to change notification settings - Fork 9.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix count SQL on products sold collection #8812
Fix count SQL on products sold collection #8812
Conversation
Hi @jameshalsall! |
If you use Example code from my project: <?php
use Magento\Reports\Model\ResourceModel\Product\Sold\CollectionFactory as ProductsSoldCollectionFactory;
class MostPurchasedProductSkuProvider
{
private $collectionFactory;
private $storeManager;
public function __construct(ProductsSoldCollectionFactory $productsSoldCollectionFactory)
{
$this->collectionFactory = $productsSoldCollectionFactory;
}
public function getSkus(int $limit, \DateTimeInterface $from, \DateTimeInterface $to): array
{
if ($limit < 1) {
return [];
}
$collection = $this->collectionFactory->create();
$collection->addOrderedQty($from->format('Y-m-d H:i:s'), $to->format('Y-m-d H:i:s'));
$collection->setOrder('ordered_qty');
$collection->setPageSize($limit);
$collection->getSelect()->columns('order_items.sku');
$skus = [];
foreach ($collection as $item) {
$skus[] = $item['sku'];
}
return $skus;
}
} |
Thanks for the update @jameshalsall! |
No problem. I'll add one later
|
5e988f3
to
dc333b4
Compare
I've added a test to cover this functionality now. |
@jameshalsall Thank you for the contribution! |
ACPT-1837: Removing unused use from ResetterInterface
No description provided.