簡體   English   中英

如何根據產品屬性將magento添加到購物車按鈕

[英]How to change magento add to cart button based on product attribute

我正在嘗試根據我的預訂屬性更改“添加到購物車”按鈕的文本,但是它無法正常工作。 目前,我的代碼如下所示:

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

任何想法將不勝感激!

我假設“預購”是“是/否”屬性?

如果是這樣,您可以使用此:

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

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

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

如果您在產品視圖頁面上,請啟用:

Used in Product Listing: YES

如果您在產品列表頁面上:

 Used in Product Listing: YES 

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

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM