@viur/shop-components 0.15.2 → 0.15.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@viur/shop-components",
3
- "version": "0.15.2",
3
+ "version": "0.15.4",
4
4
  "description": "Frontend Vue components for the shop module of ViUR",
5
5
  "repository": {
6
6
  "type": "git",
@@ -41,16 +41,10 @@ export function useCart() {
41
41
  if (_fetchCartPromise) return _fetchCartPromise;
42
42
 
43
43
  shopStore.state.cartIsLoading = true;
44
- let promise;
45
- if (shopStore.state.order != null && shopStore.state.order?.cart?.dest.key) {
46
- shopStore.state.cartRoot = shopStore.state.order.cart.dest;
47
- promise = fetchCartItems(shopStore.state.cartRoot["key"]);
48
- } else {
49
- promise = fetchCartRoot().then(() => {
50
- if (!shopStore.state.cartRoot?.["key"]) return 0;
51
- return fetchCartItems(shopStore.state.cartRoot["key"]);
52
- });
53
- }
44
+ let promise = fetchCartRoot().then(() => {
45
+ if (!shopStore.state.cartRoot?.["key"]) return 0;
46
+ return fetchCartItems(shopStore.state.cartRoot["key"]);
47
+ });
54
48
 
55
49
  _fetchCartPromise = promise.then(() => {
56
50
  shopStore.state.cartIsLoading = false;
@@ -69,6 +63,8 @@ export function useCart() {
69
63
  shopStore.state.cartRoot = data.filter(i=>i['cart_type']==='basket')?.[0] ? data.filter(i=>i['cart_type']==='basket')[0]:[]
70
64
  if (shopStore.state.cartRoot.discount){
71
65
  shopStore.state.discounts = {[shopStore.state.cartRoot.discount.dest.key]:shopStore.state.cartRoot.discount}
66
+ } else {
67
+ shopStore.state.discounts = {}
72
68
  }
73
69
  return resp
74
70
  })
@@ -97,7 +93,11 @@ export function useCart() {
97
93
  let discounts = {}
98
94
  return _collectCartItems(key, leafs, discounts).then((resp) => {
99
95
  shopStore.state.cartList = leafs
100
- Object.assign(shopStore.state.discounts, discounts)
96
+ // Include root-level discount alongside node-level discounts
97
+ if (shopStore.state.cartRoot?.discount) {
98
+ discounts[shopStore.state.cartRoot.discount.dest.key] = shopStore.state.cartRoot.discount
99
+ }
100
+ shopStore.state.discounts = discounts
101
101
 
102
102
  return resp
103
103
  })
@@ -54,6 +54,20 @@ export const usePayment = defineStore("usePaymentStore", () => {
54
54
  options.push(currentOption)
55
55
  }
56
56
 
57
+ // Sort: SORT_FIRST providers on top, SORT_LAST at the bottom, rest unchanged
58
+ const SORT_FIRST = ["unzer-paylater_invoice"]
59
+ const SORT_LAST = ["unzer-paypal", "amazonpay"]
60
+
61
+ options.sort((a, b) => {
62
+ const weight = (key) => {
63
+ const firstIdx = SORT_FIRST.indexOf(key)
64
+ if (firstIdx !== -1) return -SORT_FIRST.length + firstIdx
65
+ const lastIdx = SORT_LAST.indexOf(key)
66
+ if (lastIdx !== -1) return 1 + lastIdx
67
+ return 0
68
+ }
69
+ return weight(a.paymenttype) - weight(b.paymenttype)
70
+ })
57
71
 
58
72
  return options
59
73
  }