News:

Looking for documentation? Take a look on our wiki

Main Menu

Stock Level Icon on Product Page

Started by lanthan, February 21, 2014, 12:12:21 PM

Previous topic - Next topic

lanthan

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.

lanthan

#1
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.

Anne M

groetjes,
Anne M

lanthan


StefanSTS

Kudos, bhai!
Still working on 2.6.x.
--
Stefan Schumacher
www.jooglies.com - VirtueMart Invoice Layouts

Please use only stable versions with even numbers for your live shop! Use Alpha versions only if you know what risk you are taking.

EIF

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.

kaistudios

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