view/frontend/web/js/catalog-add-to-cart-mixin.js   A
last analyzed

Complexity

Total Complexity 9
Complexity/F 1.5

Size

Lines of Code 50
Function Count 6

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 24
c 0
b 0
f 0
dl 0
loc 50
rs 10
wmc 9
mnd 3
bc 3
fnc 6
bpm 0.5
cpm 1.5
noi 2
1
define([
2
    'jquery',
3
    'Mageprince_BuyNow/js/model/buy-now'
4
], function ($, buyNowModel) {
5
    'use strict';
6
7
    return function (catalogAddToCartWidget) {
8
9
        $.widget('mage.catalogAddToCart', catalogAddToCartWidget, {
10
            /** @inheritdoc */
11
            _create: function () {
12
                this._super();
13
                buyNowModel.initListBuyNowBtnSelector();
14
            },
15
16
            /**
17
             * @param {String} form
18
             */
19
            disableAddToCartButton: function (form) {
20
                if (this.isBuyNowRequest(form)) {
21
                    return false;
22
                }
23
                this._super(form);
0 ignored issues
show
Best Practice introduced by
There is no return statement in this branch, but you do return something in other branches. Did you maybe miss it? If you do not want to return anything, consider adding return undefined; explicitly.
Loading history...
24
            },
25
26
            /**
27
             * @param {String} form
28
             */
29
            enableAddToCartButton: function (form) {
30
                if (this.isBuyNowRequest(form)) {
31
                    return false;
32
                }
33
                this._super(form);
0 ignored issues
show
Best Practice introduced by
There is no return statement in this branch, but you do return something in other branches. Did you maybe miss it? If you do not want to return anything, consider adding return undefined; explicitly.
Loading history...
34
            },
35
36
            /**
37
             * @param {String} form
38
             * @returns {boolean}
39
             */
40
            isBuyNowRequest: function (form) {
41
                var isBuyNow = false,
42
                    formAction = form.attr('action');
43
                if (formAction.includes("buynow")) {
44
                    isBuyNow = true;
45
                }
46
                return isBuyNow;
47
            }
48
        });
49
    }
50
});
51