Sha256: e4df23697cc900b4b91dff71c87892481a5a0644d40c4ffa064ec7de86a254bc

Contents?: true

Size: 1.21 KB

Versions: 30

Compression:

Stored size: 1.21 KB

Contents

# frozen_string_literal: true

module Spree
  class OrderUpdateAttributes
    # @param order [Order] existing (persisted) order
    # @param attributes [Hash] attributes which are assigned to the new order.
    #   These attributes should already have been filtered.
    #   * :payments_attributes attributes
    def initialize(order, attributes, request_env: nil)
      @order = order
      @attributes = attributes.dup
      @payments_attributes = @attributes.delete(:payments_attributes) || []
      @request_env = request_env
    end

    # Assign the attributes to the order and save the order
    # @return true if saved, otherwise false and errors will be set on the order
    def call
      order.validate_payments_attributes(@payments_attributes)

      assign_order_attributes
      assign_payments_attributes

      order.save
    end

    alias_method :apply, :call

    private

    attr_reader :attributes, :payments_attributes, :order

    def assign_order_attributes
      order.assign_attributes attributes
    end

    def assign_payments_attributes
      @payments_attributes.each do |payment_attributes|
        PaymentCreate.new(order, payment_attributes, request_env: @request_env).build
      end
    end
  end
end

Version data entries

30 entries across 30 versions & 1 rubygems

Version Path
solidus_core-4.4.1 app/models/spree/order_update_attributes.rb
solidus_core-4.4.0 app/models/spree/order_update_attributes.rb
solidus_core-4.3.4 app/models/spree/order_update_attributes.rb
solidus_core-4.2.4 app/models/spree/order_update_attributes.rb
solidus_core-4.1.5 app/models/spree/order_update_attributes.rb
solidus_core-4.3.3 app/models/spree/order_update_attributes.rb
solidus_core-4.3.2 app/models/spree/order_update_attributes.rb
solidus_core-4.1.4 app/models/spree/order_update_attributes.rb
solidus_core-4.3.1 app/models/spree/order_update_attributes.rb
solidus_core-4.3.0 app/models/spree/order_update_attributes.rb
solidus_core-4.2.3 app/models/spree/order_update_attributes.rb
solidus_core-4.1.3 app/models/spree/order_update_attributes.rb
solidus_core-4.0.4 app/models/spree/order_update_attributes.rb
solidus_core-3.4.6 app/models/spree/order_update_attributes.rb
solidus_core-4.0.3 app/models/spree/order_update_attributes.rb
solidus_core-4.1.2 app/models/spree/order_update_attributes.rb
solidus_core-4.2.2 app/models/spree/order_update_attributes.rb
solidus_core-3.4.5 app/models/spree/order_update_attributes.rb
solidus_core-4.2.1 app/models/spree/order_update_attributes.rb
solidus_core-4.2.0 app/models/spree/order_update_attributes.rb