11

ビジネスのディレクトリを作成していて、営業時間のリストを公開するだけでなく、ビジネスが現在営業しているかどうかも公開したいと考えています。

マトリックスには、7 つの行があり、row_1 は日曜日を表し、row_7 は土曜日を表します。そこで、質問が 2 つあります。

  1. これはコードが可能な限り簡潔ですか、それとももっと良い方法がありますか?
  2. ビジネスが現在開いているかどうかを示す条件に欠陥はありますか? 現在は機能しているようですが、あまりテストされていません。

    {!-- Hours of Operation --}  
    {exp:stash:set name="hours-of-operation"}
    The Current time is: {current_time format="%g:%i%a"}<br/>
       {hours_of_operation}
       {if row_count=="1"}Sunday{/if}
       {if row_count=="2"}Monday{/if}
       {if row_count=="3"}Tuesday{/if}
       {if row_count=="4"}Wednesday{/if}
       {if row_count=="5"}Thursday{/if}
       {if row_count=="6"}Friday{/if}
       {if row_count=="7"}Saturday{/if}
       {open_time format="%g:%i%a"} - {close_time format="%g:%i%a"}<br/>
       {/hours_of_operation}
    {/exp:stash:set} 
    {!-- Hours of Operation --}
    
    {!-- Are we open? --}
    {exp:stash:set name="are-we-open"}
    {exp:mx_calc expression='{current_time format="%w"}+1'}
        {!-- matrix --}
        {hours_of_operation}                
            {if row_count=="{calc_result}"}
                Today is: {current_time format="%l"}<br/>
        <strong>
                {if '{open_time format="%H%i"}' <= '{current_time format="%H%i"}' && '{close_time format="%H%i"}' <= '{current_time format="%H%i"}'}    
                We are currently open!{if:else}We are currently closed.
            {/if}
            </strong><br/>
                Today's Hours are:<br/> <strong>{open_time format="%g:%i%a"} - {close_time format="%g:%i%a"}</strong><br/>              
            {/if}   
        {/hours_of_operation} 
        {!-- matrix --}
    {/exp:mx_calc}
    {/exp:stash:set}
    {!-- Are we open? --}
    

ここに画像の説明を入力

4

2 に答える 2

8

これは私には良さそうです。変更する唯一のことは、マトリックスの左側に別の列を追加し、クライアントが曜日を選択できるようにドロップダウンでそれを曜日と呼ぶことです。次に、コードでこれらすべての条件を取り除き、{day_of_week} だけに置き換えることができます。

于 2012-10-31T00:30:47.737 に答える
1

このロジックは機能しません。

{if '{open_time format="%H%i"}' <= '{current_time format="%H%i"}' && '{close_time format="%H%i"}' <= '{current_time format="%H%i"}'} 

current_time2 つの値の間にあることを確認するのではなく、閉店時間と開店時間の両方が 未満であることを確認していcurrent_timeます。ビジネスが営業している場合は、未満ではなく、よりclose_time多い必要があります。ロジックは次のようになります。current_time

{if 
    '{open_time format="%H%i"}' <= '{current_time format="%H%i"}' && 
    '{close_time format="%H%i"}' > '{current_time format="%H%i"}'
} 

また、うるさい場合は、1 週間のうち 1 日または複数日完全に休業しているビジネスのデータを入力する必要がある場合、人々はどうしますか? 私だったら、[終日休業] 列として[PT Switch]フィールドを挿入します。デフォルトは [いいえ] です。既存のロジックを少し調整するだけで済みます。

{if
    '{open_time format="%H%i"}' <= '{current_time format="%H%i"}' && 
    '{close_time format="%H%i"}' > '{current_time format="%H%i"}' && 
    '{closed_all_day}' != 'y'
}    
    We're currently open!
{if:else}

次に、{hours_of_operation}ループで:

{if closed_all_day != 'y'}
    {open_time format="%g:%i%a"} - {close_time format="%g:%i%a"}<br/>
{else}
    Closed<br/>
{/if}
于 2012-10-31T19:08:52.653 に答える