Skip to content

Commit

Permalink
close #2057 add purchasable_on to product and taxon (#2061)
Browse files Browse the repository at this point in the history
  • Loading branch information
LengTech11 authored Nov 19, 2024
1 parent 8416ced commit d227cea
Show file tree
Hide file tree
Showing 11 changed files with 63 additions and 4 deletions.
2 changes: 2 additions & 0 deletions app/models/spree_cm_commissioner/product_decorator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ def self.prepended(base)
base.whitelisted_ransackable_attributes = %w[description name slug discontinue_on status vendor_id]

base.after_update :update_variants_vendor_id, if: :saved_change_to_vendor_id?

base.enum purchasable_on: { both: 0, web: 1, app: 2 }
end

def associated_event
Expand Down
2 changes: 2 additions & 0 deletions app/models/spree_cm_commissioner/taxon_decorator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ def self.prepended(base)
base.before_save :set_slug

base.whitelisted_ransackable_attributes |= %w[kind]

base.enum purchasable_on: { both: 0, web: 1, app: 2 }
end

def background_color
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<!-- insert_before "[data-hook='admin_product_form_available_on']" -->

<%= f.field_container :purchasable_on do %>
<%= f.label :purchasable_on, Spree.t('purchasable_on'), class: 'form-label' %>
<%= f.select :purchasable_on,
options_for_select([['Both', 'both'], ['Web', 'web'], ['App', 'app']], f.object.purchasable_on),
{ },
{ class: 'select2 form-control' } %>
<%= f.error_message_on :purchasable_on, class: 'text-danger' %>
<% end %>
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<!-- insert_before "erb[loud]:contains('field_container :parent_id')" -->

<%= f.field_container :purchasable_on do %>
<%= f.label :purchasable_on, Spree.t('purchasable_on'), class: 'form-label' %>
<%= f.select :purchasable_on,
options_for_select([['Both', 'both'], ['Web', 'web'], ['App', 'app']], f.object.purchasable_on),
{ },
{ class: 'select2 form-control' } %>
<%= f.error_message_on :purchasable_on, class: 'text-danger' %>
<% end %>
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,15 @@ def self.prepended(base)
base.has_one :default_state, serializer: :state
base.has_one :venue, serializer: ::SpreeCmCommissioner::V2::Storefront::ProductPlaceSerializer
base.attributes :need_confirmation, :product_type, :kyc, :allowed_upload_later, :allow_anonymous_booking, :use_video_as_default
base.attributes :reveal_description, :discontinue_on, :public_metadata
base.attributes :reveal_description, :discontinue_on, :public_metadata, :purchasable_on

base.attribute :purchasable_on_app do |product|
product.purchasable_on == 'app' || product.purchasable_on == 'both'
end

base.attribute :purchasable_on_web do |product|
product.purchasable_on == 'web' || product.purchasable_on == 'both'
end
end
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,17 @@ def self.prepended(base)
base.has_one :web_banner, serializer: ::SpreeCmCommissioner::V2::Storefront::AssetSerializer
base.has_one :home_banner, serializer: ::SpreeCmCommissioner::V2::Storefront::AssetSerializer

base.attributes :custom_redirect_url, :kind, :subtitle, :from_date, :to_date, :background_color, :foreground_color, :show_badge_status
base.attributes :custom_redirect_url, :kind, :subtitle, :from_date, :to_date,
:background_color, :foreground_color, :show_badge_status,
:purchasable_on

base.attribute :purchasable_on_app do |taxon|
taxon.purchasable_on == 'app' || taxon.purchasable_on == 'both'
end

base.attribute :purchasable_on_web do |taxon|
taxon.purchasable_on == 'web' || taxon.purchasable_on == 'both'
end
end
end
end
Expand Down
1 change: 1 addition & 0 deletions config/initializers/spree_permitted_attributes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ module PermittedAttributes
preferred_background_color
preferred_foreground_color
show_badge_status
purchasable_on
]

@@store_attributes += [
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AddPurchasableOnToSpreeTaxons < ActiveRecord::Migration[7.0]
def change
add_column :spree_taxons, :purchasable_on, :integer, null: false, default: 0, if_not_exists: true
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AddPurchasableOnToSpreeProducts < ActiveRecord::Migration[7.0]
def change
add_column :spree_products, :purchasable_on, :integer, null: false, default: 0, if_not_exists: true
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,10 @@
:allowed_upload_later,
:allow_anonymous_booking,
:discontinue_on,
:use_video_as_default
:use_video_as_default,
:purchasable_on,
:purchasable_on_app,
:purchasable_on_web
)
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,10 @@
:to_date,
:background_color,
:foreground_color,
:show_badge_status
:show_badge_status,
:purchasable_on,
:purchasable_on_app,
:purchasable_on_web
)
end

Expand Down

0 comments on commit d227cea

Please sign in to comment.