diff --git a/src/components/products/index.js b/src/components/products/index.js
index ca40149..954ecb8 100644
--- a/src/components/products/index.js
+++ b/src/components/products/index.js
@@ -7,8 +7,6 @@ const Products = ({ products }) => {
return null;
}
- console.log( 'products', products );
-
return (
diff --git a/src/utils/cart/api.js b/src/utils/cart/api.js
index e69de29..b81601e 100644
--- a/src/utils/cart/api.js
+++ b/src/utils/cart/api.js
@@ -0,0 +1,20 @@
+import { getSession } from './session';
+import { isEmpty } from 'lodash';
+
+export const getAddOrViewCartConfig = () => {
+
+ const config = {
+ headers: {
+ 'X-Headless-CMS': true,
+ },
+ }
+
+ const storedSession = getSession();
+
+ if ( !isEmpty( storedSession ) ) {
+ config.headers['x-wc-session'] = storedSession;
+ }
+
+ return config;
+}
+
diff --git a/src/utils/cart/index.js b/src/utils/cart/index.js
index e69de29..8806032 100644
--- a/src/utils/cart/index.js
+++ b/src/utils/cart/index.js
@@ -0,0 +1,51 @@
+import { getSession, storeSession } from './session';
+import { getAddOrViewCartConfig } from './api';
+import axios from 'axios';
+import { CART_ENDPOINT } from '../constants/endpoints';
+import { isEmpty } from 'lodash';
+
+/**
+ * Add To Cart Request Handler.
+ *
+ * @param {int} productId Product Id.
+ * @param {int} qty Product Quantity.
+ */
+export const addToCart = ( productId, qty = 1 ) => {
+
+ const storedSession = getSession();
+ const addOrViewCartConfig = getAddOrViewCartConfig();
+
+ axios.post( CART_ENDPOINT, {
+ product_id: productId,
+ quantity: qty,
+ },
+ addOrViewCartConfig,
+ )
+ .then( ( res ) => {
+
+ if ( isEmpty( storedSession ) ) {
+ storeSession( res?.headers?.[ 'x-wc-session' ] );
+ }
+ viewCart();
+ } )
+ .catch( err => {
+ console.log( 'err', err );
+ } );
+};
+
+/**
+ * View Cart Request Handler
+ */
+export const viewCart = () => {
+
+ const addOrViewCartConfig = getAddOrViewCartConfig();
+
+ axios.get( CART_ENDPOINT, addOrViewCartConfig )
+ .then( ( res ) => {
+ console.log( 'res', res );
+ } )
+ .catch( err => {
+ console.log( 'err', err );
+ } );
+};
+
diff --git a/src/utils/cart/session.js b/src/utils/cart/session.js
index e69de29..b1ecb38 100644
--- a/src/utils/cart/session.js
+++ b/src/utils/cart/session.js
@@ -0,0 +1,15 @@
+import { isEmpty } from 'lodash';
+
+export const storeSession = ( session ) => {
+
+ if ( isEmpty( session ) ) {
+ return null;
+ }
+
+ localStorage.setItem( 'x-wc-session', session );
+}
+
+export const getSession = () => {
+ return localStorage.getItem( 'x-wc-session' );
+}
+
diff --git a/src/utils/constants/endpoints.js b/src/utils/constants/endpoints.js
index 96c919b..7e12e48 100644
--- a/src/utils/constants/endpoints.js
+++ b/src/utils/constants/endpoints.js
@@ -5,4 +5,4 @@ export const GET_PRODUCTS_ENDPOINT = `${process.env.NEXT_PUBLIC_SITE_URL}/api/ge
* Cart
* @type {string}
*/
-export const ADD_TO_CART_ENDPOINT = `${process.env.NEXT_PUBLIC_WORDPRESS_SITE_URL}/wp-json/rae/v1/cart/items/`;
+export const CART_ENDPOINT = `${process.env.NEXT_PUBLIC_WORDPRESS_SITE_URL}/wp-json/rae/v1/cart/items/`;
diff --git a/tailwind.config.js b/tailwind.config.js
index 4e78c69..e3f958f 100644
--- a/tailwind.config.js
+++ b/tailwind.config.js
@@ -3,7 +3,15 @@ module.exports = {
'./src/components/**/*.js',
'./pages/**/*.js'],
theme: {
- extend: {},
+ container: {
+ padding: {
+ DEFAULT: '1rem',
+ md: '2rem',
+ lg: '4rem',
+ xl: '5rem',
+ '2xl': '6rem',
+ },
+ },
},
variants: {},
plugins: [