0

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

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

提前致谢。

4

1 回答 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());
?>

编辑(可选)

$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;
}
于 2013-10-22T10:57:46.160 回答