Magento 目录视图,显示“添加到购物车”和“添加到购物车”预订按钮(目前为止的代码)
基本上我想要实现的是,当一个简单的产品的数量大于 0 时,它会显示“添加到购物车”按钮。当它的 order 小于 0 时,它会显示一个预订按钮。
此外,对于可配置产品,始终显示“添加到购物车”按钮。
下面是我一直在使用的代码,可能完全错误,但适用于简单的产品。然而,可配置的是显示两个 URL,因为它调用一个字符串两次。
如果任何人都可以简单地修改代码以使其正常工作,那就太好了!
<?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; ?>
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; ?>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我会做这样的事情:
I would do something like this: