I have several different ways I need to handle product, and nearly chief among these – from a marketing/ credibility standpoint – is the ability to accept “pre-orders” for product that will be arriving very shortly from the manufacturer.
Why is this important? It’s important to establish that yes, we are on the leading edge of the technology, we are authorized dealers. These are typically very high-ticket items, and people do want to order before the product is even out so they can be among the first to get it.
Again, I’m loathe to change very much in code – I’d much rather flip a switch in the Magento configuration somewhere. Backorders are backorders – I want to treat a Pre-Order as a separate, distinct entity. So here’s what I decided to do:
First, I went into Magento admin, and set “Manage Inventory” to “No” for my pre-order items. Conceptually, this feels right – I have the items on order, they’ll be here imminently, but until I have that first Receiving done, I really don’t have any inventory to manage yet. Importantly, I can always use the Product API to give me all products that I’ve set to “Don’t Manage Inventory,” so I can stay on top of it.
I want the net effect to be that products in this state have ‘use_config_manage_stock‘ and ‘manage_stock‘ both off (that is, set to zero).
Turned out to be rather simple to code, but I had a heck of a time finding out how to access the data I needed, and ended up doing a lot of print_r debugging. This is Magento-safe, as verified 12/19/08 by Unirgy (see comments).
In app/design, in my default/template/catalog/product/view/type/simple.phtml file, I made a little change:
35 36 37
<?php if($_product->isSaleable()): ?> <p class="availability"><?php echo $this->__('Availability: In stock.') ?></p> <?php else: ?>
37 38 39 40 41
<?php $__mxwA = $_product->getStockItem()->getUseConfigManageStock(); $__mxwB = $_product->getStockItem()->getManageStock(); echo ($__mxwA=="0" && $__mxwB=="0" ) ? $this->__('Accepting Orders' ) : $this->__('Availability: In stock.') ?>
On line 38, I’ve retrieved the product’s use_config_manage_stock value. On line 39, I’ve retrieved its manage_stock value. My implicit rule – which I’ve made explicit through our internal documentation – is that when both of these values are 0, I display ‘Accepting Orders’. If they aren’t, I would display ‘Availability: In Stock’.
Note that the code is inside the “if($_product->isSaleable()):” block. The “else” of this block will display ‘Availability: Out of stock.’
EDIT 16:50 12/19/2008: Thanks to Unirgy for pointing out the Magento-Safe way of obtainig the StockItem configuration variables. Previous edits of this post were using the incorrect method!