我尝试了几个可以在谷歌上找到的想法,但几天没有人为我工作。最后,我找到了一种在自定义扩展中显示 magento 捆绑产品的“最低可能价格”和“最高可能价格”的方法:
$_product_id = YOUR_BUNDLE_PRODUCT_ID;
// highest possible price for this bundle product
$return_type = 'max'; // because I used this in a helper method
// lowest possible price for this bundle product
// $return_type = 'min';
$model_catalog_product = Mage::getModel('catalog/product'); // getting product model
$_product = $model_catalog_product->load( $_product_id );
$TypeInstance = $_product->getTypeInstance(true);
$Selections = $TypeInstance->getSelectionsCollection($OptionIds, $_product );
$Options = $TypeInstance->getOptionsByIds($OptionIds, $_product);
$bundleOptions = $Options->appendSelections($Selections, true);
$minmax_pricevalue = 0; // to sum them up from 0
foreach ($bundleOptions as $bundleOption) {
if ($bundleOption->getSelections()) {
$bundleSelections = $bundleOption->getSelections();
$pricevalues_array = array();
foreach ($bundleSelections as $bundleSelection) {
$pricevalues_array[] = $bundleSelection->getPrice();
}
if ( $return_type == 'max' ) {
rsort($pricevalues_array); // high to low
} else {
sort($pricevalues_array); // low to high
}
// sum up the highest possible or lowest possible price
$minmax_pricevalue += $pricevalues_array[0];
}
}
// echo $minmax_pricevalue;
echo ''.Mage::helper('core')->currency($minmax_pricevalue, true, false).'';
如果您有更好和更短的方法,请随时在此处发布。感谢所有相关人员!
所有的背景是,我做了一个自定义扩展,还想在那里展示这种配置的“最低可能价格”和“最高可能价格”。Magento-Setup 是:本机“捆绑产品”几个“捆绑项目选项”连接了我的“捆绑产品”。每个“捆绑选项”都有多个价格不同的简单产品。我认为这就是重点。
希望一切都对某人有所帮助-喜欢分享这些东西:-)