Skip to content

Commit

Permalink
✨ create Cart method
Browse files Browse the repository at this point in the history
  • Loading branch information
DuvCharles committed Nov 15, 2023
1 parent eed4aca commit 8d11cdf
Showing 1 changed file with 15 additions and 6 deletions.
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 () => {
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 }))
];
};

0 comments on commit 8d11cdf

Please sign in to comment.