如何在Magento中获得捆绑产品价格?

Lan*_*yen 3 magento

我有一个像这样的数组的捆绑产品:(在将产品添加到购物车时从params获取)

Array
(
    [product] => 165
    [bundle_option] => Array
    (
        [17] => 47
        [22] => 60
        [16] => 46
        [15] => 42
        [14] => Array
            (
                [0] => 39
            )
    )
)
Run Code Online (Sandbox Code Playgroud)

我怎么能得到这个捆绑产品的价格?

小智 6

这样的事情也应该有效:

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 "";
    }
}
Run Code Online (Sandbox Code Playgroud)