Introduction
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.
Accepting Pre-Orders
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).
Code Changes
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:
Changed From
35 36 37 | <?php if($_product->isSaleable()): ?> <p class="availability"><?php echo $this->__('Availability: In stock.') ?></p> <?php else: ?> |
Changed To
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.') ?> |
Details
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!
Magento safe way:
getStockItem()->getUseConfigManageStock();
$__mxwB = $_product->getStockItem()->getManageStock()
echo (!$__mxwA && !$__mxwB) ? $this->__(‘Accepting Orders’ ) : $this->__(‘Availability: In stock.’);
?>
Thanks Unirgy! I’ve updated the post to reflect your corrections!
That was just the quick and dirty solution I was looking for. Thank you!
Is this also applicable to “Add to Cart” button? I want to change it to something like “Pre Order”.
Hi,
Thanks for the post. I’m trying of the same sort but want to have the “Qty for Item’s Status to become Out of Stock” variable as I want to show the available qty of the product which will be Qty – Qty for Item’s Status to become Out of Stock.
Currently i get the qty as
__(‘Available Item: ‘) ?>loadByProduct($_product)->getQty();?>
Can’t get my head around to get he other variable
Any help would be much appreciated
Cheers
When I use the original code, it works great. But when I try the “Magento Safe Way” code I get an error. I am new to php. Please help.
isSaleable()): ?>
getUseConfigManageStock();
$__mxwB = $_product->getStockItem()->getManageStock()
echo (!$__mxwA && !$__mxwB) ? $this->__(‘Accepting Orders’) : $this->__(‘Availability: In stock.’);
?>
Parse error: syntax error, unexpected T_ECHO in /home/squadspt/public_html/stage/app/design/frontend/base/default/template/catalog/product/view/type/simple.phtml on line 40
This is an excellent post. Thank you. Morphine, you are missing a semicolon after getManageStock() if you copied/pasted from the comments.
I only want to check if ManageStock is not set in the Admin/Configuration, so I changed to this. I also formatted the if-else statement to be more “Magento-ish”
getStockItem()->getManageStock() ?>
__(”) ?>
__(‘Availability:’) ?> __(‘In stock’) ?>
Sorry, trying to show code..lets see if this works.
getStockItem()->getManageStock() ?>__('') ?>
__('Availability:') ?> __('In stock') ?>
Thanks alot for that !
Nice post. Well Done
Awesome blog. Keep it up. See you
Thank\’s
Tried the suggestion, did not work for me using Modern template and version 1.5.1.0
cool idea. I just ran into the same problem. I’ll see if I can get this working with Magento 1.5
Thank u, my airsoft guns store just need this funcation.
Would you like to tell me where is the getStockItem() method defined?
Worked well for me – accept I would like to be able to customise the “out of stock” label too…. :/