Passed
Push — master ( 30d553...9c5ccb )
by Christian
12:48 queued 10s
created

src/Administration/Resources/app/administration/src/module/sw-cms/elements/buy-box/component/index.js   A

Complexity

Total Complexity 9
Complexity/F 1.29

Size

Lines of Code 67
Function Count 7

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
wmc 9
eloc 38
mnd 2
bc 2
fnc 7
dl 0
loc 67
rs 10
bpm 0.2857
cpm 1.2857
noi 1
c 0
b 0
f 0
1
import template from './sw-cms-el-buy-box.html.twig';
2
import './sw-cms-el-buy-box.scss';
3
4
const { Component, Mixin, Utils } = Shopware;
0 ignored issues
show
Bug introduced by
The variable Shopware seems to be never declared. If this is a global, consider adding a /** global: Shopware */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
5
6
Component.register('sw-cms-el-buy-box', {
7
    template,
8
9
    mixins: [
10
        Mixin.getByName('cms-element'),
11
        Mixin.getByName('placeholder')
12
    ],
13
14
    computed: {
15
        product() {
16
            if (!this.element.data || !this.element.data.product) {
17
                return {
18
                    name: 'Lorem Ipsum dolor',
19
                    productNumber: 'XXXXXX',
20
                    minPurchase: 1,
21
                    deliveryTime: {
22
                        name: '1-3 days'
23
                    },
24
                    price: [
25
                        { gross: 0.00 }
26
                    ]
27
                };
28
            }
29
30
            return this.element.data.product;
31
        },
32
33
        pageType() {
34
            return Utils.get(this.cmsPageState, 'currentPage.type', '');
35
        },
36
37
        isProductPageType() {
38
            return this.pageType === 'product_detail';
39
        },
40
41
        alignStyle() {
42
            if (!this.element.config.alignment || !this.element.config.alignment.value) {
43
                return null;
44
            }
45
46
            return `justify-content: ${this.element.config.alignment.value};`;
47
        }
48
    },
49
50
    watch: {
51
        pageType(newPageType) {
52
            this.$set(this.element, 'locked', newPageType === 'product_detail');
53
        }
54
    },
55
56
    created() {
57
        this.createdComponent();
58
    },
59
60
    methods: {
61
        createdComponent() {
62
            this.initElementConfig('buy-box');
63
            this.initElementData('buy-box');
64
            this.$set(this.element, 'locked', this.isProductPageType);
65
        }
66
    }
67
});
68