VirtueMart Forum

VirtueMart 2 + 3 + 4 => Templating & Layouts => Topic started by: stawebnice on April 20, 2015, 20:24:47 PM

Title: VM 3.0.6.2: How to add availability status on product detail?
Post by: stawebnice on April 20, 2015, 20:24:47 PM
Hi, Please help.
I am using Virtuemart template that does not show availability icon or text that the product is in stock.
Could you possibly post the PHP code to be entered into product details template file in order to show the content of the availability field here?:
http://imtp.me/9dr102lj3.p

I would like to have Availability: in stock  text on  product detail  in case that there is >1 in stock or the image or the text in the availability field in case that there is zero.
Title: Re: VM 3.0.6.2: How to add availability status on product detail?
Post by: Spiros Petrakis on April 23, 2015, 09:18:25 AM
Hi ,

i dont believe it has to do with your template it is Virtuemart that displays availability only when product is out of stock.
You need to modify the stockhandle.php sublayout file to fit your scenario.
Title: Re: VM 3.0.6.2: How to add availability status on product detail?
Post by: stawebnice on April 23, 2015, 11:43:10 AM
Hi,
Yes, I know. But question is, how to modify the sublayouts/stockhandle.php in these cases:

1. To show: Availability: in stock if there is more than 1 product in stock
2. e.g. Availability: 3 days, if the stock is 0
3. How to display Availability: %text in availability field or image% no matter what the stock is. Some people do not enter  stocks because they sell goods that is in their supplier stock, but want to show different texts for each product, e.g. On order, 7 days, Sold out etc.

Can you possibly advise how to change this?
Title: Re: VM 3.0.6.2: How to add availability status on product detail?
Post by: Spiros Petrakis on April 24, 2015, 10:46:26 AM
Hi,

please replace the default code with the following code that will display availability as the scenario you provided

<?php
$product 
$viewData['product'];
// Availability
$stockhandle VmConfig::get('stockhandle''none');
$product_available_date substr($product->product_available_date,0,10);
$current_date date("Y-m-d");

// If product availability image or text are not empty regardless stock
if (!empty($product->product_availability)) {
?>


  <div class="availability">
  <?php echo (file_exists(JPATH_BASE DS VmConfig::get('assets_general_path') . 'images/availability/' $product->product_availability)) ? JHtml::image(JURI::root() . VmConfig::get('assets_general_path') . 'images/availability/' $product->product_availability$product->product_availability, array('class' => 'availability')) : vmText::_($product->product_availability); ?>
  </div>

<?php // Else if in stock
} else if (($product->product_in_stock $product->product_ordered) > 0) {

  
// Display the date of availability if greater than current date
if ($product_available_date != '0000-00-00' and $current_date $product_available_date) {
  
?>


  <div class="availability">
<?php echo vmText::_('COM_VIRTUEMART_PRODUCT_AVAILABLE_DATE') .': 'JHtml::_('date'$product->product_available_datevmText::_('DATE_FORMAT_LC4')); ?>
</div>

<?php // Else display text In Stock
} else { ?>


  <div class="availability">
<?php echo vmText::_('COM_VIRTUEMART_PRODUCT_INSTOCK'?>
</div>

<?php }
// If stock is lower than 1
} else if (($product->product_in_stock $product->product_ordered) < 1) {

    
// Display the date of availability if greater than current date
  
if ($product_available_date != '0000-00-00' and $current_date $product_available_date) { ?>


    <div class="availability">
  <?php echo vmText::_('COM_VIRTUEMART_PRODUCT_AVAILABLE_DATE') .': 'JHtml::_('date'$product->product_available_datevmText::_('DATE_FORMAT_LC4')); ?>
  </div>

    <?php // Else display availability image or text from vm config -> Shopfront -> Availability fields
    
else
    { 
?>


    <div class="availability">
      <?php echo (file_exists(JPATH_BASE DS VmConfig::get('assets_general_path') . 'images/availability/' VmConfig::get('rised_availability'))) ? JHtml::image(JURI::root() . VmConfig::get('assets_general_path') . 'images/availability/' VmConfig::get('rised_availability''2-3d.gif'), VmConfig::get('rised_availability''2-3d.gif'), array('class' => 'availability')) : vmText::_(VmConfig::get('rised_availability')); ?>
    </div>

<?php }
?>



also create a language override for the COM_VIRTUEMART_PRODUCT_INSTOCK  constant with the value of "In Stock" or whatever you like to display when the product is in stock and you have not set availability in the product.

Title: Re: VM 3.0.6.2: How to add availability status on product detail?
Post by: stawebnice on April 24, 2015, 13:39:27 PM
Hi,

Thank you a lot! So I replaced the original contents of stockhandle.php by your code in original VM folder and in /templates/invent/html/com_virtuemart/sublayouts
but it does  not work for in stock products>

e.g. this product is in stock>
http://www.nova.pippy.cz/slevy/peprovy-obranny-sprej-k-fog-detail

has this settings> http://imtp.me/9erm02lj3.p

but no availability is shown

for products that are not in stock this setting is applied>
http://imtp.me/9ern02lj3.p

and is shows availability>
http://www.nova.pippy.cz/eshop/pono%C5%BEky-1/rox-lex-pono%C5%BEky-rotex-detail

http://imtp.me/9erp02lj3

so question is, where is the problem now?
Title: Re: VM 3.0.6.2: How to add availability status on product detail?
Post by: stawebnice on April 30, 2015, 20:13:33 PM
We have found the solution that works on Czech virtuemart forum and I posted it in Czech on my blog:
http://www.stawebnice.com/virtuemart3-zobrazovat-dostupnost-zbozi-skladem (http://www.stawebnice.com/virtuemart3-zobrazovat-dostupnost-zbozi-skladem)

stockhandle.php content in template folder should be replaced by:

<?php 
$product 
$viewData['product'];
// When stock is higher than 0
if ($product->product_in_stock $product->product_ordered 0)
{
$availabilityText 'in stock';
}
else
{
// Use Availability field on product
$availabilityText JText::_(trim($product->product_availability));
// If the field is empty, use Availability field in VM configuration 
if (empty($availabilityText)) $availabilityText JText::_(trim(VmConfig::get('rised_availability')));
// If the field is empty show the following:
if (empty($availabilityText)) $availabilityText 'in 3 days';
}
?>


<div class="availability">
Availability: <?php echo $availabilityText?>
</div>


Note: if you use multilingual eshop, you need to create language contants instead of in 3 days, in stock etc. and translate them in laguage files

Then in product detail template page default.php insert this to a place where you want to show the availability:
<?php echo shopFunctionsF::renderVmSubLayout('stockhandle', array('product'=>$this->product)); ?>
or replace the current code for availability