Files
openfoodnetwork/lib/tasks/sample_data/addressing.rb
Luis Ramos e52937c113 Use rubocop auto correct to add frozen string literal to all files
This is an unsafe auto corection, we will need to trust our build here
2021-06-17 23:07:26 +01:00

28 lines
577 B
Ruby

# frozen_string_literal: true
module Addressing
private
def address(string)
state = country.states.first
parts = string.split(", ")
Spree::Address.new(
address1: parts[0],
city: parts[1],
zipcode: parts[2],
state: state,
country: country
)
end
def zone
zone = Spree::Zone.find_or_create_by!(name: ENV.fetch('CHECKOUT_ZONE'))
zone.members.create!(zoneable: country) unless zone.zoneables.include?(country)
zone
end
def country
Spree::Country.find_by(iso: ENV.fetch('DEFAULT_COUNTRY_CODE'))
end
end