Class: Gemgento::Magento::ShipmentItemAdapter

Inherits:
Object
  • Object
show all
Defined in:
app/adapters/gemgento/magento/shipment_item_adapter.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(source, shipment = nil) ⇒ ShipmentItemAdapter

Returns a new instance of ShipmentItemAdapter.

Parameters:



8
9
10
11
# File 'app/adapters/gemgento/magento/shipment_item_adapter.rb', line 8

def initialize(source, shipment = nil)
  @source = source
  @shipment = shipment
end

Instance Attribute Details

#shipmentGemgento::Shipment

Returns:



29
30
31
# File 'app/adapters/gemgento/magento/shipment_item_adapter.rb', line 29

def shipment
  @shipment
end

#sourceObject

Returns the value of attribute source.



4
5
6
# File 'app/adapters/gemgento/magento/shipment_item_adapter.rb', line 4

def source
  @source
end

Instance Method Details

#importGemgento::ShipmentItemAdapter

Returns:

  • (Gemgento::ShipmentItemAdapter)


14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'app/adapters/gemgento/magento/shipment_item_adapter.rb', line 14

def import
  shipment_item = Gemgento::ShipmentItem.find_or_initialize_by(magento_id: self.source[:item_id])
  shipment_item.shipment = self.shipment
  shipment_item.line_item = self.order.line_items.find_by!(magento_id: self.source[:order_item_id])
  shipment_item.sku = self.source[:sku]
  shipment_item.name = self.source[:name]
  shipment_item.weight = self.source[:weight]
  shipment_item.price = self.source[:price]
  shipment_item.quantity = self.source[:qty]
  shipment_item.save!

  return shipment_item
end

#orderGemgento::Order

Returns:



34
35
36
# File 'app/adapters/gemgento/magento/shipment_item_adapter.rb', line 34

def order
  @order ||= self.shipment.order
end