From 8510e7fbe0c6f701e8870f0d1565dfda4cf9eab1 Mon Sep 17 00:00:00 2001 From: dom Date: Fri, 12 Feb 2021 21:50:59 +0100 Subject: [PATCH] add webclient with wishlist func --- webActions.go | 69 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) diff --git a/webActions.go b/webActions.go index af104cf..c99098e 100644 --- a/webActions.go +++ b/webActions.go @@ -269,3 +269,72 @@ func ExportNewOrders(client *http.Client, lastOrder int) error { return nil } + +type paxanWebClient struct { + client *http.Client + baseUrl string +} + +func Connect(user string, password string) (paxanWebClient, error) { + var pwc paxanWebClient + // New http client with cookie + cookieJar, _ := cookiejar.New(nil) + pwc.client = &http.Client{ + Jar: cookieJar, + } + + pwc.baseUrl = "https://www.hakopaxan-shop.de/html" + + loginvalues := make(url.Values) + loginvalues.Set("performAction", "processLogin") + loginvalues.Set("personlogin", user) + loginvalues.Set("personpwd", password) + loginvalues.Set("firma", "paxan") + _, err := pwc.client.PostForm("https://www.hakopaxan-shop.de/html/login.html", loginvalues) + if err != nil { + return paxanWebClient{}, err + } + + return pwc, nil +} + +func (w *paxanWebClient) Disconnect() error { + _, err := w.client.Get("https://www.hakopaxan-shop.de/html/logout-performAction-processLogout.html") + if err != nil { + return err + } + + return nil +} + +func (w *paxanWebClient) selectWishlist(id string) error { + _, err := w.client.Get("https://www.hakopaxan-shop.de/html/wishlist-wishlist__switch-" + id + ".html") + if err != nil { + return err + } + + return nil +} + +func (w *paxanWebClient) AddToWishlist(artnr string, wishlist string) error { + //w.getWishList() + w.selectWishlist("10") + //w.client.PostForm() + + formvalues := make(url.Values) + //formvalues.Set("x", "10") + //formvalues.Set("y", "8") + formvalues.Set("itemId", artnr) + formvalues.Set("wishlist_add_position", "true") + formvalues.Set("wvarid", artnr) + formvalues.Set("qty", "1") + formvalues.Set("me", "0") + _, err := w.client.PostForm("https://www.hakopaxan-shop.de/html/item.html", formvalues) + if err != nil { + return err + } + + return nil + + //set to old wishlist +}