GithubHelp home page GithubHelp logo

discounts's Introduction

Description:

This is one of the way how to realize multiple discount system. Everything is based on DiscountRuleInterface. This is something very close with Rule Engine, but more simple.

In DiscountManager\Rule you can find available rules. Every rule are stored in db:table rules. You can use any rule and create own Discount (db:table discounts) with different rule value, discount amount and product category target. That is providing scalability, in database you can create, deactivate or update discounts based on available rules.

When system will receive a request with Order, DiscountManager will get all active Discounts (db:table discounts) and it will run every rule of every discount, this rules will calculate and return a discount.

Then DiscountManager will save a total discount for order in db:table discount_history and every applied discount in discount db:table applied_discounts. This data will be serialized and returned as clear and informative response.

Requirements:

Docker version 1.10.0+

docker-compose version 1.17.1+

for local usage need to turn off your apache2 and mysql services

Installation:

  1. linux terminal: git clone https://github.com/bog-h/discounts.git
  2. Add in your hosts file a new host: 127.0.0.1 discounts.local
  3. linux terminal: CD to your cloned folder and run command "./build.sh"

extra: sometime build.sh can fail on Refuse Connection, this is not resolved yet, please just rerun "./build.sh"

How to run?

  1. Open http://discounts.local/api/doc/ (this is a page of installed and configured NelmioApiDocBundle)
  2. Press on row "POST /api/calculate-discount-for-order Calculate discount for customer order"
  3. Press Try it out
  4. Press Execute
  5. Receive a response

extra: please stop your apache and mysql services if you have.

You can execute different json examples like multiple-discounts.json from request-examples folder

Warning - This is only abstraction

Use this code only for exploring, a lot of things are missed like Real API communication channel, Order deserialization, Assertions, e.t.c.

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.