dongningce9075 2013-06-28 22:41
浏览 29
已采纳

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

I'm trying to change the add to cart button text based on my pre-order attribute, however it's not working quite as expected. Currently my code looks like this:

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

Any ideas would be greatly appreciated!

  • 写回答

2条回答 默认 最新

  • doulangbizhan5160 2013-06-29 00:06
    关注

    I am assuming Preorder is a Yes/No Attribute?

    if so you can use this:

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

    You should still be able to use your method though if you ensure the following:

    You also need to go into the edit attributes section and make sure you have enabled the setting to add the attribute to the collection/object when needed.

    If you're on the product view page enable:

    Visible on Product View Page on Front-end : YES
    

    If you're on the product listing page:

    Used in Product Listing: YES
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥30 c#打开word开启修订并实时显示批注
  • ¥15 如何解决ldsc的这条报错/index error
  • ¥15 VS2022+WDK驱动开发环境
  • ¥30 关于#java#的问题,请各位专家解答!
  • ¥30 vue+element根据数据循环生成多个table,如何实现最后一列 平均分合并
  • ¥20 pcf8563时钟芯片不启振
  • ¥20 pip2.40更新pip2.43时报错
  • ¥15 换yum源但仍然用不了httpd
  • ¥50 C# 使用DEVMOD设置打印机首选项
  • ¥15 麒麟V10 arm安装gdal