Magento:在list.phtml中显示自定义选项价格的价格范围,而不是基本价格


Magento: Show price ranges of custom option prices in list.phtml instead of base price

你好,我想只显示产品的价格范围,如果他们有自定义选项的话。我有这个代码,可以用基本价格显示价格,但如果产品有选项,则只显示选项价格,如果没有选项,则显示常规基本价格。

                <!-- 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 -->

在类别列表页面

app/design/frontend/default/{theme}/template/controlog/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; ?>