From 4d48c511cac5802917583b190d17630de4f9011f Mon Sep 17 00:00:00 2001 From: Loan Laux Date: Wed, 7 Jul 2021 19:57:31 +0300 Subject: [PATCH] pass pricing to addItem call for verification and update cart API URL Signed-off-by: Loan Laux --- components/product/ProductSidebar/ProductSidebar.tsx | 7 +++++++ framework/reactioncommerce/api/endpoints/cart/add-item.ts | 1 + framework/reactioncommerce/cart/use-add-item.tsx | 2 +- 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/components/product/ProductSidebar/ProductSidebar.tsx b/components/product/ProductSidebar/ProductSidebar.tsx index fe8a71aa5..c65290754 100644 --- a/components/product/ProductSidebar/ProductSidebar.tsx +++ b/components/product/ProductSidebar/ProductSidebar.tsx @@ -29,9 +29,16 @@ const ProductSidebar: FC = ({ product, className }) => { const addToCart = async () => { setLoading(true) try { + console.log("product", product) + console.log("variant", variant) + await addItem({ productId: String(product.id), variantId: String(variant ? variant.id : product.variants[0].id), + pricing: { + amount: variant ? Number.parseFloat(variant.price) : Number.parseFloat(product.price.value), + currencyCode: String(product.price.currencyCode), + } }) openSidebar() setLoading(false) diff --git a/framework/reactioncommerce/api/endpoints/cart/add-item.ts b/framework/reactioncommerce/api/endpoints/cart/add-item.ts index d80e777a1..5af2e815f 100644 --- a/framework/reactioncommerce/api/endpoints/cart/add-item.ts +++ b/framework/reactioncommerce/api/endpoints/cart/add-item.ts @@ -43,6 +43,7 @@ const addItem: CartEndpoint['handlers']['addItem'] = async ({ if (!item.quantity) item.quantity = 1 if (cartId === config.dummyEmptyCartId) { + console.log("pricing", item.pricing) const createdCart = await config.fetch(createCartMutation, { variables: { input: { diff --git a/framework/reactioncommerce/cart/use-add-item.tsx b/framework/reactioncommerce/cart/use-add-item.tsx index 228d99bbe..f938a68f5 100644 --- a/framework/reactioncommerce/cart/use-add-item.tsx +++ b/framework/reactioncommerce/cart/use-add-item.tsx @@ -9,7 +9,7 @@ export default useAddItem as UseAddItem export const handler: MutationHook = { fetchOptions: { - url: '/api/reactioncommerce/cart', + url: '/api/cart', method: 'POST', }, async fetcher({ input: item, options, fetch }) {