check storestock
This commit is contained in:
@@ -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"`
|
||||
|
||||
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user