VirtueMart Forum

VirtueMart 2 + 3 + 4 => Templating & Layouts => Topic started by: ch1vph on October 07, 2017, 16:26:59 PM

Title: Adding in-stock/oos code on browse view default.php
Post by: ch1vph on October 07, 2017, 16:26:59 PM
Hi there,

I have added some code into my product-details-view so my template now displays whether a product is 'in or out of stock' - as my template did not have any indication in a details view beforehand.

But I set out to change the traffic light stock level on a categories browse view!  Now as I have the working code below which adds the words in stock or out of stock.....I just need some advise on exactly where I need to add this code, as I cannot seem to find the correct position to place it inside my ja_brickstore/html/com_virtuemart/category/default.php.

Ideally I want it to show up in the same position as the traffic lights currently do on the browse view (in the ratings container) because at present anywhere I add the code in, it only seems to appear once & only before the products NOT ACTUALLY ON THEM.

Thanks in advance!

Code Used:

   if ($this->product->product_in_stock >=1) {
            echo '<div class="stock"><span class="bold">'.JText::_('').'</span><i class="green">'.JText::_('IN STOCK').'</i>&nbsp;</div>';
            }else {
            echo '<div class="stock"><span class="bold">'.JText::_('').'</span><i class="red">'.JText::_('OUT OF STOCK').'</i>&nbsp;</div>';
            }



VirtueMart 3.2.4 // Joomla! 3.7.5 // PHP Version 5.6.31
Site: https://ri2k.london/shop-all // JA Brickstore Template on T3 Framework
Title: Re: Adding in-stock/oos code on browse view default.php
Post by: GJC Web Design on October 07, 2017, 22:10:28 PM
would have to be in the sublayout products.php over ride
Title: Re: Adding in-stock/oos code on browse view default.php
Post by: ch1vph on October 07, 2017, 22:53:32 PM
Thankyou so I have the file but this code I've taken from another post for a details view is not working in the products.php

I've found the code which is bringing up the traffic light system but I'm unsure how to get it to display the words in or out of stock with the code above...

<div class="vm-product-rating-container">
<?php echo shopFunctionsF::renderVmSubLayout('rating',array('showRating'=>$showRating'product'=>$product));
if ( VmConfig::get ('display_stock'1)) { ?>

<span class="vmicon vm2-<?php echo $product->stock->stock_level ?>" title="<?php echo $product->stock->stock_tip ?>"></span>
<?php }
echo shopFunctionsF::renderVmSubLayout('stockhandle',array('product'=>$product));
?>

</div>
Title: Re: Adding in-stock/oos code on browse view default.php
Post by: GJC Web Design on October 08, 2017, 00:19:42 AM
if $product->stock->stock_level == x then echo y
Title: Re: Adding in-stock/oos code on browse view default.php
Post by: ch1vph on October 08, 2017, 13:53:00 PM
Hello again and thanks for the code!

I've tested in many different ways but cannot get it to work...could you tell me the line of code: if $product->stock->stock_level == x then echo y is to be placed in my code in the 1st post or is it just to go directly in the products.php

Either-way can you confirm if it's to go on the line where I've highlighted below inside the original products.php file...?

<div class="vm-product-rating-container">
                  <?php echo shopFunctionsF::renderVmSubLayout('rating',array('showRating'=>$showRating, 'product'=>$product));
                  if ( VmConfig::get ('display_stock', 1)) { ?>
                     <span class="vmicon vm2-<?php echo $product->stock->stock_level ?>" title="<?php echo $product->stock->stock_tip ?>"></span>
                  <?php }
                  echo shopFunctionsF::renderVmSubLayout('stockhandle',array('product'=>$product));
                  ?>
               </div>

Thanks again!
Title: Re: Adding in-stock/oos code on browse view default.php
Post by: GJC Web Design on October 08, 2017, 21:48:49 PM
Start with googling some basic php knowledge.. the snippet is only a suggestion of what to do.. not code

it would go where ever u wanted the stock to appear on your page.
I assume directly after the span

it all depends on what you want to see there

I assume

if ($product->product_in_stock >=1) {
            echo '<div class="stock"><span class="bold">'.JText::_('').'</span><i class="green">'.JText::_('IN STOCK').'</i>&nbsp;</div>';
            }else {
            echo '<div class="stock"><span class="bold">'.JText::_('').'</span><i class="red">'.JText::_('OUT OF STOCK').'</i>&nbsp;</div>';
            }
Title: Re: Adding in-stock/oos code on browse view default.php
Post by: ch1vph on October 08, 2017, 22:54:35 PM
ok thanks all understood about the positioning I've tested in various positions and do want it to appear in the product-rating-container....

Its just strange because my code works fine in a details view default.php which is why I was wondering about the exact placement in the browse view, in the product-rating-container

I've attached a ss of what it looks like when I copy my code into the products.php and also the same working code in the details view.


Title: Re: Adding in-stock/oos code on browse view default.php
Post by: GJC Web Design on October 09, 2017, 12:04:59 PM
QuoteStart with googling some basic php knowledge..
!!!!!!!!!!!!!!!!!!

No php tags

ignored the suggested change from this to product

Please: If your going to ask for help at least read the answers and apply them