Skip to content

Commit

Permalink
Add to cart completed
Browse files Browse the repository at this point in the history
  • Loading branch information
codewith-usama committed Nov 17, 2023
1 parent 8b14d32 commit d762ce9
Show file tree
Hide file tree
Showing 3 changed files with 326 additions and 271 deletions.
1 change: 1 addition & 0 deletions lib/consts/firebase_consts.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ User? currentUser = auth.currentUser;
// collections
const usersCollection = "users";
const productsCollection = "products";
const cartCollection = "cart";
28 changes: 28 additions & 0 deletions lib/controllers/product_controller.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import 'package:emart/consts/consts.dart';
import 'package:emart/models/category_model.dart';
import 'package:flutter/services.dart';
import 'package:get/get.dart';
Expand Down Expand Up @@ -33,4 +34,31 @@ class ProductController extends GetxController {
}

calculateTotalPrice(price) => totalPrice.value = price * quantity.value;

addToCart({
title,
image,
sellerName,
color,
quantity,
totalPrice,
context,
}) async {
await firestore.collection(cartCollection).doc().set({
'title': title,
'image': image,
'seller_name': sellerName,
'color': color,
'quantity': quantity,
'total_price': totalPrice,
'added_by': currentUser!.uid
}).onError(
(error, stackTrace) => VxToast.show(context, msg: error.toString()));
}

resetValues() {
quantity.value = 0;
totalPrice.value = 0;
colorIndex.value = 0;
}
}
Loading

0 comments on commit d762ce9

Please sign in to comment.