Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed
<?php
declare(strict_types=1);
/**
* User: Daschmi (daschmi@daschmi.de)
* Date: 14.01.2020
* Time: 10:04
*/
$ap = $this->view['ap'];
$pi = $this->view['product_index'];
/** @var wpsg_product $oProduct */
$oProduct = $this->view['oProduct'];
if ($ap['mode'] === wpsg_mod_printshop::MODE_AREA) {
$width = '';
$length = '';
} else if ($ap['mode'] === wpsg_mod_printshop::MODE_AREA_SELECT) {
$arWidth = [];
$arLength = [];
for ($i = intval($ap['width_min']); $i <= intval($ap['width_max']); $i += intval($ap['width_step'])) {
$arWidth[] = $i;
}
for ($i = intval($ap['length_min']); $i <= intval($ap['length_max']); $i += intval($ap['length_step'])) {
$arLength[] = $i;
}
$width = $arWidth[0];
$length = $arLength[0];
} else if ($ap['mode'] === wpsg_mod_printshop::MODE_LFM) {
$width = $ap['width'];
$length = '';
} else if ($ap['mode'] === wpsg_mod_printshop::MODE_LFM_SELECT) {
for ($i = intval($ap['length_min']); $i <= intval($ap['length_max']); $i += intval($ap['length_step'])) {
$arLength[] = $i;
}
$width = $ap['width'];
$length = $arLength[0];
}
?>
<div class="row">
<input type="hidden" name="wpsg[insertAreaProduct]" value="1" />
<?php if ($ap['mode'] === wpsg_mod_printshop::MODE_AREA) { ?>
<div class="form-group">
<label for="product_<?php echo $pi; ?>_width"><?php echo wpsg_translate(__('Breite in #1#', 'wpsg'), $ap['price_unit']); ?></label>
<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" />
</div>
<br />
<div class="form-group">
<label for="product_<?php echo $pi; ?>_length"><?php echo wpsg_translate(__('Länge in #1#', 'wpsg'), $ap['price_unit']); ?></label>
<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" />
</div>
<?php } else if ($ap['mode'] === wpsg_mod_printshop::MODE_AREA_SELECT) { ?>
<div class="form-group">
<label for="product_<?php echo $pi; ?>_width"><?php echo wpsg_translate(__('Breite x Länge in #1#', 'wpsg'), $ap['price_unit']); ?></label>
<div class="width_length_wrap">
<select name="wpsg[width]" class="form-control wpsg_mod_printshop_change" id="product_<?php echo $pi; ?>_width">
<?php foreach ($arWidth as $w) { ?>
<option value="<?php echo $w; ?>" <?php echo (($w === $width)?'selected="selected"':''); ?>><?php echo $w; ?></option>
<?php } ?>
</select>
<span>x</span>
<select name="wpsg[length]" class="form-control wpsg_mod_printshop_change" id="product_<?php echo $pi; ?>_length">
<?php foreach ($arLength as $l) { ?>
<option value="<?php echo $l; ?>" <?php echo (($l === $length)?'selected="selected"':''); ?>><?php echo $l; ?></option>
<?php } ?>
</select>
</div>
</div>
<?php } else if ($ap['mode'] === wpsg_mod_printshop::MODE_LFM) { ?>
<div class="form-group">
<label for="product_<?php echo $pi; ?>_width"><?php echo wpsg_translate(__('Breite in #1#', 'wpsg'), $ap['price_unit']); ?></label>
<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" />
</div>
<br />
<div class="form-group">
<label for="product_<?php echo $pi; ?>_length"><?php echo wpsg_translate(__('Länge in #1#', 'wpsg'), $ap['price_unit']); ?></label>
<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" />
</div>
<?php } else if ($ap['mode'] === wpsg_mod_printshop::MODE_LFM_SELECT) { ?>
<div class="form-group">
<label for="product_<?php echo $pi; ?>_width"><?php echo wpsg_translate(__('Breite in #1#', 'wpsg'), $ap['price_unit']); ?></label>
<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" />
</div>
<br />
<div class="form-group">
<label for="product_<?php echo $pi; ?>_length"><?php echo wpsg_translate(__('Länge in #1#', 'wpsg'), $ap['price_unit']); ?></label>
<select name="wpsg[length]" class="form-control wpsg_mod_printshop_change" id="product_<?php echo $pi; ?>_length">
<?php foreach ($arLength as $l) { ?>
<option value="<?php echo $l; ?>" <?php echo (($l === $length)?'selected="selected"':''); ?>><?php echo $l; ?></option>
<?php } ?>
</select>
</div>
<?php } ?>
<br />
<div class="form-group">
<label for="product_<?php echo $pi; ?>_price"><?php echo wpsg_translate(__('Stückpreis in #1#', 'wpsg'), $this->get_option('wpsg_currency')); ?></label>
<input type="text" value="" class="form-control" id="product_<?php echo $pi; ?>_price" placeholder="" disabled="disabled" />
</div>
<br />
</div>
<style>
.width_length_wrap > select { width:75px; }
.width_length_wrap > select:first-child { margin-right:5px; }
.width_length_wrap > select:last-child { margin-left:5px; }
select.form-control { width:100%; }
</style>
<script>
if (typeof wpsg_mod_printshop_calculate !== "function") {
function wpsg_mod_printshop_calculate(mode, price, product_index) {
var error = 0;
var jqWidth = jQuery('#product_' + product_index + '_width');
var jqLength = jQuery('#product_' + product_index + '_length');
var width = parseFloat(jqWidth.val().replace(',', '.'));
var length = parseFloat(jqLength.val().replace(',', '.'));
if (isNaN(width) || width <= 0) { jqWidth.addClass('wpsg_error'); error ++; }
else jqWidth.removeClass('wpsg_error');
if (isNaN(length) || length <= 0) { jqLength.addClass('wpsg_error'); error ++; }
else jqLength.removeClass('wpsg_error');
if (error === 0) {
var price = wpsg_round(width * length, 2) * price;
jQuery('#product_' + product_index + '_price').val(wpsg_numberformat(wpsg_round(price, 2), 2, ',', '.')).removeClass('wpsg_error');
} else {
jQuery('#product_' + product_index + '_price').val('<?php echo __('Keine Berechnung möglich', 'wpsg'); ?>').addClass('wpsg_error');
}
return error;
}
}
jQuery(document).ready(function() {
jQuery('#wpsg_produktform_<?php echo $pi; ?> .wpsg_mod_printshop_input, #wpsg_produktform_<?php echo $pi; ?> .wpsg_menge').on('input', function() {
wpsg_mod_printshop_calculate('<?php echo $ap['mode']; ?>', <?php echo wpsg_tf($this->view['data']['preis']); ?>, <?php echo $pi; ?>);
});
jQuery('#wpsg_produktform_<?php echo $pi; ?> .wpsg_mod_printshop_change').on('change', function() {
wpsg_mod_printshop_calculate('<?php echo $ap['mode']; ?>', <?php echo wpsg_tf($this->view['data']['preis']); ?>, <?php echo $pi; ?>);
});
jQuery('.wpsg_add_basket_<?php echo $pi; ?>').on('click', function(event) {
if (wpsg_mod_printshop_calculate('<?php echo $ap['mode']; ?>', <?php echo wpsg_tf($this->view['data']['preis']); ?>, <?php echo $pi; ?>) > 0) {
event.stopPropagation();
event.preventDefault();
return false;
}
});
wpsg_mod_printshop_calculate('<?php echo $ap['mode']; ?>', <?php echo wpsg_tf($this->view['data']['preis']); ?>, <?php echo $pi; ?>);
});
</script>