$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$productCollection = $objectManager->create('Magento\Catalog\Model\ResourceModel\Product\Collection');
$soldModel = $objectManager->get('Magento\Reports\Model\ResourceModel\Product\Sold\Collection');
$collections = $productCollection->addAttributeToSelect('*')->setOrder('entity_id', 'desc')->load();
$productdata = array();
foreach ($collections as $product){
$soldproduct = clone $soldModel;
$soldproduct = $soldproduct->addOrderedQty()->addAttributeToFilter('product_id', $product->getId())->setOrder('ordered_qty', 'desc')->getFirstItem();
$sold = (int)$soldproduct->getOrderedQty();
$product->setSold($sold);
$productdata['products'][] = $product->getData();
}
echo '<pre>';print_r($productdata);
Shopify, Shopify Apps, Magento, WordPress, Codeigniter, Joomla, Big Commerce | PHP
Thursday, 14 June 2018
Forloop query not workin in Magento 2 | Get same Ordered Qty of all products in Magento 2
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment