Skip to content

Commit

Permalink
Only sort the cart after changes
Browse files Browse the repository at this point in the history
  • Loading branch information
canac committed Dec 18, 2023
1 parent a2e3df7 commit 09b325c
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/app/cart/cart.component.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,11 @@ class CartController {
const orderByCode = this.cartData?.items?.map(item => item.code) || []
this.cartService.get()
.subscribe(data => {
// Sort the incoming cart to match the order of the previous cart, with new items at the top
data.items?.sort((item1, item2) => orderByCode.indexOf(item1.code) - orderByCode.indexOf(item2.code))
this.cartData = data
if (reload) {
// Sort the incoming cart to match the order of the previous cart, with new items at the top
data.items?.sort((item1, item2) => orderByCode.indexOf(item1.code) - orderByCode.indexOf(item2.code))
}
this.cartData = data
this.setLoadCartVars(reload)
},
error => {
Expand Down

0 comments on commit 09b325c

Please sign in to comment.