Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/create cart #19

Merged
merged 4 commits into from
Nov 21, 2023
Merged
Changes from 1 commit
Commits
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
21 changes: 15 additions & 6 deletions lib/sylius/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
import { REST_METHODS, SYLIUS_API_ENDPOINT } from 'lib/constants';
import { normalizeCart } from './normalizer/cart-normalizer';
import { normalizeCollection } from './normalizer/collection-normalizer';
import { normalizeProduct } from './normalizer/product-normalizer';
import { SyliusProduct, SyliusTaxon } from './sylius-types/product-types';
import { AddToCartPayload, Collection, GetCollectionProductsPayload, GetProductsPayload } from './types';
import {
AddToCartPayload,
Cart,
Collection,
GetCollectionProductsPayload,
GetProductsPayload
} from './types';

const DOMAIN = `${process.env.SYLIUS_STORE_DOMAIN}`;
const ENDPOINT = `${DOMAIN}${SYLIUS_API_ENDPOINT}`;
Expand Down Expand Up @@ -146,9 +153,11 @@ export const getCollectionProducts = async (payload: GetCollectionProductsPayloa
};

// Cart
export const createCart = async () => {
const cart = await syliusRequest(REST_METHODS.POST, '/orders', { localeCode: 'fr_FR' });
return cart;
export const createCart = async (): Promise<Cart> => {
const data = await syliusRequest(REST_METHODS.POST, '/orders', { localeCode: 'fr_FR' });
const syliusCart = data.body;

return normalizeCart(syliusCart);
};
export const getCart = (cartId: string) => {
syliusRequest(REST_METHODS.GET, `/orders/${cartId}`);
Expand All @@ -162,13 +171,13 @@ export const removeFromCart = () => {};
export const updateCart = () => {};

// Site
export const getMenu = async () => {
export const getMenu = async () => {
Copy link

Choose a reason for hiding this comment

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

faudrait pas juste qu'on configure le prettier ? surtout si j'arrive à faire marcher mon front et que je commence à coder haha

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Si 👍

const collections = await getCollections();
return [
{
title: 'All',
path: '/search'
},
...collections.slice(0,2).map(({ title, path }) => ({ title, path }))
...collections.slice(0, 2).map(({ title, path }) => ({ title, path }))
];
};