Skip to content

Commit

Permalink
Merge branch '2447-preserve-cart-order' into staging
Browse files Browse the repository at this point in the history
  • Loading branch information
canac committed Dec 28, 2023
2 parents 47552f1 + 3562a6a commit a423c94
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 7 deletions.
12 changes: 9 additions & 3 deletions src/app/cart/cart.component.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,17 @@ class CartController {
this.loading = true
}
// Remember the order of the existing items in the cart
const orderByCode = this.cartData?.items?.map(item => item.code) ?? []
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))
if (reload) {
// Sort the incoming cart to match the order of the previous cart, with new items at the top
// The code of recurring gifts have a suffix and look like 0123456_MON or 0123456_QUARTERLY.
// We will be able to maintain the order of items in the cart as long as the user doesn't
// change the frequency of a gift. The server prevents carts from containing multiple gifts
// with the same frequency and designation account, which would interfere with sorting.
data.items?.sort((item1, item2) => orderByCode.indexOf(item1.code) - orderByCode.indexOf(item2.code))
}
this.cartData = data
this.setLoadCartVars(reload)
},
Expand Down
2 changes: 1 addition & 1 deletion src/app/cart/cart.tpl.html
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ <h3 class="panel-name" translate>Your Gift Cart</h3>
<tbody>
<tr class="giftsum-gift-row" ng-repeat="i in $ctrl.cartData.items">
<td class="td-gift">
<img desig-src="{{i.designationNumber}}" class="giftsum-profile pull-left">
<img desig-src="{{i.designationNumber}}" class="giftsum-profile pull-left" width="90" height="51">
<span class="giftsum-person giftsum-title"><a ng-href="/{{i.designationNumber}}">{{i.displayName}}</a></span>
<span class="giftsum-accountnum giftsum-detail">#{{i.designationNumber}}</span>
</td>
Expand Down
2 changes: 1 addition & 1 deletion src/app/checkout/step-3/step-3.tpl.html
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@
</tr>
<tr class="giftsum-gift-row" ng-repeat-end>
<td class="td-gift">
<img desig-src="{{i.designationNumber}}" class="giftsum-profile pull-left">
<img desig-src="{{i.designationNumber}}" class="giftsum-profile pull-left" width="90" height="51">
<span class="giftsum-person giftsum-title">{{i.displayName}}</span>
<span class="giftsum-accountnum giftsum-detail">#{{i.designationNumber}}</span>
</td>
Expand Down
1 change: 0 additions & 1 deletion src/assets/cru-scss/_cart.scss
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
padding-bottom: 30px;
}
.giftsum-profile {
width: 90px;
height: auto;
margin-right: 15px;
}
Expand Down
1 change: 0 additions & 1 deletion src/assets/scss/_cart.scss
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@
}
}
.giftsum-profile {
width: 90px;
height: auto;
margin-right: 15px;
@include respond-to(extrasmall) {
Expand Down

0 comments on commit a423c94

Please sign in to comment.