Editing an existing price quantity does not update value/unit price/total price

Created on 25 March 2023, almost 2 years ago
Updated 19 April 2023, over 1 year ago

Problem/Motivation

If you edit an existing price quantity, delete the value OR unit price OR total price, change one of the remaining values, and save the quantity, the auto-populated value is not updated correctly and the old value appears. This leads to incorrect price quantities.

Steps to reproduce

For example, create a new price quantity with a value of 5 and a unit price of 10. When it is first saved, the total price is (correctly) calculated as 50.

Edit the price quantity, change the value to 6, delete the total price (so that it can be recalculated), and save. The total price shows 50 when it should show 60.

Proposed resolution

My hunch is that the logic in QuantityEventSubscriber is using the *saved* entity values, and not the *submitted* values of the form.

Needs more debugging...

Remaining tasks

  • Debug and determine the root cause.
  • ...

User interface changes

None.

API changes

None.

Data model changes

None.

πŸ› Bug report
Status

Fixed

Version

2.0

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States m.stenta

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @m.stenta
  • πŸ‡ΊπŸ‡ΈUnited States m.stenta

    Ah OK... I found an important clue:

    In the context of QuantityEventSubscriber::quantityPresave(), $event->quantity->get('unit_price')->fraction returns the old value, and $event->quantity->get('unit_price')->getValue() returns the new value.

    This must have something to do with how/when the Fraction module sets the ->fraction property. Maybe it isn't being updated before this event subscriber runs.

  • @mstenta opened merge request.
  • Status changed to Needs review over 1 year ago
  • πŸ‡ΊπŸ‡ΈUnited States m.stenta
  • πŸ‡ΊπŸ‡ΈUnited States m.stenta

    I dug in with XDebug and this is what I found...

    FractionProperty::getValue() runs first, but there doesn't seem to be any way to get the new value from within that method's context.

    QuantityEventSubscriber::quantityPresave() runs afterwards, and $event->quantity->get('unit_price')->fraction still has the old value, but $event->quantity->get('unit_price')->getValue() has the new value.

    The merge request I opens doesn't dig any deeper than that. It simply refactors the event listener logic to use getValue() instead of fraction.

    I'd prefer to use fraction, at least conceptually. From a DX perspective it feels like I should be able to. I may continue digging into that... but the MR I opened fixes the issue by working around that, so it's worth considering anyway.

  • Status changed to Postponed over 1 year ago
  • πŸ‡ΊπŸ‡ΈUnited States m.stenta

    I'd prefer to use fraction, at least conceptually. From a DX perspective it feels like I should be able to. I may continue digging into that...

    I opened an upstream issue in the Fraction module for this: πŸ› Update fraction and decimal properties via setValue() Fixed

    I have a working solution there, so once that gets merged we can update this module to require the new version of Fraction and close this.

  • πŸ‡ΊπŸ‡ΈUnited States m.stenta

    This was fixed upstream in Fraction 2.3.0. This module now requires that version as a minimum to fix this issue.

  • Status changed to Fixed over 1 year ago
  • Automatically closed - issue fixed for 2 weeks with no activity.

Production build 0.71.5 2024