Skip to content

Commit

Permalink
--wip-- [skip ci]
Browse files Browse the repository at this point in the history
  • Loading branch information
DuvCharles committed Nov 17, 2023
1 parent 6b369db commit 4cf720b
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 5 deletions.
4 changes: 2 additions & 2 deletions components/cart/add-to-cart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ export function AddToCart({
const router = useRouter();
const searchParams = useSearchParams();
const [isPending, startTransition] = useTransition();
const defaultVariantId = variants.length === 1 ? variants[0]?.id : undefined;
const defaultVariantId = variants.length === 1 ? variants[0]?.code : undefined;
const variant = variants.find((variant: ProductVariant) =>
variant.selectedOptions.every(
(option) => option.value === searchParams.get(option.name.toLowerCase())
)
);
const selectedVariantId = variant?.id || defaultVariantId;
const selectedVariantId = variant?.code || defaultVariantId;
const title = !availableForSale
? 'Out of stock'
: !selectedVariantId
Expand Down
7 changes: 4 additions & 3 deletions lib/sylius/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -164,9 +164,10 @@ export const getCart = async (cartId: string): Promise<Cart> => {
const syliusCart = data.body;
return normalizeCart(syliusCart);
};
export const addToCart = (cartId: string | undefined, payload: AddToCartPayload[]) => {
syliusRequest(REST_METHODS.PUT, `/orders/${cartId}/items`, payload[0]);
return {};
export const addToCart = async (cartId: string | undefined, payload: AddToCartPayload[]) => {
console.log('***** DATA *****', payload);
const data = await syliusRequest(REST_METHODS.POST, `/orders/${cartId}/items`, { productVariant: payload[0]?.merchandiseId, quantity: payload[0]?.quantity });
console.log('***** DATA *****', data.body);
};
export const removeFromCart = () => {};
export const updateCart = () => {};
Expand Down
1 change: 1 addition & 0 deletions lib/sylius/normalizer/product-normalizer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ export const normalizeProduct = (product: SyliusProduct): Product => ({
const normalizeProductVariant = (variant: SyliusProductVariant): ProductVariant => {
return {
id: variant.id.toString(),
code: variant.code,
title: variant.name,
availableForSale: variant.inStock,
selectedOptions: variant.optionValues.map((optionValue) => {
Expand Down
1 change: 1 addition & 0 deletions lib/sylius/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ export interface ProductOption {

export interface ProductVariant {
id: string;
code: string
title: string;
availableForSale: boolean;
selectedOptions: {
Expand Down

0 comments on commit 4cf720b

Please sign in to comment.