Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
5a74c2bae8 | ||
|
|
d7f1571e09 | ||
|
|
f18e21f181 | ||
|
|
d56cf589da |
@@ -1,32 +0,0 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"flag"
|
||||
"log"
|
||||
|
||||
"github.com/debyltech/go-snipcart/snipcart"
|
||||
)
|
||||
|
||||
func main() {
|
||||
snipcartApiKey := flag.String("key", "", "Snipcart API Key")
|
||||
flag.Parse()
|
||||
|
||||
if *snipcartApiKey == "" {
|
||||
log.Fatal("missing -key flag")
|
||||
}
|
||||
|
||||
Client := snipcart.NewClient(*snipcartApiKey)
|
||||
|
||||
updateOrder := snipcart.SnipcartOrderUpdate{
|
||||
Status: snipcart.Delivered,
|
||||
}
|
||||
|
||||
response, err := Client.UpdateOrder("b35990df-c0ca-4014-94de-1caa7bd7bb51", &updateOrder)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
for k, v := range response.Items {
|
||||
log.Printf("%v: %v\n", k, v)
|
||||
}
|
||||
}
|
||||
@@ -127,6 +127,18 @@ type SnipcartProductVariant struct {
|
||||
AllowBackorder bool `json:"allowOutOfStockPurchases"`
|
||||
}
|
||||
|
||||
type SnipcartProductCustomField struct {
|
||||
Name string `json:"name"`
|
||||
Placeholder string `json:"placeholder"`
|
||||
DisplayValue string `json:"displayValue"`
|
||||
Type string `json:"type"`
|
||||
Options string `json:"options"`
|
||||
Required bool `json:"required"`
|
||||
Value string `json:"value"`
|
||||
Operation float64 `json:"operation"`
|
||||
OptionsArray []string `json:"optionsArray"`
|
||||
}
|
||||
|
||||
type SnipcartProduct struct {
|
||||
Token string `json:"id"`
|
||||
Id string `json:"userDefinedId"`
|
||||
@@ -134,6 +146,7 @@ type SnipcartProduct struct {
|
||||
Stock int `json:"stock"`
|
||||
TotalStock int `json:"totalStock"`
|
||||
AllowBackorder bool `json:"allowOutOfStockPurchases"`
|
||||
CustomFields []SnipcartProductCustomField `json:"customFields"`
|
||||
Variants []SnipcartProductVariant `json:"variants"`
|
||||
}
|
||||
|
||||
@@ -308,11 +321,15 @@ func (s *Client) GetProductById(id string) (*SnipcartProduct, error) {
|
||||
|
||||
defer response.Body.Close()
|
||||
|
||||
var product SnipcartProduct
|
||||
err = json.NewDecoder(response.Body).Decode(&product)
|
||||
var products SnipcartProductsResponse
|
||||
err = json.NewDecoder(response.Body).Decode(&products)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &product, nil
|
||||
if len(products.Items) < 1 {
|
||||
return nil, fmt.Errorf("no products with id '%s'", id)
|
||||
}
|
||||
|
||||
return &products.Items[0], nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user