{% sw_extends '@Storefront/storefront/base.html.twig' %}
{% block base_script_hmr_mode %}
{{ parent() }}
{% if config('DmitsInquiry.config.customcss') %}
<style>
{{config('DmitsInquiry.config.customcss')}}
</style>
{% endif %}
{% if controllerName|lower=='product' or (config('DmitsInquiry.config.cartinquiry')==1 and controllerName|lower=='checkout') %}
<script>
var printinquiry_template="{{"dmits.inquiry.custom.printinquiry"|trans|raw|e("js")}}";
var printinquiry_filename="{{"dmits.inquiry.custom.printinquiryfilename"|trans}}";
{% if controllerName|lower=='product'%}
var pageIs="detail";
{%else %}
var pageIs="cart";
{% endif %}
window.addEventListener('load', function() {
$(document).on('click', ".inquiry-button", function() {
$("#productinquiry-message").html('');
{% if config('DmitsInquiry.config.position')=="popup" %}
$("#productinquirymodal").modal();
{% endif %}
$("#productinquiry").toggle();
});
$(document).on('submit', "#productinquiry", function(e) {
e.preventDefault();
$("#productinquiry").hide();
$("#productinquiry-message").html('<div class="loader" role="status"><span class="sr-only"></span></div>');
var me = e.currentTarget;
var firstnameca ;
if(typeof me.firstnameca!== "undefined"){
var firstnameca = me.firstnameca.value;
}
if(firstnameca){
$("#productinquiry").show();
$("#productinquiry-message").html('<div class="alert alert-danger" role="alert"><div class="alert-content-container"><div class="alert-content">Error</div></div></div>');
return;
}
var data = new FormData();
data.append('shop-id', '{{appShopId}}');
data.append('salesChannelId', '{{context.salesChannelId}}');
data.append('salesChannelName', '{{context.salesChannel.translated.name}}');
data.append('externalmail', '{{config('DmitsInquiry.config.sendexternalshop')}}');
data.append('receipter', '{{config('DmitsInquiry.config.receipterinternal')}}');
data.append('customermail', '{{config('DmitsInquiry.config.sendmailcustomer')}}');
if(typeof me.salutation!== "undefined"){
var salutation = me.salutation.value;
data.append('salutation', salutation);
}
if(typeof me.firstname!== "undefined"){
var firstname = me.firstname.value;
data.append('firstname', firstname);
}
if(typeof me.lastname!== "undefined"){
var lastname = me.lastname.value;
data.append('lastname', lastname);
}
if(typeof me.company!== "undefined"){
var company = me.company.value;
data.append('company', company);
}
if(typeof me.phone!== "undefined"){
var phone = me.phone.value;
data.append('phone', phone);
}
if(typeof me.country!== "undefined"){
var country = me.country.value;
data.append('country', country);
}
if(typeof me.street!== "undefined"){
var street = me.street.value;
data.append('street', street);
}
if(typeof me.zip!== "undefined"){
var zip = me.zip.value;
data.append('zip', zip);
}
if(typeof me.city!== "undefined"){
var city = me.city.value;
data.append('city', city);
}
if(typeof me.note!== "undefined"){
var note = me.note.value;
data.append('note', note);
}
if(typeof me.email!== "undefined"){
var email = me.email.value;
data.append('email', email);
}
if(typeof me.file!== "undefined"){
var file = me.file.files[0];
console.log(file);
data.append('file', file);
}
{% if controllerName|lower=='product'%}
data.append('type', 'product');
data.append('qty', $(".product-detail-quantity-select").val());
data.append('article-id', '{{page.product.productNumber}}');
data.append('article-name', '{{page.product.translated.name}}');
{% endif %}
{% if (config('DmitsInquiry.config.cartinquiry')==1 and controllerName|lower=='checkout')%}
data.append('type', 'cart');
{% for lineItem in page.cart.lineItems %}
data.append('qty[]', '{{ lineItem.quantity }}');
data.append('article-id[]', ' {{ lineItem.payload.productNumber }}');
data.append('article-name[]', '{{ lineItem.label }}');
{% endfor %}
{% endif %}
data.append('subject', '{{ "dmits.inquiry.custom.subject"|trans }}');
data.append('content', '{{ ("dmits.inquiry.custom.content"|trans)|replace({"\n": "<br>", "\r": "<br>", "\t": "<br>"}) }}');
data.append('subjectcustomer', '{{ "dmits.inquiry.custom.subjectcustomer"|trans }}');
data.append('contentcustomer', '{{ ("dmits.inquiry.custom.contentcustomer"|trans)|replace({"\n": "<br>", "\r": "<br>", "\t": "<br>"}) }}');
var xhr = new XMLHttpRequest();
xhr.open('POST', 'https://sw6appsinquiry.d-mit-s.de/inquiry', true);
xhr.onload = function () {
var jsonResponse = JSON.parse(this.responseText);
if(jsonResponse.code==200){
{% if config('DmitsInquiry.config.disableinquiryaftersend')==1 %}
$(".inquiry-button").hide();
$("#productinquiry").remove();
{% endif %}
$("#productinquiry-message").html('<div class="alert alert-success" role="alert"><div class="alert-content-container"><div class="alert-content">{{"dmits.inquiry.custom.success"|trans }}</div></div></div>');
}else{
$("#productinquiry-message").html('<div class="alert alert-danger" role="alert"><div class="alert-content-container"><div class="alert-content">{{"dmits.inquiry.custom.error"|trans }}</div></div></div>');
$("#productinquiry").show();
}
};
xhr.send(data);
});
{% if config('DmitsInquiry.config.customjs') %}
{{config('DmitsInquiry.config.customjs')|raw}}
{% endif %}
});
</script>
{% endif %}
{% endblock %}