Skip to Content Skip to Menu

Advice about how to store shop's opening hours in database

  • jabba84
  • jabba84
  • OFFLINE
  • Posts: 91
  • Thanks: 5
  • Karma: 0
2 years 6 months ago - 2 years 6 months ago #329349 by jabba84
Hello again, sorry to bother you again but i need some advice.
Each community builder user has his own shop, and i need to setup shop's opening hours. Daily hours are divided day by day, and this is how iv've setup it so far:



The user check as "opened" in every single day and then is promped if he works morning till evening or with a pause in the middle. So if he choose to work all the time he is promped with opening hour in the morning and closing hour in the evening (2 different fields), if he choose to have midday break he is promped with 4 fields: morning opening, morning closing, afternoon opening, afternoon closing times.
And so on for every single day of the week.

In this way i have 8 database columns for each day:
  • Opened / Closed
  • Full time or split time
  • Full time open time
  • Full time close time
  • Split time morning opening
  • Split time morning closing
  • Split time afternoon opening
  • Split time afternoon closing

The question is: do you think this is the best way to handle shop's opening times?
If this is the best way can i group fields in order to have them grouped together both in user profile editing and in user's public profile page?

Profile editing:



Frontend:



Thank you!

WebMaster & JoomlaLover @ www.pixed.it
Last edit: 2 years 6 months ago by jabba84.

Please Log in or Create an account to join the conversation.

  • krileon
  • krileon
  • ONLINE
  • Posts: 48541
  • Thanks: 8290
  • Karma: 1445
2 years 6 months ago #329355 by krileon
Probably best way is to use multiple field group fields (provided by CB Field Groups plugin) and a couple of other fields to define the times. Below is the expected number of fields, types, and a few of their parameters that you'd need to set.



All fields here should be set to display on 1 line without a title. Below example configuration.

cb_businessdays
Parameters > Field Group
Fields: cb_businessday, cb_businessopen, cb_businesstime
Button Label: Add Day
Group Limit: 7
Parameters > Display
Custom Display Rows:
Code:
<div class="d-flex" style="gap: 0.25rem"> <div class="flex-shrink-0" style="min-width: 100px">[field_cb_businessday]</div> [cb:if cb_businessopen!="1"]<div class="flex-shrink-0">[field_cb_businessopen]</div>[/cb:if] [cb:if cb_businessopen="1"]<div>[field_cb_businesstime]</div>[/cb:if] </div>
Custom Edit Rows:
Code:
<div class="d-flex" style="gap: 0.25rem"> <div class="flex-shrink-0">[field_cb_businessday]</div> <div class="flex-shrink-0">[field_cb_businessopen]</div> <div>[field_cb_businesstime]</div> </div>

cb_businesstime
Parameters > Field Group
Fields: cb_businessstart, cb_businessend
Button Label: Add Time
Group Limit: 4
Parameters > Display
Display Template: Compact
Custom Display Rows:
Code:
<div>[field_cb_businessstart][cb:if cb_businessend!="24_hours"] - [field_cb_businessend][/cb:if]</div>
Display Field Format: None
Display Empty Fields: No
Edit Template: Compact
Custom Edit Rows:
Code:
<div>[field_cb_businessstart] - [field_cb_businessend]</div>
Edit Field Format: None
Integrations > CB Conditional
Display: Field conditional show
Field: cb_businessopen
Operator: Equal To
Value: 1

For the Start and End code select fields I used the below to help generate the time selection dropdowns. Time fields felt like they were too much for this usage.

Parameters > Code
Code:
$times = [ '24_hours' => '24 Hours' ]; for ( $i = 1, $n = 12; $i <= $n; $i++ ) { $times[$i . '_00_AM'] = $i . ':00 AM'; $times[$i . '_15_AM'] = $i . ':15 AM'; $times[$i . '_30_AM'] = $i . ':30 AM'; $times[$i . '_45_AM'] = $i . ':45 AM'; } for ( $i = 1, $n = 12; $i <= $n; $i++ ) { $times[$i . '_00_PM'] = $i . ':00 PM'; $times[$i . '_15_PM'] = $i . ':15 PM'; $times[$i . '_30_PM'] = $i . ':30 PM'; $times[$i . '_45_PM'] = $i . ':45 PM'; } return $times;

All of the above combined gets you the following.

Profile Edit/Registration:


Profile View:


Kyle (Krileon)
Community Builder Team Member
Before posting on forums: Read FAQ thoroughly + Read our Documentation + Search the forums
CB links: Documentation - Localization - CB Quickstart - CB Paid Subscriptions - Add-Ons - Forge
--
If you are a Professional, Developer, or CB Paid Subscriptions subscriber and have a support issue please always post in your respective support forums for best results!
--
If I've missed your support post with a delay of 3 days or greater and are a Professional, Developer, or CBSubs subscriber please send me a private message with your thread and will reply when possible!
--
Please note I am available Monday - Friday from 8:00 AM CST to 4:00 PM CST. I am away on weekends (Saturday and Sunday) and if I've missed your post on or before a weekend after business hours please wait for the next following business day (Monday) and will get to your issue as soon as possible, thank you.
--
My role here is to provide guidance and assistance. I cannot provide custom code for each custom requirement. Please do not inquire me about custom development.

Please Log in or Create an account to join the conversation.

  • jabba84
  • jabba84
  • OFFLINE
  • Posts: 91
  • Thanks: 5
  • Karma: 0
2 years 6 months ago - 2 years 6 months ago #329364 by jabba84
WOW! Thank you!!!! I'll try this ASAP

EDIT: when i try to setup i get a warning message that says that i need to upgrade to MySQL 5.7.8+
I have MySQL 5.6.51 and unfortnately i cannot upgrade it soon. Can i still use the group field (i don't need to search in them) or i risk problems in the future?
Thanks

WebMaster & JoomlaLover @ www.pixed.it
Last edit: 2 years 6 months ago by jabba84.

Please Log in or Create an account to join the conversation.

  • krileon
  • krileon
  • ONLINE
  • Posts: 48541
  • Thanks: 8290
  • Karma: 1445
2 years 6 months ago #329373 by krileon
That warning is just for searching field group fields optimization. You can still search field group fields on MySQL 5.6, but it won't be able to use JSON search functions so it will be slower. In short nothing to worry about and you can use the field fine.


Kyle (Krileon)
Community Builder Team Member
Before posting on forums: Read FAQ thoroughly + Read our Documentation + Search the forums
CB links: Documentation - Localization - CB Quickstart - CB Paid Subscriptions - Add-Ons - Forge
--
If you are a Professional, Developer, or CB Paid Subscriptions subscriber and have a support issue please always post in your respective support forums for best results!
--
If I've missed your support post with a delay of 3 days or greater and are a Professional, Developer, or CBSubs subscriber please send me a private message with your thread and will reply when possible!
--
Please note I am available Monday - Friday from 8:00 AM CST to 4:00 PM CST. I am away on weekends (Saturday and Sunday) and if I've missed your post on or before a weekend after business hours please wait for the next following business day (Monday) and will get to your issue as soon as possible, thank you.
--
My role here is to provide guidance and assistance. I cannot provide custom code for each custom requirement. Please do not inquire me about custom development.

Please Log in or Create an account to join the conversation.

Moderators: beatnantkrileon
Powered by Kunena Forum