2013-07-24 44 views
0

您好,我想顯示產品的價格範圍,只有通過自定義選項才能顯示產品的價格範圍。我有這樣的代碼,它使我能夠以基價顯示價格,但是如果產品HAS選項僅顯示期權價格,如果沒有期權,那麼定期基準價格。Magento:在list.phtml中顯示自定義期權價格的價格範圍,而不是基準價格

   <!-- code change to show price ranges --> 
      <div class="price-box"><span class="regular-price"> 
<?php 
$product = Mage::getModel('catalog/product')->load($_product->getId()); 
$prodPrice = $product->getPrice(); 
if($product->getOptions()){ 
    $minPrices=array(); 
    $maxPrices=array(); 
    foreach ($product->getOptions() as $_option) { 
     switch ($_option->getType()) { 
      case 'field': case 'file': case 'area': case 'date_time': case 'date': case 'time': 
       if($_option->getIsRequire()){ 
        $minPrices[] = ($_option->getPriceType()=='percent') ? $prodPrice*$_option->getPrice()/100 : $_option->getPrice(); 
       } 
       $maxPrices[] = ($_option->getPriceType()=='percent') ? $prodPrice*$_option->getPrice()/100 : $_option->getPrice(); 
       break; 
      case 'radio': case 'drop_down': 
       $valuePrices=array(); 
       foreach ($_option->getValues() as $_value){ 
        $valuePrices[] = ($_value->getPriceType()=='percent') ? $prodPrice*$_value->getPrice()/100 : $_value->getPrice(); 
       } 
       sort($valuePrices,SORT_NUMERIC); 
       if($_option->getIsRequire()){ 
        $minPrices[] = $valuePrices[0]; 
       } 
       $maxPrices[] = array_pop($valuePrices); 
       break; 
      case 'multiple': case 'checkbox': 
       $valuePrices=array(); 
       foreach ($_option->getValues() as $_value){ 
        $valuePrices[] = ($_value->getPriceType()=='percent') ? $prodPrice*$_value->getPrice()/100 : $_value->getPrice(); 
       } 
       sort($valuePrices,SORT_NUMERIC); 
       if($_option->getIsRequire()){ 
        $minPrices[] = $valuePrices[0]; 
       } 
       $maxPrices[] = array_sum($valuePrices); 
       break; 
     } 
    } 
    $minTotal = $prodPrice + array_sum($minPrices); 
    $maxTotal = $prodPrice + array_sum($maxPrices); 
    if($minTotal==$maxTotal){ 
     echo Mage::helper('core')->currency($minTotal); 
    } else { 
     echo Mage::helper('core')->currency($minTotal).'-'.Mage::helper('core')->currency($maxTotal); 
    } 
} else { 
    echo Mage::helper('core')->currency($prodPrice); 
} 
?> 
</span></div> 
<!-- end price range code --> 

回答

3

在類別列表頁面

應用程序/設計/前端/默認/ {}主題/template/catalog/product/list.phtml

<?php if($_product->getRequiredOptions()) :?> 
     <span class="start-at">Starting at:</span> 
     <?php // need to format currency - echo Mage::helper('core')->currency($_product->getData('min_price'), true, false) ?> 
     <?php echo $_product->getData('min_price') ?> - <?php echo $_product->getData('max_price') ?> 
<?php else: ?> 
     <?php echo $this->getPriceHtml($_product, true); ?> 
<?php endif; ?>