2013-06-28 63 views
0

我試圖改變添加到購物車按鈕文本基於我的預訂屬性,但它不是很像預期的那樣工作。目前我的代碼如下所示:如何更改magento添加到購物車按鈕基於產品屬性

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

任何想法將不勝感激!

+0

輸出是什麼:'$ _product-> getAttributeText('preorder')'? –

回答

1

我假設預購是一個是/否屬性?

如果是的話,你可以使用這個:

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

您應該仍然能夠使用你的方法,但如果你確保滿足以下條件:

您還需要進入編輯屬性部分,並確保已啓用設置以在需要時將該屬性添加到集合/對象。

如果你的產品視圖頁面上啓用:

Visible on Product View Page on Front-end : YES 

如果你的產品列表網頁上:

Used in Product Listing: YES 
0

感謝您的想法!我意識到問題是我使用單引號而不是雙引號!衛生署!

&& $_product->getAttributeText('preorder') == "Yes"): ?> 
相關問題