package cart import ( "fmt" messages "git.k6n.net/go-cart-actor/proto/cart" ) // SetLineItemCustomFields sets/merges user-supplied custom input fields on an // existing cart line. It is the dict equivalent of LineItemMarking: keys in the // request are upserted; existing keys not present in the request are left // untouched. (Send an empty value to clear a single field at the API layer if // desired.) func SetLineItemCustomFields(grain *CartGrain, req *messages.SetLineItemCustomFields) error { for _, item := range grain.Items { if item.Id != req.Id { continue } if len(req.CustomFields) == 0 { return nil } if item.CustomFields == nil { item.CustomFields = make(map[string]string, len(req.CustomFields)) } for k, v := range req.CustomFields { item.CustomFields[k] = v } return nil } return fmt.Errorf("item with ID %d not found", req.Id) }