Skip to content

Commit

Permalink
Merge pull request #8 from jjideenschmiede/development
Browse files Browse the repository at this point in the history
Add function to create offers
  • Loading branch information
gowizzard authored Oct 12, 2021
2 parents efb594d + ea06fad commit c6799b4
Show file tree
Hide file tree
Showing 2 changed files with 200 additions and 13 deletions.
76 changes: 76 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,82 @@ if err != nil {
}
```

## Writes an offer

If you want to create a new offer, then this goes as follows. Some attributes are needed for this. You can see them in the following example. [Here](https://import.idealo.com/docs/#_put) you can find the description in the idealo documentation.

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

// Set body
body := OfferBody{
Sku: "21-Lloyd-27-600-12-Hagen-UK6.5-Gr.40",
Title: "Lloyd Men Hagen 27-600-12 Herren Schuhe Derby Schnürer Wildleder Dunkelbraun",
Price: "89.95",
Url: "http://www.shoes4friends.de",
PaymentCosts: OfferBodyPaymentCosts{
PAYPAL: "2.63",
},
DeliveryCosts: OfferBodyDeliveryCosts{
DHL: "0.69",
},
BasePrice: "",
PackagingUnit: 5,
VoucherCode: "",
BranchId: "lloyd",
Brand: "Lloyd",
Oens: nil,
CategoryPath: nil,
Description: "Lloyd Men Hagen 27-600-12 Herren Schuhe Derby Schnürer Wildleder Dunkelbraun",
ImageUrls: nil,
Eans: nil,
Hans: nil,
Pzns: nil,
Kbas: nil,
MerchantName: "",
MerchantId: "",
DeliveryComment: "",
Delivery: "1-3 Werktage",
MaxOrderProcessingTime: 1,
FreeReturnDays: 30,
Checkout: true,
CheckoutLimitPerPeriod: 13,
QuantityPerOrder: 2,
MinimumPrice: "",
FulfillmentType: "",
TwoManHandlingFee: "",
DisposalFee: "",
Eec: "",
EnergyLabels: nil,
Deposit: "",
Size: "",
Colour: "",
Gender: "",
Material: "",
Replica: false,
Used: false,
Download: false,
DynamicProductAttributes: nil,
}

// Add images
body.ImageUrls = append(body.ImageUrls, "https://www.marken-schuhmarkt.de/21-Lloyd-Herren-Schuhe-Derby-Halbschuhe-Wildleder-Hagen-27-600-12-braun-001.jpg")

// Add eans
body.Eans = append(body.Eans, "4032055134146")

// Update the timestamp
offer, err := CreateOffer(325081, body, r)
if err != nil {
fmt.Println(err)
} else {
fmt.Println(offer)
}
```

## Delete an offer

If you want to remove a special offer, you can do this with the following function. For this some attributes like shop id, sku and the access token are needed. [Here](https://import.idealo.com/docs/#_delete) you can find the description in the idealo documentation.
Expand Down
137 changes: 124 additions & 13 deletions offers.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,75 @@ import (
"fmt"
)

// OfferBody is to structure the body data
type OfferBody struct {
Sku string `json:"sku,omitempty"`
Title string `json:"title,omitempty"`
Price string `json:"price,omitempty"`
Url string `json:"url,omitempty"`
PaymentCosts OfferBodyPaymentCosts `json:"paymentCosts,omitempty"`
DeliveryCosts OfferBodyDeliveryCosts `json:"deliveryCosts,omitempty"`
BasePrice string `json:"basePrice,omitempty"`
PackagingUnit int `json:"packagingUnit,omitempty"`
VoucherCode string `json:"voucherCode,omitempty"`
BranchId string `json:"branchId,omitempty"`
Brand string `json:"brand,omitempty"`
Oens []string `json:"oens,omitempty"`
CategoryPath []string `json:"categoryPath,omitempty"`
Description string `json:"description,omitempty"`
ImageUrls []string `json:"imageUrls,omitempty"`
Eans []string `json:"eans,omitempty"`
Hans []string `json:"hans,omitempty"`
Pzns []string `json:"pzns,omitempty"`
Kbas []string `json:"kbas,omitempty"`
MerchantName string `json:"merchantName,omitempty"`
MerchantId string `json:"merchantId,omitempty"`
DeliveryComment string `json:"deliveryComment,omitempty"`
Delivery string `json:"delivery,omitempty"`
MaxOrderProcessingTime int `json:"maxOrderProcessingTime,omitempty"`
FreeReturnDays int `json:"freeReturnDays,omitempty"`
Checkout bool `json:"checkout,omitempty"`
CheckoutLimitPerPeriod int `json:"checkoutLimitPerPeriod,omitempty"`
QuantityPerOrder int `json:"quantityPerOrder,omitempty"`
MinimumPrice string `json:"minimumPrice,omitempty"`
FulfillmentType string `json:"fulfillmentType,omitempty"`
TwoManHandlingFee string `json:"twoManHandlingFee,omitempty"`
DisposalFee string `json:"disposalFee,omitempty"`
Eec string `json:"eec,omitempty"`
EnergyLabels []OfferBodyEnergyLabels `json:"energyLabels,omitempty"`
Deposit string `json:"deposit,omitempty"`
Size string `json:"size,omitempty"`
Colour string `json:"colour,omitempty"`
Gender string `json:"gender,omitempty"`
Material string `json:"material,omitempty"`
Replica bool `json:"replica,omitempty"`
Used bool `json:"used,omitempty"`
Download bool `json:"download,omitempty"`
DynamicProductAttributes interface{} `json:"dynamicProductAttributes,omitempty"`
}

type OfferBodyPaymentCosts struct {
PAYPAL string `json:"PAYPAL,omitempty"`
}

type OfferBodyDeliveryCosts struct {
DHL string `json:"DHL,omitempty"`
}

type OfferBodyEnergyLabels struct {
EfficiencyClass string `json:"efficiencyClass,omitempty"`
Spectrum string `json:"spectrum,omitempty"`
LabelUrl string `json:"labelUrl,omitempty"`
DataSheetUrl string `json:"dataSheetUrl,omitempty"`
FuelEfficiencyClass string `json:"fuelEfficiencyClass,omitempty"`
WetGripClass string `json:"wetGripClass,omitempty"`
ExternalRollingNoise int `json:"externalRollingNoise,omitempty"`
ExternalRollingNoiseClass string `json:"externalRollingNoiseClass,omitempty"`
SnowGrip bool `json:"snowGrip,omitempty"`
IceGrip bool `json:"iceGrip,omitempty"`
Version int `json:"version,omitempty"`
}

// OfferReturn is to decode the json data
type OfferReturn struct {
Sku string `json:"sku"`
Expand Down Expand Up @@ -66,19 +135,16 @@ type OfferReturn struct {
DataSheetUrl string `json:"dataSheetUrl"`
Version int `json:"version"`
} `json:"energyLabels"`
Deposit string `json:"deposit"`
Size string `json:"size"`
Colour string `json:"colour"`
Gender string `json:"gender"`
Material string `json:"material"`
Replica bool `json:"replica"`
Used bool `json:"used"`
Download bool `json:"download"`
DynamicProductAttributes struct {
Field1 []string `json:"22337"`
Field2 []string `json:"19326"`
} `json:"dynamicProductAttributes"`
FieldErrors []struct {
Deposit string `json:"deposit"`
Size string `json:"size"`
Colour string `json:"colour"`
Gender string `json:"gender"`
Material string `json:"material"`
Replica bool `json:"replica"`
Used bool `json:"used"`
Download bool `json:"download"`
DynamicProductAttributes interface{} `json:"dynamicProductAttributes"`
FieldErrors []struct {
Field string `json:"field"`
Message string `json:"message"`
} `json:"fieldErrors"`
Expand Down Expand Up @@ -123,6 +189,51 @@ func Offer(shopId int, sku string, r Request) (OfferReturn, error) {

}

// CreateOffer is to create an new offer
func CreateOffer(shopId int, body OfferBody, r Request) (OfferReturn, error) {

// Convert body
convert, err := json.Marshal(body)
if err != nil {
return OfferReturn{}, err
}

// Config new request
c := Config{
Pws: true,
Path: fmt.Sprintf("/shop/%d/offer/%s", shopId, body.Sku),
Method: "PUT",
Body: convert,
}

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

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

// Check response status
err = pwsStatusCodes(response.Status)
if err != nil {
return OfferReturn{}, err
}

// Decode data
var decode OfferReturn

err = json.NewDecoder(response.Body).Decode(&decode)
if err != nil {
return OfferReturn{}, err
}

// Return data
return decode, nil

}

// DeleteOffer is to delete an offer
func DeleteOffer(shopId int, sku string, r Request) error {

Expand Down

0 comments on commit c6799b4

Please sign in to comment.