A customer basket that allows a customer to add products and provides a total cost of the basket including applicable discounts.
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
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
-
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).
- milkDiscountCalculation ⇒
Object
Function to calculate the milk discount and billed price after applying the offer rule.
- beardDiscountCalculation ⇒
Object
Calculate the related discount and total price depend on another item (in our case, the butter is the item) quantity.
- calculateStatememnt ⇒
Object
Calculate the statement on the basket.
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. |
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. |
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. |