Skip to content

A customer basket that allows a customer to add products and provides a total cost of the basket including applicable discounts.

Notifications You must be signed in to change notification settings

momosetti/price-calculation

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

image

Live Demo 🌍

A customer basket that allows a customer to add products and provides a total cost of the basket including applicable discounts.

Project structure

src
 ┣ components
 ┃ ┣ cart
 ┃ ┃ ┣ cartCard.jsx
 ┃ ┃ ┗ cartStatement.jsx
 ┃ ┣ layout
 ┃ ┃ ┣ container.jsx
 ┃ ┃ ┗ fluidGrid.jsx
 ┃ ┗ product
 ┃ ┃ ┗ productCard.jsx
 ┣ features
 ┃ ┣ cart
 ┃ ┃ ┣ cartPane.jsx
 ┃ ┃ ┗ cartSlice.js
 ┃ ┗ product
 ┃ ┃ ┣ productPane.jsx
 ┃ ┃ ┗ productSlice.js
 ┣ utils
 ┃ ┣ constants
 ┃ ┃ ┗ dataMock.js
 ┃ ┗ helpers
 ┃ ┃ ┗ discountCalculation.js
 ┣ App.jsx
 ┣ globalStyle.js
 ┣ main.jsx
 ┗ store.js

How to run the app

After cloning the repo. Using your preferred package manager (I use Yarn).

To install dependencies:

git clone https://github.com/momosetti/price-calculation
cd price-calculation
yarn / npm install

For starting the dev server:

yarn dev

For building:

yarn build

For serving static files (after build the project):

yarn perview

Tech Stack used

  • SPA library: React.js.

  • State management (Redux.js, utility: Redux ToolKit).

  • Build tool: Vite.js

  • Style: Styled-components.

  • Source control version: GIT

  • Linting & Formatting: Eslint and Prettier (local Prettier Vscode configuration).

API

Functions

milkDiscountCalculationObject

Function to calculate the milk discount and billed price after applying the offer rule.

beardDiscountCalculationObject

Calculate the related discount and total price depend on another item (in our case, the butter is the item) quantity.

calculateStatememntObject

Calculate the statement on the basket.

milkDiscountCalculation ⇒ Object

Function to calculate the milk discount and billed price after applying the offer rule.

Returns: Object - Object contains the discountPrice and the billed price depends to the item quantity.

Param Type Description
ItemQuantity number quantity item from the basket.
unitPrice number product unit price.

beardDiscountCalculation ⇒ Object

Calculate the related discount and total price depend on another item (in our case, the butter is the item) quantity

Returns: Object - return an object with discountPrice and paidTotalPrice keys.

Param Type Description
butterItemQuantity number butter items quantity on the basket.
beardItemQuantity number beard items quantity on the basket.
unitPrice number unit price of the beard product.

calculateStatememnt ⇒Object

Calculate the statement on the basket.

Returns: Object with subTotal, discount, and total keys.

Param Type Description
itemsArray Array.<Object> array of object added to the basket.

About

A customer basket that allows a customer to add products and provides a total cost of the basket including applicable discounts.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published