Shopping cart is an application that allows you to add products to your cart (without adding the same one twice) and to be able to make a 10% discount on your final list
It is easy to reproduce it locally
Inside our shopping-cart directory open a terminal and write:
symfony server-startThen with the helps of XAMPP we will initialize our Apache and MySQL
And here we have our products:
For this application I implemented a structural pattern called Hexagonal Architecture which divides the application in 3 main layers and keeps the code separate and understandable:
- Infrastructure layer --> Here we have all "external" services that need to be as decoupled as possible: Controllers, Repositories...etc.
- Application layer --> Here we have all our UseCases for the application. I used a CQS principle in order to split the validation of data from the logic of the useCase
- Domain layer --> Here we have all the business logic: Entities & Interfaces.
We start in /products route where we can see all of our available products.
If we click on "Add to cart" we will add a new product and it will be shown in the header when we see the number of products refreshed
After that, if we click on the same product, it will prompt a message saying "Product already added" and the product won't be added. We could use this exception handling to implement a custom message inside the product with Javascript in nexts features
If we click on the "Go to cart" button or in the number of cart product (top-right in the header) we will go to /cart and see all our products added
Once we are in /cart we can see the list of our chosen products, and if we clicked in "Apply 10% discount" we will get a 10% discount (in a more efficient way I would created an Entity of discounts and I'll associated with existing users to only show that option for those users)
I created Unit Tests in /tests folder that tests the use cases of the application and check the type of the variables we are receiving
We can run our tests by running the following command:
php bin/phpunit ./tests