繁体   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