Inconsistent behavior of discount code "overrides" in checkout and via /discount/CODE

Short description of issue

Inconsistent behavior when trying to apply a discount code to a cart that already has a discount code applied.

Reproduction steps

  1. Create a discount with a couple of discount codes via the API.
  2. Apply one of the codes at checkout.
  3. Try to apply a different code of the same discount.
  4. You will see that for some codes it will “overwrite” the existing code, for some codes it will not.

Additional info

The same behavior is happening with the /discount/CODE endpoint (which seems to be depricated now?), aswell as the cart/update.js endpoint.
It also happens cross discount but it might be the intended behavior to not allow cross discount “overrides”.

When looking at the discounts in the cart after applying the initial discount code and a different code of the same discount, we can see that both have been added to the cart, where one of them is applicable.

[
  {
    "code": "TEST-DS7FYDI8WV",
    "applicable": false
  },
  {
    "code": "TEST-SY7A5G3J7T",
    "applicable": true
  }
]

Fo far so good but

  • when TEST-DS7FYDI8WV is applied first, I then enter TEST-SY7A5G3J7T, the applicable code is TEST-SY7A5G3J7T
  • when TEST-SY7A5G3J7T is applied first, I then enter TEST-DS7FYDI8WV, the applicable code is TEST-SY7A5G3J7T

This means TEST-SY7A5G3J7T always has a higher priority than TEST-DS7FYDI8WV

Is it intended that the newest code does not have priority?

What type of topic is this

Bug report