gpt4 book ai didi

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

转载 作者:搜寻专家 更新时间:2023-10-31 21:36:02 24 4
gpt4 key购买 nike

我正在尝试在产品详细信息页面上获取选定的 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com