@@ -54,7 +54,7 @@ func EcommerceProductList(db *gorm.DB, ctx context.Context, limit int, offset in
54
54
startingPrice = * filter .StartingPrice .Value ()
55
55
}
56
56
57
- if ! filter .EndingPrice .IsSet () {
57
+ if filter .EndingPrice .IsSet () {
58
58
59
59
endingPrice = * filter .EndingPrice .Value ()
60
60
}
@@ -65,34 +65,34 @@ func EcommerceProductList(db *gorm.DB, ctx context.Context, limit int, offset in
65
65
}
66
66
}
67
67
68
- if categoryName != "" {
68
+ if categoryName != "" {
69
69
70
70
listQuery = listQuery .Where ("tbl_categories.category_name = ?" , categoryName )
71
71
72
- } else if categoryId != 0 {
72
+ } else if categoryId != 0 {
73
73
74
74
listQuery = listQuery .Where ("tbl_categories.id = ?" , categoryId )
75
75
}
76
76
77
- if releaseDate != "" {
77
+ if releaseDate != "" {
78
78
79
79
listQuery = listQuery .Where ("tbl_ecom_products.created_on >= ?" , releaseDate )
80
80
}
81
81
82
- if startingPrice != 0 && endingPrice != 0 {
82
+ if startingPrice != 0 && endingPrice != 0 {
83
83
84
84
listQuery = listQuery .Where ("tbl_ecom_products.product_price between (?) and (?)" , startingPrice , endingPrice )
85
85
86
- } else if startingPrice != 0 {
86
+ } else if startingPrice != 0 {
87
87
88
88
listQuery = listQuery .Where ("tbl_ecom_products.product_price >= ?" , startingPrice )
89
89
90
- } else if endingPrice != 0 {
90
+ } else if endingPrice != 0 {
91
91
92
92
listQuery = listQuery .Where ("tbl_ecom_products.product_price <= ?" , endingPrice )
93
93
}
94
94
95
- if searchKeyword != "" {
95
+ if searchKeyword != "" {
96
96
97
97
listQuery = listQuery .Where ("LOWER(TRIM(tbl_ecom_products.product_name)) ILIKE LOWER(TRIM(?))" , "%" + searchKeyword + "%" )
98
98
}
@@ -306,7 +306,7 @@ func EcommerceAddToCart(db *gorm.DB, ctx context.Context, productID *int, produc
306
306
307
307
var count int64
308
308
309
- if err := db .Table ("tbl_ecom_carts" ).Where ("is_deleted = 0 and customer_id = ? and product_id = ?" , customer_id , productId ).Count (& count ).Error ; err != nil {
309
+ if err := db .Debug (). Table ("tbl_ecom_carts" ).Where ("is_deleted = 0 and customer_id = ? and product_id = ?" , customer_id , productId ).Count (& count ).Error ; err != nil {
310
310
311
311
c .AbortWithError (http .StatusInternalServerError , err )
312
312
@@ -315,7 +315,7 @@ func EcommerceAddToCart(db *gorm.DB, ctx context.Context, productID *int, produc
315
315
316
316
query := db .Table ("tbl_ecom_carts" )
317
317
318
- if count != 0 {
318
+ if count > 0 {
319
319
320
320
query = query .Where ("is_deleted = 0 and customer_id = ? and product_id = ?" , customer_id , productId ).UpdateColumns (map [string ]interface {}{"quantity" : gorm .Expr ("quantity + ?" , cart .Quantity ), "modified_on" : currentTime })
321
321
@@ -411,14 +411,14 @@ func EcommerceCartList(db *gorm.DB, ctx context.Context, limit, offset int) (*mo
411
411
412
412
}
413
413
414
- if * cartProduct .ProductYoutubePath != "" {
414
+ if cartProduct .ProductYoutubePath != nil {
415
415
416
416
modified_path := PathUrl + strings .TrimPrefix (* cartProduct .ProductYoutubePath , "/" )
417
417
418
418
cartProduct .ProductYoutubePath = & modified_path
419
419
}
420
420
421
- if * cartProduct .ProductVimeoPath != "" {
421
+ if cartProduct .ProductVimeoPath != nil {
422
422
423
423
modified_path := PathUrl + strings .TrimPrefix (* cartProduct .ProductVimeoPath , "/" )
424
424
@@ -515,11 +515,13 @@ func EcommerceProductOrdersList(db *gorm.DB, ctx context.Context, limit int, off
515
515
516
516
var count int64
517
517
518
- query := db .Debug ().Table ("tbl_ecom_products as p" ).Joins ("inner join tbl_ecom_product_order_details d on d.product_id = p.id" ).Joins ("inner join tbl_ecom_product_orders o on o.id = d.order_id" ).Joins ("inner join tbl_ecom_customers c on c.id = o.customer_id" ).Joins ( "inner join tbl_ecom_order_statuses s on s.order_id = o.id" ). Where ("p.is_deleted = 0 and o.is_deleted = 0 and c.member_id=?" , memberid )
518
+ query := db .Debug ().Table ("tbl_ecom_products as p" ).Joins ("inner join tbl_ecom_product_order_details d on d.product_id = p.id" ).Joins ("inner join tbl_ecom_product_orders o on o.id = d.order_id" ).Joins ("inner join tbl_ecom_customers c on c.id = o.customer_id" ).Where ("p.is_deleted = 0 and o.is_deleted = 0 and c.member_id=?" , memberid )
519
519
520
- var status , searchKeyword , orderId , startingDate , endingDate string
520
+ var (
521
+ status , searchKeyword , orderId , startingDate , endingDate string
521
522
522
- var startingPrice , endingPrice int
523
+ startingPrice , endingPrice , orderHistory , upcomingOrders int
524
+ )
523
525
524
526
if filter != nil {
525
527
@@ -558,48 +560,66 @@ func EcommerceProductOrdersList(db *gorm.DB, ctx context.Context, limit int, off
558
560
orderId = * filter .OrderID .Value ()
559
561
}
560
562
563
+ if filter .OrderHistory .IsSet (){
564
+
565
+ orderHistory = * filter .OrderHistory .Value ()
566
+ }
567
+
568
+ if filter .UpcomingOrders .IsSet (){
569
+
570
+ upcomingOrders = * filter .UpcomingOrders .Value ()
571
+ }
572
+
561
573
}
562
574
563
- if status != "" {
575
+ if upcomingOrders == 1 {
564
576
565
- query = query .Where ("s.order_status = ?" , filter .Status .Value ())
577
+ query = query .Where ("o.status in (?)" , []string {"placed" , "outofdelivery" , "shipped" })
578
+
579
+ }else if orderHistory == 1 {
580
+
581
+ query = query .Where ("o.status in (?)" , []string {"delivered" , "cancelled" })
582
+
583
+ }else if status != "" {
584
+
585
+ query = query .Where ("o.status = ?" , status )
566
586
}
567
587
568
588
if startingPrice != 0 && endingPrice != 0 {
569
589
570
- query = query .Where ("d.price between ? and ?" , filter . StartingPrice . Value (), filter . EndingPrice . Value () )
590
+ query = query .Where ("d.price between ? and ?" , startingPrice , endingPrice )
571
591
572
592
} else if startingPrice != 0 {
573
593
574
- query = query .Where ("d.price >= ?" , filter . StartingPrice . Value () )
594
+ query = query .Where ("d.price >= ?" , startingPrice )
575
595
576
596
} else if endingPrice != 0 {
577
597
578
- query = query .Where ("d.price <= ?" , filter . EndingPrice . Value () )
598
+ query = query .Where ("d.price <= ?" , endingPrice )
579
599
580
600
}
581
601
582
602
if searchKeyword != "" {
583
603
584
- query = query .Where ("LOWER(TRIM(p.product_name)) ILIKE LOWER(TRIM(?))" , "%" + * filter . SearchKeyword . Value () + "%" )
604
+ query = query .Where ("LOWER(TRIM(p.product_name)) ILIKE LOWER(TRIM(?))" , "%" + searchKeyword + "%" )
585
605
}
586
606
587
607
if startingDate != "" && endingDate != "" {
588
608
589
- query = query .Where ("o.created_on between ? and ?" , filter . StartingDate . Value (), filter . EndingDate . Value () )
609
+ query = query .Where ("o.created_on between ? and ?" , startingDate , endingDate )
590
610
591
611
} else if startingDate != "" {
592
612
593
- query = query .Where ("o.created_on >= ?" , filter . StartingDate . Value () )
613
+ query = query .Where ("o.created_on >= ?" , startingDate )
594
614
595
615
} else if endingDate != "" {
596
616
597
- query = query .Where ("o.created_on <= ?" , filter . EndingDate . Value () )
617
+ query = query .Where ("o.created_on <= ?" , endingDate )
598
618
}
599
619
600
620
if orderId != "" {
601
621
602
- query = query .Where ("o.uuid = ?" , filter . OrderID . Value () )
622
+ query = query .Where ("o.uuid = ?" , orderId )
603
623
}
604
624
605
625
if err := query .Count (& count ).Error ; err != nil {
@@ -644,7 +664,7 @@ func EcommerceProductOrdersList(db *gorm.DB, ctx context.Context, limit int, off
644
664
645
665
if err := query .Select ("p.*" ).Preload ("OrderDetails" , func (db * gorm.DB ) * gorm.DB {
646
666
647
- return db .Debug ().Select ("tbl_ecom_product_order_details.*,o.status,pm.payment_mode,o.uuid" ).Joins ("inner join tbl_ecom_product_orders o on o.id = tbl_ecom_product_order_details.order_id" ).Joins ("inner join tbl_ecom_order_payments pm on pm.order_id = o.id" )
667
+ return db .Debug ().Select ("tbl_ecom_product_order_details.*,o.status,pm.payment_mode,o.uuid,o.shipping_address " ).Joins ("inner join tbl_ecom_product_orders o on o.id = tbl_ecom_product_order_details.order_id" ).Joins ("inner join tbl_ecom_order_payments pm on pm.order_id = o.id" )
648
668
649
669
}).Limit (limit ).Offset (offset ).Find (& orderedProducts ).Error ; err != nil {
650
670
@@ -708,7 +728,7 @@ func EcommerceProductOrderDetails(db *gorm.DB, ctx context.Context, productID *i
708
728
709
729
var orderedProduct model.EcommerceProduct
710
730
711
- query := db .Debug ().Table ("tbl_ecom_products as p" ).Joins ("inner join tbl_ecom_product_order_details d on d.product_id = p.id" ).Joins ("inner join tbl_ecom_product_orders o on o.id = d.order_id" ).Joins ("inner join tbl_ecom_customers c on c.id = o.customer_id" ).Joins ( "inner join tbl_ecom_order_statuses s on s.order_id = o.id" ). Where ("p.is_deleted = 0 and o.is_deleted = 0 and c.member_id=?" , memberid )
731
+ query := db .Debug ().Table ("tbl_ecom_products as p" ).Joins ("inner join tbl_ecom_product_order_details d on d.product_id = p.id" ).Joins ("inner join tbl_ecom_product_orders o on o.id = d.order_id" ).Joins ("inner join tbl_ecom_customers c on c.id = o.customer_id" ).Where ("p.is_deleted = 0 and o.is_deleted = 0 and c.member_id=?" , memberid )
712
732
713
733
if productID != nil {
714
734
@@ -721,7 +741,7 @@ func EcommerceProductOrderDetails(db *gorm.DB, ctx context.Context, productID *i
721
741
722
742
if err := query .Select ("p.*" ).Preload ("OrderDetails" , func (db * gorm.DB ) * gorm.DB {
723
743
724
- return db .Debug ().Select ("tbl_ecom_product_order_details.*,o.status,pm.payment_mode,o.uuid" ).Joins ("inner join tbl_ecom_product_orders o on o.id = tbl_ecom_product_order_details.order_id" ).Joins ("inner join tbl_ecom_order_payments pm on pm.order_id = o.id" )
744
+ return db .Debug ().Select ("tbl_ecom_product_order_details.*,o.status,pm.payment_mode,o.uuid,o.shipping_address " ).Joins ("inner join tbl_ecom_product_orders o on o.id = tbl_ecom_product_order_details.order_id" ).Joins ("inner join tbl_ecom_order_payments pm on pm.order_id = o.id" )
725
745
726
746
}).First (& orderedProduct ).Error ; err != nil {
727
747
@@ -896,7 +916,7 @@ func EcommerceOrderPlacement(db *gorm.DB, ctx context.Context, paymentMode strin
896
916
return false , err
897
917
}
898
918
899
- if err := db .Table ("tbl_ecom_carts" ).Where ("is_deleted = 0 and product_id in (?) and customer_id = ?" ,orderedProductIds ,customerId ).UpdateColumns (map [string ]interface {}{"is_deleted" : 1 , "deleted_on" : currentTime }).Error ; err != nil {
919
+ if err := db .Table ("tbl_ecom_carts" ).Where ("is_deleted = 0 and product_id in (?) and customer_id = ?" , orderedProductIds , customerId ).UpdateColumns (map [string ]interface {}{"is_deleted" : 1 , "deleted_on" : currentTime }).Error ; err != nil {
900
920
901
921
c .AbortWithError (http .StatusInternalServerError , err )
902
922
@@ -905,3 +925,59 @@ func EcommerceOrderPlacement(db *gorm.DB, ctx context.Context, paymentMode strin
905
925
906
926
return true , nil
907
927
}
928
+
929
+ func EcommerceCustomerDetails (db * gorm.DB , ctx context.Context ) (* model.CustomerDetails , error ) {
930
+
931
+ c , _ := ctx .Value (ContextKey ).(* gin.Context )
932
+
933
+ memberid , _ := c .Get ("memberid" )
934
+
935
+ if memberid == 0 {
936
+
937
+ err := errors .New ("unauthorized access" )
938
+
939
+ c .AbortWithError (http .StatusUnauthorized , err )
940
+
941
+ return & model.CustomerDetails {}, err
942
+
943
+ }
944
+
945
+ var customerDetails model.CustomerDetails
946
+
947
+ if err := db .Table ("tbl_ecom_customers" ).Where ("is_deleted = 0 and member_id = ?" , memberid ).First (& customerDetails ).Error ; err != nil {
948
+
949
+ return & model.CustomerDetails {}, err
950
+ }
951
+
952
+ if customerDetails .ProfileImagePath != nil {
953
+
954
+ modified_path := PathUrl + strings .TrimPrefix (* customerDetails .ProfileImagePath , "/" )
955
+
956
+ customerDetails .ProfileImagePath = & modified_path
957
+ }
958
+
959
+ if customerDetails .StreetAddress != nil {
960
+
961
+ houseDetails := strings .Split (* customerDetails .StreetAddress , "," )
962
+
963
+ customerDetails .HouseNo = & houseDetails [0 ]
964
+
965
+ var area string
966
+
967
+ for index ,cut := range houseDetails {
968
+
969
+ if index == 1 {
970
+
971
+ area = area + cut
972
+
973
+ }else if index > 1 {
974
+
975
+ area = area + "," + cut
976
+ }
977
+ }
978
+
979
+ customerDetails .Area = & area
980
+ }
981
+
982
+ return & customerDetails , nil
983
+ }
0 commit comments