Skip to content

Commit

Permalink
Empty batch to avoid duplications
Browse files Browse the repository at this point in the history
  • Loading branch information
Robi9 committed Nov 22, 2024
1 parent ddc2805 commit 0333dde
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions services/external/weni/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -620,18 +620,19 @@ func CartSimulation(ProductRetailerIDS []flows.ProductEntry, sellerID string, ur
products = append(products, p.ProductRetailerIDs...)
}

var searchSeller SearchSeller
if postalCode != "" {
searchSeller.PostalCode = postalCode
searchSeller.Country = "BRA"
}

for i := 0; i < len(products); i += batchSize {
end := i + batchSize
if end > len(products) {
end = len(products)
}
batchProducts := products[i:end]

var searchSeller SearchSeller
if postalCode != "" {
searchSeller.PostalCode = postalCode
searchSeller.Country = "BRA"
}
for _, product := range batchProducts {
searchSeller.Items = append(searchSeller.Items, Item{ID: product, Quantity: 1, Seller: sellerID})
}
Expand All @@ -643,6 +644,7 @@ func CartSimulation(ProductRetailerIDS []flows.ProductEntry, sellerID string, ur
}

availableProducts = append(availableProducts, batchAvailableProducts...)
searchSeller.Items = []Item{}
}

return availableProducts, traces, nil
Expand Down

0 comments on commit 0333dde

Please sign in to comment.