{% sw_extends '@Storefront/storefront/layout/meta.html.twig' %}
{% block layout_head_inner %}
{{ parent() }}
<script>
function loadSessionData(isApp,salesChannelId) {
var xhttp = new XMLHttpRequest();
var base_url = window.location.origin;
xhttp.open("POST", base_url + "/ianeo/get-sessiondata", true);
xhttp.send();
xhttp.onload = function () {
var result = JSON.parse(this.response);
// Ist nur dann nicht undefined wenn beim Laden der Seite session.ianeoCurrentStore noch undefined war
// siehe SessionSubscriber
if(result.session.setFallbackStoreInProgress !== undefined){
if(result.session.setFallbackStoreInProgress === 'start'){
loadSessionData(isApp,salesChannelId);
}else if(result.session.setFallbackStoreInProgress === 'end'){
if (result.session.isFallbackStore !== undefined && result.session.isFallbackStore){
// TODO-NGS: need to check if customer has a standard store which we can select
// try to set store using browser geolocation
if (navigator.geolocation) {
let constSalesChannelHitseller = "{{ constant('GlobusSW6\\Core\\IaneoDefaults::SALES_CHANNEL_HITSELLER') }}";
if (salesChannelId !== constSalesChannelHitseller) {
navigator.geolocation.getCurrentPosition(showLocation, showLocation);
}
} else {
// geolocation is not supported by browser
showLocation();
}
}
}
}
}
}
window.addEventListener('load', function() {
var isApp = '{{ page.ianeoHitsellerIsApp }}';
var salesChannelId = '{{ context.salesChannelId }}';
if (!isApp) {
loadSessionData(isApp,salesChannelId);
}
});
function getCookie(name) {
let value = ';' + document.cookie;
let parts = value.split(';' + name + '=');
if (parts.length === 2) return parts.pop().split(';').shift();
}
function showLocation(position) {
var base_url = window.location.origin;
var page_url = window.location.href;
var xhttp = new XMLHttpRequest();
if (position.coords) { // browser geolocation success case
var latitude = position.coords.latitude;
var longitude = position.coords.longitude;
var json_upload = JSON.stringify({latitude: latitude, longitude: longitude, page_url: page_url});
xhttp.open("POST", base_url + "/ianeo/get-geolocation", true);
xhttp.addEventListener('load', reloadPage);
xhttp.send(json_upload);
} else { // browser geolocation not allowed/not supported
xhttp.open("POST", base_url + "/ianeo/get-geolocation", true);
xhttp.addEventListener('load', reloadPage);
xhttp.send();
}
}
function reloadPage(event) {
window.location.reload();
}
</script>
{% endblock %}