开发者

How can I filter a product's availability using isSaleable attribute?

开发者 https://www.devze.com 2022-12-19 22:16 出处:网络
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

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()开发者_如何学C ?></p>
<?php endif; ?>


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 ?
}
?>


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; ?>
0

精彩评论

暂无评论...
验证码 换一张
取 消