From f396d55b84d79d34b601eda0c8817abeaeb5194c Mon Sep 17 00:00:00 2001 From: Yuliy Date: Wed, 28 Feb 2024 12:43:37 -0500 Subject: [PATCH] Update toolkit for Paper v7.1.2 --- src/ts/cart/cart.ts | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/src/ts/cart/cart.ts b/src/ts/cart/cart.ts index 8a213c41..bdd77426 100644 --- a/src/ts/cart/cart.ts +++ b/src/ts/cart/cart.ts @@ -1,6 +1,41 @@ import { Product } from "../models.interface"; export const cart = { + updateCartNote(note: string) { + this.cart_loading = true; + fetch(`${window.Shopify.routes.root}cart/update.js`, { + method: "POST", + headers: { + "Content-Type": "application/json", + }, + body: JSON.stringify({ note: note }), + }) + .then(async (response) => { + let data = await response.json(); + + // good response + if (response.status === 200) { + this.cart.items = data.items.map((item: Product) => { + return { + ...item, + }; + }); + this.updateCart(false); + } + + // error response + else { + (this.error_title = data.message), + (this.error_message = data.description), + (this.show_alert = true); + } + }) + .catch((error) => { + console.error("Error:", error); + this.cart_loading = false; + }); + }, + // Update cart with fetched data async updateCart ( openCart: boolean