Skip to content

Commit

Permalink
Merge pull request #45 from jjideenschmiede/development
Browse files Browse the repository at this point in the history
feat: Add function to delete image.
  • Loading branch information
gowizzard authored Feb 29, 2024
2 parents 2dffaae + 41478f0 commit cbdd359
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
18 changes: 18 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,24 @@ if err != nil {
}
```

## Delete a product image

If you want to remove an image from a product, you can do so using the following function. You need the ID of the product and the ID of the image.

```go
// Define request
r := goshopify.Request{
StoreName: "",
AccessToken: "",
}

// Delete product image
err := goshopify.DeleteProductImage(7384409964728, 43713916108984, r)
if err != nil {
fmt.Println(err)
}
```

## Get a list of metafields for a product

If you want to read out all metafields of a product, you can do this as follows. You need the ID of the product.
Expand Down
20 changes: 20 additions & 0 deletions product_image.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ type ProductImageBody struct {
}

type ProductImageBodyImage struct {
Id int `json:"id,omitempty"`
Position int `json:"position,omitempty"`
Src string `json:"src"`
Alt string `json:"alt,omitempty"`
Expand Down Expand Up @@ -71,3 +72,22 @@ func AddProductImage(id int, body ProductImageBody, r Request) (ProductImageRetu
return decode, err

}

// DeleteProductImage is to delete an image of a product
func DeleteProductImage(productId, imageId int, r Request) error {

// Set config for new request
c := Config{fmt.Sprintf("/products/%d/images/%d.json", productId, imageId), http.MethodDelete, nil}

// Send request
response, err := c.Send(r)
if err != nil {
return err
}

// Close request
defer response.Body.Close()

// Return nothing
return nil
}

0 comments on commit cbdd359

Please sign in to comment.