I am using the object manager (directly and intentionally) to get the sales quantity of a product.
$objectManager = MagentoFrameworkAppObjectManager::getInstance();
$product_id = 101;
$soldproduct = $objectManager->get('MagentoReportsModelResourceModelProductSoldCollection')
->addOrderedQty()
->addAttributeToFilter('product_id', $product_id)
->getFirstItem();
This successfully allows me to get the quantity sold of a product by passing in the product ID to the attribute filter. Now I want to filter the results by a starting and end date…
$start_date = '2001-12-12 12:12';
$end_date = '2019-12-12 12:12';
… by adding this to the object manager parameters:
->addAttributeToFilter('created_at', array('from' => $start_date,'to' => $end_date))
But I can’t seem to get this code to work. How do I filter results by a starting and end date?