add country
Some checks failed
Build and Publish / BuildAndDeploy (push) Successful in 4m29s
Build and Publish / BuildAndDeployAmd64 (push) Has been cancelled

This commit is contained in:
2025-09-28 09:41:07 +02:00
parent 5c7b8d87e8
commit 8c8ff75b2d
6 changed files with 236 additions and 141 deletions

View File

@@ -127,8 +127,8 @@ func getInt(data interface{}) (int, error) {
}
}
func getItemData(sku string, qty int) (*messages.AddItem, error) {
item, err := FetchItem(sku)
func getItemData(sku string, qty int, country string) (*messages.AddItem, error) {
item, err := FetchItem(sku, country)
if err != nil {
return nil, err
}
@@ -162,11 +162,6 @@ func getItemData(sku string, qty int) (*messages.AddItem, error) {
category4, _ := item.Fields[13].(string)
category5, _ := item.Fields[14].(string)
// is own
if sellerName == "Elgiganten" {
sellerName = ""
}
return &messages.AddItem{
ItemId: int64(item.Id),
Quantity: int32(qty),
@@ -187,12 +182,13 @@ func getItemData(sku string, qty int) (*messages.AddItem, error) {
SellerName: sellerName,
ArticleType: articleType,
Disclaimer: item.Disclaimer,
Country: country,
Outlet: outlet,
}, nil
}
func (c *CartGrain) AddItem(sku string, qty int) (*FrameWithPayload, error) {
cartItem, err := getItemData(sku, qty)
func (c *CartGrain) AddItem(sku string, qty int, country string) (*FrameWithPayload, error) {
cartItem, err := getItemData(sku, qty, country)
if err != nil {
return nil, err
}
@@ -286,7 +282,7 @@ func (c *CartGrain) HandleMessage(message *Message, isReplay bool) (*FrameWithPa
c.Items = make([]*CartItem, 0, len(msg.Items))
c.mu.Unlock()
for _, item := range msg.Items {
c.AddItem(item.Sku, int(item.Quantity))
c.AddItem(item.Sku, int(item.Quantity), item.Country)
}
}
@@ -301,7 +297,7 @@ func (c *CartGrain) HandleMessage(message *Message, isReplay bool) (*FrameWithPa
existingItem.Quantity += int(msg.Quantity)
c.UpdateTotals()
} else {
return c.AddItem(msg.Sku, int(msg.Quantity)) // extent AddRequest to include quantity
return c.AddItem(msg.Sku, int(msg.Quantity), msg.Country)
}
}