Magento 目录视图,显示“添加到购物车”和“添加到购物车”预订按钮(目前为止的代码)

发布于 2024-12-21 22:11:00 字数 1067 浏览 1 评论 0原文

基本上我想要实现的是,当一个简单的产品的数量大于 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

同尘 2024-12-28 22:11:00

我会做这样的事情:

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

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; ?>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文