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

Incorrect de-duplication on addItemToOrder of OrderLines with custom fields #512

Closed
michaelbromley opened this issue Oct 19, 2020 · 0 comments
Assignees
Labels
type: bug 🐛 Something isn't working
Milestone

Comments

@michaelbromley
Copy link
Member

Describe the bug
When executing the addItemToOrder mutation, if that ProductVariant is already in the Order, it should be incremented rather than a new OrderLine being created. The logic for this is here:

let orderLine = order.lines.find(line => {
return (
idsAreEqual(line.productVariant.id, productVariantId) &&
JSON.stringify(line.customFields) === JSON.stringify(customFields)
);
});
if (!orderLine) {
const newLine = this.createOrderLineFromVariant(productVariant, customFields);
orderLine = await this.connection.getRepository(ctx, OrderLine).save(newLine);
order.lines.push(orderLine);
await this.connection.getRepository(ctx, Order).save(order, { reload: false });
}

However, if one or more custom fields is set on the OrderLine entity, and none are set in the addItemToOrder mutation, the orderLine var on line 322 is incorrectly undefined.

To Reproduce
Steps to reproduce the behavior:

  1. Define a custom field on OrderLine and start server
  2. invoke addItemToOrder with variant id 1, quantity 1, no custom fields.
  3. repeat step 2
  4. See that there are 2 OrderLines in the Order where there should only be 1.

Expected behavior
Correct de-deduplication of order lines when the custom fields are empty.

Environment (please complete the following information):

  • @vendure/core version: 0.16.1
  • Nodejs version: any
  • Database (mysql/postgres etc): any
@michaelbromley michaelbromley added the type: bug 🐛 Something isn't working label Oct 19, 2020
@michaelbromley michaelbromley added this to the v0.16.2 milestone Oct 19, 2020
@michaelbromley michaelbromley self-assigned this Oct 19, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug 🐛 Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant