将自定义期权价格添加到我的最终价格总计中

时间:2019-09-18 16:52:53

标签: magento

我正在使用Magento 1.9.3,并且我有一个带有自定义选项的产品,但是我的代码不会将它们添加到前端显示的价格中。这是捆绑商品,捆绑选项中的商品会加价。

这是代码

    var parts = selection.id.split('-');

    if (this.config['options'][parts[2]].isMulti) {
        selected = new Array();

        if (selection.tagName == 'SELECT') {
            var str ='';
            for (var i = 0; i < selection.options.length; i++) {
                if (selection.options[i].selected && selection.options[i].value != '') {

                    selected.push(selection.options[i].value);
                    var selectedText = selection.options[i].text;
                    str = str + selectedText+"<br/>";

                }
            }
            if(str =='')
            {
                str ='None';
            }
            $('extra_'+parts[2]).innerHTML ="<div class='selected-option'>"+str+"</div>";
            $('extra_'+parts[2]).style.color ='red';
            //$('extra_color_'+parts[2]).style.color = 'red';
            setTimeout(function(){ $('extra_'+parts[2]).style.color='#000';},1000);

        } else if (selection.tagName == 'INPUT') {

            selector = parts[0]+'-'+parts[1]+'-'+parts[2];
            selections = $$('.'+selector);
            var str ='';
            for (var i = 0; i < selections.length; i++) {
                if (selections[i].checked && selections[i].value != '') {
                    id =selections[i].id;
                    str =str + $$('label[for="'+id+'"]').first().innerHTML +"<br/>";
                    selected.push(selections[i].value);
                }
            }
            $('extra_'+parts[2]).innerHTML ="<div class='selected-option'>"+str+"</div>";
            $('extra_'+parts[2]).style.color ='red';
            //$('extra_color_'+parts[2]).style.color = 'red';
            setTimeout(function(){ $('extra_'+parts[2]).style.color='#000';},1000);
        }
        this.config.selected[parts[2]] = selected;
    } else {

        if (selection.value != '') {
            if(selection.type == 'select-one'){
            id =selection.id;
            var sel = document.getElementById(''+id+'');
            var selectedText = sel.options[sel.selectedIndex].text;
            $('extra_'+parts[2]).innerHTML = "<div class='selected-option'>"+selectedText+"</div>";
            $('extra_'+parts[2]).style.color = 'red';
            setTimeout(function(){ $('extra_'+parts[2]).style.color='#000';},1000);
            }else if(selection.type == 'radio')
            {

                id =selection.id;
                $('extra_'+parts[2]).innerHTML ="<div class='selected-option'>"+$$('label[for="'+id+'"]').first().innerHTML+"</div>";
                $('extra_'+parts[2]).style.color ='red';
            //$('extra_color_'+parts[2]).style.color = 'red';
                setTimeout(function(){ $('extra_'+parts[2]).style.color='#000';},1000);
            }
            this.config.selected[parts[2]] = new Array(selection.value);
        } else {
            $('extra_'+parts[2]).innerHTML ="<div class='selected-option'>"+'None'+"</div>";
            $('extra_'+parts[2]).style.color ='red';
            //$('extra_color_'+parts[2]).style.color = 'red';
            setTimeout(function(){ $('extra_'+parts[2]).style.color='#000';},1000);
            this.config.selected[parts[2]] = new Array();
        }
        this.populateQty(parts[2], selection.value);
    }
    this.reloadPrice();
    var price = $('product-price-'+'<?php echo $_product->getId();?>').innerHTML;
    $('price-right').innerHTML = price;
    var qty = $('bundle-option-'+parts[2]+'-qty-input').value;
    console.log($('extra_qty'+parts[2]));
    $('extra_qty'+parts[2]).innerHTML = qty + ' x '+ ' &nbsp;';
 },
 changeOptionQty: function (element, event) {
    var checkQty = true;
    if (typeof(event) != 'undefined') {
        if (event.keyCode == 8 || event.keyCode == 46) {
            checkQty = false;
        }
    }
    if (checkQty && (Number(element.value) == 0 || isNaN(Number(element.value)))) {
        element.value = 1;
    }
    parts = element.id.split('-');
    optionId = parts[2];

    if (!this.config['options'][optionId].isMulti) {
        selectionId = this.config.selected[optionId][0];
        this.config.options[optionId].selections[selectionId].qty = element.value*1;
        this.reloadPrice();
    }
    $('extra_qty'+parts[2]).innerHTML = element.value + ' x' + '&nbsp;';
    var price = $('product-price-'+'<?php echo $_product->getId();?>').innerHTML;
    $('price-right').innerHTML = price;
}

我相信我需要在价格重新加载中添加自定义选项,但是我不确定这是否正确。

0 个答案:

没有答案