EC-CUBEで、定休日カレンダーを改造し、指定した繁忙期を営業日にさせる方法。
デフォルトでは、土日が強制的に休日となっていますが、これでは非常に使い勝手が悪いです。
通常は日曜休みだけど、「繁忙期は休まず営業します」という場合に対応したカレンダーです。
設定例:
- 通常は、日曜だけ休み
- 7/1〜8/15は、休まず営業
- 12/1〜12/30も、休まず営業
EC-CUBE:4.2.3
Block/Calendar.twig
{# 定休日カレンダー(繁忙期は無休) #}
{# 繁忙期の設定 #}
{% macro is_busy_season(month, day) %}
{{-
(month == 7) or
(month == 8 and day <= 15) or
(month == 12 and day >= 1 and day <= 30)
-}}
{% endmacro %}
{# HTMLヘッダー定義 #}
{% set calendar_thead = '<thead><tr><th>日</th><th>月</th><th>火</th><th>水</th><th>木</th><th>金</th><th>土</th></tr></thead>' %}
{# カレンダーテーブル生成マクロ #}
{% macro calendar_table(monthTitle, calendar, id_prefix, thead) %}
{% import _self as self %}
{% set month = monthTitle|split('月')[0]|split('年')[1]|number_format %}
<table id="{{ id_prefix }}-table" class="tbl_calendar"> {{ thead|raw }}
<tbody>
<tr>
{% for day in calendar %}
{% if day.day is not empty %}
{% set is_busy = self.is_busy_season(month, day.day) %}
{% set is_holiday = (day.holiday or day.dayOfWeek == 'Sun') and not is_busy %}
{% set cell_class = day.today ? 'calendar_today' : '' %}
{% set cell_class = is_holiday ? cell_class ~ ' calendar_holiday' : cell_class %}
{% if cell_class is empty %}
{% set cell_class = 'calendar_day' %}
{% endif %}
<td id="{{ id_prefix }}-{{ day.day }}" class="{{ cell_class }}">
{{- day.day -}}
</td>
{% else %}
<td class="calendar_day"></td>
{% endif %}
{% if loop.index % 7 == 0 and loop.index != calendar|length %}
</tr>
<tr>
{% endif %}
{% endfor %}
</tr>
</tbody>
</table>
{% endmacro %}
<h2>定休日カレンダー</h2>
<div class="row g-3">
<div class="col-12 col-sm-6">
<div class="title_month">{{ ThisMonthTitle }}</div>
{% import _self as cal %}
{{ cal.calendar_table(ThisMonthTitle, ThisMonthCalendar, 'this-month', calendar_thead) }}
</div>
<div class="col-12 col-sm-6">
<div class="title_month">{{ NextMonthTitle }}</div>
{{ cal.calendar_table(NextMonthTitle, NextMonthCalendar, 'next-month', calendar_thead) }}
</div>
</div>
- {# 繁忙期の設定 #}の条件を変更すると、お好みの繁忙期を設定することができます
- デフォルトのCalendar.twigは、非常に冗長なコードなので、メンテしやすく改造してあります。
- 祭日などのイレギュラーな休日は、通常のカレンダー設定画面で行います。
- Bootstrap。
デフォルトのカレンダーの機能がマジ使えなすぎる…


コメント