update stockhandling
This commit is contained in:
@@ -5,8 +5,6 @@ import (
|
|||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
"strconv"
|
|
||||||
"strings"
|
|
||||||
|
|
||||||
"git.tornberg.me/go-cart-actor/pkg/cart"
|
"git.tornberg.me/go-cart-actor/pkg/cart"
|
||||||
messages "git.tornberg.me/go-cart-actor/pkg/messages"
|
messages "git.tornberg.me/go-cart-actor/pkg/messages"
|
||||||
@@ -61,27 +59,27 @@ func ToItemAddMessage(item *index.DataItem, storeId *string, qty int, country st
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
stk := item.GetStock()
|
||||||
stock := cart.StockStatus(0)
|
stock := cart.StockStatus(0)
|
||||||
centralStockValue, ok := item.GetStringFieldValue(3)
|
|
||||||
if storeId == nil {
|
if storeId == nil {
|
||||||
|
centralStock, ok := stk[country]
|
||||||
if ok {
|
if ok {
|
||||||
if !item.Buyable {
|
if !item.Buyable {
|
||||||
return nil, fmt.Errorf("item not available")
|
return nil, fmt.Errorf("item not available")
|
||||||
}
|
}
|
||||||
pureNumber := strings.Replace(centralStockValue, "+", "", -1)
|
|
||||||
if centralStock, err := strconv.ParseInt(pureNumber, 10, 64); err == nil {
|
if centralStock == 0 && item.SaleStatus == "TBD" {
|
||||||
stock = cart.StockStatus(centralStock)
|
|
||||||
}
|
|
||||||
if stock == cart.StockStatus(0) && item.SaleStatus == "TBD" {
|
|
||||||
return nil, fmt.Errorf("no items available")
|
return nil, fmt.Errorf("no items available")
|
||||||
}
|
}
|
||||||
|
stock = cart.StockStatus(centralStock)
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
if !item.BuyableInStore {
|
if !item.BuyableInStore {
|
||||||
return nil, fmt.Errorf("item not available in store")
|
return nil, fmt.Errorf("item not available in store")
|
||||||
}
|
}
|
||||||
storeStock, ok := item.Stock.GetStock()[*storeId]
|
storeStock, ok := stk[*storeId]
|
||||||
if ok {
|
if ok {
|
||||||
stock = cart.StockStatus(storeStock)
|
stock = cart.StockStatus(storeStock)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -41,7 +41,7 @@ func UpsertSubscriptionDetails(g *CartGrain, m *messages.UpsertSubscriptionDetai
|
|||||||
if !ok {
|
if !ok {
|
||||||
n := &SubscriptionDetails{
|
n := &SubscriptionDetails{
|
||||||
Id: *m.Id,
|
Id: *m.Id,
|
||||||
Version: 1,
|
Version: 0,
|
||||||
}
|
}
|
||||||
g.SubscriptionDetails[*m.Id] = n
|
g.SubscriptionDetails[*m.Id] = n
|
||||||
existing = n
|
existing = n
|
||||||
|
|||||||
Reference in New Issue
Block a user