refactor/checkout (#8)
Co-authored-by: matst80 <mats.tornberg@gmail.com> Reviewed-on: #8 Co-authored-by: Mats Törnberg <mats@tornberg.me> Co-committed-by: Mats Törnberg <mats@tornberg.me>
This commit was merged in pull request #8.
This commit is contained in:
26
pkg/cart/mutation_clear_cart.go
Normal file
26
pkg/cart/mutation_clear_cart.go
Normal file
@@ -0,0 +1,26 @@
|
||||
package cart
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
messages "git.k6n.net/go-cart-actor/proto/cart"
|
||||
)
|
||||
|
||||
func ClearCart(g *CartGrain, m *messages.ClearCartRequest) error {
|
||||
if m == nil {
|
||||
return fmt.Errorf("ClearCart: nil payload")
|
||||
}
|
||||
if g.CheckoutStatus != nil {
|
||||
return fmt.Errorf("ClearCart: cart is in checkout")
|
||||
}
|
||||
// Clear items, vouchers, etc., but keep userId, etc.
|
||||
g.Items = g.Items[:0]
|
||||
g.Vouchers = g.Vouchers[:0]
|
||||
g.Notifications = g.Notifications[:0]
|
||||
g.OrderReference = ""
|
||||
g.Processing = false
|
||||
|
||||
// g.InventoryReserved = false maybe should release inventory
|
||||
g.UpdateTotals()
|
||||
return nil
|
||||
}
|
||||
Reference in New Issue
Block a user