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 +4 -4
- data/Gemfile.lock +1 -1
- data/app/controllers/spree/api/v2/storefront/seat_layouts_controller.rb +46 -0
- data/app/models/concerns/spree_cm_commissioner/event_metadata.rb +4 -4
- data/app/models/spree_cm_commissioner/block.rb +10 -1
- data/app/models/spree_cm_commissioner/guest.rb +14 -0
- data/app/models/spree_cm_commissioner/seat_layout.rb +12 -6
- data/app/models/spree_cm_commissioner/seats/blocks_holder.rb +3 -0
- data/app/models/spree_cm_commissioner/seats/blocks_reserver.rb +2 -0
- data/app/models/spree_cm_commissioner/taxon_decorator.rb +1 -1
- data/app/serializers/spree/v2/storefront/taxon_serializer_decorator.rb +1 -1
- data/app/serializers/spree_cm_commissioner/v2/storefront/block_serializer.rb +1 -0
- data/app/serializers/spree_cm_commissioner/v2/storefront/seat_layout_serializer.rb +5 -2
- data/config/routes.rb +1 -1
- data/lib/spree_cm_commissioner/version.rb +1 -1
- metadata +1 -1
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA256:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: acb7fbb875f336918c3f656d38400951956f6e4ae5c1cefa44ce946912334c17
         | 
| 4 | 
            +
              data.tar.gz: 4ec51fea1eb1807a071805fe98d175ad631c009198ee1ea28ffdcfd396176cd2
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: 9fe75fa019c2603487547366cf6c9d579c33a1d51559eb7b61a243806c3a11d244522fad83f4afb17a724af9ffb03077a65a9ca313b566ced63ae4fe0b0f97e4
         | 
| 7 | 
            +
              data.tar.gz: 6c1674cefe433ac9cbe1f934397eb63818d738a7c3ecbc614fd66451ade6dab719a1643ff1314d62ca79794c60829129bddb7bd191a24a69fb09bfa39f10d098
         | 
    
        data/Gemfile.lock
    CHANGED
    
    
| @@ -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 | 
            -
                  #  | 
| 17 | 
            -
                  #  | 
| 18 | 
            -
                  # The  | 
| 19 | 
            -
                  store_public_metadata : | 
| 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 | 
            -
                   | 
| 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  | 
| 34 | 
            -
                    layoutable.update | 
| 35 | 
            -
             | 
| 36 | 
            -
                    layoutable.update!( | 
| 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
         | 
| @@ -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. | 
| 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 : | 
| 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'
         | 
| @@ -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 | 
            -
             | 
| 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]
         |