@@ -48,6 +48,7 @@ function CheckoutDetails() {
4848 body : JSON . stringify ( { order_id : oID } ) ,
4949 } ) ;
5050 const data = await response . json ( ) ;
51+ console . log ( data ) ;
5152
5253 for ( let i = 0 ; i < data . length ; ++ i ) {
5354 let categories = data [ i ] . categories
@@ -57,7 +58,7 @@ function CheckoutDetails() {
5758
5859 for ( let j = 0 ; j < categories . length ; ++ j ) {
5960 if ( discount . categories . includes ( categories [ j ] ) ) {
60- orderTotal += ( data [ i ] . price * 1 ) ;
61+ orderTotal += ( data [ i ] . price * 1 * data [ i ] . product_quantity ) ;
6162 j = categories . length ;
6263 }
6364 }
@@ -67,16 +68,24 @@ function CheckoutDetails() {
6768 }
6869 }
6970
71+ console . log ( "Initial" ) ;
72+ console . log ( finalAmount ) ;
7073 if ( discount . type === 'percent' ) {
7174 let percent = ( discount . amount * 1 ) / 100 ;
7275 finalAmount = ( orderTotal * 1 * percent ) . toFixed ( 2 ) ;
73- if ( finalAmount * 1 > discount . maximum_allowed * 1 ) {
74- finalAmount = ( discount . maximum_allowed * 1 ) . toFixed ( 2 ) ;
75- }
7676 } else if ( discount . type === 'amount' ) {
7777 finalAmount = ( discount . amount * 1 ) . toFixed ( 2 ) ;
7878 }
7979
80+ console . log ( "After calculation" )
81+
82+ if ( finalAmount * 1 > discount . maximum_allowed * 1 ) {
83+ finalAmount = ( discount . maximum_allowed * 1 ) . toFixed ( 2 ) ;
84+ }
85+ if ( orderTotal * 1 < discount . minimum_required * 1 ) {
86+ finalAmount = 0 ;
87+ }
88+
8089 if ( finalAmount > 0 ) {
8190 setDiscount ( finalAmount ) ;
8291 } else {
@@ -95,10 +104,6 @@ function CheckoutDetails() {
95104 . then ( ( response ) => response . json ( ) )
96105 . then ( ( data ) => {
97106 if ( data ) {
98- // verify minimum amount required is hit
99- if ( order . total_cost < data . minimum_required ) {
100- throw ( order . total_cost ) ;
101- }
102107 // verify code is active
103108 if ( currentDateTime . toLocaleString ( ) < formatTime ( data . start_time ) || currentDateTime . toLocaleString ( ) > formatTime ( data . end_time ) ) {
104109 throw ( data . start_time + " - " + data . end_time ) ;
@@ -193,10 +198,11 @@ function CheckoutDetails() {
193198 else if ( userId ) {
194199 oID = 0 ;
195200 }
201+ const total = onlineTotalCost ( order . total_cost ) . toFixed ( 2 ) ;
196202 fetch ( "/api/updateOrderInfo.php" , {
197203 method : "POST" ,
198204 headers : { "Content-Type" : "application/json" } ,
199- body : JSON . stringify ( { first, last, email, shipping, dbLocation, order_id : oID } ) ,
205+ body : JSON . stringify ( { first, last, email, shipping, dbLocation, order_id : oID , total , discount } ) ,
200206 } )
201207 . then ( ( response ) => response . json ( ) )
202208 . then ( ( data ) => {
0 commit comments