`
kirenenko04
  • 浏览: 152052 次
  • 性别: Icon_minigender_2
  • 来自: 上海
社区版块
存档分类
最新评论

Get Price of Configurable Product options

 
阅读更多

Here is how you can get the prices of the simple products. The example is for a single configurable product but you can integrate it in your loop.
There may be a problem with performance because there are a lot of foreach loops but at least you have a place to start. You can optimize later.

//the configurable product id
$productId = 126; 
//load the product - this may not be needed if you get the product from a collection with the prices loaded.
$product = Mage::getModel('catalog/product')->load($productId); 
//get all configurable attributes
$attributes = $product->getTypeInstance(true)->getConfigurableAttributes($product);
//array to keep the price differences for each attribute value
$pricesByAttributeValues = array();
//base price of the configurable product 
$basePrice = $product->getFinalPrice();
//loop through the attributes and get the price adjustments specified in the configurable product admin page
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'];
        }
    }
}

//get all simple products
$simple = $product->getTypeInstance()->getUsedProducts();
//loop through the products
foreach ($simple as $sProduct){
    $totalPrice = $basePrice;
    //loop through the configurable attributes
    foreach ($attributes as $attribute){
        //get the value for a specific attribute for a simple product
        $value = $sProduct->getData($attribute->getProductAttribute()->getAttributeCode());
        //add the price adjustment to the total price of the simple product
        if (isset($pricesByAttributeValues[$value])){
            $totalPrice += $pricesByAttributeValues[$value];
        }
    }
    //in $totalPrice you should have now the price of the simple product
    //do what you want/need with it
}

 The code above was tested on CE-1.7.0.2 with the Magento sample data for 1.6.0.0.

I tested on the product Zolof The Rock And Roll Destroyer: LOL Cat T-shirt and it seams to work. I get as results the same prices as I see in the frontend after configuring the product by Size and Color

分享到:
评论

相关推荐

    Magento-Configurable-Product-Price-Overriding-Simple-Product-Price:此扩展名用于使用简单产品价格覆盖可配置产品价格

    标题中的“Magento-Configurable-Product-Price-Overriding-Simple-Product-Price”是一个特定的扩展,它的目标是改变默认的价格逻辑,使得可配置产品的价格可以根据所选的简单产品价格进行调整,而不是使用预先设定...

    spring Configurable注解用法

    在Spring框架中,`@Configurable`注解是Spring AOP(面向切面编程)的一部分,主要用于实现依赖注入(DI)到非Spring管理的对象中,比如由其他框架创建或者通过new关键字实例化的对象。这个特性使得即使在这些“不...

    A novel SRAM-based FPGA architecture for defect and fault tolerance of configurable logic blocks1

    ### 基于SRAM的FPGA架构:针对可配置逻辑块的缺陷与容错机制 #### 摘要 本文介绍了一种新颖的基于SRAM的现场可编程门阵列(FPGA)架构,该架构特别适用于在设计中考虑缺陷和容错性的场景。所提出的容错(FT)方法...

    7237090_Configurable_out_of_order_data_t.pdf

    CPU Configurable_out_of_order_data_t

    dry-configurable, 一个简单的mixin使 ruby 类可以配置.zip

    dry-configurable, 一个简单的mixin使 ruby 类可以配置 干可以配置 概要class App extend Dry::Configurable # Pass a block for nested configuration (works to any

    Python库 | configurable-http-proxy-0.2.2.tar.gz

    了解HTTP的工作原理,包括请求方法(GET、POST等)、状态码、报头等,对于使用这个库创建代理服务至关重要。 3. **代理服务器**:代理服务器作为客户端和目标服务器之间的中介,可以用来隐藏原始IP地址、缓存数据、...

    国外嵌入式系统论文 A Highly-Configurable Cache Architecture For Embedded Systems

    ### 国外嵌入式系统论文《一种高度可配置的缓存架构用于嵌入式系统》 #### 摘要及研究背景 本篇论文主要介绍了一种针对嵌入式系统的高度可配置缓存架构。在当前技术背景下,能量消耗是嵌入式计算系统中的一个重大...

    Community-wide-Dataset-of-Configurable-Systems

    Community-wide-Dataset-of-Configurable-Systems

    A general and configurable use.zip

    A general and configurable use

    前端开源库-define-configurable

    "define-configurable"是一个专门为前端开发设计的开源库,它专注于定义和管理对象的可配置属性。这个库利用了JavaScript语言中的核心特性——`Object.defineProperty()`方法,帮助开发者更加灵活地控制对象的属性...

    spring-configurable-sample

    #自述文件使用 spring @Configurable 注释的“原型”bean 类型的示例(也请记住单例 bean),即使用普通的“new”运算符创建 bean,然后 spring 进一步控制初始化 bean,替换 @Value 占位符 bean 属性上的值,调用 ...

    Low-Power Implementation of the Bluetooth Subband Audio Codec.pdf

    The design uses a configurable Weighted Overlap-Add (WOLA) filterbank coprocessor to implement the analysis and synthesis filterbanks. A new method to convert the two-times over-sampled, complex ...

    configurable-http-proxy:node-http-proxy加上REST API

    目录使用REST API REST API基础通过传递令牌进行身份验证获取路由表添加新路线删除路线自定义错误页面基于主机的路由故障排除 安装先决条件: Node.js≥6 如果要在Linux中安装configurable-http-proxy ,则可以按照...

    Store_02.01.09_Install DNN

    It is entirely configurable: you can choose the category of product displayed in the module, choose the template which will be used to display the product (HTML file with Tokens)… Store Account ...

    Store_02.01.09_SkinObjects_Install FOR DNN

    It is entirely configurable: you can choose the category of product displayed in the module, choose the template which will be used to display the product (HTML file with Tokens)… Store Account ...

    Store_02.01.09

    It is entirely configurable: you can choose the category of product displayed in the module, choose the template which will be used to display the product (HTML file with Tokens)… Store Account ...

    Configurable C++ platform adapter.zip

    "Configurable C++ platform adapter"是一个关键的概念,它指的是一个能够根据不同的目标平台进行配置的C++适配器或库。这个适配器的主要目的是解决跨平台开发中的兼容性问题,允许代码在多个操作系统或硬件架构上...

    Stylus1.5.9.zip

    * Versatility of theme installation options. Stylus supports installs from popular online repositories. Additionally, styles can now also be installed from .user.css or .user.styl URLs (see Usercss ...

    dropwizard-configurable-assets-bundle-0.1.9.zip

    《Dropwizard Configurable Assets Bundle 0.1.9与Ollie开源项目解析》 在IT行业中,开源项目扮演着至关重要的角色,它们为开发者提供了丰富的工具和资源,极大地推动了技术的发展。今天我们将深入探讨的是名为...

Global site tag (gtag.js) - Google Analytics