News:

Looking for documentation? Take a look on our wiki

Main Menu

Adding in-stock/oos code on browse view default.php

Started by ch1vph, October 07, 2017, 16:26:59 PM

Previous topic - Next topic

ch1vph

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

GJC Web Design

would have to be in the sublayout products.php over ride
GJC Web Design
VirtueMart and Joomla Developers - php developers https://www.gjcwebdesign.com
VM4 AusPost Shipping Plugin - e-go Shipping Plugin - VM4 Postcode Shipping Plugin - Radius Shipping Plugin - VM4 NZ Post Shipping Plugin - AusPost Estimator
Samport Payment Plugin - EcomMerchant Payment Plugin - ccBill payment Plugin
VM2 Product Lock Extension - VM2 Preconfig Adresses Extension - TaxCloud USA Taxes Plugin - Virtuemart  Product Review Component
https://extensions.joomla.org/profile/profile/details/67210
Contact for any VirtueMart or Joomla development & customisation

ch1vph

#2
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>

GJC Web Design

GJC Web Design
VirtueMart and Joomla Developers - php developers https://www.gjcwebdesign.com
VM4 AusPost Shipping Plugin - e-go Shipping Plugin - VM4 Postcode Shipping Plugin - Radius Shipping Plugin - VM4 NZ Post Shipping Plugin - AusPost Estimator
Samport Payment Plugin - EcomMerchant Payment Plugin - ccBill payment Plugin
VM2 Product Lock Extension - VM2 Preconfig Adresses Extension - TaxCloud USA Taxes Plugin - Virtuemart  Product Review Component
https://extensions.joomla.org/profile/profile/details/67210
Contact for any VirtueMart or Joomla development & customisation

ch1vph

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!

GJC Web Design

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>';
            }
GJC Web Design
VirtueMart and Joomla Developers - php developers https://www.gjcwebdesign.com
VM4 AusPost Shipping Plugin - e-go Shipping Plugin - VM4 Postcode Shipping Plugin - Radius Shipping Plugin - VM4 NZ Post Shipping Plugin - AusPost Estimator
Samport Payment Plugin - EcomMerchant Payment Plugin - ccBill payment Plugin
VM2 Product Lock Extension - VM2 Preconfig Adresses Extension - TaxCloud USA Taxes Plugin - Virtuemart  Product Review Component
https://extensions.joomla.org/profile/profile/details/67210
Contact for any VirtueMart or Joomla development & customisation

ch1vph

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.



GJC Web Design

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
GJC Web Design
VirtueMart and Joomla Developers - php developers https://www.gjcwebdesign.com
VM4 AusPost Shipping Plugin - e-go Shipping Plugin - VM4 Postcode Shipping Plugin - Radius Shipping Plugin - VM4 NZ Post Shipping Plugin - AusPost Estimator
Samport Payment Plugin - EcomMerchant Payment Plugin - ccBill payment Plugin
VM2 Product Lock Extension - VM2 Preconfig Adresses Extension - TaxCloud USA Taxes Plugin - Virtuemart  Product Review Component
https://extensions.joomla.org/profile/profile/details/67210
Contact for any VirtueMart or Joomla development & customisation