diff --git a/src/components/cart/add-to-cart.js b/src/components/cart/add-to-cart.js index 6067096..85ef167 100644 --- a/src/components/cart/add-to-cart.js +++ b/src/components/cart/add-to-cart.js @@ -1,9 +1,5 @@ import { isEmpty } from 'lodash'; - -import axios from 'axios'; -import { ADD_TO_CART_ENDPOINT } from '../../utils/constants/endpoints'; -import { getSession, storeSession } from '../../utils/cart/session'; -import { getAddOrViewCartConfig, getAddToCartConfig } from '../../utils/cart/api'; +import {addToCart} from '../../utils/cart'; const AddToCart = ( { product } ) => { @@ -11,43 +7,12 @@ const AddToCart = ( { product } ) => { return null; } - const addToCart = ( productId, qty = 1 ) => { - const storedSession = getSession(); - const addOrViewCartConfig = getAddOrViewCartConfig(); - axios.post( ADD_TO_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 ); - } ); - }; - - const viewCart = () => { - const addOrViewCartConfig = getAddOrViewCartConfig(); - axios.get( ADD_TO_CART_ENDPOINT, addOrViewCartConfig ) - .then( ( res ) => { - console.log( 'res', res ); - } ) - .catch( err => { - console.log( 'err', err ); - } ); - }; - - return ( + onClick={ () => addToCart( product?.id ?? 0 ) }> + Add to cart + ); }; diff --git a/src/components/layouts/header/index.js b/src/components/layouts/header/index.js index 1aa1d1b..023a068 100644 --- a/src/components/layouts/header/index.js +++ b/src/components/layouts/header/index.js @@ -18,7 +18,7 @@ const Header = ( { header } ) => {
-