spree_cm_commissioner 2.3.0.pre.pre4 → 2.3.0.pre.pre5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7e7546de16834ee46678d06170bf2c9cd1f20bb41df2df1e6861b8228d5c493f
4
- data.tar.gz: c455d1a19ea25846649e857e2f426e914a8e5f326782ed9fbc70f727778f516b
3
+ metadata.gz: acb7fbb875f336918c3f656d38400951956f6e4ae5c1cefa44ce946912334c17
4
+ data.tar.gz: 4ec51fea1eb1807a071805fe98d175ad631c009198ee1ea28ffdcfd396176cd2
5
5
  SHA512:
6
- metadata.gz: 014ac4197bd506955cf8aff2546b459beb51aa01dadf086e162071652ecbdcdc064de97b881ed744ad6da0b0a7e90d22a19ed0e58aca903a9b8c40dc44b92be6
7
- data.tar.gz: 83e89ee73435330e30591565e446494efc7c90202f5bf1b4680b6bc9ae8783cf80617cd3bcf9e0503258ed82058b72c7bb4302742ae89791bf6b1a5480aa109b
6
+ metadata.gz: 9fe75fa019c2603487547366cf6c9d579c33a1d51559eb7b61a243806c3a11d244522fad83f4afb17a724af9ffb03077a65a9ca313b566ced63ae4fe0b0f97e4
7
+ data.tar.gz: 6c1674cefe433ac9cbe1f934397eb63818d738a7c3ecbc614fd66451ade6dab719a1643ff1314d62ca79794c60829129bddb7bd191a24a69fb09bfa39f10d098
data/Gemfile.lock CHANGED
@@ -34,7 +34,7 @@ GIT
34
34
  PATH
35
35
  remote: .
36
36
  specs:
37
- spree_cm_commissioner (2.3.0.pre.pre4)
37
+ spree_cm_commissioner (2.3.0.pre.pre5)
38
38
  activerecord-multi-tenant
39
39
  activerecord_json_validator (~> 2.1, >= 2.1.3)
40
40
  aws-sdk-cloudfront
@@ -8,6 +8,37 @@ module Spree
8
8
  module V2
9
9
  module Storefront
10
10
  class SeatLayoutsController < Spree::Api::V2::ResourceController
11
+ # GET /api/v2/storefront/seat_layouts?
12
+ # - variant_ids[]=[1,2]
13
+ # - include_details=true|false (optional, default: true)
14
+ def index
15
+ render_serialized_payload do
16
+ collection_serializer.new(
17
+ collection,
18
+ { include: resource_includes, params: serializer_params }
19
+ ).serializable_hash
20
+ end
21
+ end
22
+
23
+ # GET /api/v2/storefront/seat_layouts/:id
24
+ # - include_details=true|false (optional, default: true)
25
+ def show
26
+ render_serialized_payload { serialize_resource(resource) }
27
+ end
28
+
29
+ # override
30
+ def collection
31
+ scope = if include_details?
32
+ SpreeCmCommissioner::SeatLayout.active.includes(:top_level_blocks, seat_sections: :blocks)
33
+ else
34
+ SpreeCmCommissioner::SeatLayout.active
35
+ end
36
+
37
+ @collection = scope.joins(:blocks)
38
+ .where(blocks: { variant_id: params[:variant_ids] })
39
+ .distinct
40
+ end
41
+
11
42
  # override
12
43
  def resource
13
44
  SpreeCmCommissioner::SeatLayout.includes(
@@ -29,6 +60,21 @@ module Spree
29
60
  def resource_serializer
30
61
  SpreeCmCommissioner::V2::Storefront::SeatLayoutSerializer
31
62
  end
63
+
64
+ # override
65
+ def collection_serializer
66
+ SpreeCmCommissioner::V2::Storefront::SeatLayoutSerializer
67
+ end
68
+
69
+ # override
70
+ def serializer_params
71
+ super.merge(include_details: include_details?)
72
+ end
73
+
74
+ # default return true
75
+ def include_details?
76
+ params.fetch(:include_details, 'true') == 'true'
77
+ end
32
78
  end
33
79
  end
34
80
  end
@@ -13,10 +13,10 @@ module SpreeCmCommissioner
13
13
  # For certain large events, admin can disable this manually.
14
14
  store_public_metadata :allow_manual_search_for_operator, :boolean, default: true
15
15
 
16
- # This model has no seat_layout column (polymorphic association), so we store the preload_seat_layout_id ID in public_metadata.
17
- # This lets us check if a seat layout exists without triggering a database query.
18
- # The ID is automatically updated whenever the seat_layout is saved.
19
- store_public_metadata :preload_seat_layout_id, :integer
16
+ # We store the preload_seat_layout_ids in public_metadata which lets
17
+ # us check if a seat layout exists without triggering a database query.
18
+ # The IDs are automatically updated whenever the seat_layout is saved.
19
+ store_public_metadata :preload_seat_layout_ids, :array, default: []
20
20
 
21
21
  before_validation :validate_at_least_one_check_in_flow_presence
22
22
  end
@@ -6,6 +6,7 @@ module SpreeCmCommissioner
6
6
  driver: 3,
7
7
  bathroom: 4,
8
8
  text: 5,
9
+ standing: 6,
9
10
  other: 0
10
11
  }
11
12
 
@@ -27,17 +28,25 @@ module SpreeCmCommissioner
27
28
  before_validation :assign_layout_from_section, if: -> { seat_layout.nil? && seat_section.present? }
28
29
 
29
30
  def label_required?
30
- seatable? || %w[other text].include?(block_type.to_s)
31
+ sellable? || %w[other text].include?(block_type.to_s)
31
32
  end
32
33
 
33
34
  def self.seatable?(block_type)
34
35
  block_type.to_s.in?(%w[sleeping_seat seat])
35
36
  end
36
37
 
38
+ def self.sellable?(block_type)
39
+ seatable?(block_type) || block_type.to_s == 'standing'
40
+ end
41
+
37
42
  def seatable?
38
43
  self.class.seatable?(block_type)
39
44
  end
40
45
 
46
+ def sellable?
47
+ self.class.sellable?(block_type)
48
+ end
49
+
41
50
  def assign_layout_from_section
42
51
  self.seat_layout = seat_section.seat_layout
43
52
  end
@@ -80,6 +80,20 @@ module SpreeCmCommissioner
80
80
  ]
81
81
  end
82
82
 
83
+ # Only allow holding a block if it represents a seat.
84
+ # Other block types, like standing, don’t need a hold.
85
+ # Use the variant's inventory item to track availability instead.
86
+ def can_hold_block?
87
+ block.present? && block.seatable?
88
+ end
89
+
90
+ # Only allow holding a block if it represents a seat.
91
+ # Other block types, like standing, don’t need a hold.
92
+ # Use the variant's inventory item to track availability instead.
93
+ def can_reserve_block?
94
+ block.present? && block.seatable?
95
+ end
96
+
83
97
  # no validation for each field as we allow user to save data to model partially.
84
98
  def allowed_checkout?
85
99
  kyc_fields.all? { |field| allowed_checkout_for?(field) }
@@ -27,13 +27,19 @@ module SpreeCmCommissioner
27
27
 
28
28
  private
29
29
 
30
- # layoutable (taxon, vehicle) must have preload_seat_layout_id attribute,
31
- # either as a column or as a key in a JSONB column (e.g., metadata)
32
30
  def sync_seat_layout_id_to_layoutable!
33
- if destroyed?
34
- layoutable.update!(preload_seat_layout_id: nil)
35
- else
36
- layoutable.update!(preload_seat_layout_id: id)
31
+ if layoutable.respond_to?(:seat_layouts)
32
+ # for layoutable (eg. event) that has many seat layouts, we update preload_seat_layout_ids attribute.
33
+ # either as a column or as a key in a JSONB column (e.g., metadata)
34
+ layoutable.update!(preload_seat_layout_ids: layoutable.seat_layouts.pluck(:id))
35
+ elsif layoutable.respond_to?(:seat_layout)
36
+ # layoutable (eg. taxon, vehicle) must have preload_seat_layout_id attribute,
37
+ # either as a column or as a key in a JSONB column (e.g., metadata)
38
+ if destroyed?
39
+ layoutable.update!(preload_seat_layout_id: nil)
40
+ else
41
+ layoutable.update!(preload_seat_layout_id: id)
42
+ end
37
43
  end
38
44
  end
39
45
  end
@@ -24,6 +24,9 @@ module SpreeCmCommissioner
24
24
 
25
25
  ActiveRecord::Base.transaction do
26
26
  guests_with_blocks.each do |guest|
27
+ next unless guest.can_hold_block?
28
+
29
+ # here i want to set if guest can hold? (it mean should it hold block & follow inventory logics with count instead)
27
30
  inventory_items.each do |inventory_item|
28
31
  reserved_blocks << hold_specific_block!(inventory_item, guest)
29
32
  end
@@ -19,6 +19,8 @@ module SpreeCmCommissioner
19
19
 
20
20
  ActiveRecord::Base.transaction do
21
21
  guests_with_blocks.each do |guest|
22
+ next unless guest.can_reserve_block?
23
+
22
24
  inventory_items.each do |inventory_item|
23
25
  reserve_specific_block!(inventory_item, guest)
24
26
  end
@@ -21,7 +21,7 @@ module SpreeCmCommissioner
21
21
  base.has_many :check_ins, as: :checkinable, class_name: 'SpreeCmCommissioner::CheckIn', dependent: :nullify
22
22
  base.has_many :customer_taxons, class_name: 'SpreeCmCommissioner::CustomerTaxon'
23
23
 
24
- base.has_one :seat_layout, as: :layoutable, class_name: 'SpreeCmCommissioner::SeatLayout', dependent: :destroy
24
+ base.has_many :seat_layouts, as: :layoutable, class_name: 'SpreeCmCommissioner::SeatLayout', dependent: :destroy
25
25
  base.has_one :category_icon, as: :viewable, dependent: :destroy, class_name: 'SpreeCmCommissioner::TaxonCategoryIcon'
26
26
 
27
27
  base.has_one :web_banner, as: :viewable, dependent: :destroy, class_name: 'SpreeCmCommissioner::TaxonWebBanner'
@@ -18,7 +18,7 @@ module Spree
18
18
  :purchasable_on, :vendor_id, :available_on, :hide_video_banner
19
19
 
20
20
  # To get full seat layout details, call the seat_layouts API with this ID.
21
- base.attribute :seat_layout_id, &:preload_seat_layout_id
21
+ base.attribute :seat_layout_ids, &:preload_seat_layout_ids
22
22
 
23
23
  base.attribute :purchasable_on_app do |taxon|
24
24
  taxon.purchasable_on == 'app' || taxon.purchasable_on == 'both'
@@ -5,6 +5,7 @@ module SpreeCmCommissioner
5
5
  attributes :label, :width, :height, :x, :y, :rotation, :block_type, :variant_id
6
6
 
7
7
  attribute :seatable, &:seatable?
8
+ attribute :sellable, &:sellable?
8
9
  end
9
10
  end
10
11
  end
@@ -4,8 +4,11 @@ module SpreeCmCommissioner
4
4
  class SeatLayoutSerializer < BaseSerializer
5
5
  attributes :name, :status, :width, :height
6
6
 
7
- has_many :seat_sections, serializer: SpreeCmCommissioner::V2::Storefront::SeatSectionSerializer
8
- has_many :top_level_blocks, serializer: SpreeCmCommissioner::V2::Storefront::BlockSerializer
7
+ has_many :seat_sections, serializer: SpreeCmCommissioner::V2::Storefront::SeatSectionSerializer,
8
+ if: proc { |_, params| params && params[:include_details] == true }
9
+
10
+ has_many :top_level_blocks, serializer: SpreeCmCommissioner::V2::Storefront::BlockSerializer,
11
+ if: proc { |_, params| params && params[:include_details] == true }
9
12
  end
10
13
  end
11
14
  end
data/config/routes.rb CHANGED
@@ -674,7 +674,7 @@ Spree::Core::Engine.add_routes do
674
674
  post :user_order_transfer, to: 'user_order_transfer#create'
675
675
  resources :anonymous_orders, path: 'o', only: %i[show]
676
676
 
677
- resources :seat_layouts, only: %i[show]
677
+ resources :seat_layouts, only: %i[show index]
678
678
  resources :inventory_items, only: %i[index]
679
679
  namespace :transit do
680
680
  resources :draft_orders, only: %i[create]
@@ -1,5 +1,5 @@
1
1
  module SpreeCmCommissioner
2
- VERSION = '2.3.0-pre4'.freeze
2
+ VERSION = '2.3.0-pre5'.freeze
3
3
 
4
4
  module_function
5
5
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: spree_cm_commissioner
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.3.0.pre.pre4
4
+ version: 2.3.0.pre.pre5
5
5
  platform: ruby
6
6
  authors:
7
7
  - You