diff --git a/app/furniture/marketplace/breadcrumbs.rb b/app/furniture/marketplace/breadcrumbs.rb index 4e56c5bf3..3436bd855 100644 --- a/app/furniture/marketplace/breadcrumbs.rb +++ b/app/furniture/marketplace/breadcrumbs.rb @@ -47,6 +47,16 @@ link "Edit", product.location(:edit) end +crumb :marketplace_delivery_areas do |marketplace| + parent :edit_marketplace, marketplace + link t("marketplace.delivery_areas.index.link_to"), marketplace.location(child: :delivery_areas) +end + +crumb :new_delivery_area do |delivery_area| + parent :marketplace_delivery_areas, delivery_area.marketplace + link "Add a Delivery Area", marketplace.location(:new, child: :delivery_area) +end + crumb :marketplace_tax_rates do |marketplace| parent :edit_marketplace, marketplace link t("marketplace.tax_rates.index.link_to"), marketplace.location(child: :tax_rates) diff --git a/app/furniture/marketplace/delivery_area.rb b/app/furniture/marketplace/delivery_area.rb new file mode 100644 index 000000000..58e9d45d8 --- /dev/null +++ b/app/furniture/marketplace/delivery_area.rb @@ -0,0 +1,10 @@ +class Marketplace + class DeliveryArea < Record + self.table_name = "marketplace_delivery_areas" + self.location_parent = :marketplace + + belongs_to :marketplace, inverse_of: :delivery_areas + + monetize :price_cents + end +end diff --git a/app/furniture/marketplace/delivery_area_policy.rb b/app/furniture/marketplace/delivery_area_policy.rb new file mode 100644 index 000000000..3a0fca8de --- /dev/null +++ b/app/furniture/marketplace/delivery_area_policy.rb @@ -0,0 +1,15 @@ +class Marketplace + class DeliveryAreaPolicy < ApplicationPolicy + alias_method :delivery_area, :object + + def create? + person.operator? || person.member_of?(delivery_area.marketplace.space) + end + + class Scope < ApplicationScope + def resolve + scope.all + end + end + end +end diff --git a/app/furniture/marketplace/delivery_areas/_form.html.erb b/app/furniture/marketplace/delivery_areas/_form.html.erb new file mode 100644 index 000000000..c2cff7903 --- /dev/null +++ b/app/furniture/marketplace/delivery_areas/_form.html.erb @@ -0,0 +1,6 @@ +<%= form_with(model: delivery_area.location) do |delivery_area_form| %> + <%= render "text_field", attribute: :label, form: delivery_area_form %> + <%= render "money_field", attribute: :price, form: delivery_area_form, required: true, step: 0.01, min: 0 %> + + <%= delivery_area_form.submit %> +<%- end %> diff --git a/app/furniture/marketplace/delivery_areas/index.html.erb b/app/furniture/marketplace/delivery_areas/index.html.erb new file mode 100644 index 000000000..42c4c2f57 --- /dev/null +++ b/app/furniture/marketplace/delivery_areas/index.html.erb @@ -0,0 +1,12 @@ +<%- breadcrumb(:marketplace_delivery_areas, marketplace) %> + +
+
+
+ <%= render delivery_areas %> +
+
+ +
\ No newline at end of file diff --git a/app/furniture/marketplace/delivery_areas/new.html.erb b/app/furniture/marketplace/delivery_areas/new.html.erb new file mode 100644 index 000000000..8bbacb49a --- /dev/null +++ b/app/furniture/marketplace/delivery_areas/new.html.erb @@ -0,0 +1,2 @@ +<%- breadcrumb :new_delivery_area, delivery_area %> +<%= render "form", delivery_area: delivery_area %> diff --git a/app/furniture/marketplace/delivery_areas_controller.rb b/app/furniture/marketplace/delivery_areas_controller.rb new file mode 100644 index 000000000..806b0563a --- /dev/null +++ b/app/furniture/marketplace/delivery_areas_controller.rb @@ -0,0 +1,18 @@ +class Marketplace + class DeliveryAreasController < Controller + def index + end + + def new + delivery_area + end + + helper_method def delivery_area + @delivery_area ||= authorize(delivery_areas.new) + end + + helper_method def delivery_areas + @delivery_areas ||= policy_scope(marketplace.delivery_areas) + end + end +end diff --git a/app/furniture/marketplace/locales/en.yml b/app/furniture/marketplace/locales/en.yml index 3087149d0..4788f525b 100644 --- a/app/furniture/marketplace/locales/en.yml +++ b/app/furniture/marketplace/locales/en.yml @@ -1,6 +1,9 @@ en: marketplace: + delivery_areas: + index: + link_to: "Delivery Areas" delivery_window: edit: "Change Delivery Window" delivery_info: diff --git a/app/furniture/marketplace/marketplace.rb b/app/furniture/marketplace/marketplace.rb index b3825714b..18e14405e 100644 --- a/app/furniture/marketplace/marketplace.rb +++ b/app/furniture/marketplace/marketplace.rb @@ -9,6 +9,7 @@ class Marketplace < Furniture has_many :orders, inverse_of: :marketplace has_many :tax_rates, inverse_of: :marketplace + has_many :delivery_areas, inverse_of: :marketplace def has_controller_edit? true diff --git a/app/furniture/marketplace/routes.rb b/app/furniture/marketplace/routes.rb index da266139c..ac0327277 100644 --- a/app/furniture/marketplace/routes.rb +++ b/app/furniture/marketplace/routes.rb @@ -11,6 +11,8 @@ def self.append_routes(router) router.resources :tax_rates + router.resources :delivery_areas + router.resources :orders, only: [:show, :index] router.resources :products router.resource :stripe_account