{% sw_extends '@Storefront/storefront/base.html.twig' %}
{% block base_header %}
{% if config('DmitsShippingCountdown.config.active') and config('DmitsShippingCountdown.config.showheader') %}
{% sw_include "@Storefront/storefront/shippingholiday.html.twig" with { 'DmitsShippingCountdownBlock': 'header'} %}
{% endif %}
{{ parent() }}
{% endblock %}
{% block base_script_hmr_mode %}
{% if config('DmitsShippingCountdown.config.active') %}
<script>
{% set holidays=[] %}
{% set holiday_german=["01.01.2021","02.04.2021","04.04.2021","05.04.2021","01.05.2021","13.05.2021","23.05.2021","24.05.2021","03.10.2021","25.12.2021","26.12.2021",
"01.01.2022","15.04.2022","17.04.2022","18.04.2022","01.05.2022","26.05.2022","05.06.2022","06.06.2022","03.10.2022","25.12.2022","26.12.2022",
"01.01.2023","07.04.2023","09.04.2023","10.04.2023","01.05.2023","18.05.2023","28.05.2023","29.05.2023","03.10.2023","25.12.2023","26.12.2023",
"01.01.2024","29.03.2024","30.03.2024","01.04.2024","01.05.2024","09.05.2024","19.05.2024","20.05.2024","03.10.2024","25.12.2024","26.12.2024",
"01.01.2025","18.04.2025","20.04.2025","21.04.2025","01.05.2025","29.05.2025","08.06.2025","09.06.2025","03.10.2025","25.12.2025","26.12.2025"] %}
{% set holidaythreekings=["06.01.2021","06.01.2022","06.01.2023","06.01.2024","06.01.2025"]%}
{% set holidaycorpuschristi=["03.06.2021","16.06.2022","08.06.2023","30.05.2024","19.06.2025"]%}
{% set holidayassumptionday=["15.08.2021","15.08.2022","15.08.2023","15.08.2024","15.08.2025",]%}
{% set holidayreformation=["31.10.2021","31.10.2022","31.10.2023","31.10.2024","31.10.2025"]%}
{% set holidayallsaints=["01.11.2021","01.11.2022","01.11.2023","01.11.2024","01.11.2025"]%}
{% set holidayprayerrepentance=["17.11.2021","16.11.2022","15.11.2023","20.11.2024","19.11.2025",]%}
{% if config('DmitsShippingCountdown.config.holidaygerman') %}
{% set holidays=holidays|merge(holiday_german) %}
{% endif %}
{% if config('DmitsShippingCountdown.config.holidaythreekings') %}
{% set holidays=holidays|merge(holidaythreekings) %}
{% endif %}
{% if config('DmitsShippingCountdown.config.holidaycorpuschristi') %}
{% set holidays=holidays|merge(holidaycorpuschristi) %}
{% endif %}
{% if config('DmitsShippingCountdown.config.holidayassumptionday') %}
{% set holidays=holidays|merge(holidayassumptionday) %}
{% endif %}
{% if config('DmitsShippingCountdown.config.holidayreformation') %}
{% set holidays=holidays|merge(holidayreformation) %}
{% endif %}
{% if config('DmitsShippingCountdown.config.holidayallsaints') %}
{% set holidays=holidays|merge(holidayallsaints) %}
{% endif %}
{% if config('DmitsShippingCountdown.config.holidayprayerrepentance') %}
{% set holidays=holidays|merge(holidayprayerrepentance) %}
{% endif %}
{% if config('DmitsShippingCountdown.config.holidaymoredays') %}
{% set holidays=holidays|merge((config('DmitsShippingCountdown.config.holidaymoredays')|split(";"))) %}
{% endif %}
var shippingtext= "{{"dmits.shippingcountdown.custom.shippingtext"|trans|replace({"\n": "<br>", "\r": "<br>", "\t": "<br>"})|raw }}";
var dmitsOnlyhours=1;
{% if config('DmitsShippingCountdown.config.onlyhours') %}
dmitsOnlyhours=0;
{% endif %}
function getShippingCountdownValue(){
{% set currentday=0 %}
{% set shipdayToday=0 %}
{% set shipday=0 %}
{% set shipTime=0 %}
{% set days=["Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday"] %}
{% set runLoop= true %}
{% for key, day in days %}
{% if runLoop%}
{% if day|lower in (config('DmitsShippingCountdown.config.ordernoshipping')) %}
{% endif %}
{% if now|date("l") ==day %}
{% if now|date("d.m.Y") in holidays%}
{% else %}
{% if config('DmitsShippingCountdown.config.dailyconfig')%}
{% set shipTime=config('DmitsShippingCountdown.config.ordertill'~day|lower)|date('H:i') %}
{% set runLoop= false %}
{% else %}
{% if day|lower not in (config('DmitsShippingCountdown.config.ordernoshipping')) %}
{% if config('DmitsShippingCountdown.config.ordertillwe') and (day=="Saturday" or day=="Sunday")%}
{% set shipTime=config('DmitsShippingCountdown.config.ordertillwe')|date('H:i') %}
{% else %}
{% set shipTime=config('DmitsShippingCountdown.config.ordertill')|date('H:i') %}
{% endif %}
{% set runLoop= false %}
{% endif %}
{% endif%}
{% if config('DmitsShippingCountdown.config.showdayname')%}
{% set shipdayToday=("dmits.shippingcountdown.custom."~day|lower)|trans %}
{% else %}
{% set shipdayToday=("dmits.shippingcountdown.custom.today")|trans %}
{% endif %}
{% set currentday=key %}
{% endif%}
{% endif %}
{% endif %}
{% endfor %}
{% if shipTime>now|date('H:i')%}
{% set shipday=shipdayToday %}
{% set nextDayTime=shipTime %}
{% else %}
{% set nextDayTime=0%}
{% if currentday==6 %}
{% set nextDayArray=days|slice(0,7) %}
{% elseif currentday==0 %}
{% set nextDayArray=days|slice(1,7)|merge(days|slice(0,1)) %}
{% else %}
{% set nextDayArray=days|slice((currentday+1),7)|merge(days|slice(0,(currentday+1))) %}
{% endif %}
{% set runLoop= true %}
{% set nextDayloop=1 %}
{% for key, day in nextDayArray %}
{% if runLoop%}
{% set nextday=(now|date('U')+(60*60*24*nextDayloop))|date("d.m.Y") %}
{% if nextday in holidays%}
{% else %}
{% if config('DmitsShippingCountdown.config.ordertill'~day|lower) or not config('DmitsShippingCountdown.config.dailyconfig') %}
{% if config('DmitsShippingCountdown.config.showdayname') or nextDayloop>1%}
{% set shipday=("dmits.shippingcountdown.custom."~day|lower)|trans %}
{% else %}
{% set shipday=("dmits.shippingcountdown.custom.tomorrow")|trans %}
{% endif %}
{% if config('DmitsShippingCountdown.config.dailyconfig')%}
{% set nextDayTime=nextday~" "~config('DmitsShippingCountdown.config.ordertill'~day|lower)|date('H:i')%}
{% set runLoop= false %}
{% else %}
{% if day|lower not in (config('DmitsShippingCountdown.config.ordernoshipping')) %}
{% if config('DmitsShippingCountdown.config.ordertillwe') and (day=="Saturday" or day=="Sunday")%}
{% set nextDayTime=nextday~" "~config('DmitsShippingCountdown.config.ordertillwe')|date('H:i')%}
{% set runLoop= false %}
{% elseif config('DmitsShippingCountdown.config.ordertill') %}
{% set nextDayTime=nextday~" "~config('DmitsShippingCountdown.config.ordertill')|date('H:i')%}
{% set runLoop= false %}
{% endif %}
{% endif %}
{% endif %}
{% endif %}
{% endif %}
{% endif %}
{% set nextDayloop=nextDayloop+1 %}
{% if (config('DmitsShippingCountdown.config.maximumdays'))<nextDayloop%}
{% set runLoop= false %}
{% endif %}
{% endfor %}
{% endif %}
var shiptoday="{{shipdayToday}}";
var shipday="{{shipday}}";
var livecountdown=0;
{% if config('DmitsShippingCountdown.config.livecountdown')%}
livecountdown=1;
{% endif %}
var shipTime="{{shipTime|date('U',"UTC")}}";
var nextDayTime="{{nextDayTime|date('U',"UTC")}}";
var timestampnextday="{{nextDayTime|date('U',"UTC")-now|date('U')}}";
return {"timestamp":"{{shipTime|date('U')-now|date('U')}}",
"timestampnextday":timestampnextday,
"shipday":shipday,
"livecountdown":livecountdown,
"shipTime":shipTime,
"nextDayTime":nextDayTime,
"timestampnextday":timestampnextday
};
}
</script>
{% endif %}
{{ parent() }}
{% endblock %}