Completed
Push — master ( 1a26ad...341936 )
by Florian
04:37
created

mixin.updateAddress   B

Complexity

Conditions 5
Paths 4

Size

Total Lines 17

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 17
rs 8.8571
cc 5
nc 4
nop 0
1
/**
2
 * PAYONE Magento 2 Connector is free software: you can redistribute it and/or modify
3
 * it under the terms of the GNU Lesser General Public License as published by
4
 * the Free Software Foundation, either version 3 of the License, or
5
 * (at your option) any later version.
6
 *
7
 * PAYONE Magento 2 Connector is distributed in the hope that it will be useful,
8
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10
 * GNU Lesser General Public License for more details.
11
 *
12
 * You should have received a copy of the GNU Lesser General Public License
13
 * along with PAYONE Magento 2 Connector. If not, see <http://www.gnu.org/licenses/>.
14
 *
15
 * PHP version 5
16
 *
17
 * @category  Payone
18
 * @package   Payone_Magento2_Plugin
19
 * @author    FATCHIP GmbH <[email protected]>
20
 * @copyright 2003 - 2016 Payone GmbH
21
 * @license   <http://www.gnu.org/licenses/> GNU Lesser General Public License
22
 * @link      http://www.payone.de
23
 */
24
/*jshint browser:true jquery:true*/
25
/*global alert*/
26
define([
27
    'jquery',
28
    'Payone_Core/js/action/addresscheck'
29
], function ($, addresscheck) {
30
    'use strict';
31
32
    var mixin = {
33
        payoneCheckAddress: function () {
34
            if (window.checkoutConfig.payment.payone.addresscheckEnabled && window.checkoutConfig.payment.payone.addresscheckBillingEnabled) {
35
                return true;
36
            }
37
            return false;
38
        },
39
        updateAddress: function () {
40
            if (!(this.selectedAddress() && this.selectedAddress() != this.newAddressOption) && !this.payoneCheckAddress()) {
41
                return this._super();
42
            }
43
            
44
            var addressChecked = this.source.get('payone_address_checked');
45
            if (!addressChecked) {
46
                var address = this.source.get(this.dataScopePrefix);
47
                if (!this.isAddressFormVisible()) {
48
                    address = this.selectedAddress()
49
                }
50
                addresscheck(address, true, this, 'saveNewAddress');
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...
51
            } else {
52
                this.source.set('payone_address_checked', false);
53
                return this._super();
54
            }
55
        },
56
        payoneUpdateAddress: function (addressData) {
57
            this.source.set(this.dataScopePrefix + '.firstname', addressData.firstname);
58
            this.source.set(this.dataScopePrefix + '.lastname', addressData.lastname);
59
            this.source.set(this.dataScopePrefix + '.street.0', addressData.street[0]);
60
            this.source.set(this.dataScopePrefix + '.postcode', addressData.postcode);
61
            this.source.set(this.dataScopePrefix + '.city', addressData.city);
62
        },
63
        payoneContinue: function () {
64
            this.source.set('payone_address_checked', true);
65
            this.updateAddress();
66
        }
67
    }
68
69
    return function (billing_address) {
70
        return billing_address.extend(mixin);
71
    };
72
});
73