From 39a2e8012ba38d6663820ae27080a2b843c08c5f Mon Sep 17 00:00:00 2001 From: Rafi Zadanly Date: Wed, 14 Dec 2022 12:01:13 +0700 Subject: Add to cart to localstorage --- src/pages/404.js | 4 ++-- src/pages/shop/cart.js | 51 ++++++++++++++++++++++++++++++++++++++++ src/pages/shop/product/[slug].js | 8 +++++-- 3 files changed, 59 insertions(+), 4 deletions(-) create mode 100644 src/pages/shop/cart.js (limited to 'src/pages') diff --git a/src/pages/404.js b/src/pages/404.js index 3eafbb08..b7f8b8ef 100644 --- a/src/pages/404.js +++ b/src/pages/404.js @@ -13,10 +13,10 @@ export default function PageNotFound() { Halaman Tidak Ditemukan - Indoteknik

Halaman tidak ditemukan

- + Kembali ke beranda - + Tanya admin
diff --git a/src/pages/shop/cart.js b/src/pages/shop/cart.js new file mode 100644 index 00000000..2de1a7ac --- /dev/null +++ b/src/pages/shop/cart.js @@ -0,0 +1,51 @@ +import { useEffect } from "react"; +import Header from "../../components/Header"; +import Layout from "../../components/Layout"; +import Link from "../../components/Link"; +import { getCart } from "../../helpers/cart"; +import ChevronLeftIcon from "../../icons/chevron-left.svg"; + +export default function Cart() { + useEffect(() => { + console.log(getCart()); + }) + return ( + <> +
+ +
+ {/* Progress Bar */} +
+
+
1
+

Keranjang

+
+
+
+
+
+
2
+

Pembayaran

+
+
+
+
+
+
3
+

Selesai

+
+
+ {/* [End] Progress Bar */} + {/* Title */} +
+ + + +

Keranjang Saya

+
+ {/* [End] Title */} +
+
+ + ); +} \ No newline at end of file diff --git a/src/pages/shop/product/[slug].js b/src/pages/shop/product/[slug].js index 5fce1c85..e44cfeca 100644 --- a/src/pages/shop/product/[slug].js +++ b/src/pages/shop/product/[slug].js @@ -9,6 +9,7 @@ import { LazyLoadImage } from "react-lazy-load-image-component"; import "react-lazy-load-image-component/src/effects/blur.css"; import ProductSlider from "../../../components/product/ProductSlider"; import Layout from "../../../components/Layout"; +import { addToCart } from "../../../helpers/cart"; export async function getServerSideProps( context ) { const { slug } = context.query; @@ -80,7 +81,10 @@ export default function ProductDetail({ product }) { setQuantity("1"); } - let addToCart = () => { + let addItemToCart = () => { + if (quantity > 0) { + addToCart(activeVariant.id, parseInt(quantity)); + } return true; } @@ -136,7 +140,7 @@ export default function ProductDetail({ product }) {
- +
-- cgit v1.2.3