如何为分组项目获得相同的价格

时间:2014-04-03 18:27:00

标签: javascript jquery for-loop

此代码适用于具有相同地址的项目。 如果它们具有相同的addressId,那么它们将在一个地址下组合在一起。

5个项目相同的地址显示罚款,但每个项目的运费相同。

只需要显示相同的地址,同一组项目只需支付一笔运费。 请帮助,我在过去的两天里一直在尝试。不知道如何退还一组物品的运费。

var itemshippingGroup,应该分组运费,显示,只收取其中一项费用,而不是每项5项作为单独费用。

见下面的代码

//cart rows
var numofItems = productCart.length;
var productSubTotal = 0, shipping = 0;



var retriveAdd = getStoredData(address_cookie_name);
//alert(retriveAdd);
var productAddress = $.parseJSON(retriveAdd);
var k = 0;
for(var ad in productAddress){
    var j = 0;
    for(var i in productCart) {
        var ship = 0;
        var value = productCart[i];
        var addressId = productCart[i].addressId;
        var shippingId = parseFloat(productCart[i].shippingmethod).toFixed(2);
        if(ad == addressId){
            var item = parseInt(i)+1;

            var address = productAddress[productCart[i].addressId];
            var itemshipping = parseFloat(productCart[i].shippingmethod).toFixed(2);

            var fName = '', lName = '';
            if(address){
                fName = address.firstName;
                lName = address.lastName;
                itemAddress = address.address1+" <br> "+ address.city+","+address.state+" "+address.zipcode;
                if(addressId == shippingId){
                    var itemshippingGroup = shippingId;
                }
            }



            // Sub Total
            productSubTotal = productSubTotal + ((parseFloat(value.productPrice) + parseFloat(value.productTax)) * value.productQty);
            var trStyle = "style='background-color:#FFFFFF;'";
            if(k%2 == 0){
                trStyle = "style='background-color:#F1F1F1;'";
            }                           
            cart_html += '<tr id="cart_row_'+i+'" class="cart_row" '+trStyle+'>';
            cart_html += '<td class="confirm-product"><span class="clearfix first_item last_item"><img src="'+value.productImage+'"   alt="" title="'+value.productName+'" class="cart-images"></td>';
            cart_html += '<td>'+value.productName+'<br>'+fName+' '+lName+'</td>';
            if(j == 0){
                cart_html += '<td>'+itemAddress+'</td>';
            }else{
                cart_html += '<td> </td>';
            }
            j++;
            cart_html += '<td>'+currencySymbol+''+parseFloat(value.productPrice).toFixed(2)+'</td>';
            cart_html += '<td>'+currencySymbol+''+parseFloat(value.productTax)+'</td>';
            cart_html += '<td class="itemshipping">'+currencySymbol+' '+itemshipping+'</td>';

            //cart_html += '<td>'+currencySymbol+' '+itemshipping+'</td>';

            cart_html += '<td>'+currencySymbol+' '+ ((parseFloat(value.productPrice) + parseFloat(value.productTax))*value.productQty).toFixed(2)+'</td>';
            //cart_html += '<td><a href="#" id="delete_prod_id'+i+'" class="close delete_product_from_cart" title="Delete">&times;</a></td>';

            cart_html += '</tr>';
            checkButton(value.uProductID);
            total_items += value.productQty;

            shipping += parseFloat(productCart[i].shippingmethod);
        }
    }
    k++;
}

0 个答案:

没有答案