首页 文章

如何在magento中显示自定义选项的价格范围

提问于
浏览
0

我正在使用magento 1.7,在产品详细信息价格上我有一些自定义选项和一些可配置的产品选项 .

我想要做的是,我想显示范围内所有选项的价格,例如,如果最低总价格选项是18.50,最高总价格选项是55.90,它应该显示在产品页面上某处,如“18.50 - 55.90” .

提前致谢 .

1 回答

  • 0

    尝试以下代码

    //load configurable product    
    $product = Mage::getModel('catalog/product')->load(some_id);  
    //load all children
    $childProducts = Mage::getModel('catalog/product_type_configurable')
                        ->getUsedProducts(null,$product);   
    foreach($childProducts as $child){
        $_child = Mage::getModel('catalog/product')->load($child->getId());
        $childPrice =  $_child->getPrice();
        //compare the $childPrice
    }
    

    或者对于内联查询应该是这样的

    <?php
        $db = Mage::getSingleton('core/resource')->getConnection('core_write');
        $result = $db->query('SELECT a.product_id, a.product_super_attribute_id, ap.product_super_attribute_id, ap.pricing_value FROM catalog_product_super_attribute AS a INNER JOIN catalog_product_super_attribute_pricing AS ap ON a.product_super_attribute_id=ap.product_super_attribute_id WHERE a.product_id='.$_product->getId().' ORDER BY ap.pricing_value DESC LIMIT 1');
        $rows = $result->fetch();
        echo 'From '.Mage::helper('core')->currency($_product->getPrice()).' to '.Mage::helper('core')->currency($rows ['pricing_value']+$_product->getPrice());
    ?>
    

    Edit (optional)

    $prices = array();
    $associated = $_product->getTypeInstance(true)->getAssociatedProductCollection($_product)
    ->addAttributeToSelect('special_pric$
    foreach ($associated as $assoc) {
        $prices[] = $assoc->getSpecialPrice();
    }
    if (count($prices)) {
        $min_price = min($prices);
        $max_price = max($prices);
    } else {
        $min_price = 0;
        $max_price = 0;
    }
    

相关问题