Class: Workarea::GlobalE::Parcel

Inherits:
Object
  • Object
show all
Defined in:
app/services/workarea/global_e/parcel.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(fulfillment, package) ⇒ Parcel

Returns a new instance of Parcel.



6
7
8
9
# File 'app/services/workarea/global_e/parcel.rb', line 6

def initialize(fulfillment, package)
  @fulfillment = fulfillment
  @package = package
end

Instance Attribute Details

#fulfillmentObject (readonly)

Returns the value of attribute fulfillment.



4
5
6
# File 'app/services/workarea/global_e/parcel.rb', line 4

def fulfillment
  @fulfillment
end

#packageObject (readonly)

Returns the value of attribute package.



4
5
6
# File 'app/services/workarea/global_e/parcel.rb', line 4

def package
  @package
end

Instance Method Details

#as_jsonObject



11
12
13
14
15
16
17
# File 'app/services/workarea/global_e/parcel.rb', line 11

def as_json(*)
  {
    ParcelCode: parcel_code,
    Products: products,
    TrackingDetails: tracking_details
  }
end

#parcel_codeString

Code used to identify the Parcel on the Merchant’s site

Returns:

  • (String)


23
24
25
# File 'app/services/workarea/global_e/parcel.rb', line 23

def parcel_code
  package.tracking_number
end

#productsHash

List of products contained in the parcel (for each Product object the following fields are relevant when used in Parcel class: ProductCode, CartItemId, DeliveryQuantity). Products list is applicable only when including the list of products in each parcel is mandatory (such as in UpdateParcelDispatch method).

Returns:

  • (Hash)


35
36
37
38
39
40
41
42
# File 'app/services/workarea/global_e/parcel.rb', line 35

def products
  @products ||= package.items.map do |fulfillment_item|
    GlobalE::Product.from_order_item(
      fulfillment_item,
      delivery_quantity: fulfillment_item.quantity
    ).as_json.slice(:CartItemId, :DeliveryQuantity, :ProductCode)
  end
end

#tracking_detailsWorkarea::GlobalE::TrackingDetails

Tracking information about the order/parcel.



48
49
50
# File 'app/services/workarea/global_e/parcel.rb', line 48

def tracking_details
  TrackingDetails.new(tracking_number: package.tracking_number)
end