0

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

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

任何想法将不胜感激!

4

2 回答 2

1

我假设预购是一个是/否属性?

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

isSaleable() && $_product->getPreorder()):?>

如果您确保以下内容,您仍然应该能够使用您的方法:

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

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

Visible on Product View Page on Front-end : YES

如果您在产品列表页面上:

Used in Product Listing: YES
于 2013-06-29T00:06:52.253 回答
0

感谢您的想法!我意识到问题在于我使用的是单引号而不是双引号!嗬!

&& $_product->getAttributeText('preorder') == "Yes"): ?>
于 2013-06-29T06:01:57.680 回答