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

Promotion adjustments not removed #710

Closed
hendrik-advantitge opened this issue Feb 13, 2021 · 0 comments
Closed

Promotion adjustments not removed #710

hendrik-advantitge opened this issue Feb 13, 2021 · 0 comments
Assignees
Labels
type: bug 🐛 Something isn't working
Milestone

Comments

@hendrik-advantitge
Copy link
Contributor

hendrik-advantitge commented Feb 13, 2021

Describe the bug
The applyOrderPromotions() method removes all adjustments on the different OrderItems prior to calculating new adjustments. If there were adjustments on the OrderItems before, but the new calculation does not generate any adjustments, the updatedItems array remains empty and no OrderItems are returned. As a consequence, the adjustments are not actually cleared from the Order.

To Reproduce
Steps to reproduce the behavior:

  1. Create a promotion action, like this one here:
import { idsAreEqual,  LanguageCode,  Order,  PromotionOrderAction,  RequestContext } from '@vendure/core'
export const exampleAction = new PromotionOrderAction({
  code: 'example',
  description: [ { languageCode: LanguageCode.en, value: 'Buy { product_1 } get { product_2 } free' } ],
  args: { product_1: { type: 'ID' }, product_2: { type: 'ID' } },
  execute: async function (ctx: RequestContext, order: Order, { product_1, product_2 } ): Promise<number> {
    const productLine_1 = order.lines.find(line => idsAreEqual(line.productVariant.id, product_1))
    const productLine_2 = order.lines.find(line => idsAreEqual(line.productVariant.id, product_2))
    if (productLine_1 && productLine_2) {
      return -1 * Math.min(productLine_1.quantity, productLine_2.quantity) * productLine_2.unitPriceWithTax
    }
    return 0
  },
})
  1. Create the promotion in the AdminUI, product_1 = 1, product_2 = 2
  2. Add product 1 and product 2 to Order
  3. A discount should be added
  4. Remove product 2 from Order
  5. The discount is still there

Expected behavior
The discount should no longer be applied.

Environment (please complete the following information):

  • @vendure/core version: 0.18.4
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

2 participants