php - Magento : How to get selected bundle option title and value from bundle product?

标签 php jquery magento magento-1.7

我正在尝试在产品详细信息页面上获取选定的 bundle 选项标题和值。

单位颜色*:Antelope Audio Zodiac 数模转换器 +£0.00

我使用下面的代码但它返回选项列表而不是选择的选项值但不是像Unit color这样的标题

$bundled_product = new Mage_Catalog_Model_Product();
    $bundled_product->load($_product->getId());
    $selectionCollection = $bundled_product->getTypeInstance(true)->getSelectionsCollection(
        $bundled_product->getTypeInstance(true)->getOptionsIds($bundled_product), $bundled_product
    );
    $bundled_items = array();
    foreach($selectionCollection as $option)
    {
        echo "<pre>";
        print_r($option);die;
        $bundled_items[] = $option->product_id;
    }

请同时检查下图。 enter image description here

所以请建议我如何获得标题和选定的值。

谢谢

最佳答案

免责声明:此代码段适用于 magento 演示站点上的捆绑产品: http://demo.magentocommerce.com/my-computer.html

如果我将以下带有前缀 javascript: 和后缀 generate_options_label_and_value() 的代码段放入浏览器 URL 栏中,它对单选按钮工作正常。如果您需要更多扩展案例(支持下拉菜单/复选框),请告诉我。这只是一个简短的片段:

function generate_options_label_and_value(){ 
    var generated_html = '';
    $$("#product-options-wrapper>dl>dt").each( function (dt){ 
        if(dt.next('dd').select('input:checked[type=radio]').length > 0 ){
            generated_html += dt.select("label")[0].innerHTML;
            generated_html += dt.next('dd').select('input:checked[type=radio]')[0].next('span').innerHTML;
        }
    });
    if(!$('selected_options_div')){
        $$('.add-to-cart')[0].insert({ top : "<div id='selected_options_div'></div>"});
    }
    $('selected_options_div').update(generated_html);
}

这是用原型(prototype)写的

关于php - Magento : How to get selected bundle option title and value from bundle product?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19403017/

相关文章:

PHPMYADMIN 调整编辑器高度大小

php - 将数据保存到SQL并根据json数组计数显示它们

php - 查找具有最多行 MYSQL 的范围

javascript - 哪个 jQuery 代码更高效?

php - Mysql - 选择具有最高平均值的不同客户端代码

javascript - Flot Graph时间不格式化

javascript - 使用 JavaScript 获取下拉选项的名称

php - 如何在 Magento 中以编程方式获取自定义选项

Magento 中的 JavaScript 控制台日志

Magento,如何在点击数据库之前从 Redis 查询集合