Sha256: 21919934156c232fdde853cc5dbae70bdfafd34a3af5814b1e31771982d1af45

Contents?: true

Size: 726 Bytes

Versions: 26

Compression:

Stored size: 726 Bytes

Contents

module Spree
  module Cart
    class Create
      prepend Spree::ServiceModule::Base

      def call(user:, store:, currency:, public_metadata: {}, private_metadata: {}, order_params: {})
        order_params ||= {}

        # we cannot create an order without store
        return failure(:store_is_required) if store.nil?

        default_params = {
          user: user,
          currency: currency || store.default_currency,
          token: Spree::GenerateToken.new.call(Spree::Order),
          public_metadata: public_metadata.to_h,
          private_metadata: private_metadata.to_h
        }

        order = store.orders.create!(default_params.merge(order_params))
        success(order)
      end
    end
  end
end

Version data entries

26 entries across 26 versions & 1 rubygems

Version Path
spree_core-4.10.1 app/services/spree/cart/create.rb
spree_core-4.10.0 app/services/spree/cart/create.rb
spree_core-4.9.0 app/services/spree/cart/create.rb
spree_core-4.8.3 app/services/spree/cart/create.rb
spree_core-4.8.2 app/services/spree/cart/create.rb
spree_core-4.7.3 app/services/spree/cart/create.rb
spree_core-4.6.6 app/services/spree/cart/create.rb
spree_core-4.5.5 app/services/spree/cart/create.rb
spree_core-4.4.1 app/services/spree/cart/create.rb
spree_core-4.5.4 app/services/spree/cart/create.rb
spree_core-4.6.5 app/services/spree/cart/create.rb
spree_core-4.7.2 app/services/spree/cart/create.rb
spree_core-4.7.1 app/services/spree/cart/create.rb
spree_core-4.6.4 app/services/spree/cart/create.rb
spree_core-4.7.0 app/services/spree/cart/create.rb
spree_core-4.6.3 app/services/spree/cart/create.rb
spree_core-4.6.2 app/services/spree/cart/create.rb
spree_core-4.6.1 app/services/spree/cart/create.rb
spree_core-4.6.0 app/services/spree/cart/create.rb
spree_core-4.5.3 app/services/spree/cart/create.rb