Показать сообщение отдельно
  #2 (permalink)  
Старый 21.05.2017, 22:42
Аватар для рони
Профессор
Отправить личное сообщение для рони Посмотреть профиль Найти все сообщения от рони
 
Регистрация: 27.05.2010
Сообщений: 33,121

movingToJS,
var total = [],
    z = 0;

function tot(itemTotal, index) {
    total[index] = itemTotal;
    var sum = total.reduce(function(a, b) {
        return a + b
    }, 0);
    $(".allTotal span").html(sum)
}

function productCalc(a, b, c, d, e, f, g, h, i, j, k, l, m, n, z) {
    $("#lumbersCartForm input").on("ifChanged change", function(event) {
        if ($(a + " .Wet").is(":checked")) {
            if ($(a + " .Retail").is(":checked")) {
                if ($(a + " .IsMeter").is(":checked")) var itemPrice = b;
                else if ($(a + " .IsPcs").is(":checked")) itemPrice = c;
                var itemTotal = itemPrice * d.val();
                $(a + " .price span").text(itemTotal);
                $(a + " .price input[type='hidden']").val(itemTotal)
            } else if ($(a + " .Wholesale").is(":checked")) {
                if ($(a + " .IsMeter").is(":checked")) itemPrice = e;
                else if ($(a +
                        " .IsPcs").is(":checked")) itemPrice = f;
                itemTotal = itemPrice * d.val();
                $(a + " .price span").text(itemTotal);
                $(a + " .price input[type='hidden']").val(itemTotal)
            }
            $("#cart tbody ." + g + " .humidity").html("Option 1 - Value 1")
        }
        if ($(a + " .Dry").is(":checked")) {
            if ($(a + " .Retail").is(":checked")) {
                if ($(a + " .IsMeter").is(":checked")) itemPrice = h;
                else if ($(a + " .IsPcs").is(":checked")) itemPrice = i;
                itemTotal = itemPrice * d.val();
                $(a + " .price span").text(itemTotal);
                $(a + " .price input[type='hidden']").val(itemTotal)
            } else if ($(a +
                    " .Wholesale").is(":checked")) {
                if ($(a + " .IsMeter").is(":checked")) itemPrice = j;
                else if ($(a + " .IsPcs").is(":checked")) itemPrice = k;
                itemTotal = itemPrice * d.val();
                $(a + " .price span").text(itemTotal);
                $(a + " .price input[type='hidden']").val(itemTotal)
            }
            $("#cart tbody ." + g + " .humidity").html("Option 1 - Value 2")
        }
        if ($(a + " .IsMeter").is(":checked")) var itemQtyType = "Option 3 - Value 1",
            itemVolTotal = parseFloat(d.val(), 10);
        else {
            itemVolTotal = parseFloat((l * d.val()).toFixed(2), 10);
            itemQtyType = "Option 3 - Value 2"
        }
        tot(itemTotal,
            z);
        if (!$(a + " .Add").is(":checked")) {
            itemTotal = 0;
            itemVolTotal = 0
        }
        if ($(a + " .Add").is(":checked")) {
            if (!$("#cart tbody ." + g).length) $("#cart tbody #profiledBeams").after(' <tr class="' + g + '">                                <td>' + m + '</td>                                <td class="humidity">' + n + '</td>                                <td class="qty">' + d.val() + itemQtyType + '</td>                                <td class="price">' + $(a + " .price input[type='hidden']").val() + "</td>                              </tr> ")
        } else {
            $("." +
                g).remove();
            $(a + " .price input[type='hidden']").val(0)
        }
        $("#cart tbody ." + g + " .qty").html(d.val() + itemQtyType);
        $("#cart tbody ." + g + " .price").html($(a + " .price input[type='hidden']").val())
    });

    function addToCart() {
        $(a + " .btnAdd").on("click", function() {
            if ($(this).hasClass("added")) {
                $(a + " .Add").prop("checked", false).change();
                $(this).toggleClass("added btn-danger").text("Add to cart");
                $(this).parent().siblings(".price").find("input").val(0)
            } else {
                $(a + " .Add").prop("checked", true).change();
                $(this).toggleClass("added btn-danger").text("Remove")
            }
        })
    }
    addToCart()
}
var itemSelector = "#item",
    qtySelector = $('input[name="itemQty"]'),
    cartItemSelector = "cartItem",
    itemTitle = $("input[name='itemAdd']").val(),
    itemHumidity = $(itemSelector + " input[name='itemHumidity']").val(),
    price1 = 8500,
    price2 = 765,
    price3 = 8300,
    price4 = 747,
    price5 = 10500,
    price6 = 945,
    price7 = 1E4,
    price8 = 900,
    pcsInMeter = .09;
productCalc(itemSelector, price1, price2, qtySelector, price3, price4, cartItemSelector, price5, price6, price6, price8, pcsInMeter, itemTitle, itemHumidity, z++);
var itemSelector = "#item2",
    qtySelector = $('input[name="item2Qty"]'),
    cartItemSelector = "cartItem2",
    itemTitle = $("input[name='item2Add']").val(),
    itemHumidity = $(itemSelector + " input[name='item2Humidity']").val(),
    price1 = 8500,
    price2 = 1148,
    price3 = 8300,
    price4 = 1121,
    price5 = 10500,
    price6 = 1418,
    price7 = 1E4,
    price8 = 1350,
    pcsInMeter = .135;
productCalc(itemSelector, price1, price2, qtySelector, price3, price4, cartItemSelector, price5, price6, price6, price8, pcsInMeter, itemTitle, itemHumidity, z++);
Ответить с цитированием