Sha256: e275d83f2f5c2afdfc4040f0937cfaccaa40841c9f15721c2c313dfc20d5cffc

Contents?: true

Size: 861 Bytes

Versions: 1

Compression:

Stored size: 861 Bytes

Contents

module Gemgento
  class Magento::ShipmentTrackAdapter

    attr_accessor :source, :shipment

    # @param source [Hash]
    # @param shipment [Gemgento::Shipment]
    def initialize(source, shipment = nil)
      @source = source
      @shipment = shipment
    end

    # @return [Gemgento::ShipmentTrackAdapter]
    def import
      shipment_track = Gemgento::ShipmentTrack.find_or_initialize_by(magento_id: self.source[:track_id])
      shipment_track.shipment = self.shipment
      shipment_track.carrier_code = self.source[:carrier_code]
      shipment_track.title = self.source[:title]
      shipment_track.number = self.source[:number]
      shipment_track.save!

      return shipment_track
    end

    # @return [Gemgento::Shipment]
    def shipment
      @shipment ||= Gemgento::Shipment.find_by!(magento_id: self.source[:parent_id])
    end

  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
gemgento-2.8.0 app/adapters/gemgento/magento/shipment_track_adapter.rb