Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/simara-svatopluk/cart
Domain-Driven Design shop cart demonstration
https://github.com/simara-svatopluk/cart
cart ddd ddd-samples doctrine eshop-cart model tdd
Last synced: about 2 months ago
JSON representation
Domain-Driven Design shop cart demonstration
- Host: GitHub
- URL: https://github.com/simara-svatopluk/cart
- Owner: simara-svatopluk
- Created: 2017-08-21T18:52:16.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2023-04-14T09:31:06.000Z (about 1 year ago)
- Last Synced: 2024-02-04T20:26:15.824Z (5 months ago)
- Topics: cart, ddd, ddd-samples, doctrine, eshop-cart, model, tdd
- Language: PHP
- Homepage:
- Size: 90.8 KB
- Stars: 101
- Watchers: 4
- Forks: 11
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
Lists
- awesome-ddd - Shop Cart in PHP - Sample project that demonstrates how simple shop cart can look like. Domain objects,Doctrine integration.,TDD,layers,unit testing (Sample Projects / PHP)
README
# Cart
[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/simara-svatopluk/cart/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/simara-svatopluk/cart/?branch=master)
[![Code Coverage](https://scrutinizer-ci.com/g/simara-svatopluk/cart/badges/coverage.png?b=master)](https://scrutinizer-ci.com/g/simara-svatopluk/cart/?branch=master)
[![Travis CS & Static Analysis](https://travis-ci.com/simara-svatopluk/cart.svg?branch=master)](https://travis-ci.com/github/simara-svatopluk/cart)
[![Build Status](https://scrutinizer-ci.com/g/simara-svatopluk/cart/badges/build.png?b=master)](https://scrutinizer-ci.com/g/simara-svatopluk/cart/build-status/master)Sample project that demonstrates how simple e-shop cart can look like. Created to show how do I understand domain-driven design.
* Domain objects
* Layers
* Unit testing
* Contract testing
* Doctrine infrastructureYou can also see how do I program, commit, what technology I can handle...
## Dynamic Prices
Prices are not stored in the Cart itself but are loaded on demand.
This is a common use-case because we usually need fresh prices from a database or ERP.Cart is separated from "loading prices" by an interface [`Prices`](src/Domain/Prices/Prices.php).
This is a domain element but have to be implemented by the project needs - by API calls or database queries.## Fixed Prices
Once we add a product into the cart, the price may be fixed.
If it is the project use-case, check out [fixed-prices version](https://github.com/simara-svatopluk/cart/tree/fixed-prices).## How to Assemble Real Application
### Demo
Take a loot at [`app.php`](example/app.php)
### Longer explanation
We have to implement domain interfaces by our infrastructure, eg. if we use Doctrine, we implement [`DoctrineRepository`](src/Infrastructure/DoctrineCartRepository.php),
if we use CSV for storing pricing, we implement [`CsvPrices`](src/Infrastructure/CsvPrices.php) and so on by the project needs.We can use domain objects directly in UI/CLI/target layer, and then we have to pass objects like [`Repositories`](src/Domain/Cart/CartRepository.php) to that layer.
Or we can wrap domain objects into classes that represent full use-cases.
You may call them handlers/facades/[`useCases`](src/Application/CartUseCaseApplication.php)/... depending on the project infrastructure.Then we register these classes in or favorite DI container.
If you don't know how, you can find inspiration that uses Symfony/DI [`ContainerBuilderFactory`](src/Infrastructure/Symfony/ContainerBuilderFactory.php).## TDD
This project was written in the spirit of TDD, see [commits](https://github.com/simara-svatopluk/cart/commits/TDD).