Class: EPlat::Mapping::VirtualCollection::Bigcommerce::OrderLineItems
- Inherits:
-
VirtualCollection::Base
- Object
- VirtualCollection::Base
- EPlat::Mapping::VirtualCollection::Bigcommerce::OrderLineItems
- Defined in:
- lib/e_plat/mapping/virtual_collection/bigcommerce/order_line_items.rb
Instance Attribute Summary collapse
-
#resource ⇒ Object
Returns the value of attribute resource.
Instance Method Summary collapse
-
#initialize(resource:, map_from:) ⇒ OrderLineItems
constructor
will create an array of EPlat::Order::LineItem objects with no proper attributes, only aliases i.e.
- #native_attribute_aliases(i) ⇒ Object
Constructor Details
#initialize(resource:, map_from:) ⇒ OrderLineItems
will create an array of EPlat::Order::LineItem objects with no proper attributes, only aliases i.e. e_plat_key will always be virtual, whilst the native key will point to a proper attributes other resources Order line_items do actually exist in BigCommerce, but they’re in a much deeper level of the JSON that order.line_items Using a virtual collection, allows us to treat the line_items as if they were in the proper position: order.line_items
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/e_plat/mapping/virtual_collection/bigcommerce/order_line_items.rb', line 13 def initialize(resource:, map_from:) @resource = resource super return unless @resource.try :consignments #map_from @resource.line_items = (@resource.consignments[0].try(:shipping).presence || @resource.consignments[0].try(:pickups))&.first&.line_items.map.with_index do |data, i| item = EPlat::Order::LineItem.new(order_id: @resource.id) item.mapping.virtual_collection = self item.add_aliases!(native_attribute_aliases(i), EPlat::Order::LineItem.schema) item end end |
Instance Attribute Details
#resource ⇒ Object
Returns the value of attribute resource.
7 8 9 |
# File 'lib/e_plat/mapping/virtual_collection/bigcommerce/order_line_items.rb', line 7 def resource @resource end |
Instance Method Details
#native_attribute_aliases(i) ⇒ Object
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 74 75 76 77 78 79 80 81 |
# File 'lib/e_plat/mapping/virtual_collection/bigcommerce/order_line_items.rb', line 29 def native_attribute_aliases(i) [ { alias_attribute: { native_key: "[consignments][0][shipping][0][line_items][#{i}][id]", e_plat_key: "id", virtual_collection: true } }, { alias_attribute: { native_key: "[consignments][0][shipping][0][line_items][#{i}][variant_id]", e_plat_key: "variant_id", virtual_collection: true } }, { alias_attribute: { native_key: "[consignments][0][shipping][0][line_items][#{i}][name]", e_plat_key: "name", virtual_collection: true } }, { alias_attribute: { native_key: "[consignments][0][shipping][0][line_items][#{i}][price]", e_plat_key: "price", virtual_collection: true } }, { alias_attribute: { native_key: "[consignments][0][shipping][0][line_items][#{i}][product_id]", e_plat_key: "product_id", virtual_collection: true } }, { alias_attribute: { native_key: "[consignments][0][shipping][0][line_items][#{i}][quantity]", e_plat_key: "quantity", virtual_collection: true } }, { alias_attribute: { native_key: "[consignments][0][shipping][0][line_items][#{i}][sku]", e_plat_key: "sku", virtual_collection: true } }, ] end |