Skip to content

Commit f0b180a

Browse files
committed
Fix order listing bug
In typical Shopify fashion they now require an explicit status to be provided. They claim it defaults to open but without an explicit status nothing is returned, even when an ID is given! We also add the -s option to specify a status filter
1 parent bbc5c8f commit f0b180a

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

cmd/orders/orders.go

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ var Cmd cli.Command
1616
type listOrdersOptions struct {
1717
Ids []int64 `url:"ids,comma,omitempty"`
1818
CreatedAtMin time.Time `url:"created_at_min,omitempty"`
19+
Status string `url:"status,omitempty"`
1920
}
2021

2122
func userAgentAction(c *cli.Context) error {
@@ -48,8 +49,7 @@ func userAgentAction(c *cli.Context) error {
4849
}
4950

5051
func listAction(c *cli.Context) error {
51-
var options listOrdersOptions
52-
52+
options := listOrdersOptions{Status: "open"}
5353

5454
if c.NArg() > 0 {
5555
for i := 0; i < c.NArg(); i++ {
@@ -63,6 +63,10 @@ func listAction(c *cli.Context) error {
6363

6464
}
6565

66+
if len(c.String("status")) > 0 {
67+
options.Status = c.String("status")
68+
}
69+
6670
orders, err := cmd.NewShopifyClient(c).Order.List(options)
6771
if err != nil {
6872
return fmt.Errorf("Cannot list orders: %s", err)
@@ -139,10 +143,19 @@ func printLineItems(lines []shopify.LineItem) {
139143
}
140144

141145
func init() {
146+
ordersFlags := []cli.Flag{
147+
&cli.StringFlag{
148+
Name: "status",
149+
Aliases: []string{"s"},
150+
Usage: "Orders status to filter, defaults to 'open'",
151+
},
152+
}
153+
142154
Cmd = cli.Command{
143155
Name: "orders",
144156
Aliases: []string{"o"},
145157
Usage: "Information about orders",
158+
146159
Subcommands: []*cli.Command{
147160
{
148161
Name: "useragent",
@@ -154,7 +167,7 @@ func init() {
154167
{
155168
Name: "ls",
156169
Usage: "List the shop's orders or the orders given by the specified IDs",
157-
Flags: cmd.Flags,
170+
Flags: append(cmd.Flags, ordersFlags...),
158171
Action: listAction,
159172
},
160173
},

0 commit comments

Comments
 (0)