Passed
Push — master ( 34c669...9a4c09 )
by Christian
13:27 queued 13s
created

src/Administration/Resources/app/administration/src/module/sw-extension/component/sw-extension-listing-card/index.js   A

Complexity

Total Complexity 14
Complexity/F 1.17

Size

Lines of Code 97
Function Count 12

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 52
dl 0
loc 97
rs 10
c 0
b 0
f 0
wmc 14
mnd 2
bc 2
fnc 12
bpm 0.1666
cpm 1.1666
noi 3
1
import template from './sw-extension-listing-card.html.twig';
2
import './sw-extension-listing-card.scss';
3
4
const { Utils, Filter } = 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
const { Component } = Shopware;
7
8
Component.register('sw-extension-listing-card', {
9
    template,
10
11
    inject: [
12
        'shopwareExtensionService'
13
    ],
14
15
    props: {
16
        extension: {
17
            type: Object,
18
            required: true
19
        }
20
    },
21
22
    computed: {
23
        previewMedia() {
24
            const image = Utils.get(this.extension, 'images[0]', null);
25
26
            if (!image) {
27
                return {
28
                    'background-image': this.defaultThemeAsset
29
                };
30
            }
31
32
            return {
33
                'background-image': `url('${image.remoteLink}')`,
34
                'background-size': 'cover'
35
            };
36
        },
37
38
        defaultThemeAsset() {
39
            return `url('${this.assetFilter('/administration/static/img/theme/default_theme_preview.jpg')}')`;
40
        },
41
42
        recommendedVariant() {
43
            return this.shopwareExtensionService.orderVariantsByRecommendation(this.extension.variants)[0];
44
        },
45
46
        hasActiveDiscount() {
47
            return this.shopwareExtensionService.isVariantDiscounted(this.recommendedVariant);
48
        },
49
50
        discountClass() {
51
            return {
52
                'sw-extension-listing-card__info-price-discounted': this.hasActiveDiscount
53
            };
54
        },
55
56
        calculatedPrice() {
57
            if (!this.recommendedVariant) {
58
                return null;
59
            }
60
61
            return this.$tc(
62
                'sw-extension-store.general.labelPrice',
63
                this.shopwareExtensionService.mapVariantToRecommendation(this.recommendedVariant),
64
                {
65
                    price: Utils.format.currency(
66
                        this.shopwareExtensionService.getPriceFromVariant(this.recommendedVariant), 'EUR'
67
                    )
68
                }
69
            );
70
        },
71
72
        isInstalled() {
73
            return !!Shopware.State.get('shopwareExtensions').installedExtensions.data.find((installedExtension) => {
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...
74
                return installedExtension.name === this.extension.name;
75
            });
76
        },
77
78
        isLicensed() {
79
            return !!Shopware.State.get('shopwareExtensions').licensedExtensions.data.find((license) => {
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...
80
                return license.licensedExtension.name === this.extension.name;
81
            });
82
        },
83
84
        assetFilter() {
85
            return Filter.getByName('asset');
86
        }
87
    },
88
89
    methods: {
90
        openDetailPage() {
91
            this.$router.push({
92
                name: 'sw.extension.store.detail',
93
                params: { id: this.extension.id.toString() }
94
            });
95
        }
96
    }
97
});
98