Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
142 commits
Select commit Hold shift + click to select a range
95b0d59
feat: created method with card
artmigalev Jun 9, 2025
cf066c6
feat: add scopes with api manager_my_orders
artmigalev Jun 9, 2025
3711ef2
feat: method created cart
artmigalev Jun 9, 2025
60a63fc
fix: client
artmigalev Jun 9, 2025
b316a94
feat: created anonymous customer
artmigalev Jun 9, 2025
53a1ac1
feat: check customer
artmigalev Jun 9, 2025
2f134dc
feat: merge cards
artmigalev Jun 9, 2025
de7b56e
feat: merge carts
artmigalev Jun 9, 2025
845a1ed
feat: created cart with anonymous customer and created curt new cust…
artmigalev Jun 9, 2025
3d049af
feat: create anonymous flow
artmigalev Jun 9, 2025
46da23d
fix : prettier errors
artmigalev Jun 10, 2025
006876b
feat: get Cart
artmigalev Jun 12, 2025
78d8d63
feat: add product
artmigalev Jun 12, 2025
9ce4fe7
fix: cart
artmigalev Jun 12, 2025
3ba851b
fix: merge
artmigalev Jun 12, 2025
62acc06
fix: prettier
artmigalev Jun 13, 2025
70150f9
feat: add product with anonymous customer
artmigalev Jun 13, 2025
4d84c38
feat: сlear shopping cart
artmigalev Jun 13, 2025
884bde8
feat: Recalculate Total Cost
artmigalev Jun 13, 2025
e782187
feat: Apply Promo Code
artmigalev Jun 13, 2025
e54a5b4
fix: fix imports
artmigalev Jun 13, 2025
6da053b
Merge branch 'recovered-work' into methods-cart
artmigalev Jun 13, 2025
a81dca8
feat: discount
artmigalev Jun 13, 2025
3142e08
feat: discount
artmigalev Jun 13, 2025
e35e968
fix: add enum and fix types
artmigalev Jun 13, 2025
9a09e8a
fix: prettier
artmigalev Jun 13, 2025
aef4971
fix:errors lint
artmigalev Jun 13, 2025
36ad1a1
feat: add types and prettier
artmigalev Jun 13, 2025
2b42a79
feat: add types with codes
artmigalev Jun 13, 2025
054c1bb
feat: discount
artmigalev Jun 13, 2025
93326ae
feat: discount
artmigalev Jun 13, 2025
c775004
feat: add types and prettier
artmigalev Jun 13, 2025
7dbc58c
feat: add types with codes
artmigalev Jun 13, 2025
10cb274
feat: Apply Promo Code
artmigalev Jun 13, 2025
e9913c1
fix: add enum and fix types
artmigalev Jun 13, 2025
13ebd38
fix: add enums
artmigalev Jun 13, 2025
26093e3
Merge branch 'discount' of github.com:dmalashev/eCommerce-Application…
artmigalev Jun 13, 2025
5d4bc95
feat: discount
artmigalev Jun 13, 2025
3902ffb
feat: discount
artmigalev Jun 13, 2025
47adf0f
feat: add types and prettier
artmigalev Jun 13, 2025
bccd280
feat: add types with codes
artmigalev Jun 13, 2025
20cf883
feat: Apply Promo Code
artmigalev Jun 13, 2025
618785b
fix: add enum and fix types
artmigalev Jun 13, 2025
756f60c
feat: discount
artmigalev Jun 13, 2025
1dbe030
feat: discount
artmigalev Jun 13, 2025
736c484
Merge branch 'shopping-cart-integration' of github.com:dmalashev/eCom…
artmigalev Jun 13, 2025
e431279
feat: add titles component
Shakhrii Jun 14, 2025
4f5877e
feat: add cart item
Shakhrii Jun 14, 2025
8c9fe00
feat: add promocode form component
Shakhrii Jun 14, 2025
5a1f665
feat: add cart page with responsive design
Shakhrii Jun 14, 2025
166e55b
feat: add cart navigation from header menu
Shakhrii Jun 14, 2025
c646b5b
feat: add empty cart state
Shakhrii Jun 14, 2025
a10cd88
Merge branch 'shopping-cart-integration' into cart-api-synchronization
Shakhrii Jun 14, 2025
6b164d8
feat: add function for fetching data about a product
dmalashev Jun 13, 2025
7d4b613
feat: add component for the product page
dmalashev Jun 13, 2025
dcdf270
feat: add route for the product page
dmalashev Jun 13, 2025
a8c9e16
feat: add link to the product page into the card component
dmalashev Jun 13, 2025
6caec54
feat: implement adaptive design for the Product Page
dmalashev Jun 14, 2025
163f020
fix: fix eslint error with price variable
dmalashev Jun 14, 2025
30e5c0b
feat: add displaying of a discounted price
dmalashev Jun 14, 2025
d34d3df
fix: fix react error
dmalashev Jun 14, 2025
bdbd238
Merge pull request #43 from dmalashev/SCRUM-72
dmalashev Jun 14, 2025
346c6f1
Merge branch 'release/basket-about_us' into shopping-cart-integration
dmalashev Jun 14, 2025
6c48eed
Merge pull request #44 from dmalashev/shopping-cart-integration
dmalashev Jun 14, 2025
f688fc8
feat: change order in login request and check if cart exists
Shakhrii Jun 15, 2025
f82b791
fix: get products from cart
Shakhrii Jun 15, 2025
37b21b0
feat: add clientBuilder with password flow
Shakhrii Jun 15, 2025
162c2f0
feat: add discount for product
Shakhrii Jun 15, 2025
4543f26
feat: add removing product
Shakhrii Jun 15, 2025
c64bf46
feat: add changing quantity
Shakhrii Jun 15, 2025
64b07e6
feat: add removing cart
Shakhrii Jun 15, 2025
bfc8f36
feat: add promocode applying
Shakhrii Jun 15, 2025
8647c95
merge with release/basket-about_us
Shakhrii Jun 15, 2025
bfcba52
feat: add button to add product from catalog
Shakhrii Jun 15, 2025
46c4187
feat: add message after clear cart
Shakhrii Jun 15, 2025
430a45c
Merge pull request #45 from dmalashev/cart-api-synchronization
dmalashev Jun 15, 2025
dc0864f
feat: add array of items in the cart to the auth-context
dmalashev Jun 15, 2025
ebef93a
Merge pull request #46 from dmalashev/SCRUM-91
dmalashev Jun 15, 2025
84e79c2
feat: modify addItemToCart to return cart object
dmalashev Jun 15, 2025
5f4b98d
feat: implement button for adding product to the cart
dmalashev Jun 15, 2025
b25e638
fix: fix bug with cart for logged customer
dmalashev Jun 16, 2025
fefaef6
fix: change returned response with line items
dmalashev Jun 16, 2025
2473593
refactor: delete useless code and comments
dmalashev Jun 16, 2025
662a1c6
feat: add error message when adding to the cart fails
dmalashev Jun 16, 2025
0099252
fix: add key to cades
artmigalev Jun 16, 2025
2863b8b
fix: apiRootCustomer
artmigalev Jun 16, 2025
2593c7e
fix: apply promocode
Shakhrii Jun 16, 2025
c094a16
Merge pull request #47 from dmalashev/SCRUM-87
Shakhrii Jun 16, 2025
1a87550
feat: add codes
artmigalev Jun 16, 2025
5d1b8d4
Merge branch 'release/basket-about_us' into cart-api-synchronization
Shakhrii Jun 16, 2025
66da538
Merge pull request #48 from dmalashev/cart-api-synchronization
dmalashev Jun 16, 2025
cce9a3f
feat: change the type of response from Product to ProductProjection
dmalashev Jun 16, 2025
672f5e6
feat: add "Add to Cart" button
dmalashev Jun 16, 2025
ebbda85
feat: add "Remove from Cart" button
dmalashev Jun 16, 2025
b17c595
feat: add success message when product has removed from the cart
dmalashev Jun 16, 2025
5b60451
Merge pull request #49 from dmalashev/SCRUM-89
dmalashev Jun 16, 2025
8e63b64
feat: implement updating the state of itemsInCart state when loading …
dmalashev Jun 16, 2025
492ec5b
feat: add interface to main page
Shakhrii Jun 16, 2025
d437e1b
Merge branch 'release/basket-about_us' into cart-api-synchronization
Shakhrii Jun 16, 2025
3cce2dd
feat: add responsive design
Shakhrii Jun 16, 2025
e0e9c79
feat: add update of itemsInCart state in the Cart component
dmalashev Jun 16, 2025
e04ad56
feat: add counter of products to the cart button
dmalashev Jun 16, 2025
2230095
Merge pull request #50 from dmalashev/cart-api-synchronization
dmalashev Jun 17, 2025
873db2f
Merge branch 'release/basket-about_us' into SCRUM-91
dmalashev Jun 17, 2025
b5dc3b0
Merge pull request #51 from dmalashev/SCRUM-91
dmalashev Jun 17, 2025
601d7c9
fix: solve eslint errors
dmalashev Jun 17, 2025
2b89393
fix: solve eslint errors in test files
dmalashev Jun 17, 2025
bb3b14d
fix: fix bug with displaying of tab icons on the deploy
dmalashev Jun 17, 2025
8fe1e78
refactor: solve stylelint warnings
dmalashev Jun 17, 2025
d5bcd8d
fix: delete the second cart button
dmalashev Jun 17, 2025
414338e
fix: return a strikeout line for the pice on product cards with discount
dmalashev Jun 17, 2025
b3e16c9
Merge pull request #52 from dmalashev/SCRUM-96
dmalashev Jun 17, 2025
b14394a
feat: add about us page template
dmalashev Jun 17, 2025
adc8c37
feat: add template for a card
dmalashev Jun 17, 2025
da9e2b6
feat: add photos and short bios of shakhri and artyom
dmalashev Jun 17, 2025
ea2841e
fix: change apiRoot for requests
Shakhrii Jun 17, 2025
35bd58d
feat: add contributions for shakhri and artyom
dmalashev Jun 17, 2025
5e78047
feat: add github links for artyom and shakhri
dmalashev Jun 17, 2025
9925400
feat: add roles for artyom and shakhri
dmalashev Jun 17, 2025
74a8094
Merge branch 'release/basket-about_us' of github.com:dmalashev/eComme…
artmigalev Jun 17, 2025
229f475
feat: add card with dmitriy's info
dmalashev Jun 17, 2025
0f47819
feat: add introduction
dmalashev Jun 17, 2025
c73a628
feat: add rs school logo
dmalashev Jun 17, 2025
213c7a3
feat: add adaptive design
dmalashev Jun 17, 2025
2d4eab5
fix: solve linter errors
dmalashev Jun 17, 2025
5069253
Merge pull request #53 from dmalashev/SCRUM-93
dmalashev Jun 17, 2025
3060971
fix: limit products
artmigalev Jun 17, 2025
8518858
Merge branch 'release/basket-about_us' of github.com:dmalashev/eComme…
artmigalev Jun 17, 2025
fbe4332
feat: pagination products
artmigalev Jun 17, 2025
551c479
feat: add pagination component to the Catalog Page
dmalashev Jun 17, 2025
104f8eb
fix: fix bug with displaying prices on the card
dmalashev Jun 17, 2025
870ddab
fix: fix linter errors
dmalashev Jun 17, 2025
e7922e3
fix: applying promocode
Shakhrii Jun 17, 2025
20f4d0f
fix: removing cart with anonymous user
Shakhrii Jun 17, 2025
933eb18
fix: fetch cart items after log in
dmalashev Jun 17, 2025
ca78f7d
feat: add a confirmation prompt to "Remove all goods" button
dmalashev Jun 17, 2025
2d0212c
docs: update README.md
dmalashev Jun 18, 2025
32a1a2b
fix: get request for apiRootCustomer
artmigalev Jun 18, 2025
9a59883
fix: clear storage and creatAnon when customer reload page
artmigalev Jun 18, 2025
05a6fda
fix: prevent errors during loading the Cart page
dmalashev Jun 18, 2025
9af16a4
fix: fix bug with loading cart items in logged state
dmalashev Jun 18, 2025
b86a4c6
fix: merge cart
artmigalev Jun 19, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ This is an educational project which represents a website for sale vinyl records
[Authors](#authors)

## About the project
The project represents a website where you can find vinyl records, audio cassettes and compact disks with music. Each item has its own card with information. You can find a catalog with items and sort them by different parameters. You can also create and manage your personal account. It enables you to add items to the basket and proceed to checkout.
**The project represents a website where you can find vinyl records, audio cassettes and compact disks with music.** Each product has its own **page with detailed information**. You can find all of the products on the **Catalog page**. You can add every product to a cart on the Catalog page or on the page of some particular product. All the products that have been added to the cart are displayed on the **Cart page**. On this page you can change an amount of every product or delete it or you can also clean the whole basket. This page also provides the ability to apply a promocode for discount. You have the ability to create your personal account on the **Registration page** and manage it on the **Profile page**. To log in you account use the form on the **Login page**. The backend part of the project is implemented with using the CommerceTools platform.

## How to start the application
1. Run this command to clone the repository:
Expand Down Expand Up @@ -54,6 +54,8 @@ Here are scripts you can use during the interaction with the project. Run the co

`test:ui` - run Vitest providing UI for runnning tests

`coverage` - check the information about test coverage of the code

`format` - check the code of `.ts`, `.tsx` and `.css` files by Prettier formatter and fix all possible problems

`format:check` - check the code of `.ts`, `.tsx` and `.css` files by Prettier formatter
Expand All @@ -67,11 +69,15 @@ Here are scripts you can use during the interaction with the project. Run the co
`pre-commit` - run formatters and linters for `.ts`, `.tsx` and `.css` files

`prepare` - initialize Husky in the project

## The technology stack
Here is the technology stack used for creating this application:
- TypeScript
- React
- React Router
- Zustand
- Ant Design
- Commercetools platform-sdk
- Prettier
- Eslint (with eslint-plugin-unicorn)
- StyleLint
Expand Down
6 changes: 3 additions & 3 deletions eCommerce-Application/.env
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ VITE_SCOPES=manage_project:rss-ecomm-jsfe2024q4 manage_api_clients:rss-ecomm-jsf

// USER SCOPES

VITE_USER_API_CLIENT_SECRET=KAk6B0aXuZHktxVbhvZRIo3Qlt4bEMbs
VITE_USER_API_CLIENT_ID=DMZCKQOB1EjzsY6oyODvGz4_
VITE_USER_API_SCOPES=view_categories:rss-ecomm-jsfe2024q4 view_products:rss-ecomm-jsfe2024q4 view_cart_discounts:rss-ecomm-jsfe2024q4 manage_my_profile:rss-ecomm-jsfe2024q4 manage_order_edits:rss-ecomm-jsfe2024q4 manage_orders:rss-ecomm-jsfe2024q4 manage_customers:rss-ecomm-jsfe2024q4 manage_cart_discounts:rss-ecomm-jsfe2024q4 manage_products:rss-ecomm-jsfe2024q4 manage_customer_groups:rss-ecomm-jsfe2024q4
VITE_USER_API_CLIENT_SECRET=aY3TBDtlZNVMz9yZ7Z_9HZ-WHjCthpA-
VITE_USER_API_CLIENT_ID=WuwGUM1Rctqt613uAaVFuUqE
VITE_USER_API_SCOPES=view_categories:rss-ecomm-jsfe2024q4 view_sessions:rss-ecomm-jsfe2024q4 manage_sessions:rss-ecomm-jsfe2024q4 view_products:rss-ecomm-jsfe2024q4 view_standalone_prices:rss-ecomm-jsfe2024q4 view_published_products:rss-ecomm-jsfe2024q4 view_types:rss-ecomm-jsfe2024q4 manage_my_quotes:rss-ecomm-jsfe2024q4 manage_orders:rss-ecomm-jsfe2024q4 view_discount_codes:rss-ecomm-jsfe2024q4 view_project_settings:rss-ecomm-jsfe2024q4 manage_my_quote_requests:rss-ecomm-jsfe2024q4 manage_my_shopping_lists:rss-ecomm-jsfe2024q4 manage_my_payments:rss-ecomm-jsfe2024q4 view_cart_discounts:rss-ecomm-jsfe2024q4 manage_shopping_lists:rss-ecomm-jsfe2024q4 manage_products:rss-ecomm-jsfe2024q4 manage_customer_groups:rss-ecomm-jsfe2024q4 view_shipping_methods:rss-ecomm-jsfe2024q4 manage_my_profile:rss-ecomm-jsfe2024q4 manage_order_edits:rss-ecomm-jsfe2024q4 view_product_selections:rss-ecomm-jsfe2024q4 manage_my_orders:rss-ecomm-jsfe2024q4 manage_customers:rss-ecomm-jsfe2024q4 create_anonymous_token:rss-ecomm-jsfe2024q4 view_tax_categories:rss-ecomm-jsfe2024q4
180 changes: 180 additions & 0 deletions eCommerce-Application/src/api/Cart/add.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,180 @@
import {
ApiRoot,
Cart,
ClientResponse,
createApiBuilderFromCtpClient,
LineItemDraft,
ProductProjection,
LineItem,
} from '@commercetools/platform-sdk';
import {
// apiRoot,
apiRootCustomer,
authMiddleware,
client,
createClientWithPasswordFlow,
// createAuthMiddleware,
httpMiddleware,
projectKey,
} from '../client/client';
import { createAnonymousCustomer } from '../customer/anonymous-customer';
import { getCart, getCartPasswordFlow } from './get';
// import { ClientBuilder } from '@commercetools/ts-client';





export async function addItemToCart(product: ProductProjection, quantity: number = 1): Promise<LineItem[] | undefined> {
const item: LineItemDraft = {
productId: product.id,
quantity: quantity,
};

const isLogined: boolean = !!localStorage.getItem('access_token');
// const apiRootCustomer: ApiRoot = createApiBuilderFromCtpClient(
// client.withProjectKey(projectKey).withHttpMiddleware(httpMiddleware).build(),
// );

if (isLogined) {
const response: ClientResponse<Cart> = await apiRootCustomer
.withProjectKey({ projectKey })
.me()
.activeCart()
.get()
.execute();

const addItemResponse: ClientResponse<Cart> = await apiRootCustomer
.withProjectKey({ projectKey })
.me()
.carts()
.withId({ ID: response.body.id })
.post({
body: {
version: response.body.version,
actions: [
{
action: 'addLineItem',
...item,
},
],
},
})
.execute();

return addItemResponse.body.lineItems;
} else if (!localStorage.getItem('cartId')) {
await createAnonymousCustomer();
}
if (localStorage.getItem('anonymousId')) {
const cartId: string = localStorage.getItem('cartId')!;
const version: number = Number(localStorage.getItem('cartVersion'));
const apiRootAnonymous: ApiRoot = createApiBuilderFromCtpClient(
client.withProjectKey(projectKey).withHttpMiddleware(httpMiddleware).build(),
);
const response: ClientResponse<Cart> = await apiRootAnonymous
.withProjectKey({ projectKey })
.carts()
.withId({ ID: cartId })
.post({
body: {
version,
actions: [
{
action: 'addLineItem',
...item,
},
],
},
})
.execute();
localStorage.setItem('cartVersion', response.body.version.toString());

return response.body.lineItems;
}
}

// Apply Promo Code and Display Updated Prices

export async function applyPromoCode(code: string, email?: string, password?: string): Promise<boolean> {
let isCode = false;
const isLogined: boolean = !!localStorage.getItem('access_token');
if (isLogined) {
try {
const apiRoot: ApiRoot = createApiBuilderFromCtpClient(
createClientWithPasswordFlow(email || '', password || '')
.withProjectKey(projectKey)
.withHttpMiddleware(httpMiddleware)
.build(),
);
const response = await apiRoot
.withProjectKey({ projectKey })
.discountCodes()
.withKey({ key: code })
.get()
.execute();
isCode = !!response.body.id;
console.log(await apiRoot.withProjectKey({ projectKey }).discountCodes().get().execute());
if (isCode) {
const cart = await getCartPasswordFlow(email, password);
await apiRoot
.withProjectKey({ projectKey })
.me()
.carts()
.withId({ ID: cart.id })
.post({
body: {
version: cart.version,
actions: [
{
action: 'addDiscountCode',
code: code,
},
],
},
})
.execute();
}
} catch {
return false;
}
} else {
try {
const apiRootAnonymous: ApiRoot = createApiBuilderFromCtpClient(
client.withProjectKey(projectKey).withHttpMiddleware(httpMiddleware).build(),
);

const response = await apiRootAnonymous
.withProjectKey({ projectKey })
.discountCodes()
.withKey({ key: code })
.get()
.execute();
isCode = !!response.body.id;
if (isCode) {
const cart = await getCart();
await apiRootAnonymous
.withProjectKey({ projectKey })
.me()
.carts()
.withId({ ID: cart.id })
.post({
body: {
version: cart.version,
actions: [
{
action: 'addDiscountCode',
code: code,
},
],
},
})
.execute();
}
} catch {
return false;
}
}
// console.log(await getTotalCost());
return isCode;
}
25 changes: 25 additions & 0 deletions eCommerce-Application/src/api/Cart/create.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { ApiRoot } from '@commercetools/platform-sdk';
import { projectKey } from '../client/client';
import { createAnonymousCustomer } from '../customer/anonymous-customer';
import { CountriesCodes, CurrencyCodes, StorageKeys, StorageTokenKeys } from '../../types/enums';

export async function createCart(api?: ApiRoot): Promise<void> {
if (!localStorage.getItem(StorageKeys.ANONYMOUS_ID) && !localStorage.getItem(StorageTokenKeys.ACCESS_TOKEN)) {
await createAnonymousCustomer();
}

const result = await api
?.withProjectKey({ projectKey })
.me()
.carts()
.post({
body: {
currency: CurrencyCodes.USD,
country: CountriesCodes.US,
},
})
.execute();
localStorage.setItem(StorageKeys.CART_ID, result?.body.id || '');
localStorage.setItem(StorageKeys.CART_VERSION, result?.body.version.toString() || '');
console.log(result);
}
Loading