Sha256: 68f077a2ab9354313979db9a0e12c60e8791bdaa8eb2d4d039d589546175cdc4

Contents?: true

Size: 1.19 KB

Versions: 23

Compression:

Stored size: 1.19 KB

Contents

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 apply
      assign_order_attributes
      assign_payments_attributes

      if order.save
        order.set_shipments_cost if order.shipments.any?
        true
      else
        false
      end
    end

    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

23 entries across 23 versions & 1 rubygems

Version Path
solidus_core-2.0.2 app/models/spree/order_update_attributes.rb
solidus_core-1.4.1 app/models/spree/order_update_attributes.rb
solidus_core-2.1.0 app/models/spree/order_update_attributes.rb
solidus_core-2.1.0.rc1 app/models/spree/order_update_attributes.rb
solidus_core-2.0.1 app/models/spree/order_update_attributes.rb
solidus_core-2.1.0.beta1 app/models/spree/order_update_attributes.rb
solidus_core-2.0.0 app/models/spree/order_update_attributes.rb
solidus_core-1.4.0 app/models/spree/order_update_attributes.rb
solidus_core-2.0.0.rc1 app/models/spree/order_update_attributes.rb
solidus_core-1.4.0.rc1 app/models/spree/order_update_attributes.rb
solidus_core-2.0.0.beta1 app/models/spree/order_update_attributes.rb
solidus_core-1.4.0.beta1 app/models/spree/order_update_attributes.rb
solidus_core-1.3.1 app/models/spree/order_update_attributes.rb
solidus_core-1.3.0 app/models/spree/order_update_attributes.rb
solidus_core-1.3.0.rc2 app/models/spree/order_update_attributes.rb
solidus_core-1.3.0.rc1 app/models/spree/order_update_attributes.rb
solidus_core-1.3.0.beta1 app/models/spree/order_update_attributes.rb
solidus_core-1.2.2 app/models/spree/order_update_attributes.rb
solidus_core-1.2.1 app/models/spree/order_update_attributes.rb
solidus_core-1.2.0 app/models/spree/order_update_attributes.rb