– 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; ?> |
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; ?> |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
< ?php $_finalPrice = $this->helper('tax')->getPrice($_product, $_product->getFinalPrice()); $_regularPrice = $this->helper('tax')->getPrice($_product, $_product->getPrice()); if ($_regularPrice != $_finalPrice){ $sku = nl2br($_product->getSku()); $to = $_product->getResource()->formatDate(time()); $from = $_product->getResource()->formatDate(time() - 60 * 60 * 24 * 1); $_productCollection = Mage::getResourceModel('reports/product_collection') ->addOrderedQty($from, $to, true) ->addAttributeToFilter('sku', $sku) ->setOrder('ordered_qty', 'desc') ->getFirstItem(); $product = $_productCollection; echo 'Already Bought Today '.(int)$product->ordered_qty; } if ((int) Mage::getModel('cataloginventory/stock_item')->loadByProduct($_product)->getQty()==1){ ?> <p style="color:#990000; padding:5px 0; text-align:right;"><strong>ONLY 1 LEFT IN STOCK!</strong></p> < ?php } ?> |