Stock level on product details page

GK User
Thu May 14, 2015 3:58 pm
I like to have the stock level bar shown on the product catergory page, also displayed on the product details page.

The piece of code I found is this:

Code: Select all
               <?php if ( VmConfig::get ('display_stock', 1)) : ?>
               <div class="stockLavel"> <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> </div>
               <?php endif; ?>


It works, but it is not the same as on the category. Now star images indicates the stock level and not the tight green bar I like to have.

Any ideas how to fix this?
User avatar
Expert Boarder

teitbite
Sun May 17, 2015 1:14 pm
Could you please provide me with a URL to your website, either here or via PM (click the “Private Message” text underneath my avatar) so that I may analyze it? It is a lot easier for us to diagnose issues when we have a live site to examine.
User avatar
Moderator

GK User
Wed May 20, 2015 7:36 am
Yes, of course. The stocklevel icon on the details page is also wrong.

First look here: http://www.waterpijp-bong.nl/waterpijpen/1-slang/junior-hookah-waterpijp-flame-1-slang-zwart-headshop
You can see a stock level with stars, 5 stars, so there must be stock.

Then look here for the same item: http://www.waterpijp-bong.nl/waterpijpen/1-slang
As you can see there is no stock. (which is true).

So 2 problems:
1: the icons indicates wrong stock level
2: I like to have the space stock level icon (horizontal bar) on the product detail pages, as on the product category page.
User avatar
Expert Boarder

GK User
Fri May 22, 2015 8:50 pm
I don't got an answer yet, but I just removed the stock level indication on the product detail page, because customers are complaining now about the wrong stock level.

Please let me know when you have to look. Then I will put it back online. Can't keep wrong information online...
User avatar
Expert Boarder

teitbite
Sun May 24, 2015 1:17 pm
Hi

Just let me know where this has to be activated and send me an access to joomla panel. So I'll enable it and see what can be wrong.
User avatar
Moderator

teitbite
Thu Jun 04, 2015 9:12 am
Hi

Looks like there is no stock informations picked up from database for product page, but this code is pretty close I guess.

Code: Select all

            <?php if( $this->product->product_in_stock ) : ?>
               <div class="stockLavel">
                  <span class="vmicon vm2-normalstock" title="Wij hebben meer dan voldoende voorraad van dit artikel"></span> <span class="stock-level"><?php echo JText::_('COM_VIRTUEMART_STOCK_LEVEL_DISPLAY_TITLE_TIP') ?></span>
               </div>
            <?php endif; ?>
User avatar
Moderator

GK User
Wed Jun 10, 2015 7:41 am
I used that code, as you can see in my opening post. It does show a stocklevel bar, but it's incorrect. It now always says there is stock, also when there isn't. It looks like it doesn't check the stock. On the category page this stock level does work correct, but not on the product detail page.
User avatar
Expert Boarder

GK User
Wed Jun 10, 2015 8:00 am
Seems to be a virtuemart issue.
I solved it by the code below. This code displays the correct stock level. However, there is still an issue. When an item is sold when there is no stock, so stock quantity is below 0, for example: -1 or -2, then the stock level displays again the wrong stock.

Code: Select all
<?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>
User avatar
Expert Boarder

teitbite
Thu Jun 11, 2015 8:12 pm
Hi

Code You provided above is very good. But I think it's missing a case when stock is equal to lowstock. Is this the case when sold product start showing wrong stock ?

Try a simple change from:

Code: Select all
if ($stock < $lowstock) {


to

Code: Select all
if ($stock <= $lowstock) {
User avatar
Moderator

GK User
Fri Jun 12, 2015 8:24 am
That didn't the trick. The problem is when the stock quantity is negative, it thinks it is low stock. Of course it should think it is 'out of stock'. Strangly, on the product category page the stock level is correct...

For now, because I don't use 'low stock' in the backed, I just changed the translation of "COM_VIRTUEMART_SEARCH_ORDER_LOW_STOCK_NOTIFICATION". The translation is now the same as 'Out of stock', so there is no difference.
I removed the stock level image, so there is only text, saying the item is on stock or isn't on stock. I used this code:

Code: Select all
<?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');}
?>
<span class="stock-level">
User avatar
Expert Boarder

GK User
Fri Jun 12, 2015 8:57 am
Can't edit my post anymore, but this line of code should be there too:

Code: Select all
            <?php echo JText::_ ('COM_VIRTUEMART_STOCK_LEVEL_DISPLAY_TITLE_TIP') ?>&nbsp;<b><?php echo $stocktip; ?></b>
            </span>
User avatar
Expert Boarder

teitbite
Sun Jun 14, 2015 5:31 pm
Hi

I've checked the code for category layout and I do not see Your code there at all. So I think I do not understand. Is stock level in product details or in category layout wrong ? I checked the one in category layout and VM is picking up a value "normalstock" for "Junior Hookah Waterpijp Flame 1 slang zwart" product You said is out of stock.

When I'm disabling template override for it than stock is still showing "normalstock" for this product. It has to be a bug in VM, so I will not be able to help with this unfortunately. You need to report this to VM developers.
User avatar
Moderator

GK User
Sun Jun 14, 2015 8:25 pm
The category is correct, but the product detail page is wrong.
I think it's a VM issue indeed. But for me it's no problem now, because I just use 'stock' and 'no stock', instead of using 'low stock' too.
Thanks for help though.
User avatar
Expert Boarder

teitbite
Tue Jun 16, 2015 8:35 pm
Hi

Och sorry I've misunderstood You. Glad You've fond a workaround for this problem :)
User avatar
Moderator


cron