Skip to content
No description, website, or topics provided.
PHP
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.idea
src
vendor
.gitignore
README.md
composer.json
runner.php

README.md

THE NILE TECH TEST

IMPLEMENTATION NOTES

I came across some old codes that I wrote as a tech test solution while I was applying a software engineer role for an ecommerce company few years back in 2016. I remember as it was one of the more interesting code kata amongst many tech test that I had done. It was meant to be a straight-forward 2 hours exercise solving what it looked like an easy little problem.

https://www.stellalie.com/2019/10/06/design-pattern-rules-engine/

PROBLEM

The Nile wants to offer a wide variety of discounts to our customers.

Your task is to develop a system to allow for discounts to be applied to a customers cart. The system should be flexible, allowing for the creation of new discount types easily.

Given these products:

SKU Name Price
9325336130810 Game of Thrones: Season 1 $39.49
9325336028278 The Fresh Prince of Bel-Air $19.99
9780201835953 The Mythical Man-Month $31.87
9781430219484 Coders at Work $28.72
9780132071482 Artificial Intelligence $119.92
-------------- ------------------------------ ----------

Initially we would like to offer our customers these discounts:

  • Buy 10 or more copies of The Mythical Man-Month, and receive them at the discounted price of $21.99
  • We would like to offer a 3 for the price of 2 deal on Coders at Work. (Buy 3 get 1 free);
  • Customers who purchase Game of Thrones: Season 1, will get The Fresh Prince of Bel-Air free.

Examples:

Products in cart: 9780201835953 x 10, 9325336028278 Expected total: $239.89

Products in cart: 9781430219484 x 3, 9780132071482 Expected total: $177.36

Products in cart: 9325336130810, 9325336028278, 9780201835953 Expected total: $71.36

Example interface:

$cart = new Cart($pricingRules); $cart->addProduct("9780201835953"); $cart->addProduct("9781430219484"); $cart->total();

  • use any language you wish
  • do not use any external libraries (Zend etc.)
  • do not use a database
  • do not create a GUI (we are only interested in your implementation)
  • try not to spend more than two hours on this, we don't want you working all day!

SOLUTION

See comments on runner.php, to run:

php runner.php

You can’t perform that action at this time.