如何根据产品属性更改magento添加到购物车按钮

时间:2013-06-28 22:41:57

标签: php magento magento-1.7

我正在尝试根据我的预订属性更改添加到购物车按钮文字,但是它没有按预期工作。目前我的代码如下所示:

<?php if($_product->isSaleable() && $_product->getAttributeText('preorder') == 'Yes'): ?>                   
    <p><button type="button" title="<?php echo $this->__('Pre-Order') ?>" class="button btn-cart" onclick="setLocation('<?php echo $this->getAddToCartUrl($_product) ?>')"><span><span><?php echo $this->__('Pre-Order') ?></span></span></button></p>
<?php elseif($_product->isSaleable() && $_product->getAttributeText('preorder') == 'No'): ?>
    <p><button type="button" title="<?php echo $this->__('Add to Cart') ?>" class="button btn-cart" onclick="setLocation('<?php echo $this->getAddToCartUrl($_product) ?>')"><span><span><?php echo $this->__('Add to Cart') ?></span></span></button></p>
<?php else: ?> 
    <p class="availability out-of-stock"><span><a href="<?php echo $_product->getProductUrl() ?>" title="<?php echo $_productNameStripped; ?>"><?php echo $this->__('Product Info') ?></a></span></p>
<?php endif; ?>

任何想法都将不胜感激!

2 个答案:

答案 0 :(得分:1)

我假设Preorder是Yes / No Attribute?

如果是这样,你可以使用它:

isSaleable()&amp;&amp; $ _product-&GT; getPreorder()):&GT;

如果您确保以下内容,您仍然可以使用您的方法:

您还需要进入编辑属性部分,并确保已启用该设置,以便在需要时将属性添加到集合/对象。

如果您在产品视图页面上启用:

Visible on Product View Page on Front-end : YES

如果您在产品详情页面上:

Used in Product Listing: YES

答案 1 :(得分:0)

感谢您的想法!我意识到问题是我使用单引号而不是双引号!卫生署!

&& $_product->getAttributeText('preorder') == "Yes"): ?>