From d86295ec2d9e00bb80cc8a0bf03b6f3b5c676708 Mon Sep 17 00:00:00 2001 From: Soner Sayakci Date: Fri, 17 Jan 2025 08:36:19 +0100 Subject: [PATCH] fix: crashes in shopware shop listing --- account-api/merchant.go | 2 +- cmd/account/account_merchant_shop_composer.go | 44 +++++++++++++++---- 2 files changed, 37 insertions(+), 9 deletions(-) diff --git a/account-api/merchant.go b/account-api/merchant.go index 1f017f0d..5f27b282 100644 --- a/account-api/merchant.go +++ b/account-api/merchant.go @@ -49,7 +49,7 @@ type MerchantShop struct { DocumentComment string `json:"documentComment"` Activated bool `json:"activated"` AccountId string `json:"accountId"` - ShopNumber int `json:"shopNumber"` + ShopNumber string `json:"shopNumber"` CreationDate string `json:"creationDate"` Branch interface{} `json:"branch"` SubscriptionModules []struct { diff --git a/cmd/account/account_merchant_shop_composer.go b/cmd/account/account_merchant_shop_composer.go index 3464734d..6bf36c32 100644 --- a/cmd/account/account_merchant_shop_composer.go +++ b/cmd/account/account_merchant_shop_composer.go @@ -79,14 +79,42 @@ var accountCompanyMerchantShopComposerCmd = &cobra.Command{ composer["repositories"] = make(map[string]interface{}) } - repositories, _ := composer["repositories"].(map[string]interface{}) - - repositories["shopware-packages"] = struct { - Type string `json:"type"` - Url string `json:"url"` - }{ - Type: "composer", - Url: "https://packages.shopware.com", + repositories, ok := composer["repositories"].(map[string]interface{}) + + if ok { + repositories["shopware-packages"] = struct { + Type string `json:"type"` + Url string `json:"url"` + }{ + Type: "composer", + Url: "https://packages.shopware.com", + } + } else { + repositories := composer["repositories"].([]interface{}) + + repoExists := false + + for _, repo := range repositories { + mappedRepo, ok := repo.(map[string]interface{}) + + if !ok { + continue + } + + if mappedRepo["url"] == "https://packages.shopware.com" { + repoExists = true + break + } + } + + if !repoExists { + repositories = append(repositories, map[string]interface{}{ + "type": "composer", + "url": "https://packages.shopware.com", + }) + + composer["repositories"] = repositories + } } if content, err = json.MarshalIndent(composer, "", " "); err != nil {