如何通过参数(post 数据)从自定义选择数组中计算捆绑产品价格?

how to calculate bundle product price from array of custom selection through parameter(post data)?

从post得到的数据是。

[productid] => 3
[product_type] => bundle
[bundle_option] => Array
    (
        [1] => Array
            (
                [0] => 1
                [1] => 2
            )

        [2] => Array
            (
                [0] => 3
                [1] => 4
            )

    )

[qty] => 1

如何计算我的选择的捆绑价格。 magento 核心功能更可取。

请使用以下代码:

public function getDisplayPrice($product) {
    if($product->getFinalPrice()) {
        return $product->getFormatedPrice();
    } else if ($product->getTypeId() == Mage_Catalog_Model_Product_Type::TYPE_BUNDLE) {
        $optionCol= $product->getTypeInstance(true)
                            ->getOptionsCollection($product);
        $selectionCol= $product->getTypeInstance(true)
                               ->getSelectionsCollection(
            $product->getTypeInstance(true)->getOptionsIds($product),
            $product
        );
        $optionCol->appendSelections($selectionCol);
        $price = $product->getPrice();

        foreach ($optionCol as $option) {
            if($option->required) {
                $selections = $option->getSelections();
                $minPrice = min(array_map(function ($s) {
                                return $s->price;
                            }, $selections));
                if($product->getSpecialPrice() > 0) {
                    $minPrice *= $product->getSpecialPrice()/100;
                }

                $price += round($minPrice,2);
            }  
        }
        return Mage::app()->getStore()->formatPrice($price);
    } else {
        return "";
    }
}

我用自己的方法解决了,不知道能不能接受

$bundle_option = Mage::app ()->getRequest ()->getParam('bundle_option');
$bundle_option_array = call_user_func_array('array_merge', $bundle_option);
$price =  Mage::Helper('airhotels/bundle')->getBundlePrice($productid,$bundle_option_array);

我的帮助文件是

public function getBundlePrice($productId,$bundle_option_array) {
$product = new Mage_Catalog_Model_Product();
$product->load($productId);
$price=0;
$selectionCollection = $product->getTypeInstance(true)->getSelectionsCollection($product->getTypeInstance(true)->getOptionsIds($product), $product);
foreach($selectionCollection as $option) 
{
    if (in_array($option->getSelectionId(), $bundle_option_array)){
        $price += $option->price; 
    }
}
return $price;
}