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
1 change: 1 addition & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
- Add FulfillmentEvent resource ([#454](https://github.com/Shopify/shopify_python_api/pull/454))
- Fix for being unable to get the len() of a filter ([#456](https://github.com/Shopify/shopify_python_api/pull/456))
- Add ApplicationCredit resource ([#457](https://github.com/Shopify/shopify_python_api/pull/457))
- Add support for retrieving all orders using customer_id ([#466](https://github.com/Shopify/shopify_python_api/pull/466))

== Version 8.2.0
- [Feature] Add support for Dynamic API Versioning. When the library is initialized, it will now make a request to
Expand Down
4 changes: 4 additions & 0 deletions shopify/resources/customer.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from ..base import ShopifyResource
from shopify import mixins
from .customer_invite import CustomerInvite
from .order import Order


class Customer(ShopifyResource, mixins.Metafields):
Expand All @@ -24,3 +25,6 @@ def search(cls, **kwargs):
def send_invite(self, customer_invite=CustomerInvite()):
resource = self.post("send_invite", customer_invite.encode())
return CustomerInvite(Customer.format.decode(resource.body))

def orders(self):
return Order.find(customer_id=self.id)
9 changes: 9 additions & 0 deletions shopify/resources/order.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,15 @@


class Order(ShopifyResource, mixins.Metafields, mixins.Events):
_prefix_source = "/customers/$customer_id/"

@classmethod
def _prefix(cls, options={}):
customer_id = options.get("customer_id")
if customer_id:
return "%s/customers/%s" % (cls.site, customer_id)
else:
return cls.site

def close(self):
self._load_attributes_from_response(self.post("close"))
Expand Down
9 changes: 9 additions & 0 deletions test/customer_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,12 @@ def test_send_invite_with_params(self):
self.assertEqual(customer_invite, json.loads(self.http.request.data.decode("utf-8")))
self.assertIsInstance(customer_invite_response, shopify.CustomerInvite)
self.assertEqual(customer_invite['customer_invite']['to'], customer_invite_response.to)

def test_get_customer_orders(self):
self.fake('customers/207119551', method='GET', body=self.load_fixture('customer'))
customer = shopify.Customer.find(207119551)
self.fake('customers/207119551/orders', method='GET', body=self.load_fixture('orders'))
orders = customer.orders()
self.assertIsInstance(orders[0], shopify.Order)
self.assertEqual(450789469, orders[0].id)
self.assertEqual(207119551, orders[0].customer.id)
206 changes: 206 additions & 0 deletions test/fixtures/orders.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,206 @@
{
"orders": [
{
"id": 450789469,
"email": "bob.norman@hostmail.com",
"closed_at": null,
"created_at": "2008-01-10T11:00:00-05:00",
"updated_at": "2008-01-10T11:00:00-05:00",
"number": 1,
"note": null,
"token": "b1946ac92492d2347c6235b4d2611184",
"gateway": "authorize_net",
"test": false,
"total_price": "598.94",
"subtotal_price": "597.00",
"total_weight": 0,
"total_tax": "11.94",
"taxes_included": false,
"currency": "USD",
"financial_status": "partially_refunded",
"confirmed": true,
"total_discounts": "10.00",
"total_line_items_price": "597.00",
"cart_token": "68778783ad298f1c80c3bafcddeea02f",
"buyer_accepts_marketing": false,
"name": "#1001",
"referring_site": "http://www.otherexample.com",
"landing_site": "http://www.example.com?source=abc",
"cancelled_at": null,
"cancel_reason": null,
"total_price_usd": "598.94",
"checkout_token": "bd5a8aa1ecd019dd3520ff791ee3a24c",
"reference": "fhwdgads",
"user_id": null,
"location_id": null,
"source_identifier": "fhwdgads",
"source_url": null,
"processed_at": "2008-01-10T11:00:00-05:00",
"device_id": null,
"phone": "+557734881234",
"customer_locale": null,
"app_id": null,
"browser_ip": "0.0.0.0",
"client_details": {
"accept_language": null,
"browser_height": null,
"browser_ip": "0.0.0.0",
"browser_width": null,
"session_hash": null,
"user_agent": null
},
"landing_site_ref": "abc",
"order_number": 1001,
"payment_details": {
"credit_card_number": "•••• •••• •••• 4242",
"credit_card_company": "Visa"
},
"payment_gateway_names": [
"bogus"
],
"tags": "",
"contact_email": "bob.norman@hostmail.com",
"order_status_url": "https://apple.myshopify.com/690933842/orders/b1946ac92492d2347c6235b4d2611184/authenticate?key=ccde591a93123786bd8d257abd970200",
"presentment_currency": "USD",
"total_line_items_price_set": {
"shop_money": {
"amount": "597.00",
"currency_code": "USD"
},
"presentment_money": {
"amount": "597.00",
"currency_code": "USD"
}
},
"total_discounts_set": {
"shop_money": {
"amount": "10.00",
"currency_code": "USD"
},
"presentment_money": {
"amount": "10.00",
"currency_code": "USD"
}
},
"total_shipping_price_set": {
"shop_money": {
"amount": "0.00",
"currency_code": "USD"
},
"presentment_money": {
"amount": "0.00",
"currency_code": "USD"
}
},
"subtotal_price_set": {
"shop_money": {
"amount": "597.00",
"currency_code": "USD"
},
"presentment_money": {
"amount": "597.00",
"currency_code": "USD"
}
},
"total_price_set": {
"shop_money": {
"amount": "598.94",
"currency_code": "USD"
},
"presentment_money": {
"amount": "598.94",
"currency_code": "USD"
}
},
"total_tax_set": {
"shop_money": {
"amount": "11.94",
"currency_code": "USD"
},
"presentment_money": {
"amount": "11.94",
"currency_code": "USD"
}
},
"admin_graphql_api_id": "gid://shopify/Order/450789469",
"billing_address": {
"first_name": "Bob",
"address1": "Chestnut Street 92",
"phone": "555-625-1199",
"city": "Louisville",
"zip": "40202",
"province": "Kentucky",
"country": "United States",
"last_name": "Norman",
"address2": "",
"company": null,
"latitude": 45.41634,
"longitude": -75.6868,
"name": "Bob Norman",
"country_code": "US",
"province_code": "KY"
},
"shipping_address": {
"first_name": "Bob",
"address1": "Chestnut Street 92",
"phone": "555-625-1199",
"city": "Louisville",
"zip": "40202",
"province": "Kentucky",
"country": "United States",
"last_name": "Norman",
"address2": "",
"company": null,
"latitude": 45.41634,
"longitude": -75.6868,
"name": "Bob Norman",
"country_code": "US",
"province_code": "KY"
},
"customer": {
"id": 207119551,
"email": "bob.norman@hostmail.com",
"accepts_marketing": false,
"created_at": "2021-02-12T13:51:00-05:00",
"updated_at": "2021-02-12T13:51:00-05:00",
"first_name": "Bob",
"last_name": "Norman",
"orders_count": 1,
"state": "disabled",
"total_spent": "199.65",
"last_order_id": 450789469,
"note": null,
"verified_email": true,
"multipass_identifier": null,
"tax_exempt": false,
"phone": "+16136120707",
"tags": "",
"last_order_name": "#1001",
"currency": "USD",
"accepts_marketing_updated_at": "2005-06-12T11:57:11-04:00",
"marketing_opt_in_level": null,
"tax_exemptions": [],
"admin_graphql_api_id": "gid://shopify/Customer/207119551",
"default_address": {
"id": 207119551,
"customer_id": 207119551,
"first_name": null,
"last_name": null,
"company": null,
"address1": "Chestnut Street 92",
"address2": "",
"city": "Louisville",
"province": "Kentucky",
"country": "United States",
"zip": "40202",
"phone": "555-625-1199",
"name": "",
"province_code": "KY",
"country_code": "US",
"country_name": "United States",
"default": true
}
}
}
]
}
7 changes: 7 additions & 0 deletions test/order_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,10 @@ def test_get_order_transaction(self):
self.fake('orders/450789469/transactions', method='GET', body=self.load_fixture('transactions'))
transactions = order.transactions()
self.assertEqual("409.94", transactions[0].amount)

def test_get_customer_orders(self):
self.fake("customers/207119551/orders", method='GET', body=self.load_fixture('orders'), code=200)
orders = shopify.Order.find(customer_id=207119551)
self.assertIsInstance(orders[0], shopify.Order)
self.assertEqual(450789469, orders[0].id)
self.assertEqual(207119551, orders[0].customer.id)