Skip to content

Commit d762ce9

Browse files
Add to cart completed
1 parent 8b14d32 commit d762ce9

File tree

3 files changed

+326
-271
lines changed

3 files changed

+326
-271
lines changed

lib/consts/firebase_consts.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,4 @@ User? currentUser = auth.currentUser;
88
// collections
99
const usersCollection = "users";
1010
const productsCollection = "products";
11+
const cartCollection = "cart";

lib/controllers/product_controller.dart

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import 'package:emart/consts/consts.dart';
12
import 'package:emart/models/category_model.dart';
23
import 'package:flutter/services.dart';
34
import 'package:get/get.dart';
@@ -33,4 +34,31 @@ class ProductController extends GetxController {
3334
}
3435

3536
calculateTotalPrice(price) => totalPrice.value = price * quantity.value;
37+
38+
addToCart({
39+
title,
40+
image,
41+
sellerName,
42+
color,
43+
quantity,
44+
totalPrice,
45+
context,
46+
}) async {
47+
await firestore.collection(cartCollection).doc().set({
48+
'title': title,
49+
'image': image,
50+
'seller_name': sellerName,
51+
'color': color,
52+
'quantity': quantity,
53+
'total_price': totalPrice,
54+
'added_by': currentUser!.uid
55+
}).onError(
56+
(error, stackTrace) => VxToast.show(context, msg: error.toString()));
57+
}
58+
59+
resetValues() {
60+
quantity.value = 0;
61+
totalPrice.value = 0;
62+
colorIndex.value = 0;
63+
}
3664
}

0 commit comments

Comments
 (0)