Giter Site home page Giter Site logo

product-cart's Introduction

Product Cart

This is CLI for a cart of products, accepts multiple products, combines offers, and displays a total detailed bill in different currencies (based on user selection).

Installation

  • cp .env.example .env

  • Put this in your .env

    • TAX=14
    • PRECISION=2
    • CURRENCY=USD
    • DEFAULT_CURRENCY=USD
  • docker-compose up -d

From PHP image

  • docker-compose exec php bash
    • composer install
    • php artisan key:generate

Usage

php artisan create: cart {currency} {items}

ex:

  • php artisan create: cart USD jacket shoes jacket t-shirt
  • php artisan create: cart EGP Pants

Architecture

  • you can set these value-form .env to be the dynamic overall project

    • TAX=14
    • PRECISION=2 //number of PRECISION you want to view price
    • CURRENCY=USD // if the currency not given
    • DEFAULT_CURRENCY=USD
  • If you want to add a new discount you can go to app/Enums/DiscountPlans and add the plan number that you will insert in Offer table when inserting the item and then got to app\strategies\DiscountPlans and implement your new plan.

  • if you want to add a new section to the bill like service just go to app/composite/ and your new class and implement interface bill

Design Pattern Used

1- Static Factory pattern to convert plan Number from DB to the according class should be implemented

2- Strategy pattern that I can dynamically implement any discount plan according to plan number from DB

3- Composite pattern to composite bill sections dynamically

3- service pattern I added all business logic in separate classes each class contains only one responsibility.


Performance

1- I chose to add all currencies and all Opposite symbols in a file in the config you can find it config/currencies as reading from a file will be better than reading from third-party or even DB,Because these currencies rarely changed.

2- I Put an index on name column as this will make the query faster.

Testing

From PHP image

  • docker-compose exec php bash

Run

vendor/phpunit/bin

Tools

  • PHP7.4
  • Laravel
  • Docker
  • phpunit
  • mysql 8

product-cart's People

Contributors

hodaa avatar

Stargazers

mohamedSayedMish avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.