dougang1967 2013-10-16 12:09
浏览 19
已采纳

Magento:如何从捆绑产品中获取选定的捆绑选项标题和价值?

I am trying to get selected bundle option title and value on product detail page.

Unit Colour* : Antelope Audio Zodiac Digital to Anologue Converter +£0.00

I use the below code but it return me option list and not selected option value but not title like 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;
    }

Please check below image also. enter image description here

So please suggest me idea how can i get title and selected value.

Thanks

  • 写回答

1条回答 默认 最新

  • donglian3055 2013-10-16 15:35
    关注

    Disclaimer: this snippet works fine with the bundle product on magento demo site: http://demo.magentocommerce.com/my-computer.html

    If I put into browser URL bar the below snippet with prefix javascript: and postfix generate_options_label_and_value(), it works fine for the radio buttons. If you need more extended case (supporting dropdowns/checkboxes), let me know. This is just a quick snippet:

    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);
    }
    

    This is written in prototype

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法
  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图