2

我创建了一个可配置的产品,它允许用户在产品的重复版本和非重复版本之间进行选择(每个版本都是一个简单的产品)。我遇到的问题是,当用户选择重复选项时,他们不会看到他们会看到的简单重复产品的重复配置信息。如何让 Magento 有条件地为可配置产品显示此信息?

4

1 回答 1

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" 
}
于 2013-03-21T02:17:19.220 回答