我创建了一个可配置产品,允许用户在产品的重复版本和非重复版本之间进行选择(每个版本都是一个简单的产品)。我遇到的问题是,当用户选择重复选项时,他们不会看到他们在简单的重复产品中看到的重复配置文件信息。如何让 Magento 有条件地为可配置产品显示此信息?
最佳答案
这是一个可行的解决方案,是通过一些幸运的猜测得出的。
// check to see if the product is configurable
if ( $_product->getTypeID() == 'configurable' ) {
// get the associated products
$associatedProducts = $_product->getTypeInstance()->getUsedProducts();
// iterate through the products, checking for recurring products
foreach ( $associatedProducts as $associatedProduct ) {
if ($associatedProduct->isRecurring()) {
// get the recurring profile
$profile = $associatedProduct->getRecurringProfile();
// echo whichever array members you need
echo '<p>billed '.$profile['period_frequency'].' time(s) per '.$profile['period_unit'].'</p>';
}
}
}
我在这里得到了一些帮助:http://www.phptechi.com/how-to-get-associated-child-product.html
然后我刚刚对 getRecurringProfile()
进行了一个幸运的方法名称猜测。
var_dump($linkedProduct->getRecurrringProfile())
产量:
array(13) {
["start_date_is_editable"]=> string(1) "1"
["schedule_description"]=> string(0) ""
["suspension_threshold"]=> string(0) ""
["bill_failed_later"]=> string(1) "1" ["period_unit"]=> string(5) "month"
["period_frequency"]=> string(1) "1" ["period_max_cycles"]=> string(0) ""
["trial_period_unit"]=> string(0) "" ["trial_period_frequency"]=> string(0) ""
["trial_period_max_cycles"]=> string(0) "" ["trial_billing_amount"]=> string(0) ""
["init_amount"]=> string(0) "" ["init_may_fail"]=> string(1) "0"
}
关于Magento:如何显示可配置重复产品的重复配置文件信息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15531348/