Skip to content

Commit

Permalink
Remove duplicate products
Browse files Browse the repository at this point in the history
  • Loading branch information
Robi9 committed Nov 22, 2024
1 parent 950b28d commit 9c8d4af
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions services/external/weni/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,6 @@ func (s *service) Call(session flows.Session, params assets.MsgCatalogParam, log
} else if params.SearchType == "vtex" {
searchResult, searchResultSponsored, traces, err = GetProductListFromVtex(product, params.SearchUrl, params.ApiType, catalog.FacebookCatalogID(), s.rtConfig, hasVtexAds, hideUnavailableItems, sellerID)
callResult.Traces = append(callResult.Traces, traces...)
allProducts = append(allProducts, searchResult...)
if searchResult == nil {
continue
}
Expand Down Expand Up @@ -187,7 +186,7 @@ func (s *service) Call(session flows.Session, params assets.MsgCatalogParam, log
if postalCode_ != "" && sellerID != "1" {
var tracesSimulation []*httpx.Trace
hasSimulation = true
existingProductsIds, tracesSimulation, err = CartSimulation(allProducts, sellerID, params.SearchUrl, postalCode_)
existingProductsIds, tracesSimulation, err = CartSimulation(callResult.ProductRetailerIDS, sellerID, params.SearchUrl, postalCode_)
callResult.Traces = append(callResult.Traces, tracesSimulation...)
if err != nil {
return callResult, err
Expand Down Expand Up @@ -609,14 +608,19 @@ func VtexSponsoredSearch(searchUrl string, productSearch string, hideUnavailable

}

func CartSimulation(products []string, sellerID string, url string, postalCode string) ([]string, []*httpx.Trace, error) {
func CartSimulation(ProductRetailerIDS []flows.ProductEntry, sellerID string, url string, postalCode string) ([]string, []*httpx.Trace, error) {
const batchSize = 300
var traces []*httpx.Trace
var availableProducts []string
var products []string

urlSplit := strings.Split(url, "api")
urlSimulation := urlSplit[0] + "api/checkout/pub/orderForms/simulation"

for _, p := range ProductRetailerIDS {
products = append(products, p.ProductRetailerIDs...)
}

for i := 0; i < len(products); i += batchSize {
end := i + batchSize
if end > len(products) {
Expand Down

0 comments on commit 9c8d4af

Please sign in to comment.