X
X
Xtrm7772021-03-12 11:06:47
JavaScript
Xtrm777, 2021-03-12 11:06:47

The script works twice, how to fix it?

Hello. It costs opencart 3.0.3.3, when you click on the plus or minus button in the product, the product in quantity is displayed in increments of 2, that is, 2,4,6,8, etc. For some reason, the script works twice. Please help me figure out what the problem is. I am attaching the code. A link to an example of a product is also https://edelveystex.ru/zhenskij-trikotazh/halaty/h...

/* Quantity plus minus - Product Detail
 ========================================================*/
$(function ($) {
    "use strict";
    $.initQuantity = function ($control) {
        $control.each(function () {
            var $this = $(this),
                data = $this.data("inited-control"),
                $plus = $(".input-group-addon:last", $this),
                $minus = $(".input-group-addon:first", $this),
                $value = $(".form-control", $this);
            if (!data) {
                $control.attr("unselectable", "on").css({
                    "-moz-user-select": "none",
                    "-o-user-select": "none",
                    "-khtml-user-select": "none",
                    "-webkit-user-select": "none",
                    "-ms-user-select": "none",
                    "user-select": "none"
                }).bind("selectstart", function () {
                    return false
                });
                $plus.click(function () {
                    console.log($value.val())
                    if (!$($value).is('.size-quantity:disabled') && !($($value).is('.main-quantity') && $('.all-sizes:checked').length == 0)) {
                        var val = parseInt($value.val()) + 1;
                        $value.val(val);

                        if ($($value).is('.main-quantity') && $('.all-sizes:checked').length > 0) {
                            $('.size-quantity').val($($value).val());
                        }

                        if ($($value).is('.size-quantity') && $('.all-sizes:checked').length === 0) {
                            $('.main-quantity').val($.map($('.size-quantity'),(s)=> parseInt($(s).val())).reduce((c,b)=> c+b,0));
                        }
                        getProductSummary();
                    }
                    return false
                });
                $minus.click(function () {
                    if (!$($value).is('.size-quantity:disabled') && !($($value).is('.main-quantity') && $('.all-sizes:checked').length == 0)) {
                        var val = parseInt($value.val()) - 1;
                        $value.val(val > -1 ? val : 0);
                        if ($($value).is('.main-quantity') && $('.all-sizes:checked').length > 0) {
                            $('.size-quantity').val($($value).val());
                        }

                        if ($($value).is('.size-quantity') && $('.all-sizes:checked').length === 0) {
                            $('.main-quantity').val($.map($('.size-quantity'),(s)=> parseInt($(s).val())).reduce((c,b)=> c+b,0));
                        }
                        getProductSummary();
                    }
                    return false
                });
                $value.blur(function () {
                    if (!$($value).is('.size-quantity:disabled') && !($($value).is('.main-quantity') && $('.all-sizes:checked').length == 0)) {
                        var val = parseInt($value.val());
                        $value.val(val > -1 ? val : 0);
                        if ($($value).is('.main-quantity') && $('.all-sizes:checked').length > 0) {
                            $('.size-quantity').val($($value).val());
                        }

                        if ($($value).is('.size-quantity') && $('.all-sizes:checked').length === 0) {
                            $('.main-quantity').val($.map($('.size-quantity'),(s)=> parseInt($(s).val())).reduce((c,b)=> c+b,0));
                        }
                        getProductSummary();
                    }
                })
            }
        })
    };
    $.initQuantity($(".quantity-control"));
    $.initSelect = function ($select) {
        $select.each(function () {
            var $this = $(this),
                data = $this.data("inited-select"),
                $value = $(".value", $this),
                $hidden = $(".input-hidden", $this),
                $items = $(".dropdown-menu li > a", $this);
            if (!data) {
                $items.click(function (e) {
                    if ($(this).closest(".sort-isotope").length >
                        0) e.preventDefault();
                    var data = $(this).attr("data-value"),
                        dataHTML = $(this).html();
                    $this.trigger("change", {
                        value: data,
                        html: dataHTML
                    });
                    $value.html(dataHTML);
                    if ($hidden.length) $hidden.val(data)
                });
                $this.data("inited-select", true)
            }
        })
    };
    $.initSelect($(".btn-select"))
});

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Arseny, 2021-03-12
@Xtrm777

Connect scripts in a single amount to the page.

X
Xtrm777, 2021-03-12
@Xtrm777

Arseniy Matytsin can you explain in more detail, please

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question