Shopping cart

What do we want to build?

We are building a shopping cart for an online grocery shop.  The idea of this kata is to build the product in an iterative way.

Technical requirements

  • The price per unit is calculated based on the product cost and the percentage of revenue that the company wants for that product.
  • The price has to be rounded up; so if a price per unit calculated is 1.7825, then the expected price per unit for that product is 1.79
  • The final price of the product is then calculated as the price per unit with the VAT rounded up.
  • Products are not allowed to have the same name.

List of products

Name Cost % Revenue Price per unit Tax Final price
Iceberg ๐Ÿฅฌ 1.55 โ‚ฌ 15 % 1,79 โ‚ฌ Normal (21%) 2.17 โ‚ฌ
Tomato ๐Ÿ… 0.52 โ‚ฌ 15 % 0.60 โ‚ฌ Normal (21%) 0.73 โ‚ฌ
Chicken ๐Ÿ— 1.34 โ‚ฌ 12 % 1.51 โ‚ฌ Normal (21%) 1.83 โ‚ฌ
Bread ๐Ÿž 0.71 โ‚ฌ 12 % 0.80 โ‚ฌ First necessity (10%) 0.88 โ‚ฌ
Corn ๐ŸŒฝ 1.21 โ‚ฌ 12 % 1.36 โ‚ฌ First necessity (10%) 1.50 โ‚ฌ

List of discounts

Discounts code Amount
PROMO_5 5%
PROMO_10 10%

 

Use cases

List the shopping cart

As customer
I want to see my shipping cart

Empty cart

--------------------------------------------
| Product name | Price with VAT | Quantity |
| ----------- | -------------- | -------- |
|------------------------------------------|
| Promotion: |
--------------------------------------------
| Total productos: 0 |
| Total price: 0.00 โ‚ฌ |
--------------------------------------------


Add product to shopping cart

As customer
I want to add Iceberg ๐Ÿฅฌ to my shipping cart
I want to add Tomatoe ๐Ÿ… to my shipping cart
I want to add Chicken ๐Ÿ— to my shipping cart
I want to add Bread ๐Ÿž to my shipping cart
I want to add Corn ๐ŸŒฝ to my shipping cart
I want to see my shipping cart
--------------------------------------------
| Product name | Price with VAT | Quantity |
| ----------- | -------------- | -------- |
| Iceberg ๐Ÿฅฌ | 2.17 โ‚ฌ | 1 |
| Tomatoe ๐Ÿ… | 0.73 โ‚ฌ | 1 |
| Chicken ๐Ÿ— | 1.83 โ‚ฌ | 1 |
| Bread ๐Ÿž | 0.88 โ‚ฌ | 1 |
| Corn ๐ŸŒฝ | 1.50 โ‚ฌ | 1 |
|------------------------------------------|
| Promotion: |
--------------------------------------------
| Total productos: 5 |
| Total price: 7.11 โ‚ฌ |
--------------------------------------------

Add product to shopping cart

As customer
I want to add Iceberg ๐Ÿฅฌ to my shipping cart
I want to add Iceberg ๐Ÿฅฌ to my shipping cart
I want to add Iceberg ๐Ÿฅฌ to my shipping cart
I want to add Tomatoe ๐Ÿ… to my shipping cart
I want to add Chicken ๐Ÿ— to my shipping cart
I want to add Bread ๐Ÿž to my shipping cart
I want to add Bread ๐Ÿž to my shipping cart
I want to add Corn ๐ŸŒฝ to my shipping cart
I want to see my shipping cart

 

--------------------------------------------
| Product name | Price with VAT | Quantity |
| ----------- | -------------- | -------- |
| Iceberg ๐Ÿฅฌ | 2.17 โ‚ฌ | 3 |
| Tomatoe ๐Ÿ… | 0.73 โ‚ฌ | 1 |
| Chicken ๐Ÿ— | 1.83 โ‚ฌ | 1 |
| Bread ๐Ÿž | 0.88 โ‚ฌ | 2 |
| Corn ๐ŸŒฝ | 1.50 โ‚ฌ | 1 |
|------------------------------------------|
| Promotion: |
--------------------------------------------
| Total productos: 8 |
| Total price: 12.33 โ‚ฌ |
--------------------------------------------

 

Apply discount to the shopping cart

As customer
I want to add Iceberg ๐Ÿฅฌ to my shipping cart
I want to add Iceberg ๐Ÿฅฌ to my shipping cart
I want to add Iceberg ๐Ÿฅฌ to my shipping cart
I want to add Tomatoe ๐Ÿ… to my shipping cart
I want to add Chicken ๐Ÿ— to my shipping cart
I want to add Bread ๐Ÿž to my shipping cart
I want to add Bread ๐Ÿž to my shipping cart
I want to add Corn ๐ŸŒฝ to my shipping cart
I want to apply my coupon code PROMO_5
I want to see my shipping cart
--------------------------------------------
| Product name | Price with VAT | Quantity |
| ----------- | -------------- | -------- |
| Iceberg ๐Ÿฅฌ | 2.17 โ‚ฌ | 3 |
| Tomatoe ๐Ÿ… | 0.73 โ‚ฌ | 1 |
| Chicken ๐Ÿ— | 1.83 โ‚ฌ | 1 |
| Bread ๐Ÿž | 0.88 โ‚ฌ | 2 |
| Corn ๐ŸŒฝ | 1.50 โ‚ฌ | 1 |
|------------------------------------------|
| Promotion: 5% off with code PROMO_5 |
--------------------------------------------
| Total productos: 8 |
| Total price: 11.71 โ‚ฌ |
--------------------------------------------

Possible API for the ShoppingCart

You could change this API this is only for example purposes.

Approach 1 passing objects as arguments could be DTO

public interface ShoppingCart {
public void addItem(Product product);
public void deletItem(Product product);
public void applyDiscount(Discount discount)
public void printShoppingCart();
}

Approach 2 passing primitives as arguments
 
public interface ShoppingCart {
public void addItem(String productName);
public void deletItem(String productName);
public void applyDiscount(Double discount)
public void printShoppingCart();
}

Approach 3 passing primitives as arguments and returning a DTO

public
interface ShoppingCart {
public void addItem(String productName);
public void deletItem(String productName);
public void applyDiscount(Double discount)
public ShoppingCartList getShoppingCart();
}

Disclaimer

The graphic examples that you see on the kata are not there to be implemented if you don't want to, are there as a reference of how the kata works