Class: SolidusBacktracs::Api::ShipmentSerializer

Inherits:
Object
  • Object
show all
Defined in:
lib/solidus_backtracs/api/shipment_serializer.rb

Instance Method Summary collapse

Constructor Details

#initialize(shipment:) ⇒ ShipmentSerializer

Returns a new instance of ShipmentSerializer.



7
8
9
10
11
# File 'lib/solidus_backtracs/api/shipment_serializer.rb', line 7

def initialize(shipment:)
  @shipment = shipment
  @config = SolidusBacktracs.config
  @property_id = ::Spree::Property.find_by(name: SolidusBacktracs.config.default_property_name)&.id
end

Instance Method Details

#call(sguid: nil) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/solidus_backtracs/api/shipment_serializer.rb', line 13

def call(sguid: nil)
  order = @shipment.order
  user = @shipment.user

  xml = Builder::XmlMarkup.new 
  xml.instruct!(:xml, :encoding => "UTF-8")

  xml.soap(:Envelope, {"xmlns:xsi" => "http://www.w3.org/2001/XMLSchema-instance", "xmlns:xsd" => "http://www.w3.org/2001/XMLSchema", "xmlns:soap" => "http://schemas.xmlsoap.org/soap/envelope/"}) do
    xml.soap :Body do
      xml.CreateNew({"xmlns" => "http://bactracs.andlor.com/rmaservice"}) do
        xml.sGuid                       sguid
        xml.NewRMA {
          xml.RMANumber                 @shipment.number
          xml.RMATypeName               @config.default_rma_type
          xml.RMASubTypeName            
          xml.CustomerRef               
          xml.InboundShippingPriority   
          xml.InboundTrackingNumber     @shipment.tracking

          xml.Ship {
            xml.Carrier                 @config.default_carrier
            xml.ShipMethod              @config.default_ship_method
            xml.ShipDate                @shipment.created_at.strftime(SolidusBacktracs::ExportHelper::BACTRACS_DATE_FORMAT)
            xml.TrackingNumber          @shipment.tracking
            xml.SerialNumber            @shipment.number
            xml.Ud1                     
          }
          xml.Customer {
            SolidusBacktracs::ExportHelper.backtracs_address(xml, order, :ship)
            SolidusBacktracs::ExportHelper.backtracs_address(xml, order, :bill)
          }
          xml.Rep {
            xml.Code                    
            xml.Name                    user.full_name
            xml.Email                   user.email
          }        

          xml.RMALines {
            @shipment.line_items.each do |line|
              product = line.product
              if product.respond_to?(:assembly?) && product.assembly?
                product.parts.each do |part|
                  next unless part.product.product_properties.where(property_id: @property_id).present?
                  line_items_xml(xml: xml, line_item: line, variant: part, order: order)
                end
              else
                line_items_xml(xml: xml, line_item: line, variant: line.variant, order: order)
              end
            end
          }
          xml.OrderDate     order.completed_at.strftime(SolidusBacktracs::ExportHelper::BACTRACS_DATE_FORMAT)
          xml.CreateDate    @shipment.created_at.strftime(SolidusBacktracs::ExportHelper::BACTRACS_DATE_FORMAT)
          xml.Status        @config.default_status
          xml.RMAId         @shipment.id
          xml.ClientGuid
        }
      end
    end 
  end
  xml
end

#find_sku_variant(variant) ⇒ Object



98
99
100
# File 'lib/solidus_backtracs/api/shipment_serializer.rb', line 98

def find_sku_variant(variant)
  @config.sku_map[variant.sku].present? ? @config.sku_map[variant.sku] : variant.sku
end

#line_items_xml(xml: nil, line_item: nil, variant: nil, order: nil) ⇒ Object



75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
# File 'lib/solidus_backtracs/api/shipment_serializer.rb', line 75

def line_items_xml(xml: nil, line_item: nil, variant: nil, order: nil)
  shipment_notice = @shipment.shipment_notice        
  xml.RMALine {
    xml.DFItem                  find_sku_variant(variant)
    xml.DFModelNum              find_sku_variant(variant)
    xml.DFCategory              
    xml.DFCategoryDescription   
    xml.DFQuantity              line_item.quantity
    xml.DFUnitPrice             line_item.price
    xml.DFSerialNumbers         
    xml.Ud1s                    
    xml.CurrentWarranties       
    xml.DFComments              
    xml.DFStatus                @shipment.state
    xml.PurchaseDate            order.completed_at.strftime(SolidusBacktracs::ExportHelper::BACTRACS_DATE_FORMAT)
    xml.ServiceProvider         shipment_notice&.service
    xml.WarrantyRepair          
    xml.RMALineTest             
    xml.InboundShipWeight       variant.weight.to_f
    xml.RPLocation              @config.default_rp_location
  } 
end