我需要配置产品价格范围
if(Mage::getSingleton('customer/session')->isLoggedIn()) { // Get group Id $groupId = Mage::getSingleton('customer/session')->getCustomerGroupId(); } else { $groupId = 0; } $db = Mage::getSingleton('core/resource')->getConnection('core_write'); $result = $db->query('SELECT price,final_price,min_price,max_price,tier_price,group_price FROM catalog_product_index_price WHERE entity_id='.$_product->getId().' AND customer_group_id ='.$groupId.' ORDER BY customer_group_id ASC LIMIT 1'); $rows = $result->fetch();
我还需要配置产品的常规价格范围.我也认为我的产品名称之后的范围是错误的,因为在你的价格中有一个价格135美元所以我怎样才能获得最低价格和最高特价以及正常价格?
我怎么能得到那个?
感谢致敬
This answer到Magento StackExchange上的类似问题是一个很好的工作基础.使用它,这是一个解决这个问题的方法,它考虑了具有多个价格变化属性的可配置产品的潜力.
原文链接:https://www.f2er.com/php/137104.html我把它写成了一个带有可配置产品ID的函数,并返回一个min到max的字符串.应该非常清楚如何将其应用到您需要的上下文中.
function getPriceRange($productId) { $max = ''; $min = ''; $pricesByAttributeValues = array(); $product = Mage::getModel('catalog/product')->load($productId); $attributes = $product->getTypeInstance(true)->getConfigurableAttributes($product); $basePrice = $product->getFinalPrice(); foreach ($attributes as $attribute){ $prices = $attribute->getPrices(); foreach ($prices as $price){ if ($price['is_percent']){ //if the price is specified in percents $pricesByAttributeValues[$price['value_index']] = (float)$price['pricing_value'] * $basePrice / 100; } else { //if the price is absolute value $pricesByAttributeValues[$price['value_index']] = (float)$price['pricing_value']; } } } $simple = $product->getTypeInstance()->getUsedProducts(); foreach ($simple as $sProduct){ $totalPrice = $basePrice; foreach ($attributes as $attribute){ $value = $sProduct->getData($attribute->getProductAttribute()->getAttributeCode()); if (isset($pricesByAttributeValues[$value])){ $totalPrice += $pricesByAttributeValues[$value]; } } if(!$max || $totalPrice > $max) $max = $totalPrice; if(!$min || $totalPrice < $min) $min = $totalPrice; } return "$min - $max"; }