Basically what I am trying to achieve is when a simple product has >0 quantity it shows add to cart button. When it has equal to order less than 0 it displays a pre order button.
Also for configurable products to display always an add to cart button.
Below is the code that I have been playing with, may be completely the wrong way round it, but works for simple products. However for configurable is displaying two URL's as it's calling a string twice.
If anyone could simply modify the code it so it works correctly that would be great!
<?php if($_product->isSaleable()): ?>
<a href="#" onclick="setLocation('<?php echo $this->getAddToCartUrl($_product) ?>')"><img src="<?PHP
$str = $this->getSkinUrl('images/btn_add_to_cart.gif');
$stre = $this->getSkinUrl('images/pre-order.gif');
if ($_product->isConfigurable())
{print "str";} ?>
<?PHP if ((int) Mage::getModel('cataloginventory/stock_item')->loadByProduct($_product)->getQty()> 0)
{print "$str";
}
else
{print "$stre";}?>" alt="<?php echo $this->__('Add to Cart') ?>" title="<?php echo $this->__('Add to Cart') ?>";}?>
</a>
<?php else: ?>
<div class="out-of-stock"><?php echo $this->__('Out of stock') ?></div>
<?php endif; ?>
I would do something like this:
<?php if ($_product->isSaleable()): ?>
<a href="#" onclick="setLocation('<?php echo $this->getAddToCartUrl($_product); ?>')"><img
<?php if ($_product->isConfigurable()
|| 0 < (int) Mage::getModel('cataloginventory/stock_item')->loadByProduct($_product)->getQty()): ?>
src="<?php echo $this->getSkinUrl('images/btn_add_to_cart.gif'); ?>"
<?php else: ?>
src="<?php echo $this->getSkinUrl('images/pre-order.gif'); ?>"
<?php endif; ?>
alt="<?php echo $this->__('Add to Cart'); ?>"
title="<?php echo $this->__('Add to Cart'); ?>" /></a>
<?php else: ?>
<div class="out-of-stock"><?php echo $this->__('Out of stock'); ?></div>
<?php endif; ?>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.