VirtueMart Forum

VirtueMart 2 + 3 + 4 => Templating & Layouts => Topic started by: lanthan on February 21, 2014, 12:12:21 PM

Title: Stock Level Icon on Product Page
Post by: lanthan on February 21, 2014, 12:12:21 PM
Hi,

2.5.18, VM 2.0.26d

I tried to display the current valid product stock level icon on my product page by adding

<span class="vmicon vm2-<?php echo $product->stock->stock_level ?>" title="<?php echo $product->stock->stock_tip ?>"></span>
<span class="stock-level"><?php echo JText::_ ('COM_VIRTUEMART_STOCK_LEVEL_DISPLAY_TITLE_TIP') ?></span>

But the icon does not show up.

$product->stock->stock_level

is not avaiable on the product page. Any help to get this var direct would be great..

Thanks.
Title: Re: Stock Level Icon on Product Page
Post by: lanthan on February 26, 2014, 00:01:24 AM
Ok, I was a little blind. "$this->product" has to be used here.

<div class="paddingtop8">
<span class="vmicon vm2-normalstock"<?php echo $this->product->stock->stock_level ?>" title="<?php echo $this->product->stock->stock_tip ?>"></span>
<span class="stock-level"><?php echo JText::('COM_VIRTUEMART_STOCK_LEVEL_DISPLAY_TITLE_TIP'?></span>
</div>


But nevertheless this does not work fine. Sometimes you get a wrong stock level. For e.g. I lowered the stock level under the stock level where you should get a message. Not yellow, still green. Then I changed the stock level to zero still green.

Ok, here is my solution to show the "correct" stock level on productdetails. Ad this code to your productdetails "default.php" where you want to show up the stock level icon.


<?php
$ProductModel
VmModel::getModel('product');
$product $ProductModel->getProduct($item->virtuemart_product_id);
$stock $product->product_in_stock;
$lowstock $product->low_stock_notification;
$stocklevel"normalstock";
$stocktip JText::('COM_VIRTUEMART_PRODUCT_IN_STOCK');
if (
$stock $lowstock) {
$stocklevel "lowstock";
$stocktip JText::('COM_VIRTUEMART_SEARCH_ORDER_LOW_STOCK_NOTIFICATION');}
 if (empty(
$stock)) {
$stocklevel "nostock";
$stocktip JText::('COM_VIRTUEMART_CART_PRODUCT_OUT_OF_STOCK');}
?>

<div class="paddingtop8">
<span class="vmicon vm2-<?php echo $stocklevel?>" title="<?php echo $stocktip?>"></span>
<span class="stock-level"><?php echo JText::('COM_VIRTUEMART_STOCK_LEVEL_DISPLAY_TITLE_TIP'?></span>
</div>


This works fine. Hope this helps someone.
Title: Re: Stock Level Icon on Product Page
Post by: Anne M on April 07, 2014, 22:48:59 PM
It solved my problem. Thank u.
Title: Re: Stock Level Icon on Product Page
Post by: lanthan on April 08, 2014, 12:47:25 PM
Thank you for your thank you!
Title: Re: Stock Level Icon on Product Page
Post by: StefanSTS on May 21, 2015, 19:41:49 PM
Kudos, bhai!
Still working on 2.6.x.
Title: Re: Stock Level Icon on Product Page
Post by: EIF on June 10, 2015, 09:03:22 AM
This code works, however, there is still an issue.
When an item is sold when there is no stock, so stock level is negative, for example -1 or -2, then the stocklevel displays the wrong information, saying there is stock.

Using this code within VM 3.0.9.
Title: Re: Stock Level Icon on Product Page
Post by: kaistudios on February 08, 2016, 06:11:23 AM
Quote from: EIF on June 10, 2015, 09:03:22 AM
This code works, however, there is still an issue.
When an item is sold when there is no stock, so stock level is negative, for example -1 or -2, then the stocklevel displays the wrong information, saying there is stock.

Using this code within VM 3.0.9.

I'm having that exact issue as well. did you find a solution? VirtueMart 3.0.10