@labdigital/commercetools-mock 1.3.0 → 1.3.2
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/dist/index.js +5 -9
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +5 -9
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
- package/src/index.ts +1 -1
- package/src/lib/projectionSearchFilter.ts +1 -1
- package/src/repositories/cart.ts +5 -10
- package/dist/index.global.js +0 -46297
- package/dist/index.global.js.map +0 -1
package/package.json
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@labdigital/commercetools-mock",
|
|
3
3
|
"author": "Michael van Tellingen",
|
|
4
|
-
"version": "1.3.
|
|
4
|
+
"version": "1.3.2",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"main": "dist/index.js",
|
|
7
|
-
"module": "dist/
|
|
7
|
+
"module": "dist/index.mjs",
|
|
8
8
|
"typings": "dist/index.d.ts",
|
|
9
9
|
"files": [
|
|
10
10
|
"dist",
|
package/src/index.ts
CHANGED
|
@@ -5,8 +5,8 @@
|
|
|
5
5
|
import type { ProductProjection, ProductVariant } from '@commercetools/platform-sdk'
|
|
6
6
|
import perplex from 'perplex'
|
|
7
7
|
import Parser from 'pratt'
|
|
8
|
-
import type { Writable } from '../types'
|
|
9
8
|
import { nestedLookup } from '../helpers'
|
|
9
|
+
import type { Writable } from '../types'
|
|
10
10
|
|
|
11
11
|
type MatchFunc = (target: any) => boolean
|
|
12
12
|
|
package/src/repositories/cart.ts
CHANGED
|
@@ -158,12 +158,11 @@ export class CartRepository extends AbstractResourceRepository<'cart'> {
|
|
|
158
158
|
)
|
|
159
159
|
if (alreadyAdded) {
|
|
160
160
|
// increase quantity and update total price
|
|
161
|
-
resource.lineItems.
|
|
161
|
+
resource.lineItems.forEach((x) => {
|
|
162
162
|
if (x.productId === product?.id && x.variant.id === variant?.id) {
|
|
163
163
|
x.quantity += quantity
|
|
164
164
|
x.totalPrice.centAmount = calculateLineItemTotalPrice(x)
|
|
165
165
|
}
|
|
166
|
-
return x
|
|
167
166
|
})
|
|
168
167
|
} else {
|
|
169
168
|
// add line item
|
|
@@ -243,20 +242,17 @@ export class CartRepository extends AbstractResourceRepository<'cart'> {
|
|
|
243
242
|
})
|
|
244
243
|
}
|
|
245
244
|
|
|
246
|
-
|
|
247
|
-
if (shouldDelete) {
|
|
245
|
+
if (quantity === 0) {
|
|
248
246
|
// delete line item
|
|
249
247
|
resource.lineItems = resource.lineItems.filter(
|
|
250
248
|
(x) => x.id !== lineItemId
|
|
251
249
|
)
|
|
252
250
|
} else {
|
|
253
|
-
|
|
254
|
-
resource.lineItems.map((x) => {
|
|
251
|
+
resource.lineItems.forEach((x) => {
|
|
255
252
|
if (x.id === lineItemId && quantity) {
|
|
256
|
-
x.quantity
|
|
253
|
+
x.quantity = quantity
|
|
257
254
|
x.totalPrice.centAmount = calculateLineItemTotalPrice(x)
|
|
258
255
|
}
|
|
259
|
-
return x
|
|
260
256
|
})
|
|
261
257
|
}
|
|
262
258
|
|
|
@@ -285,12 +281,11 @@ export class CartRepository extends AbstractResourceRepository<'cart'> {
|
|
|
285
281
|
)
|
|
286
282
|
} else {
|
|
287
283
|
// decrease quantity and update total price
|
|
288
|
-
resource.lineItems.
|
|
284
|
+
resource.lineItems.forEach((x) => {
|
|
289
285
|
if (x.id === lineItemId && quantity) {
|
|
290
286
|
x.quantity -= quantity
|
|
291
287
|
x.totalPrice.centAmount = calculateLineItemTotalPrice(x)
|
|
292
288
|
}
|
|
293
|
-
return x
|
|
294
289
|
})
|
|
295
290
|
}
|
|
296
291
|
|