views/js/supercheckout.js   A
last analyzed

Complexity

Total Complexity 31
Complexity/F 6.2

Size

Lines of Code 107
Function Count 5

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 0
nc 1
dl 0
loc 107
rs 9.8
c 0
b 0
f 0
wmc 31
mnd 3
bc 28
fnc 5
bpm 5.6
cpm 6.2
noi 25

3 Functions

Rating   Name   Duplication   Size   Complexity  
A $(document).click 0 3 1
A $(ꞌ#supercheckout_confirm_orderꞌ).click 0 7 1
B supercheckout.js ➔ check_pagantis_ready 0 10 5
1
/**
2
* 2007-2017 PrestaShop
3
*
4
* NOTICE OF LICENSE
5
*
6
* This source file is subject to the Academic Free License (AFL 3.0)
7
* that is bundled with this package in the file LICENSE.txt.
8
* It is also available through the world-wide-web at this URL:
9
* http://opensource.org/licenses/afl-3.0.php
10
* If you did not receive a copy of the license and are unable to
11
* obtain it through the world-wide-web, please send an email
12
* to [email protected] so we can send you a copy immediately.
13
*
14
* DISCLAIMER
15
*
16
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
17
* versions in the future. If you wish to customize PrestaShop for your
18
* needs please refer to http://www.prestashop.com for more information.
19
*
20
*  @author    PrestaShop SA <[email protected]>
21
*  @copyright 2007-2017 PrestaShop SA
22
*  @license   http://opensource.org/licenses/afl-3.0.php  Academic Free License (AFL 3.0)
23
*  International Registered Trademark & Property of PrestaShop SA
24
*/
25
26
function fill_the_form(){
27
  firstname_input = document.getElementsByName("payment_address[firstname]");
0 ignored issues
show
Bug introduced by
The variable firstname_input seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.firstname_input.
Loading history...
28
  billing_firstname = '';
0 ignored issues
show
Bug introduced by
The variable billing_firstname seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.billing_firstname.
Loading history...
29
  if (firstname_input.length > 0){
30
      billing_firstname = firstname_input[0].value;
31
  }
32
  billing_lastname = '';
0 ignored issues
show
Bug introduced by
The variable billing_lastname seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.billing_lastname.
Loading history...
33
  lastname_input = document.getElementsByName("payment_address[lastname]");
0 ignored issues
show
Bug introduced by
The variable lastname_input seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.lastname_input.
Loading history...
34
  if (lastname_input.length > 0){
35
      billing_lastname = lastname_input[0].value;
36
  }
37
  shipping_firstname = '';
0 ignored issues
show
Bug introduced by
The variable shipping_firstname seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.shipping_firstname.
Loading history...
38
  firstname_input = document.getElementsByName("shipping_address[firstname]");
39
  if (firstname_input.length > 0){
40
      shipping_firstname = firstname_input[0].value;
41
  }
42
  shipping_lastname = '';
0 ignored issues
show
Bug introduced by
The variable shipping_lastname seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.shipping_lastname.
Loading history...
43
  lastname_input = document.getElementsByName("shipping_address[lastname]");
44
  if (lastname_input.length > 0){
45
      shipping_lastname = lastname_input[0].value;
46
  }
47
  email = '';
0 ignored issues
show
Bug introduced by
The variable email seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.email.
Loading history...
48
  email_input = document.getElementsByName("supercheckout_email");
0 ignored issues
show
Bug introduced by
The variable email_input seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.email_input.
Loading history...
49
  if (email_input.length > 0){
50
      email = email_input[0].value;
51
  }
52
  billing_name = billing_firstname + " " + billing_lastname;
0 ignored issues
show
Bug introduced by
The variable billing_name seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.billing_name.
Loading history...
53
  shipping_name = shipping_firstname + " " + shipping_lastname;
0 ignored issues
show
Bug introduced by
The variable shipping_name seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.shipping_name.
Loading history...
54
  if (document.getElementById("paylater_full_name").value.trim() == '') {
55
      if (billing_name.trim() != '') {
56
          document.getElementById("paylater_full_name").value = billing_name;
57
      } else if (shipping_name.trim() != '') {
58
        document.getElementById("paylater_full_name").value = shipping_name;
59
      }
60
  }
61
  if (document.getElementById("paylater_email").value.trim() == '') {
62
      document.getElementById("paylater_email").value = email;
63
  }
64
  dni = '';
0 ignored issues
show
Bug introduced by
The variable dni seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.dni.
Loading history...
65
  dni_input = document.getElementsByName("shipping_address[dni]");
0 ignored issues
show
Bug introduced by
The variable dni_input seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.dni_input.
Loading history...
66
  if (dni_input.length > 0){
67
      dni = dni_input[0].value;
68
  }
69
  if (document.getElementById("paylater_full_name") == document.getElementsByName("shipping[full_name]")[0].value ) {
70
      if (document.getElementById("paylater_dni").value.trim() != '') {
71
          document.getElementById("paylater_dni").value = dni;
72
      }
73
  }
74
  saddress1 = document.getElementsByName("shipping_address[address1]");
0 ignored issues
show
Bug introduced by
The variable saddress1 seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.saddress1.
Loading history...
75
  saddress2 = document.getElementsByName("shipping_address[address2]");
0 ignored issues
show
Bug introduced by
The variable saddress2 seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.saddress2.
Loading history...
76
  sa1 = '';
0 ignored issues
show
Bug introduced by
The variable sa1 seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.sa1.
Loading history...
77
  sa2 = '';
0 ignored issues
show
Bug introduced by
The variable sa2 seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.sa2.
Loading history...
78
  if (saddress1.length > 0){
79
      sa1 = saddress1[0].value;
80
  }
81
  if (saddress2.length > 0){
82
      sa2 = saddress2[0].value;
83
  }
84
  saddress = sa1 + " " + sa1;
0 ignored issues
show
Bug introduced by
The variable saddress seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.saddress.
Loading history...
85
86
  address1 = document.getElementsByName("payment_address[address1]");
0 ignored issues
show
Bug introduced by
The variable address1 seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.address1.
Loading history...
87
  address2 = document.getElementsByName("payment_address[address2]");
0 ignored issues
show
Bug introduced by
The variable address2 seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.address2.
Loading history...
88
  a1 = '';
0 ignored issues
show
Bug introduced by
The variable a1 seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.a1.
Loading history...
89
  a2 = '';
0 ignored issues
show
Bug introduced by
The variable a2 seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.a2.
Loading history...
90
  if (address1.length > 0){
91
      a1 = address1[0].value;
92
  }
93
  if (address2.length > 0){
94
      a2 = address2[0].value;
95
  }
96
  address = sa1 + " " + sa1;
0 ignored issues
show
Bug introduced by
The variable address seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.address.
Loading history...
97
  if (document.getElementsByName("shipping[full_name]")[0].value.trim() == '') {
98
      document.getElementsByName("shipping[full_name]")[0].value = saddress;
99
  }
100
  if (document.getElementsByName("billing[full_name]")[0].value.trim() == '') {
101
      document.getElementsByName("billing[full_name]")[0].value = address;
102
  }
103
  dob_1 = document.getElementsByName("customer_personal[dob_days]");
0 ignored issues
show
Bug introduced by
The variable dob_1 seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.dob_1.
Loading history...
104
  dob_2 = document.getElementsByName("customer_personal[dob_months]");
0 ignored issues
show
Bug introduced by
The variable dob_2 seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.dob_2.
Loading history...
105
  dob_3 = document.getElementsByName("customer_personal[dob_years]");
0 ignored issues
show
Bug introduced by
The variable dob_3 seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.dob_3.
Loading history...
106
  if (dob_1.length > 0 && dob_2.length > 0 && dob_3.length > 0){
107
    if (document.getElementById("paylater_dob").value.trim() == '') {
108
        document.getElementById("paylater_dob").value = dob_3[0].value + "-" + dob_2[0].value + "-" + dob_1[0].value;
109
    }
110
  }
111
}
112
function check_pagantis_ready(){
113
    if (document.getElementById("paylater_email").value.trim() != '' &&
114
      document.getElementById("paylater_full_name").value.trim() != '') {
115
          if ($('input:radio[id=paylater]').is(":checked")){
116
            if ($(".permanent-warning").size() <= 0) {
117
                $('#paylater_form').submit();
118
            }
119
          }
120
      }
121
}
122
$(document).on("click", function(){
123
  fill_the_form();
124
});
125
126
$("#supercheckout_confirm_order").on("click", function(){
127
  fill_the_form();
128
  setTimeout(function(){
129
    check_pagantis_ready();
130
  }, 1500);
131
132
});
133