Limiting store hours in Spree?

81 Views Asked by At

I've integrated Spree with my current website (which is built with Ruby on Rails).

It's a fast-food ordering service, and I want orders to be placed ONLY in the opening hours (12:00 - 22:00).

I've never done this before, can someone guide me a bit? Thanks!

2

There are 2 best solutions below

2
On

You can use strftime to get the current time. Then use a simple if/else statement (if between 12:00 and 22:00 we'll accept orders/else we won't)

puts Time.now.strftime("%I:%M:%S %z") # "09:33:00 -0400"

puts Time.now.strftime("%I:%M:%S %Z %z") # "09:33:00 EDT -0400"
0
On

I've never used spree so I'm not exactly sure where this would go but you can check if a time is between two other times w/ between?

open = Time.now.beginning_of_day + 12.hours
close = Time.now.end_of_day - 2.hours

Time.now.between? open, close