views:

345

answers:

2

Instead of stating that an item is out of stock, I like to have it available for order with the exception of a warning that states the availability of product for shipment. I created an attribute and assigned a date input type.

Below is my attempt to get this working with no luck so far. Appreciate some help. Thanks.

<?php $empty="" ?>
<?php $_product = $this->getProduct() ?>
<?php if($_product->isSaleable() && $empty==$_product->getProductAvailableDate()): // getProductAvailableDate is an date attribute ?> 
    <p><?php echo $this->__('Availability: In stock.') ?></p>
<?php else($_product->isSaleable() && $empty!=$_product->getProductAvailableDate()): ?>
    <p><?php echo $this->__('Availability: Temporarily Out of stock.<br/>Due to high demand for this product, it is not available until ') ?>
    <?php echo $_product->getProductAvailableDate() ?></p>
<?php endif; ?>
A: 

Hi,

following code should work (depending on your data), if a product is not available it has an empty available date. (what if available date is in the past ?)

<?php
$product = $this->getProduct();

if($product->isSaleable(){
    if($product->getProductAvailableDate()!=''){
        echo '<p>'.$this->__('Availability: In stock.').'</p>';
    }else{
        echo '<p>'.$this->__('Availability: Temporarily out of stock.<br />Due to high demand for this product, it is not available until ').$product->getProductAvailableDate().'</p>';
    }
}else{
    // item not saleable, do you need this part ?
}
?>
Rufinus
Thanks Rufinus. Your code didn't work, but using some parts of it I was able to get it working. See my answer for final code.
monocat
A: 

With a little help from Rufinus and some changes, I got it working. Hope it helps someone.

<?php $_product = $this->getProduct() ?>

<?php if($_product->isSaleable()): ?>

        <?php if($_product->getProductAvailableDate() == date('')){
            echo '<p>'.$this->__('Availability: In stock.').'</p>'; 
            }else{ 
            echo '<p>'.$this->__('Availability: Temporarily out of stock.<br />Due to high demand for this product, it is not available until ').$_product->getProductAvailableDate().'</p>';
            } ?>


<?php else: ?>

      <?php echo $this->__('Availability: Out of stock.') ?>

<?php endif; ?>
monocat