What you don't want to do:
Don't implement (or take any advice to implement) a count based on the sales/order collection. Why? Any operation happening on that table has the potential to cause a lock and will have direct impact live production orders (this is why they use a table sales_flat_order_grid
for the admin view).
What you can do:
There are dozens of ways to do this. All of them involve querying the database and updating a record somewhere. It depends on how real-time this needs to be. I'm guessing doing this every day or so is probably sufficient.
You could, for instance:
- Create a Magento Custom Variable that stores the value and then echo it via a static block on the homepage
- Create a Magento Store Config value and access it from just about anywhere with
Mage::getStoreConfig('my_stores/awesome/sales_number_is_so_high
);
Some (including me) may consider that this is an abuse of store config... and you'd probably be right. But maybe you want that number to appear higher some days? This allows you to override the number from the admin. It also has the benefit of being cached.
In all cases, though, you'll be updating it on a schedule. I highly recommend you read up on how Magento CRON works.
How you tackle this problem really has a lot to do with how much load you are under; if it is significant I would possibly make a custom table with a value that can be cached by both Magento (at the block level or even with cache tag) and potentially MySQL at the db layer. Regardless, you shouldn't be updating this very often as to incur invalidated caches.
Speaking of cache, you're on Community so you don't have EE Full Page Cache to have out in front of this functionality... so best be on the safe side and get it into something like Config XML that can be cached by default in an in-memory cache (APC/memcached/redis).
In terms of potential load, if you do have a very high sales volume that is, most sites eschew a realtime/ajax loader for a faked javascript counter that averages orders/day or hour.
Just show me the code
Getting the order count is simple:
$orderCount = Mage::getModel('sales/order')->getCollection()->getSize();
If you decide save it into the config:
$orderCount = Mage::getModel('sales/order')->getCollection()->getSize();
Mage::getModel('core/config')->saveConfig('sales/order/count', $orderCount );
Now to get it back out:
echo Mage::getStoreConfig('sales/order/count');