html - 将 magento 可配置产品选项下拉列表转换为可选链接或单选按钮

标签 html magento

我需要将 magento 可配置产品选项下拉列表转换为可选链接或样式类似于可选链接的单选按钮。有一些付费主题提供它,但如何做到我的购物者主题在任何地方都不可用。

我想要的是这样的东西而不是默认的下拉菜单..

enter image description here

最佳答案

正如我所说,我已经编写了简单的 javascript 来将下拉列表转换为链接。下面的脚本将下拉列表转换为链接并显示选定的组合..

function replaceDropDowns() {
    jQuery('.product_attribute_option_link').remove();
    jQuery('#selected_combination').text('');
    jQuery(".super-attribute-select").each(function() {
        var drop_down = jQuery(this);
        drop_down.hide();
        drop_down.find("option[value!='']").each(function() {
            var option = jQuery(this);
            jQuery("<a>", { 
                    text: option.text(),
                    href: '#',
                    class: 'product_attribute_option_link',
                    'data-id': drop_down.attr('id'),
                    'data-name': drop_down.attr('name'),
                    'data-value': option.val(),
                    'data-label': option.text(),
                    click: function() { 
                        drop_down.val(option.val());
                        var obj = drop_down.get();
                        Event.observe(obj[0],'change',function(){});
                        fireEvent(obj[0],'change');
                        replaceDropDowns();
                        var selected_combination = [];
                        jQuery(".super-attribute-select").each(function() {
                            if(jQuery(this).val()) {
                                jQuery(".product_attribute_option_link[data-value="+jQuery(this).val()+"]").addClass('product_attribute_option_link_selected');
                                selected_combination.push(jQuery(this).find("option:selected").text());
                            }
                        });
                        jQuery.each(selected_combination, function(index, selection) {
                            jQuery('#selected_combination').append(selection);
                            if(index+1 < selected_combination.length)
                                jQuery('#selected_combination').append(" - ");
                        })
                        return false;
                    }
            }).appendTo(drop_down.parent());
        })
    });
}

jQuery(function() {
    replaceDropDowns();
})

关于html - 将 magento 可配置产品选项下拉列表转换为可选链接或单选按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20926520/

相关文章:

html - 如何避免内联元素中的换行符?

javascript - Magento Image Clean 扩展错误

php - 第 463 行的 fatal error : Call to a member function getModelInstance() on a non-object in/Applications/XAMPP/xamppfiles/htdocs/magento/app/Mage. php

Magento 1.7 - 从/customer/account/create/中的注册中删除字段

java - 如何在Android中使用XMLRPC调用magento的 "cart_payment.method"API

php - 动态插入 MySQL-PHP 组合

javascript - 如何在 onclick 事件后设置恢复到条件?

javascript - 需要更改 slider 的宽度和高度,但图像重叠

html - 容器左侧的绝对图像

magento - Magento 中的 FK 和 M2M 关系