-
Notifications
You must be signed in to change notification settings - Fork 474
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add save, update_tracking, and cancel actions to FulfillmentOrderFulfillment resource #639
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,5 +9,39 @@ def order_id | |
def cancel; load_attributes_from_response(post(:cancel, {}, only_id)); end | ||
def complete; load_attributes_from_response(post(:complete, {}, only_id)); end | ||
def open; load_attributes_from_response(post(:open, {}, only_id)); end | ||
|
||
def order_id=(order_id) | ||
prefix_options[:order_id] = order_id | ||
end | ||
|
||
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 | ||
|
||
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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this a way of migrating fulfillments? Why are you doing this? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We do this not for any sort of migration but because we have different endpoints with different supported operations. We have this situation because the backend has two REST paths for fulfillments, the existing pre-FulfillmentOrder one at |
||
load(fulfillmentV2.attributes, false, true) | ||
result | ||
end | ||
end | ||
|
||
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 | ||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
module ShopifyAPI | ||
class FulfillmentV2 < Base | ||
self.element_name = 'fulfillment' | ||
|
||
def update_tracking(tracking_info:, notify_customer:) | ||
body = { | ||
fulfillment: { | ||
tracking_info: tracking_info, | ||
notify_customer: notify_customer | ||
} | ||
} | ||
load_attributes_from_response(post(:update_tracking, {}, body.to_json)) | ||
end | ||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
require 'test_helper' | ||
|
||
class FulfillmentV2Test < Test::Unit::TestCase | ||
context "FulfillmentV2" do | ||
context "#update_tracking" do | ||
should "be able to update tracking info for a fulfillment" do | ||
tracking_info = { | ||
number: 'JSDHFHAG', | ||
url: 'https://example.com/fulfillment_tracking/JSDHFHAG', | ||
company: 'ACME co', | ||
} | ||
fake_fulfillment = ActiveSupport::JSON.decode(load_fixture('fulfillment'))['fulfillment'] | ||
fake_fulfillment['tracking_number'] = tracking_info[:number] | ||
fake_fulfillment['tracking_numbers'] = [tracking_info[:number]] | ||
fake_fulfillment['tracking_url'] = tracking_info[:url] | ||
fake_fulfillment['tracking_urls'] = [tracking_info[:url]] | ||
fake_fulfillment['tracking_company'] = tracking_info[:company] | ||
|
||
request_body = { | ||
fulfillment: { | ||
tracking_info: tracking_info, | ||
notify_customer: true | ||
} | ||
} | ||
fake "fulfillments/#{fake_fulfillment['id']}/update_tracking", method: :post, | ||
request_body: ActiveSupport::JSON.encode(request_body), | ||
body: ActiveSupport::JSON.encode(fulfillment: fake_fulfillment) | ||
|
||
fulfillment = ShopifyAPI::FulfillmentV2.new(id: fake_fulfillment['id']) | ||
assert fulfillment.update_tracking(tracking_info: tracking_info, notify_customer: true) | ||
|
||
assert_equal tracking_info[:number], fulfillment.tracking_number | ||
assert_equal [tracking_info[:number]], fulfillment.tracking_numbers | ||
assert_equal tracking_info[:url], fulfillment.tracking_url | ||
assert_equal [tracking_info[:url]], fulfillment.tracking_urls | ||
assert_equal tracking_info[:company], fulfillment.tracking_company | ||
end | ||
end | ||
end | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We still need to support the ability to create fulfillments using the old endpoint, as well as the new fulfillment create:
We can do so by inspecting the passed in params and deciding if the client intended to use the legacy/new endpoint.