summaryrefslogtreecommitdiff
path: root/src-migrate/services/cart.ts
diff options
context:
space:
mode:
authortrisusilo48 <tri.susilo@altama.co.id>2024-07-10 15:58:51 +0700
committertrisusilo48 <tri.susilo@altama.co.id>2024-07-10 15:58:51 +0700
commit2e3c726bc8217f3960cfecec44b81303b03de72b (patch)
tree1b85ced7f61f3e4c3f1f27b577b37aa161615065 /src-migrate/services/cart.ts
parent2b3bd9c0a454dbad69ce29cee877bfb1fca5dfa6 (diff)
parenta99bf6480eea556e53b85e6db45f3b8c2361e693 (diff)
Merge branch 'release' into development
# Conflicts: # src/pages/shop/product/variant/[slug].jsx
Diffstat (limited to 'src-migrate/services/cart.ts')
-rw-r--r--src-migrate/services/cart.ts41
1 files changed, 41 insertions, 0 deletions
diff --git a/src-migrate/services/cart.ts b/src-migrate/services/cart.ts
new file mode 100644
index 00000000..11f87125
--- /dev/null
+++ b/src-migrate/services/cart.ts
@@ -0,0 +1,41 @@
+import odooApi from '~/libs/odooApi';
+
+export const getUserCart = async (userId: number) => {
+ return await odooApi('GET', `/api/v1/user/${userId}/cart`);
+};
+
+interface UpsertUserCartProps {
+ userId: number;
+ type: 'product' | 'promotion';
+ id: number;
+ qty: number;
+ selected: boolean;
+ source?: 'buy' | 'add_to_cart';
+ qtyAppend?: boolean;
+}
+
+export const upsertUserCart = async ({
+ userId,
+ type,
+ id,
+ qty,
+ selected,
+ source = 'add_to_cart',
+ qtyAppend = false,
+}: UpsertUserCartProps) => {
+ return await odooApi('POST', `/api/v1/user/${userId}/cart/create-or-update`, {
+ product_id: type === 'product' ? id : null,
+ qty,
+ selected,
+ program_line_id: type === 'promotion' ? id : null,
+ source,
+ qty_append: qtyAppend,
+ });
+};
+
+export const deleteUserCart = async (userId: number, ids: number[]) => {
+ return await odooApi(
+ 'DELETE',
+ `/api/v1/user/${userId}/cart?ids=${ids.join(',')}`
+ );
+};