# Shopping cart

Jan 28, 2023 9:00:00 AM

## Emmanuel Valverde

See author's bio and posts

## 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%

## List the shopping cart

``As a customerI want to see my shopping cart``

#### Empty cart

``--------------------------------------------| Product name | Price with VAT | Quantity || -----------  | -------------- | -------- ||------------------------------------------|| Promotion:                               |--------------------------------------------| Total products: 0                        || Total price: 0.00 โฌ                      |--------------------------------------------``

## Add product to shopping cart

``As a customerI want to add Iceberg ๐ฅฌ to my shopping cartI want to add Tomato  ๐ to my shopping cartI want to add Chicken ๐ to my shopping cartI want to add Bread ๐ to my shopping cartI want to add Corn ๐ฝ to my shopping cartI want to see my shopping cart``
``--------------------------------------------| Product name | Price with VAT | Quantity || -----------  | -------------- | -------- || Iceberg ๐ฅฌ   | 2.17 โฌ         | 1        || Tomato  ๐   | 0.73 โฌ         | 1        || Chicken ๐   | 1.83 โฌ         | 1        || Bread ๐     | 0.88 โฌ         | 1        || Corn ๐ฝ      | 1.50 โฌ         | 1        ||------------------------------------------|| Promotion:                               |--------------------------------------------| Total products: 5                        || Total price: 7.11 โฌ                      |--------------------------------------------``

## Add product to shopping cart

``As a customerI want to add Iceberg ๐ฅฌ to my shopping cartI want to add Iceberg ๐ฅฌ to my shopping cartI want to add Iceberg ๐ฅฌ to my shopping cartI want to add Tomato  ๐ to my shopping cartI want to add Chicken ๐ to my shopping cartI want to add Bread ๐ to my shopping cartI want to add Bread ๐ to my shopping cartI want to add Corn ๐ฝ to my shopping cartI want to see my shopping cart``

``--------------------------------------------| Product name | Price with VAT | Quantity || -----------  | -------------- | -------- || Iceberg ๐ฅฌ   | 2.17 โฌ         | 3        || Tomato  ๐   | 0.73 โฌ         | 1        || Chicken ๐   | 1.83 โฌ         | 1        || Bread ๐     | 0.88 โฌ         | 2        || Corn ๐ฝ      | 1.50 โฌ         | 1        ||------------------------------------------|| Promotion:                               |--------------------------------------------| Total products: 8                        || Total price: 12.33 โฌ                     |--------------------------------------------``

## Apply discount to the shopping cart

``As a customerI want to add Iceberg ๐ฅฌ to my shopping cartI want to add Iceberg ๐ฅฌ to my shopping cartI want to add Iceberg ๐ฅฌ to my shopping cartI want to add Tomato  ๐ to my shopping cartI want to add Chicken ๐ to my shopping cartI want to add Bread ๐ to my shopping cartI want to add Bread ๐ to my shopping cartI want to add Corn ๐ฝ to my shopping cartI want to apply my coupon code PROMO_5I want to see my shopping cart``
``--------------------------------------------| Product name | Price with VAT | Quantity || -----------  | -------------- | -------- || Iceberg ๐ฅฌ   | 2.17 โฌ         | 3        || Tomato  ๐   | 0.73 โฌ         | 1        || Chicken ๐   | 1.83 โฌ         | 1        || Bread ๐     | 0.88 โฌ         | 2        || Corn ๐ฝ      | 1.50 โฌ         | 1        ||------------------------------------------|| Promotion: 5% off with code PROMO_5      |--------------------------------------------| Total products: 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 deleteItem(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 deleteItem(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 deleteItem(String productName);    public void applyDiscount(Double discount)    public ShoppingCartList getShoppingCart();}``

## Disclaimer

The graphic examples that you can see in the assignment are not there to be implemented if you don't want to. They are provided as a reference of how the shopping cart works