diff --git a/order.go b/order.go index 7de0eda8..f14fd997 100644 --- a/order.go +++ b/order.go @@ -18,6 +18,7 @@ type OrderService interface { Count(interface{}) (int, error) Get(int, interface{}) (*Order, error) Create(Order) (*Order, error) + Update(Order) (*Order, error) // MetafieldsService used for Order resource to communicate with Metafields resource MetafieldsService @@ -314,6 +315,15 @@ func (s *OrderServiceOp) Create(order Order) (*Order, error) { return resource.Order, err } +// Update order +func (s *OrderServiceOp) Update(order Order) (*Order, error) { + path := fmt.Sprintf("%s/%d.json", ordersBasePath, order.ID) + wrappedData := OrderResource{Order: &order} + resource := new(OrderResource) + err := s.client.Put(path, wrappedData, resource) + return resource.Order, err +} + // List metafields for an order func (s *OrderServiceOp) ListMetafields(orderID int, options interface{}) ([]Metafield, error) { metafieldService := &MetafieldServiceOp{client: s.client, resource: ordersResourceName, resourceID: orderID} diff --git a/order_test.go b/order_test.go index 9dbb360b..05b62c48 100644 --- a/order_test.go +++ b/order_test.go @@ -223,6 +223,30 @@ func TestOrderCreate(t *testing.T) { } } +func TestOrderUpdate(t *testing.T) { + setup() + defer teardown() + + httpmock.RegisterResponder("PUT", "https://fooshop.myshopify.com/admin/orders/1.json", + httpmock.NewStringResponder(201, `{"order":{"id": 1}}`)) + + order := Order{ + ID: 1, + FinancialStatus: "paid", + FulfillmentStatus: "fulfilled", + } + + o, err := client.Order.Update(order) + if err != nil { + t.Errorf("Order.Update returned error: %v", err) + } + + expected := Order{ID: 1} + if o.ID != expected.ID { + t.Errorf("Order.Update returned id %d, expected %d", o.ID, expected.ID) + } +} + func TestOrderListMetafields(t *testing.T) { setup() defer teardown()