Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d7f1571e09 | ||
|
|
f18e21f181 |
@@ -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 int `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"`
|
||||
}
|
||||
|
||||
@@ -297,7 +310,7 @@ func (s *Client) GetProducts(queries map[string]string) (*SnipcartProductsRespon
|
||||
return &products, nil
|
||||
}
|
||||
|
||||
func (s *Client) GetProductById(id string) (*SnipcartProductsResponse, error) {
|
||||
func (s *Client) GetProductById(id string) (*SnipcartProduct, error) {
|
||||
response, err := helper.Get(productsUri, "Basic", s.AuthBase64, map[string]string{"userDefinedId": id})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -314,5 +327,9 @@ func (s *Client) GetProductById(id string) (*SnipcartProductsResponse, error) {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &products, 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