Skip to content
This repository was archived by the owner on Oct 6, 2026. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
- Added support for Fulfillment.update_tracking ([#432](https://github.com/Shopify/shopify_python_api/pull/432))

== Version 8.2.0
- [Feature] Add support for Dynamic API Versioning. When the library is initialized, it will now make a request to
Shopify to fetch a list of the available API versions. ([#441](https://github.com/Shopify/shopify_python_api/pull/441))
Expand Down
19 changes: 19 additions & 0 deletions shopify/resources/fulfillment.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from ..base import ShopifyResource
import json


class Fulfillment(ShopifyResource):
Expand All @@ -13,6 +14,24 @@ def complete(self):
def open(self):
self._load_attributes_from_response(self.post("open"))

def update_tracking(self, tracking_info, notify_customer):
fulfill = FulfillmentV2()
fulfill.id = self.id
self._load_attributes_from_response(fulfill.update_tracking(tracking_info, notify_customer))


class FulfillmentOrders(ShopifyResource):
_prefix_source = "/orders/$order_id/"

class FulfillmentV2(ShopifyResource):

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure I follow the idea of the V2 nomenclature, is there a particular reason we can't just do this in Fulfillment? If the class is absolutely necessary, we might want to consider renaming it to something that better conveys what it does.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't believe we can do it in the original Fulfillment class because that class points to /orders/$order_id/fulfillment/$fulfillment_id, and the endpoint in this case is only fulfillment/$fulfillment_id. I would also prefer to do it in 1 class, but I'm not quite sure how..
The V2 nomenclature is from shopify_api (that is used by Fulfillment.rb) in a similar manner. Thought I would keep it consistent between the two libs

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All of that makes perfect sense, thanks for the context! I'm still not a fan of calling it V2 but I agree we should keep them consistent.

Not saying we should do this, but I wonder if it wouldn't be cleaner to change _prefix_source for that particular method rather than adding a whole new class for it.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried manipulating _prefix_source but wasn't successful with my attempt. I do believe the convention of changing prefixes is to override the classmethod _prefix depending on passed in options, but in this case the usage is after we define a Fulfillment object already :/
Thus new class

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nothing wrong with this approach, I was just thinking aloud there!

_singular = 'fulfillment'
_plural = 'fulfillments'

def update_tracking(self, tracking_info, notify_customer):
body = {
"fulfillment": {
"tracking_info": tracking_info,
"notify_customer": notify_customer
}
}
return self.post("update_tracking", json.dumps(body).encode())
4 changes: 2 additions & 2 deletions test/fixtures/fulfillment.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"order_id": 450789469,
"service": "manual",
"status": "pending",
"tracking_company": null,
"tracking_company": "null-company",
"updated_at": "2013-11-01T16:06:08-04:00",
"tracking_number": "1Z2345",
"tracking_numbers": [
Expand Down Expand Up @@ -46,4 +46,4 @@
}
]
}
}
}
23 changes: 22 additions & 1 deletion test/fulfillment_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from pyactiveresource.activeresource import ActiveResource

class FulFillmentTest(TestCase):

def setUp(self):
super(FulFillmentTest, self).setUp()
self.fake("orders/450789469/fulfillments/255858046", method='GET', body=self.load_fixture('fulfillment'))
Expand Down Expand Up @@ -40,3 +40,24 @@ def test_able_to_cancel_fulfillment(self):
self.assertEqual('pending', fulfillment.status)
fulfillment.cancel()
self.assertEqual('cancelled', fulfillment.status)

def test_update_tracking(self):
fulfillment = shopify.Fulfillment.find(255858046, order_id=450789469)

tracking_info = { "number": 1111, "url": "http://www.my-url.com", "company": "my-company"}
notify_customer = False

update_tracking = self.load_fixture('fulfillment')
update_tracking = update_tracking.replace(b'null-company', b'my-company')
update_tracking = update_tracking.replace(b'http://www.google.com/search?q=1Z2345', b'http://www.my-url.com')
update_tracking = update_tracking.replace(b'1Z2345', b'1111')

self.fake("fulfillments/255858046/update_tracking", method="POST", headers={'Content-type': 'application/json'}, body=update_tracking)

self.assertEqual("null-company", fulfillment.tracking_company)
self.assertEqual("1Z2345", fulfillment.tracking_number)
self.assertEqual("http://www.google.com/search?q=1Z2345", fulfillment.tracking_url)
fulfillment.update_tracking(tracking_info, notify_customer)
self.assertEqual("my-company", fulfillment.tracking_company)
self.assertEqual('1111', fulfillment.tracking_number)
self.assertEqual('http://www.my-url.com', fulfillment.tracking_url)