Thursday, December 2, 2010

Magento: Edit in stock/out of stock messages

Hi all,

Today I've learnt another new thing on Magento. That is to edit the in stock and out of stock messages on the product page.

By default, the messages are:
Availability: In stock.
Availability: Out of stock.

The issue is, some people might want to customize or remove the stock message.
So let's begin on how to edit it:

First the files are located in:
/public_html/app/design/frontend/default/default/template/catalog/product/view/type

Important!!!
If you want to keep your changes, be sure to use a custom template instead. E.g.
/public_html/app/design/frontend/default/Your_Template_Name/template/catalog/product/view/type\

Next, just a bit of code editing. Do note that if you use all the 4 types of products in Magento you'll have to edit all 4 .phmtl files.


Now here's something a little advanced.

What if we want to do something special for certain products? Like a new hot product, but needs a special message like "Available in 2 days, check back soon!" instead of "Out of stock"?.

You can create a custom attribute to be tagged to all your product types. For example, I'll create "product_sale_status" attribute with the "normal" and "special" options.



All I have changed is:

if($_product->isSaleable()): ?>

to:

if($_product->isSaleable() && $_product->getData('product_sale_status') != 152): ?>

So on the product pages, if you wish to have a custom message, all you have to do is to select the product status to "Special" and enter your custom text in the appropriate places (I'm using Comparison Chart Link field). Note: To get the data number 152, use an php echo on the getData('product_sale_status') somewhere, preferably HTML commented.

Have fun!

2 comments:

  1. thank you. Closest so far to what im trying to accomplish. Can you please expand (explain more for nube) regarding the attribute advanced option. Comparison Chart Link Field? 152?
    thank you!!!

    ReplyDelete
  2. Hey there, sorry for the late reply. I'll be sure to subscribe to all posts replies from here on.

    I can't remember what I was doing with Magento, this was at least a year old.

    Anyhow, for other readers, the 152 is the code generated when I created a new attribute. Seems that Magento generates these codes on it's own. What I did (or remember doing) was updating the "Sale Status" (custom attribute) to "Special" and echo-ing out the code status. It gave me 152, so I checked for that in my templates.

    ReplyDelete