我需要配置产品价格范围
对于产品名称:$140 – 310我使用下面的代码
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上的类似问题是一个很好的工作基础.使用它,这是一个解决这个问题的方法,它考虑了具有多个价格变化属性的可配置产品的潜力.
我把它写成了一个带有可配置产品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"; }
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。