I actually can’t take credit for the art itself - I’ve been building it from assets provided by a client - but the layout is pretty fun to develop as it really stretches the default magento templates.
Hi Sherrie,
That’s an interesting way to display inventory. I have to say I kind of like it. I think I may have a solution on how to do that. Let me play around with it for a couple of minutes and see if I can get it to work. By the way, I like the look of “glad rags”.
HI Sherrie,
I was playing around with the inventory qty’s last night and managed to get the inventory bar graph display to work for simple and grouped products, but not for configurable products. I’m looking into the Configurable.php model right now and will hopefully be able to pull the qty’s for the product collection called by the getUsedProducts function. Once this is done, displaying the graph is a piece of cake. I’ll let you know if I make any progress.
Sherrie,
I got distracted for a bit at work, but I’ve got your problem definitely figured out. I just have a couple of questions to make sure that it works right for your situation. We don’t use any configurable products, so I just want to cover all of the bases with your clients operation. Are they using multiple attributes such as color, size, style or just size? I’m not in the t-shirt biz myself, so I’m not sure what their plans are or how they layout their products. Let me know and I’ll post my findings.
Ok,
That makes it pretty easy. Pretty much what I did was pull the inventory qty for the allowed products in the configurable product and have this set the width of the bar graph. You only need to add the following to the catalog->product->view->type->configurable.phtml file.
Since by default, Magento stores inventory in decimals in the db, the top function just cleans up the qty value so it can be used as a css width value. Moving down, $this->getAllowProducts() calls the products used to make the configurable product. Then there are two divs: one to call the attribute label and one that actually draws the bar graph. For this bit, $_item->getAttributeText(’tshirt_size’), you’ll need to replace ‘tshirt_size’ with the attribute code for your size attribute. I’m thinking that its probably just size. This will put the label in front of each bar, ie S,M, L or Small, Medium, Large however you have your attribute labels setup.
The next div controls the actual bar for the graph. In the boxes.css, I just created a class with bgcolor, height, float, border, etc..but no width. The width of the bar is called by the style tag set by the allowed product’s qty. Here’s where you’ll have to tweak for their application and your design. First, I didn’t know how wide of a container you were going to put the inv bar graph in and I didn’t know the stock levels that your client keeps. So if your container that’s going to hold the graph is 300px, but they have 600 t-shirts on hand, well then its going to skew your design. Or if your container is 600px and they keep 5 tshirts on hand, well, you may want to skew the proportion on the graph so it can actually be seen. To do that, you can add a multiplier or divider after the last closing parentheses in clean_num(Mage::getModel(’cataloginventory/stock_item’)->loadByProduct($_item)->getQty()) so it would look like, clean_num(Mage::getModel(’cataloginventory/stock_item’)->loadByProduct($_item)->getQty())*2 or
clean_num(Mage::getModel(’cataloginventory/stock_item’)->loadByProduct($_item)->getQty())/10.
You can certainly play around with that though for presentation purposes. Also if you need a unique setup per configurable product that can be done as well. I was just thinking that if they have one t-shirt that sells really well, in lrg, med and small sizes, they may have 1500 total - 500 of each size. But then they may have another that doesn’t sell as well, maybe 15 - 5 in each size, then your graph may look distorted across different products. If this is the case, we can build in some conditionals that will keep the ratio between products looking consistent.
Also, the generic css that I used to test it is:
.graph_bar{height:10px; border:1px solid #999999; margin-top:3px;background-color:#006666; float:left;}
.graph_name{font-size:11px;float:left; width:50px;}
FanTAStic! Thank you SO much! I’ve been playing around with it already and customizing it quite a bit.
I do have a couple more questions though - is it possible to write a logic statement into that says if the length is less than a certain # to change the color? Also, this is what mine looks like now:
is it possible to write a logic statement into that says if the length is less than a certain # to change the color? Also, this is what mine looks like now:
Yep..when defining the style for the bar, after the width, you could add something like:
background-color: <?php if(clean_num(Mage::getModel('cataloginventory/stock_item')->loadByProduct($_item)->getQty())<[USE YOUR MINIMUM VALUE]) echo ('#[YOUR COLOR CODE]');?>;"
This should override the background color in the css for any qty below what you set and change the color.
However, the “Out of Stock. Request a Reprint” doesn’t display. Any idea why?
I’m not sure off the top of my head...I’ll take a look into it.
I just noticed why your out of stock condition doesn’t work. $_product refers to getProduct which is the configurable product itself. Also, as I remember correctly, getAllowProducts is set to only pull products that are Saleable, which is why if a size goes out of stock it doesn’t show up on the drop down either. I just took a look at the Configurable.php Block and it does have an
if ($product->isSaleable())
for the getAllowProducts function. If I removed it, then you can use your Saleable logic by using <?php if($_item->isSaleable()): ?>. $_item refers to our associated products rather than the main configurable products. The down side to this is:
1. You should probably overwrite the class from a local code pool to make sure its stable across upgrades.
2. The out of stock item still shows up in the attribute select drop down. They can select the item, but it won’t let them add it to the cart. Lets say medium is out of stock and they try to select a medium and hit add to cart, they will just get a warning that re-iterates, “yes, the tshirt is really out of stock. look at the graph.”
Otherwise, as always, especially with Magento, everything is doable.
That makes sense, it will still be upgradeable as I can put that as a local copy - but when I remove that line from Configurable.php I get this:
Parse error: syntax error, unexpected T_RETURN, expecting T_FUNCTION in app/code/local/Mage/Catalog/Block/Product/View/Type/Configurable.php on line 62
Hi, can this be modified to show for simple products? a basic status bar next to STOCK LEVEL: ? Luv the way you patiently explained what you script does, oh by the way hi to everyone else.
Cheers.
Alex