Sha256: 3280e5f30f175b068e119db4e25c9d01928f4445d4ec86f0c27785f33d6f76a5

Contents?: true

Size: 1.25 KB

Versions: 15

Compression:

Stored size: 1.25 KB

Contents

module Spree
  class ShipmentHandler
    class << self
      def factory(shipment)
        # Do we have a specialized shipping-method-specific handler? e.g:
        # Given shipment.shipping_method = Spree::ShippingMethod::DigitalDownload
        # do we have Spree::ShipmentHandler::DigitalDownload?
        if sm_handler = "Spree::ShipmentHandler::#{shipment.shipping_method.name.split('::').last}".constantize rescue false
          sm_handler.new(shipment)
        else
          new(shipment)
        end
      end
    end

    def initialize(shipment)
      @shipment = shipment
    end

    def perform
      @shipment.inventory_units.each &:ship!
      @shipment.process_order_payments if Spree::Config[:auto_capture_on_dispatch]
      send_shipped_email
      @shipment.touch :shipped_at
      update_order_shipment_state
    end

    private
      def send_shipped_email
        ShipmentMailer.shipped_email(@shipment.id).deliver_later
      end

      def update_order_shipment_state
        order = @shipment.order

        new_state = OrderUpdater.new(order).update_shipment_state
        order.update_columns(
                             shipment_state: new_state,
                             updated_at: Time.now,
                             )
      end
  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
spree_core-3.0.10 app/models/spree/shipment_handler.rb
spree_core-3.0.9 app/models/spree/shipment_handler.rb
spree_core-3.0.8 app/models/spree/shipment_handler.rb
spree_core-3.0.7 app/models/spree/shipment_handler.rb
spree_core-3.0.6.1 app/models/spree/shipment_handler.rb
spree_core-3.0.6 app/models/spree/shipment_handler.rb
spree_core-3.0.5 app/models/spree/shipment_handler.rb
spree_core-3.0.4 app/models/spree/shipment_handler.rb
spree_core-3.0.3 app/models/spree/shipment_handler.rb
spree_core-3.0.2 app/models/spree/shipment_handler.rb
spree_core-3.0.1 app/models/spree/shipment_handler.rb
spree_core-3.0.0 app/models/spree/shipment_handler.rb
spree_core-3.0.0.rc4 app/models/spree/shipment_handler.rb
spree_core-3.0.0.rc3 app/models/spree/shipment_handler.rb
spree_core-3.0.0.rc1 app/models/spree/shipment_handler.rb