Skip to content

Conversation

@akseee
Copy link
Collaborator

@akseee akseee commented Jun 13, 2025

  1. Task:

  2. Screenshot:
    {CB3215C0-868E-4E40-ABA1-FE0A104F88EC}

  3. Deploy

  4. Done 13.06.2025 / deadline 17.06.2025

  5. Tasks:

✅ Acceptance Criteria

  • Each product card has an "Add to Cart" 🛒 button, which can be a traditional button or an icon.
    If the product is already in the shopping cart, the "Add to Cart" button is inactive or provides a relevant notice.

✅ Acceptance Criteria

  • The "Add to Cart" button on each product card triggers an API call to add the corresponding product to the user's shopping cart.
  • If the user does not yet have a cart, the "Add to Cart" button triggers an API call to create a new cart using the "MyCart" endpoint.
  • If the user already has a cart, the "Add to Cart" button triggers an API call to add the new product as a line item in the existing cart.
  • A loading indicator or some feedback is shown while the API call is in progress.

🔒 Authentication Flows:

  • For logged-in users, utilize the "Password Flow" for authentication.
  • For anonymous users, use the "Anonymous Session Flow" for establishing a temporary session.

🔨 Implementation Details

  • Add to Cart Functionality: Once a product is added to the cart, the "Add to Cart" button on the product card should trigger an API call to update the user's shopping cart with the chosen product.
  • Cart Management: If the user does not yet have a cart, the API call should first create a new cart using the "MyCart" endpoint. If the user already has a cart, the API call should add the new product as a line item in the existing cart.

🔨 Implementation Details

  • Add to Cart Button: Incorporate an "Add to Cart" 🛒 button on each product card. This button should be clearly visible and intuitively placed to encourage users to add items to their cart. The button could be a traditional button with a label or an icon that represents adding an item to the cart.

🎨 Visual Implementation Ideas

  • Icon Use: Consider using an icon for the "Add to Cart" 🛒 button, such as a shopping cart or a ➕ plus sign. Icons can help users quickly understand the button's function and save space on the product card.
  • Color Contrast: If you choose to use a traditional button with a label, consider using a contrasting color to make it stand out on the product card.
  • Button Position: Place the "Add to Cart" button in a prominent position on the product card, such as below the product image or next to the product description.

Comment on lines 39 to 43
setNotification({
severity: 'info',
open: true,
message: 'Adding game to cart...',
});
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Эта часть кода повторяется три раза + она переиспользуемая в других файлах. Можно создать или вспомогательную функцию с параметрами:
const showNotification = (severity: 'success' | 'error' | 'info', message: string) => { setNotification({ severity, open: true, message, }); };

А затем использовать так:
showNotification('info', 'Adding game to cart...');
showNotification('success', 'The game added to cart');
showNotification('error', Failed to add game: ${err.message});


Ещё один вариант — использовать хук. Я взяла твою реализацию за основу и сделала удобный хук useNotification. С ним код получается компактнее. Плюс его можно переиспользовать.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Спасибо, хорошая идея, доделала:)

Comment on lines 176 to 197
<Button
size="small"
variant="outlined"
onClick={onCartClick}
color="secondary"
sx={{
backgroundColor: theme.palette.primary.main,
color: theme.palette.primary.contrastText,
border: 'none',
transition:
'transform 0.2s ease, background-color 0.2s ease, color 0.2s ease',
'&:hover': {
backgroundColor: theme.palette.primary.dark,
color: theme.palette.getContrastText(
theme.palette.primary.main
),
transform: 'scale(1.05)',
},
}}
>
<AddShoppingCartIcon /> add to cart
</Button>
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Обе кнопки ("View details" и "Add in Cart") очень похожи — различие только в цвете фона. Такие компоненты лучше делать универсальными и переиспользуемыми.

Чтобы избежать дублирования, я создала в своей ветке компонент ActionButton. Кнопке можно передавать состояния, стили и т.д.

Думаю, использовать один компонент — это удобно.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Изменила и перезалила с общим компонентом!

import { getApiRoot } from '@/shared/api/commerceTools';
import type { Cart } from '@commercetools/platform-sdk';

export const addLineItem = async (
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

отлично

import { Alert, IconButton, Snackbar } from '@mui/material';
import CloseIcon from '@mui/icons-material/Close';

export const SnackNotification = ({
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Супер)

@cherkasovaa cherkasovaa merged commit be13bc4 into sprint-4 Jun 16, 2025
2 checks passed
@akseee akseee deleted the feature/catalog-enhancements branch June 19, 2025 19:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants