我创建了一个可配置的产品,允许用户在产品的定期版本和非定期版本之间进行选择(每个版本都是简单的产品)。我遇到的问题是,当用户选择定期选项时,他们不会看到他们为简单的重复产品看到的重复的配置文件信息。如何让Magento有条件地为可配置产品显示此信息?
答案 0 :(得分:3)
这是一个有效的解决方案,通过一些幸运的猜测得出。
// 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($associatedProduct->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"
}