Giter Site home page Giter Site logo

supermarket-checkout's Introduction

Supermarket Checkout

This repository contains code to implement a supermarket style checkout system, where product are "scanned" one by one, and the total is calculated against a set of pricing rules.

The code is inspired by a YouTube video published on Laravel Daily channel.

The video is about a job interview where the candidate was asked to satisfy some basic requirements to apply interactively a set of discount rules while the scanner passes the products. In the requirements there was some examples of carts and expected totals, so it was a perfect task to improve my skills on TDD. For this reason I've decided to write the code by myself and publish it on Github for future reference.

Usage

The code has no "entry points", so to execute it you have just to run the tests.

First of all install dev dependencies after cloning the repository

$ composer install

Then run phpunit tests with the script provided in composer.json

$ composer test

Have fun exploring how the test was passed using the Strategy Pattern, start from tests/Feature/CheckoutTest.php and traverse the source trough the classes and methods used on the test code.

Since this was just a proof-of-concept, I didn't code any database interface object, but I've just used a plain array sto store products and rules in a repository class, where products are mapped to models and rules are considered as a strategy classes to calculate the price against the quantity in the cart.

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.