Sha256: 607ca24c57664df53301938c02da6aec2ee280205c7262ce2625c073dc6fa098

Contents?: true

Size: 1.37 KB

Versions: 9

Compression:

Stored size: 1.37 KB

Contents

module SpreeDeliveryOptions
  module BaseHelper

    def current_order_cutoff_time
      return nil unless (current_order && current_order.delivery_date)
      
      cutoff_time = Time.zone.now.change(hour: SpreeDeliveryOptions::Config.delivery_cut_off_hour)
      cutoff_date = current_order.delivery_date - 1.day
      "#{cutoff_date.strftime('%A, %d %b')} before #{cutoff_time.strftime("%l%P")}"
    end

    def next_delivery_slot
      delivery_options = JSON.parse(SpreeDeliveryOptions::Config.delivery_time_options)

      delivery_day = next_delivery_day
      return "" unless delivery_day

      "#{delivery_day.strftime('%A').titleize} between #{delivery_options[delivery_day.strftime('%A').downcase].first}"
    end

    def next_delivery_day
      delivery_options = JSON.parse(SpreeDeliveryOptions::Config.delivery_time_options)

      cutoff_time = Time.zone.now.change(hour: SpreeDeliveryOptions::Config.delivery_cut_off_hour)

      current_day = Time.zone.now > cutoff_time ? (Date.current + 2.days) : (Date.current + 1.day)
      next_available_day = nil
      counter = 0

      until next_available_day || counter > 7 do
        if delivery_options[current_day.strftime('%A').downcase]
          next_available_day = current_day
        else
          current_day = current_day + 1.day
          counter = counter + 1
        end
      end
      next_available_day
    end

  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
spree_delivery_options-2.2.8 app/helpers/spree_delivery_options/base_helper.rb
spree_delivery_options-2.2.7 app/helpers/spree_delivery_options/base_helper.rb
spree_delivery_options-2.2.6 app/helpers/spree_delivery_options/base_helper.rb
spree_delivery_options-2.2.5 app/helpers/spree_delivery_options/base_helper.rb
spree_delivery_options-2.2.4 app/helpers/spree_delivery_options/base_helper.rb
spree_delivery_options-2.2.3 app/helpers/spree_delivery_options/base_helper.rb
spree_delivery_options-2.2.2 app/helpers/spree_delivery_options/base_helper.rb
spree_delivery_options-2.2.1 app/helpers/spree_delivery_options/base_helper.rb
spree_delivery_options-2.2.0 app/helpers/spree_delivery_options/base_helper.rb