7706 |
daniel |
1 |
<?php
|
|
|
2 |
|
|
|
3 |
declare(strict_types=1);
|
|
|
4 |
|
|
|
5 |
/**
|
|
|
6 |
* User: Daschmi (daschmi@daschmi.de)
|
|
|
7 |
* Date: 14.01.2020
|
|
|
8 |
* Time: 10:04
|
|
|
9 |
*/
|
|
|
10 |
|
|
|
11 |
$ap = $this->view['ap'];
|
|
|
12 |
|
|
|
13 |
$pi = $this->view['product_index'];
|
|
|
14 |
|
|
|
15 |
/** @var wpsg_product $oProduct */
|
|
|
16 |
$oProduct = $this->view['oProduct'];
|
|
|
17 |
|
|
|
18 |
if ($ap['mode'] === wpsg_mod_printshop::MODE_AREA) {
|
|
|
19 |
|
|
|
20 |
$width = '';
|
|
|
21 |
$length = '';
|
|
|
22 |
|
|
|
23 |
} else if ($ap['mode'] === wpsg_mod_printshop::MODE_AREA_SELECT) {
|
|
|
24 |
|
|
|
25 |
$arWidth = [];
|
|
|
26 |
$arLength = [];
|
|
|
27 |
|
|
|
28 |
for ($i = intval($ap['width_min']); $i <= intval($ap['width_max']); $i += intval($ap['width_step'])) {
|
|
|
29 |
|
|
|
30 |
$arWidth[] = $i;
|
|
|
31 |
|
|
|
32 |
}
|
|
|
33 |
|
|
|
34 |
for ($i = intval($ap['length_min']); $i <= intval($ap['length_max']); $i += intval($ap['length_step'])) {
|
|
|
35 |
|
|
|
36 |
$arLength[] = $i;
|
|
|
37 |
|
|
|
38 |
}
|
|
|
39 |
|
|
|
40 |
$width = $arWidth[0];
|
|
|
41 |
$length = $arLength[0];
|
|
|
42 |
|
|
|
43 |
} else if ($ap['mode'] === wpsg_mod_printshop::MODE_LFM) {
|
|
|
44 |
|
|
|
45 |
$width = $ap['width'];
|
|
|
46 |
$length = '';
|
|
|
47 |
|
|
|
48 |
} else if ($ap['mode'] === wpsg_mod_printshop::MODE_LFM_SELECT) {
|
|
|
49 |
|
|
|
50 |
for ($i = intval($ap['length_min']); $i <= intval($ap['length_max']); $i += intval($ap['length_step'])) {
|
|
|
51 |
|
|
|
52 |
$arLength[] = $i;
|
|
|
53 |
|
|
|
54 |
}
|
|
|
55 |
|
|
|
56 |
$width = $ap['width'];
|
|
|
57 |
$length = $arLength[0];
|
|
|
58 |
|
|
|
59 |
}
|
|
|
60 |
|
|
|
61 |
?>
|
|
|
62 |
|
|
|
63 |
<div class="row">
|
|
|
64 |
|
|
|
65 |
<input type="hidden" name="wpsg[insertAreaProduct]" value="1" />
|
|
|
66 |
|
|
|
67 |
<?php if ($ap['mode'] === wpsg_mod_printshop::MODE_AREA) { ?>
|
|
|
68 |
|
|
|
69 |
<div class="form-group">
|
|
|
70 |
<label for="product_<?php echo $pi; ?>_width"><?php echo wpsg_translate(__('Breite in #1#', 'wpsg'), $ap['price_unit']); ?></label>
|
|
|
71 |
<input type="text" name="wpsg[width]" value="<?php echo $width; ?>" class="wpsg_mod_printshop_input form-control" id="product_<?php echo $pi; ?>_width" placeholder="<?php echo wpsg_translate(__('Breite in #1#', 'wpsg'), $ap['price_unit']); ?>" required="required" />
|
|
|
72 |
</div>
|
|
|
73 |
|
|
|
74 |
<br />
|
|
|
75 |
|
|
|
76 |
<div class="form-group">
|
|
|
77 |
<label for="product_<?php echo $pi; ?>_length"><?php echo wpsg_translate(__('Länge in #1#', 'wpsg'), $ap['price_unit']); ?></label>
|
|
|
78 |
<input type="text" name="wpsg[length]" value="<?php echo $length; ?>" class="wpsg_mod_printshop_input form-control" id="product_<?php echo $pi; ?>_length" placeholder="<?php echo wpsg_translate(__('Länge in #1#', 'wpsg'), $ap['price_unit']); ?>" required="required" />
|
|
|
79 |
</div>
|
|
|
80 |
|
|
|
81 |
<?php } else if ($ap['mode'] === wpsg_mod_printshop::MODE_AREA_SELECT) { ?>
|
|
|
82 |
|
|
|
83 |
<div class="form-group">
|
|
|
84 |
<label for="product_<?php echo $pi; ?>_width"><?php echo wpsg_translate(__('Breite x Länge in #1#', 'wpsg'), $ap['price_unit']); ?></label>
|
|
|
85 |
<div class="width_length_wrap">
|
|
|
86 |
|
|
|
87 |
<select name="wpsg[width]" class="form-control wpsg_mod_printshop_change" id="product_<?php echo $pi; ?>_width">
|
|
|
88 |
<?php foreach ($arWidth as $w) { ?>
|
|
|
89 |
<option value="<?php echo $w; ?>" <?php echo (($w === $width)?'selected="selected"':''); ?>><?php echo $w; ?></option>
|
|
|
90 |
<?php } ?>
|
|
|
91 |
</select>
|
|
|
92 |
|
|
|
93 |
<span>x</span>
|
|
|
94 |
|
|
|
95 |
<select name="wpsg[length]" class="form-control wpsg_mod_printshop_change" id="product_<?php echo $pi; ?>_length">
|
|
|
96 |
<?php foreach ($arLength as $l) { ?>
|
|
|
97 |
<option value="<?php echo $l; ?>" <?php echo (($l === $length)?'selected="selected"':''); ?>><?php echo $l; ?></option>
|
|
|
98 |
<?php } ?>
|
|
|
99 |
</select>
|
|
|
100 |
|
|
|
101 |
</div>
|
|
|
102 |
</div>
|
|
|
103 |
|
|
|
104 |
<?php } else if ($ap['mode'] === wpsg_mod_printshop::MODE_LFM) { ?>
|
|
|
105 |
|
|
|
106 |
<div class="form-group">
|
|
|
107 |
<label for="product_<?php echo $pi; ?>_width"><?php echo wpsg_translate(__('Breite in #1#', 'wpsg'), $ap['price_unit']); ?></label>
|
|
|
108 |
<input name="wpsg[width]" type="text" value="<?php echo wpsg_ff($width, false, true, 0); ?>" class="wpsg_mod_printshop_input form-control" id="product_<?php echo $pi; ?>_width" placeholder="<?php echo wpsg_translate(__('Breite in #1#', 'wpsg'), $ap['price_unit']); ?>" disabled="disabled" readonly="readonly" />
|
|
|
109 |
</div>
|
|
|
110 |
|
|
|
111 |
<br />
|
|
|
112 |
|
|
|
113 |
<div class="form-group">
|
|
|
114 |
<label for="product_<?php echo $pi; ?>_length"><?php echo wpsg_translate(__('Länge in #1#', 'wpsg'), $ap['price_unit']); ?></label>
|
|
|
115 |
<input name="wpsg[length]" type="text" value="<?php echo wpsg_ff($length, false, true, 0); ?>" class="wpsg_mod_printshop_input form-control" id="product_<?php echo $pi; ?>_length" placeholder="<?php echo wpsg_translate(__('Länge in #1#', 'wpsg'), $ap['price_unit']); ?>" required="required" />
|
|
|
116 |
</div>
|
|
|
117 |
|
|
|
118 |
<?php } else if ($ap['mode'] === wpsg_mod_printshop::MODE_LFM_SELECT) { ?>
|
|
|
119 |
|
|
|
120 |
<div class="form-group">
|
|
|
121 |
<label for="product_<?php echo $pi; ?>_width"><?php echo wpsg_translate(__('Breite in #1#', 'wpsg'), $ap['price_unit']); ?></label>
|
|
|
122 |
<input type="text" value="<?php echo $width; ?>" class="wpsg_mod_printshop_input form-control" id="product_<?php echo $pi; ?>_width" placeholder="<?php echo wpsg_translate(__('Breite in #1#', 'wpsg'), $ap['price_unit']); ?>" disabled="disabled" readonly="readonly" />
|
|
|
123 |
</div>
|
|
|
124 |
|
|
|
125 |
<br />
|
|
|
126 |
|
|
|
127 |
<div class="form-group">
|
|
|
128 |
<label for="product_<?php echo $pi; ?>_length"><?php echo wpsg_translate(__('Länge in #1#', 'wpsg'), $ap['price_unit']); ?></label>
|
|
|
129 |
<select name="wpsg[length]" class="form-control wpsg_mod_printshop_change" id="product_<?php echo $pi; ?>_length">
|
|
|
130 |
<?php foreach ($arLength as $l) { ?>
|
|
|
131 |
<option value="<?php echo $l; ?>" <?php echo (($l === $length)?'selected="selected"':''); ?>><?php echo $l; ?></option>
|
|
|
132 |
<?php } ?>
|
|
|
133 |
</select>
|
|
|
134 |
</div>
|
|
|
135 |
|
|
|
136 |
<?php } ?>
|
|
|
137 |
|
|
|
138 |
<br />
|
|
|
139 |
|
|
|
140 |
<div class="form-group">
|
|
|
141 |
<label for="product_<?php echo $pi; ?>_price"><?php echo wpsg_translate(__('Stückpreis in #1#', 'wpsg'), $this->get_option('wpsg_currency')); ?></label>
|
|
|
142 |
<input type="text" value="" class="form-control" id="product_<?php echo $pi; ?>_price" placeholder="" disabled="disabled" />
|
|
|
143 |
</div>
|
|
|
144 |
|
|
|
145 |
<br />
|
|
|
146 |
|
|
|
147 |
</div>
|
|
|
148 |
|
|
|
149 |
<style>
|
|
|
150 |
|
|
|
151 |
.width_length_wrap > select { width:75px; }
|
|
|
152 |
.width_length_wrap > select:first-child { margin-right:5px; }
|
|
|
153 |
.width_length_wrap > select:last-child { margin-left:5px; }
|
|
|
154 |
select.form-control { width:100%; }
|
|
|
155 |
|
|
|
156 |
</style>
|
|
|
157 |
|
|
|
158 |
<script>
|
|
|
159 |
|
|
|
160 |
if (typeof wpsg_mod_printshop_calculate !== "function") {
|
|
|
161 |
|
|
|
162 |
function wpsg_mod_printshop_calculate(mode, price, product_index) {
|
|
|
163 |
|
|
|
164 |
var error = 0;
|
|
|
165 |
|
|
|
166 |
var jqWidth = jQuery('#product_' + product_index + '_width');
|
|
|
167 |
var jqLength = jQuery('#product_' + product_index + '_length');
|
|
|
168 |
|
|
|
169 |
var width = parseFloat(jqWidth.val().replace(',', '.'));
|
|
|
170 |
var length = parseFloat(jqLength.val().replace(',', '.'));
|
|
|
171 |
|
|
|
172 |
if (isNaN(width) || width <= 0) { jqWidth.addClass('wpsg_error'); error ++; }
|
|
|
173 |
else jqWidth.removeClass('wpsg_error');
|
|
|
174 |
|
|
|
175 |
if (isNaN(length) || length <= 0) { jqLength.addClass('wpsg_error'); error ++; }
|
|
|
176 |
else jqLength.removeClass('wpsg_error');
|
|
|
177 |
|
|
|
178 |
if (error === 0) {
|
|
|
179 |
|
|
|
180 |
var price = wpsg_round(width * length, 2) * price;
|
|
|
181 |
|
|
|
182 |
jQuery('#product_' + product_index + '_price').val(wpsg_numberformat(wpsg_round(price, 2), 2, ',', '.')).removeClass('wpsg_error');
|
|
|
183 |
|
|
|
184 |
} else {
|
|
|
185 |
|
|
|
186 |
jQuery('#product_' + product_index + '_price').val('<?php echo __('Keine Berechnung möglich', 'wpsg'); ?>').addClass('wpsg_error');
|
|
|
187 |
|
|
|
188 |
}
|
|
|
189 |
|
|
|
190 |
return error;
|
|
|
191 |
|
|
|
192 |
}
|
|
|
193 |
|
|
|
194 |
}
|
|
|
195 |
|
|
|
196 |
jQuery(document).ready(function() {
|
|
|
197 |
|
|
|
198 |
jQuery('#wpsg_produktform_<?php echo $pi; ?> .wpsg_mod_printshop_input, #wpsg_produktform_<?php echo $pi; ?> .wpsg_menge').on('input', function() {
|
|
|
199 |
|
|
|
200 |
wpsg_mod_printshop_calculate('<?php echo $ap['mode']; ?>', <?php echo wpsg_tf($this->view['data']['preis']); ?>, <?php echo $pi; ?>);
|
|
|
201 |
|
|
|
202 |
});
|
|
|
203 |
|
|
|
204 |
jQuery('#wpsg_produktform_<?php echo $pi; ?> .wpsg_mod_printshop_change').on('change', function() {
|
|
|
205 |
|
|
|
206 |
wpsg_mod_printshop_calculate('<?php echo $ap['mode']; ?>', <?php echo wpsg_tf($this->view['data']['preis']); ?>, <?php echo $pi; ?>);
|
|
|
207 |
|
|
|
208 |
});
|
|
|
209 |
|
|
|
210 |
jQuery('.wpsg_add_basket_<?php echo $pi; ?>').on('click', function(event) {
|
|
|
211 |
|
|
|
212 |
if (wpsg_mod_printshop_calculate('<?php echo $ap['mode']; ?>', <?php echo wpsg_tf($this->view['data']['preis']); ?>, <?php echo $pi; ?>) > 0) {
|
|
|
213 |
|
|
|
214 |
event.stopPropagation();
|
|
|
215 |
event.preventDefault();
|
|
|
216 |
|
|
|
217 |
return false;
|
|
|
218 |
|
|
|
219 |
}
|
|
|
220 |
|
|
|
221 |
});
|
|
|
222 |
|
|
|
223 |
wpsg_mod_printshop_calculate('<?php echo $ap['mode']; ?>', <?php echo wpsg_tf($this->view['data']['preis']); ?>, <?php echo $pi; ?>);
|
|
|
224 |
|
|
|
225 |
});
|
|
|
226 |
|
|
|
227 |
</script>
|