– If you want to show stock sold on the product page for the entire duration the product has been active, try this code:
1 2 3 4 5 6 7 8 9 10 |
< ?php $sku = nl2br($_product->getSku()); $product = Mage::getResourceModel('reports/product_collection') ->addOrderedQty() ->addAttributeToFilter('sku', $sku) ->setOrder('ordered_qty', 'desc') ->getFirstItem(); echo 'Total sale '.(int)$product->ordered_qty; ?> |
– If you want to how many have been sold of the product for today, try this code:
1 2 3 4 5 6 7 8 9 10 11 |
< ?php $sku = nl2br($_product->getSku()); $to = $_product->getResource()->formatDate(time()); $from = $_product->getResource()->formatDate(time() - 60 * 60 * 24 * 1); $product = Mage::getResourceModel('reports/product_collection') ->addOrderedQty($from, $to, true) ->addAttributeToFilter('sku', $sku) ->setOrder('ordered_qty', 'desc') ->getFirstItem(); echo 'Total Ordered Today '.(int)$product->ordered_qty; ?> |
– If you want to have it so that it only […]