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

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

报告相同问题?

悬赏问题

  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog