2017-06-16 27 views

回答

0

我解決它通過自己的方法,不能確定其接受。

$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; 
} 
0

請使用如下代碼:

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 ""; 
    } 
} 
+0

謝謝.....但是這個代碼獲取所有默認包選項從產品....我的孩子產品的定製選擇來自POST ..如何在代碼中添加我的選擇數組.... –

相關問題