VirtueMart Forum

VirtueMart 2 + 3 + 4 => Virtuemart Development and bug reports => Topic started by: OpenGlobal on May 21, 2012, 22:19:18 PM

Title: Availability field for out of stock products [BUG FIX]
Post by: OpenGlobal on May 21, 2012, 22:19:18 PM
It has been mentioned in other threads that the out of stock option "Products Out of Stock are orderable, and the field 'Availability' below is displayed" does absolutely nothing.

I can confirm this bug and I've found the bit of code causing the problem. In /components/com_virtuemart/views/productdetails/tmpl/default.php the block that handles this "Availability" field is as follows:


<?php
// Availability Image
/* TO DO add width and height to the image */
if (!empty($this->product->product_availability)) {
    $stockhandle VmConfig::get('stockhandle''none');
    if ($stockhandle == 'risetime' and ($this->product->product_in_stock $this->product->product_ordered) < 1) {
?>
<div class="availability">
    <?php echo JHTML::image(JURI::root() . VmConfig::get('assets_general_path') . 'images/availability/' VmConfig::get('rised_availability''7d.gif'), VmConfig::get('rised_availability''7d.gif'), array('class' => 'availability')); ?>
</div>
    <?php } else {
?>

<div class="availability">
<?php echo JHTML::image(JURI::root() . VmConfig::get('assets_general_path') . 'images/availability/' $this->product->product_availability$this->product->product_availability, array('class' => 'availability')); ?>
</div>
<?php
    }
}
?>



But the "if" blocks are in completely the wrong order. The code should be as follows:


<?php
// Availability Image
$stockhandle VmConfig::get('stockhandle''none');
if ($stockhandle == 'risetime' and ($this->product->product_in_stock $this->product->product_ordered) < 1) {
?>
<div class="availability">
    <?php echo JHTML::image(JURI::root() . VmConfig::get('assets_general_path') . 'images/availability/' VmConfig::get('rised_availability''7d.gif'), VmConfig::get('rised_availability''7d.gif'), array('class' => 'availability')); ?>
</div>
    <?php
} else if (!empty($this->product->product_availability)) {
?>

<div class="availability">
<?php echo JHTML::image(JURI::root() . VmConfig::get('assets_general_path') . 'images/availability/' $this->product->product_availability$this->product->product_availability, array('class' => 'availability')); ?>
</div>
<?php
}
?>



This allows the config availability image to be displayed if the product is out of stock, and if the product is in stock, the product availability image is shown instead (if specified).

However, the config screen says that the "text" should be shown if an image is not selected. So, this code block should really be like this:

<?php
// Availability Image
$stockhandle VmConfig::get('stockhandle''none');
if ($stockhandle == 'risetime' and ($this->product->product_in_stock $this->product->product_ordered) < 1) {
?>
<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''7d.gif'), VmConfig::get('rised_availability''7d.gif'), array('class' => 'availability')) : VmConfig::get('rised_availability'); ?>
</div>
    <?php
} else if (!empty($this->product->product_availability)) {
?>

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



The first bug fixes are essential really. In my opinion the second lot of changes are less urgent, but still required due to the wording in the Virtuemart backend.

Any thoughts?

OpenGlobal
Title: Re: Availability field for out of stock products
Post by: OpenGlobal on June 04, 2012, 01:18:58 AM
Any chance this could make it into the next release?

OpenGlobal
Title: Re: Availability field for out of stock products
Post by: OpenGlobal on June 06, 2012, 10:05:48 AM
Anyone?

OpenGlobal
Title: Re: Availability field for out of stock products [BUG FIX]
Post by: inopia on July 06, 2012, 10:42:57 AM
Openglobal, this fix helps me a lot. Thank you very much.
Title: Re: Availability field for out of stock products [BUG FIX]
Post by: OpenGlobal on July 06, 2012, 10:59:23 AM
This fix is now in 2.0.8.

OpenGlobal