Welcome to my first tutorial to learn the popular PHP Symfony Framework by creating a simple Shopping Cart from scratch.
A shopping cart on a website facilitates the purchase of a product or service.
I've been developing with Symfony for more than 8 years and I think it's time for me to share my experience with you through this series of articles. I made this tutorial for you to learn Symfony by doing. I have always learned to use a framework or a library by creating personal or professional projects.
Also, writing this tutorial was an exercise for me. Indeed, knowing how to use Symfony is one thing, knowing how to explain how to use Symfony is another.
The tutorial describes the creation of a shopping cart, from scratch and step by step. We will manage the basic shopping cart features:
- Add products to the cart,
- Update the quantity of products in the cart,
- Remove products from the cart,
- Clear the cart,
- See the list of products in the cart,
- See the quantity of products in the cart,
- See the summary of the cart.
The checkout and order process won't be developed but let me know if you are interested, I will try to do it and add some additional steps to this tutorial. Also, the design is not the goal of this project, we will just make it functional.
We will try to respect the best practices and use the base concepts of Symfony to allow you to reuse code and create your projects independently.
- Create a project with Symfony 5 (from scratch),
- Build a Shopping Cart using Symfony 5,
- Use the most popular Symfony components,
- Create static and dynamic forms with Symfony Form,
- Create pages with Twig,
- Store data in session using the Session service,
- Create and register Services in Symfony,
- Create and Persist entities in a database using Doctrine,
- Write custom DQL queries using the Query Builder of Doctrine,
- Validate entities with Symfony Validator,
- Load fake data with Doctrine Fixtures,
- Create a CLI command with Symfony Console,
- Write functional tests with Symfony Browser Kit and PHPUnit.
- For PHP developers who want to discover Symfony 5 using a concrete and complex project,
- Developers who want to go beyond the documentation offered by Symfony and take action.
I created a repository that contains all the code of the shopping cart. If you want, you can clone it somewhere on your local machine:
$ git clone https://github.com/qferr/happy-shop
Ready to code? Let's start to install and configure our working environment in the first step.