我嘗試了幾個想法,我可以在谷歌找到,但沒有人爲我工作了幾天。最後,我找到了一種方法自定義擴展,以顯示「最小可能的價格」和「最大可能的價格」捆綁產品在Magento: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是:本地「捆綁產品」幾個「捆綁項目選項」連接我的「捆綁產品」。每個「捆綁選項」都有多個不同價格的簡單產品。我認爲這是重點。
希望所有幫助別人 - 愛分享這種東西:-)
獲取錯誤$ OptionIds未定義。任何線索? – aravind 2016-02-05 16:06:31