Class: ShopifyAPI::Fulfillment

Inherits:
Base
  • Object
show all
Defined in:
lib/shopify_api/resources/fulfillment.rb

Instance Method Summary collapse

Methods inherited from Base

activate_session, api_version, api_version=, #as_json, clear_session, early_july_pagination?, #encode, headers, init_prefix, init_prefix_explicit, #persisted?, prefix, prefix=, prefix_source, resource_prefix, resource_prefix=, version_validation!

Methods included from Countable

#count

Instance Method Details

#cancelObject


9
# File 'lib/shopify_api/resources/fulfillment.rb', line 9

def cancel; load_attributes_from_response(post(:cancel, {}, only_id)); end

#completeObject


10
# File 'lib/shopify_api/resources/fulfillment.rb', line 10

def complete; load_attributes_from_response(post(:complete, {}, only_id)); end

#load(attributes, remove_root = false, persisted = false) ⇒ Object


17
18
19
20
21
# File 'lib/shopify_api/resources/fulfillment.rb', line 17

def load(attributes, remove_root = false, persisted = false)
  order_id = attributes['order_id']
  prefix_options[:order_id] = order_id if order_id
  super(attributes, remove_root, persisted)
end

#openObject


11
# File 'lib/shopify_api/resources/fulfillment.rb', line 11

def open; load_attributes_from_response(post(:open, {}, only_id)); end

#order_idObject


5
6
7
# File 'lib/shopify_api/resources/fulfillment.rb', line 5

def order_id
  @prefix_options[:order_id]
end

#order_id=(order_id) ⇒ Object


13
14
15
# File 'lib/shopify_api/resources/fulfillment.rb', line 13

def order_id=(order_id)
  prefix_options[:order_id] = order_id
end

#saveObject


23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/shopify_api/resources/fulfillment.rb', line 23

def save
  if prefix_options[:order_id].present?
    super
  else
    line_items = attributes['line_items_by_fulfillment_order'] || attributes[:line_items_by_fulfillment_order]
    if line_items.blank?
      raise ShopifyAPI::ValidationException,
            "either 'line_items_by_fulfillment_order' or prefix_options[:order_id] is required"
    end

    fulfillmentV2 = FulfillmentV2.new(attributes)
    result = fulfillmentV2.save
    load(fulfillmentV2.attributes, false, true)
    result
  end
end

#update_tracking(tracking_info:, notify_customer:) ⇒ Object


40
41
42
43
44
45
# File 'lib/shopify_api/resources/fulfillment.rb', line 40

def update_tracking(tracking_info:, notify_customer:)
  fulfillmentV2 = FulfillmentV2.new(attributes)
  result = fulfillmentV2.update_tracking(tracking_info: tracking_info, notify_customer: notify_customer)
  load(fulfillmentV2.attributes, false, true)
  result
end