S++Business systems language
DEMO SOURCE · SPP / APP / PHYRead the book

petshop-10-services.spp

petshop/cart/petshop-10-services.spp

Download original file · Petstore source contents

1domain petshop;23atomic calculate captureCartLines(Cart, CartLine[]) {4    CartLine[] = new CartLine[] {5    };6    for (CartLine line : Cart.lines) {7        CartLine[] = append(CartLine[], copy(line));8    }9}1011atomic check checkCart(Buyer, Cart) {12    require(Cart.buyer == Buyer, "CART_NOT_FOUND");13}1415atomic calculate addCartProduct(Goods, Cart, CartAdditionAgreement) {16    CartLine[] result = new CartLine[] {17    };18    int previousQuantity = 0;19    for (CartLine line : Cart.lines) {20        if (line.goods.sku != Goods.sku) {21            result = append(result, copy(line));22        } else {23            previousQuantity = line.quantity;24        }25    }26    CartLine added = new CartLine();27    added.buyer = Cart.buyer;28    added.goods = Goods;29    added.quantity = previousQuantity + CartAdditionAgreement.quantity;30    Cart.lines = append(result, added);31}3233atomic calculate setCartProductQuantity(Goods, Cart, CartQuantityAgreement) {34    CartLine[] result = new CartLine[] {35    };36    for (CartLine line : Cart.lines) {37        if (line.goods.sku != Goods.sku) {38            result = append(result, copy(line));39        }40    }41    CartLine added = new CartLine();42    added.buyer = Cart.buyer;43    added.goods = Goods;44    added.quantity = CartQuantityAgreement.quantity;45    Cart.lines = append(result, added);46}4748atomic calculate removeCartProduct(Goods, Cart) {49    CartLine[] result = new CartLine[] {50    };51    for (CartLine line : Cart.lines) {52        if (line.goods.sku != Goods.sku) {53            result = append(result, copy(line));54        }55    }56    Cart.lines = result;57}5859atomic calculate clearCartProducts(Cart) {60    Cart.lines = new CartLine[] {61    };62}