This will pull the JSON Order live from the Data Store on GitHub by providing the relevant Order ID number.
You can POST raw JSON in the body of a request for it to process the order provided.
A file has been created in /src/classes/discounts.json where new discounts can be added at any time in the 3 types required for the excersise.
- MultiItem = A discount (% or Flat) is applied when multiple items are purchased of any quantity.
- BuyXGetYFree = A free item is given when a certain number of products are purchased - optionally can be enabled/disabled in multiples.
- CustomerTotal = A discount (% or Flat) is applied if the customers total revenue meets a specified threshold.
New Discount types can be added in /src/classes/discountTypes/ when required ensuring the name formation remains as "TYPE.class.php"
- With MultiItem discounts, it is not clear if all of the cheapest items should be discounted, or just a single item within the cheapest item.
- With MultiItem discounts, it is not clear if when purchasing more than 2 items if multiple discounts should apply (EG. 6 "Tools" = 3 items at 20% off.)
- It was not clear if multiple discounts could apply to the same order - if not, the priority of this (which discount should be applied over another).
- For BuyXGetYFree, it is not clear if you can buy 3 of one item, and 2 of another item in a certain category to be eligible.
- For BuyXGetYFree, it is not clear if the free item should be pre-added by the customer or not (IE: Buy 5 get 6th free will discount the 6th item added to nil, rather than adding another item automatically).
- Better error handling
- Connect to a database instead of an API
- Authentication / Security Tokens
- Adding discounted line item price totals.
{
"id": "1",
"customer-id": "1",
"items": [
{
"product-id": "B102",
"quantity": "10",
"unit-price": "4.99",
"total": "49.90"
}
],
"total": "49.90"
}
{
"id": "1",
"customer-id": "1",
"items": [
{
"product-id": "B102",
"quantity": "10",
"unit-price": "4.99",
"total": "49.90"
},
{
"product-id": "B102",
"quantity": "2",
"unit-price": "0.00",
"total": "0.00"
}
],
"total": "49.90",
"discount-amount": "0.00",
"discounts-applied": [
"Buy 5 Switches get 1 Free (Added 2 Free of Press button)"
]
}
{
"id": "2",
"customer-id": "2",
"items": [
{
"product-id": "B102",
"quantity": "5",
"unit-price": "4.99",
"total": "24.95"
}
],
"total": "24.95"
}
{
"id": "2",
"customer-id": "2",
"items": [
{
"product-id": "B102",
"quantity": "5",
"unit-price": "4.99",
"total": "24.95"
},
{
"product-id": "B102",
"quantity": "1",
"unit-price": "0.00",
"total": "0.00"
}
],
"total": "22.45",
"discount-amount": "2.50",
"discounts-applied": [
"10% Customer Loyalty Discount",
"Buy 5 Switches get 1 Free (Added 1 Free of Press button)"
]
}
{
"id": "3",
"customer-id": "3",
"items": [
{
"product-id": "A101",
"quantity": "2",
"unit-price": "9.75",
"total": "19.50"
},
{
"product-id": "A102",
"quantity": "1",
"unit-price": "49.50",
"total": "49.50"
}
],
"total": "69.00"
}
{
"id": "3",
"customer-id": "3",
"items": [
{
"product-id": "A101",
"quantity": "2",
"unit-price": "9.75",
"total": "19.50"
},
{
"product-id": "A102",
"quantity": "1",
"unit-price": "49.50",
"total": "49.50"
}
],
"total": "67.05",
"discount-amount": "1.95",
"discounts-applied": [
"Buy 2+ Tools for 20% Off (Applied against A101 - Screwdriver)"
]
}
{
"id": "4",
"customer-id": "6",
"items": [
{
"product-id": "A101",
"quantity": "2",
"unit-price": "9.75",
"total": "19.50"
}
],
"total": "19.50"
}
{
"id": "4",
"customer-id": "6",
"items": [
{
"product-id": "A101",
"quantity": "2",
"unit-price": "9.75",
"total": "19.50"
}
],
"total": "19.50",
"discount-error": "Customer ID could not be located."
}