![](/img/trans.png)
[英]Add to cart button showing in configurable products but not in simple products in magento
[英]Magento. Change “Add to cart” button to “Pre-order” button for configurable products
本教程有一個php條件,它正在尋找Qty值。 問題是,對於可配置產品,您需要加載關聯的簡單產品才能提取“數量”值。
建議:您是否嘗試過使用issale? 如果該產品不可銷售,則只會顯示“預購”按鈕。
<?php if( $_product->isSaleable() ): echo $addtocart; else: echo $preorder; endif; ?>
如果您簡單地希望所有可配置產品都具有“ Pre-Order”按鈕,而與庫存無關,則一種解決方案是修改此“數量”條件,以僅檢查其是否為可配置產品。 一種方法是更改所有這種情況:
<?php if($_product->getStockItem()->getQty()>0): echo $addtocart; else: echo $preorder; endif; ?>
對此:
<?php if( $_product->getTypeId() == 'configurable' ): echo $preorder; else: echo $addtocart; endif; ?>
這是加載相關聯的簡單產品以獲取數量值的示例。 由於它比較復雜,因此可能不需要。
foreach ($_product->getTypeInstance(true)->getUsedProducts ( null, $_product) as $simple) {
Mage::getModel('cataloginventory/stock_item')->loadByProduct($simple)->getQty();
}
在pordut / list.phtml中,嘗試檢查產品類型,如圖所示
<?php if( $_product->getTypeId() == 'configurable' ): ?>
首先轉到app / design / frontend / [您的程序包] / [您的主題] /template/catalog/product/view/addtocart.phtml。 您可以在其中編寫如下代碼:
<?php if($_product ->getTypeId() == 'configurable'): ?>
//Do your part
祝一切順利
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.