From 68b7c59cda24af8fb725dfbbb65221909f690867 Mon Sep 17 00:00:00 2001 From: zubair-ce07 Date: Tue, 16 Apr 2024 13:38:00 +1000 Subject: [PATCH] fix: incorporated feedback comments and update the code --- src/payment/PaymentPage.jsx | 20 ++++++++++++++++---- src/payment/checkout/Checkout.jsx | 8 ++++++++ src/payment/data/reducers.js | 3 --- 3 files changed, 24 insertions(+), 7 deletions(-) diff --git a/src/payment/PaymentPage.jsx b/src/payment/PaymentPage.jsx index 0756237a4..ba26378d1 100644 --- a/src/payment/PaymentPage.jsx +++ b/src/payment/PaymentPage.jsx @@ -43,13 +43,25 @@ class PaymentPage extends React.Component { } componentDidMount() { - const sku = localStorage.getItem('sku'); + const rawSkus = localStorage.getItem('skus'); + const skus = JSON.parse(rawSkus); // Check if SKU is not null - if (sku !== null) { - const paymentPage = `${getConfig().ECOMMERCE_BASE_URL}/basket/add/?sku=${sku}`; + if (skus !== null) { + const baseURL = getConfig().ECOMMERCE_BASE_URL; + + // Constructing the URL with the sku parameters + let paymentPage = `${baseURL}/basket/add/?`; + // Appending each sku value to the URL + Object.values(skus).forEach(sku => { paymentPage += `sku=${sku}&`; }); + // for (const sku of skus) { + // paymentPage += `sku=${sku}&`; + // } + // Removing the extra '&' character at the end + paymentPage = paymentPage.slice(0, -1); + // const paymentPage = `${getConfig().ECOMMERCE_BASE_URL}/basket/add/?sku=${sku}`; window.location.href = paymentPage; - localStorage.removeItem('sku'); + localStorage.removeItem('skus'); } else { this.props.fetchBasket(); sendPageEvent(); diff --git a/src/payment/checkout/Checkout.jsx b/src/payment/checkout/Checkout.jsx index 7831f459a..d349bf7a4 100644 --- a/src/payment/checkout/Checkout.jsx +++ b/src/payment/checkout/Checkout.jsx @@ -47,6 +47,14 @@ class Checkout extends React.Component { ); this.props.submitPayment({ method: 'paypal' }); + + const { products } = this.props; + const skus = []; + + for (const product of products){ + skus.push(product.sku) + } + localStorage.setItem('skus', JSON.stringify(skus)); }; // eslint-disable-next-line react/no-unused-class-component-methods diff --git a/src/payment/data/reducers.js b/src/payment/data/reducers.js index 847233eec..fcf5dc41f 100644 --- a/src/payment/data/reducers.js +++ b/src/payment/data/reducers.js @@ -36,9 +36,6 @@ const basket = (state = basketInitialState, action = null) => { }; case BASKET_DATA_RECEIVED: - if (action.payload.products && action.payload.products.length > 0) { - localStorage.setItem('sku', action.payload.products[0].sku); - } return { ...state, ...action.payload }; case BASKET_PROCESSING: return {