Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: allow addedAt override in add to wishlist and add to cart #217

Merged
merged 2 commits into from
Sep 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/wet-poems-appear.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@labdigital/commercetools-mock": patch
---

allows addedAt override in add to cart and add to wishlist
10 changes: 9 additions & 1 deletion src/repositories/cart/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,14 @@ export class CartUpdateHandler
addLineItem(
context: RepositoryContext,
resource: Writable<Cart>,
{ productId, variantId, sku, custom, quantity = 1 }: CartAddLineItemAction,
{
productId,
variantId,
sku,
custom,
quantity = 1,
addedAt,
}: CartAddLineItemAction,
) {
let product: Product | null = null;

Expand Down Expand Up @@ -157,6 +164,7 @@ export class CartUpdateHandler
}
resource.lineItems.push({
id: uuidv4(),
addedAt: addedAt ? addedAt : new Date().toISOString(),
productId: product.id,
productKey: product.key,
productSlug: product.masterData.current.slug,
Expand Down
10 changes: 8 additions & 2 deletions src/repositories/shopping-list/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,13 @@ export class ShoppingListUpdateHandler
addLineItem(
context: RepositoryContext,
resource: Writable<ShoppingList>,
{ productId, variantId, sku, quantity = 1 }: ShoppingListAddLineItemAction,
{
productId,
variantId,
sku,
quantity = 1,
addedAt,
}: ShoppingListAddLineItemAction,
) {
let product: Product | null = null;

Expand Down Expand Up @@ -90,7 +96,7 @@ export class ShoppingListUpdateHandler
} else {
// add line item
resource.lineItems.push({
addedAt: new Date().toISOString(),
addedAt: addedAt ? addedAt : new Date().toISOString(),
id: uuidv4(),
productId: product.id,
productSlug: product.masterData.current.slug,
Expand Down