简体   繁体   中英

Magento. Change “Add to cart” button to “Pre-order” button for configurable products

Thank you in advance for any help (I first post my question here , but there is no reply for several days).

In Magento, I am looking to change "Add to cart" button to "Pre-order" button for configurable products which inventory qty is set to 0.

Using this tutorial , I managed to accomplish what I am looking for but as it seems this solution works for simple products only, not for configurable ones (or I missed something)

I looked this post, where a person says that SCP Simple Configurable Product extension made by Organic Internet solved his issue. I am not sure how it helped him. I have this extension installed on my site. It seems that there is no option for changing button from "add to cart" to "pre-order" or anything like that. Perhaps I miss something.

Can anyone give me a hand in solving this issue or point me in the right direction?

The tutorial has a php condition which is looking for the Qty value. The problem is, with configurable products, you need to load the associated simple products in order to pull the Qty values.

Suggestion: have you tried using issaleable? This would only show the "Pre-Order" button if the product is NOT saleable.

<?php if( $_product->isSaleable() ): echo $addtocart; else: echo $preorder; endif; ?>

If you simple want ALL your configurable products to have the "Pre-Order" button regardless of inventory, one solution is to modify this Qty condition to only check if its a Configurable product or not instead. One way is to change all occurrences of this:

<?php if($_product->getStockItem()->getQty()>0): echo $addtocart; else: echo $preorder; endif; ?>

to this:

<?php if( $_product->getTypeId() == 'configurable' ): echo $preorder; else: echo $addtocart; endif; ?>

Here's an example of loading the associated simple products, in order to get the Qty values. This may not be needed since its more complex.

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' ): ?>

First of all go to app/design/frontend/[your-package]/[your-theme]/template/catalog/product/view/addtocart.phtml. There you can code like:

<?php if($_product ->getTypeId() == 'configurable'): ?>
//Do your part

All the best

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM