@@ -314,37 +314,6 @@ export function addToCart(cartId: string, productId: string): string {
314314 return "success" ;
315315}
316316
317- export function decreaseQuantity ( cartId : string , productId : string ) : string {
318- const cartItemId = cartId + "_" + productId ;
319- const cartItemQuantity = collections . getText (
320- consts . cartItemsCollection ,
321- cartItemId ,
322- ) ;
323-
324- if ( cartItemQuantity === null || cartItemQuantity === "" ) {
325- console . log ( "Failed to retrieve cart item quantity for:" ) ;
326- return "error" ;
327- }
328-
329- const newQuantity = parseFloat ( cartItemQuantity ) - 1 ;
330- if ( newQuantity === 0 ) {
331- return removeFromCart ( cartId , productId ) ;
332- }
333-
334- const upsertQuantityResult = collections . upsert (
335- consts . cartItemsCollection ,
336- cartItemId ,
337- newQuantity . toString ( ) ,
338- ) ;
339-
340- if ( ! upsertQuantityResult . isSuccessful ) {
341- console . log ( "Failed to update quantity:" ) ;
342- return upsertQuantityResult . error ;
343- }
344-
345- return "success" ;
346- }
347-
348317export function removeFromCart ( cartId : string , productId : string ) : string {
349318 const cartItemId = cartId + "_" + productId ;
350319 const result = collections . remove ( consts . cartItemsCollection , cartItemId ) ;
@@ -361,15 +330,16 @@ export function getCart(cartId: string): Cart {
361330 const cartItems = cartItemIds . split ( "," ) ;
362331 const items = new Array < CartItemObject > ( ) ;
363332 for ( let i = 0 ; i < cartItems . length ; i ++ ) {
333+ const cartItemID = cartItems [ i ] ;
364334 const quantity = collections . getText (
365335 consts . cartItemsCollection ,
366- cartId + "_" + cartItems [ i ] ,
336+ cartId + "_" + cartItemID ,
367337 ) ;
368- const product = getProduct ( cartItems [ i ] ) ;
338+ const product = getProduct ( cartItemID ) ;
369339 const cartItemObject = new CartItemObject (
340+ cartItemID ,
370341 product ,
371342 parseFloat ( quantity ) ,
372- cartItems [ i ] ,
373343 ) ;
374344 items . push ( cartItemObject ) ;
375345 }
0 commit comments