diff --git a/cmd/cart/cart-grain.go b/cmd/cart/cart-grain.go index 30bc743..02db668 100644 --- a/cmd/cart/cart-grain.go +++ b/cmd/cart/cart-grain.go @@ -16,12 +16,6 @@ import ( type StockStatus int -const ( - OutOfStock StockStatus = 0 - LowStock StockStatus = 1 - InStock StockStatus = 2 -) - type ItemMeta struct { Name string `json:"name"` Brand string `json:"brand,omitempty"` diff --git a/cmd/cart/product-fetcher.go b/cmd/cart/product-fetcher.go index cdf273f..6819338 100644 --- a/cmd/cart/product-fetcher.go +++ b/cmd/cart/product-fetcher.go @@ -40,22 +40,27 @@ func GetItemAddMessage(sku string, qty int, country string, storeId *string) (*m if err != nil { return nil, err } + return ToItemAddMessage(item, storeId, qty, country), nil +} + +func ToItemAddMessage(item *index.DataItem, storeId *string, qty int, country string) *messages.AddItem { orgPrice, _ := getInt(item.GetNumberFieldValue(5)) // getInt(item.Fields[5]) - price, priceErr := getInt(item.GetNumberFieldValue(4)) //Fields[4] - - if priceErr != nil { - return nil, fmt.Errorf("invalid price") + price, err := getInt(item.GetNumberFieldValue(4)) //Fields[4] + if err != nil { + return nil } - stock := InStock - item.HasStock() - stockValue, ok := item.GetNumberFieldValue(3) - if !ok || stockValue == 0 { - stock = OutOfStock + stock := StockStatus(0) + centralStockValue, ok := item.GetNumberFieldValue(3) + if storeId == nil { + if ok { + stock = StockStatus(centralStockValue) + } } else { - if stockValue < 5 { - stock = LowStock + storeStock, ok := item.Stock.GetStock()[*storeId] + if ok { + stock = StockStatus(storeStock) } } @@ -80,7 +85,7 @@ func GetItemAddMessage(sku string, qty int, country string, storeId *string) (*m Quantity: int32(qty), Price: int64(price), OrgPrice: int64(orgPrice), - Sku: sku, + Sku: item.GetSku(), Name: item.Title, Image: item.Img, Stock: int32(stock), @@ -98,7 +103,7 @@ func GetItemAddMessage(sku string, qty int, country string, storeId *string) (*m Country: country, Outlet: outlet, StoreId: storeId, - }, nil + } } func getTax(articleType string) int32 {