VirtueMart Forum

VirtueMart 2 + 3 + 4 => Templating & Layouts => Topic started by: YZF on April 15, 2015, 21:32:10 PM

Title: How to hide quantity in stock
Post by: YZF on April 15, 2015, 21:32:10 PM
Does anyone know how to remove the stock quantity on the product detail page so it just says "In stock" or "out of stock" without the quantity being displayed?

Before you mention to uncheck the box that says "Display stock level", we did that; the quantity still shows up (bug?).

We are using VirtueMart 3.0.2 and Joomla 3.3.6.

I found this old link which seems to talk about what I want to do, but the file referred to in the example doesn't exist.
http://forum.virtuemart.net/index.php?topic=80684.0

Any assistance is greatly appreciated.
Title: Re: How to hide quantity in stock
Post by: GJC Web Design on April 15, 2015, 22:21:15 PM
in the default.php somewhere

if($this->product->product_in_stock >0{
echo 'In Stock';
}else{
echo 'Out of Stock';
}
Title: Re: How to hide quantity in stock
Post by: YZF on April 15, 2015, 23:04:51 PM
Thank you GJC. I'll give that a try.
Title: Re: How to hide quantity in stock
Post by: YZF on April 16, 2015, 01:14:58 AM
Another question... which default.php file do I edit?

I found one here:
httpdocs/templates/t3_blank/tpls/default.php

There is also another one here:
httpdocs/templates/t3_blank/html/com_virtuemart/virtuemart/default.php

and one here:
httpdocs/templates/t3_blank/html/com_virtuemart/productdetails/default.php

There's more, but you get the idea.

Also, I don't have much experience editing php files. Am I just adding the code to the file, or editing existing code.
Title: Re: How to hide quantity in stock
Post by: GJC Web Design on April 16, 2015, 12:42:56 PM
httpdocs/templates/t3_blank/html/com_virtuemart/productdetails/default.php
adding
Title: Re: How to hide quantity in stock
Post by: YZF on April 16, 2015, 21:27:18 PM
Hello again GJC, Thank you for your help so far.

I found the following code on the default.php page:

-------------------------------------------------

            <?php
            // Manufacturer of the Product
            if (VmConfig::get('show_manufacturers', 1) && !empty($this->product->virtuemart_manufacturer_id)) {
              echo  $this->loadTemplate('manufacturer');
            }
            if ($this->product->product_in_stock >=1) {
            echo '<div class="stock"><span class="bold">'.JText::_('DR_AVAILABILITY_NEW').':</span><i class="green">'.JText::_('DR_IN_STOCK_NEW').'</i>&nbsp;<b>'.$this->product->product_in_stock.'&nbsp;'.JText::_('DR_ITEMS_NEW').'</b></div>';
            }else {
            echo '<div class="stock"><span class="bold">'.JText::_('DR_AVAILABILITY_NEW').':</span><i class="red">'.JText::_('DR_OUT_STOCK_NEW').'</i>&nbsp;<b>'.$this->product->product_in_stock.'&nbsp;'.JText::_('DR_ITEMS_NEW').'</b></div>';
            }
            echo '<div class="code"><span class="bold">'.JText::_('DR_PRODUCT_CODE_NEW').':</span>'.$this->product->product_sku.'</div>';
         ?>

-----------------------------------

I am assuming I should add the code after the last </div>'; but before ?>
So code should look like the following:

------------------------------------

            echo '<div class="code"><span class="bold">'.JText::_('DR_PRODUCT_CODE_NEW').':</span>'.$this->product->product_sku.'</div>';
         
if($this->product->product_in_stock >0{
echo 'In Stock';
}else{
echo 'Out of Stock';
}

?>

---------------------------------------
Does that sound right?
Title: Re: How to hide quantity in stock
Post by: GJC Web Design on April 17, 2015, 00:03:06 AM
should work -- but no test like trying..  ;)
Title: Re: How to hide quantity in stock
Post by: YZF on April 17, 2015, 00:28:31 AM
I tried.... nothing happened.  :-\

At least the site didn't break, but nothing changed.

Maybe I pasted the code in the wrong place?
Title: Re: How to hide quantity in stock
Post by: YZF on April 17, 2015, 21:19:16 PM
I tried something new (experimenting... )

Original code:

            if ($this->product->product_in_stock >=1) {
            echo '<div class="stock"><span class="bold">'.JText::_('DR_AVAILABILITY_NEW').':</span><i class="green">'.JText::_('DR_IN_STOCK_NEW').'</i>&nbsp;<b>'.$this->product->product_in_stock.'&nbsp;'.JText::_('DR_ITEMS_NEW').'</b></div>';
            }else {
            echo '<div class="stock"><span class="bold">'.JText::_('DR_AVAILABILITY_NEW').':</span><i class="red">'.JText::_('DR_OUT_STOCK_NEW').'</i>&nbsp;<b>'.$this->product->product_in_stock.'&nbsp;'.JText::_('DR_ITEMS_NEW').'</b></div>';
            }

-------------------

Modified Code:

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

-----------------

I basically removed this part from both sections:
<b>'.$this->product->product_in_stock.'&nbsp;'.JText::_('DR_ITEMS_NEW').'</b>

Result .... nothing changed.

I'm not sure of my next move.
Title: Re: How to hide quantity in stock
Post by: YZF on April 23, 2015, 21:13:53 PM
I found the problem (with help from Frans D). I was modifying default.php. The site was using default2.php

The code above in my last post seems to work.