update
Some checks failed
Build and Publish / BuildAndDeployAmd64 (push) Failing after 27s
Build and Publish / BuildAndDeployArm64 (push) Failing after 3m10s

This commit is contained in:
2025-11-25 20:27:04 +01:00
parent ff8a332e3b
commit b0907aee41
2 changed files with 28 additions and 6 deletions

View File

@@ -2,6 +2,7 @@ package cart
import (
"encoding/json"
"log"
"slices"
"strings"
"sync"
@@ -234,12 +235,21 @@ func (c *CartGrain) Notify(event actor.Event) {
defer c.mu.Unlock()
// Example: if event is inventory change for a SKU in the cart
if strings.HasPrefix(event.Topic, "inventory:") {
sku := strings.TrimPrefix(event.Topic, "inventory:")
skuAndLocationId := strings.TrimPrefix(event.Topic, "inventory:")
parts := strings.Split(skuAndLocationId, ":")
if len(parts) != 2 {
return
}
sku := parts[0]
locationId := parts[1]
log.Printf("cart grain got inventory update: %s", event.Topic)
for _, item := range c.Items {
if item.Sku == sku {
if item.Sku == sku && item.StoreId != nil && *item.StoreId == locationId {
// Update stock status based on payload, e.g., if payload is bool available
if available, ok := event.Payload.(bool); ok {
if available {
if quantity, ok := event.Payload.(int64); ok {
log.Printf("cart grain got item stock update %d", quantity)
if quantity > 0 {
item.Stock = 1 // assuming 1 is in stock
} else {
item.Stock = 0 // out of stock