Author Topic: Adding in-stock/oos code on browse view default.php  (Read 383 times)

ch1vph

  • Beginner
  • *
  • Posts: 21
  • A beginner
Adding in-stock/oos code on browse view default.php
« 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:

Code: [Select]
   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

  • 3rd party VirtueMart Developer
  • Super Hero
  • *
  • Posts: 7654
  • Virtuemart, Joomla & php developer
    • GJC Web Design
  • VirtueMart Version: 2.6.22 & 3.2.2
Re: Adding in-stock/oos code on browse view default.php
« Reply #1 on: October 07, 2017, 22:10:28 pm »
would have to be in the sublayout products.php over ride
GJC Web Design
VirtueMart and Joomla Developers - php developers http://www.gjcwebdesign.com
VM3 AusPost Shipping Plugin - e-go Shipping Plugin - VM3 Postcode Shipping Plugin - Radius Shipping Plugin - VM3 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
http://extensions.joomla.org/profile/profile/details/67210
Contact for any VirtueMart or Joomla development & customisation

ch1vph

  • Beginner
  • *
  • Posts: 21
  • A beginner
Re: Adding in-stock/oos code on browse view default.php
« Reply #2 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...

Code: [Select]
<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

  • 3rd party VirtueMart Developer
  • Super Hero
  • *
  • Posts: 7654
  • Virtuemart, Joomla & php developer
    • GJC Web Design
  • VirtueMart Version: 2.6.22 & 3.2.2
Re: Adding in-stock/oos code on browse view default.php
« Reply #3 on: October 08, 2017, 00:19:42 am »
if $product->stock->stock_level == x then echo y
GJC Web Design
VirtueMart and Joomla Developers - php developers http://www.gjcwebdesign.com
VM3 AusPost Shipping Plugin - e-go Shipping Plugin - VM3 Postcode Shipping Plugin - Radius Shipping Plugin - VM3 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
http://extensions.joomla.org/profile/profile/details/67210
Contact for any VirtueMart or Joomla development & customisation

ch1vph

  • Beginner
  • *
  • Posts: 21
  • A beginner
Re: Adding in-stock/oos code on browse view default.php
« Reply #4 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!

GJC Web Design

  • 3rd party VirtueMart Developer
  • Super Hero
  • *
  • Posts: 7654
  • Virtuemart, Joomla & php developer
    • GJC Web Design
  • VirtueMart Version: 2.6.22 & 3.2.2
Re: Adding in-stock/oos code on browse view default.php
« Reply #5 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>';
            }
GJC Web Design
VirtueMart and Joomla Developers - php developers http://www.gjcwebdesign.com
VM3 AusPost Shipping Plugin - e-go Shipping Plugin - VM3 Postcode Shipping Plugin - Radius Shipping Plugin - VM3 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
http://extensions.joomla.org/profile/profile/details/67210
Contact for any VirtueMart or Joomla development & customisation

ch1vph

  • Beginner
  • *
  • Posts: 21
  • A beginner
Re: Adding in-stock/oos code on browse view default.php
« Reply #6 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.



GJC Web Design

  • 3rd party VirtueMart Developer
  • Super Hero
  • *
  • Posts: 7654
  • Virtuemart, Joomla & php developer
    • GJC Web Design
  • VirtueMart Version: 2.6.22 & 3.2.2
Re: Adding in-stock/oos code on browse view default.php
« Reply #7 on: October 09, 2017, 12:04:59 pm »
Quote
Start 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 http://www.gjcwebdesign.com
VM3 AusPost Shipping Plugin - e-go Shipping Plugin - VM3 Postcode Shipping Plugin - Radius Shipping Plugin - VM3 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
http://extensions.joomla.org/profile/profile/details/67210
Contact for any VirtueMart or Joomla development & customisation