-
Notifications
You must be signed in to change notification settings - Fork 13
/
main.go
50 lines (42 loc) · 1.09 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package main
import (
"log"
"github.com/hermsi1337/go-magento2/pkg/magento2/api"
"github.com/hermsi1337/go-magento2/pkg/magento2/products"
)
func main() {
// initiate storeconfig
storeConfig := &api.StoreConfig{
Scheme: "https",
HostName: "magento2.hermsi.localhost",
StoreCode: "default",
}
// initiate bearer payload
bearerToken := "yd1o9zs1hb1qxnn8ek68eu8nwqjg5hrv"
// create a new apiClient
apiClient, err := api.NewAPIClientFromIntegration(storeConfig, bearerToken)
if err != nil {
panic(err)
}
log.Printf("Obtained client: '%v'", apiClient)
// define your product
product := products.Product{
Name: "Spaget-Shirt",
Sku: "spaget1234",
Price: 1000,
AttributeSetID: 4,
TypeID: "simple",
}
productSaveOptions := true
// create product on remote
mProduct, err := products.CreateOrReplaceProduct(&product, productSaveOptions, apiClient)
if err != nil {
panic(err)
}
// here you go
log.Printf("Created product: %+v", mProduct)
err = mProduct.UpdateQuantityForStockItem("1", 200, true)
if err != nil {
panic(err)
}
}