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

[4.x]: validate() function removes tax adjustment from line item #3354

Closed
jonleverrier opened this issue Dec 19, 2023 · 2 comments
Closed

[4.x]: validate() function removes tax adjustment from line item #3354

jonleverrier opened this issue Dec 19, 2023 · 2 comments
Labels
bug commerce4 Issues related to Commerce v4

Comments

@jonleverrier
Copy link

jonleverrier commented Dec 19, 2023

What happened?

Description

When creating a manual order, I have a module that runs the validation function on the EVENT_BEFORE_SAVE event. When validation is run, it removes the tax adjustment from the line item.

Steps to reproduce

Event::on(
    Order::class,
    Order::EVENT_BEFORE_SAVE,
    function (ModelEvent $event) {

        if (Craft::$app->request->isCpRequest) {
            $this->updateLineItemQuantity($event);
        }

    }
);

private function updateLineItemQuantity($event): void
{
    $order = $event->sender;

    // this line removes tax adjuster from line item for some reason
    // stop here if the order has errors for the admin to fix
    if (!$order->validate()) return;

}
  1. Create some required "order fields"
  2. Load module code as above
  3. Create new manual order
  4. Add/input customer and add one line item that has a price excluding tax to the order (notice the tax adjustment figure/percentage below the line item is shown when added to the order)
  5. Click "Update order", and notice how the tax line vanishes

Expected behaviour

Tax on line items to be persistent when validating an order for "errors"

Actual behavior

Tax line is not persistent when validating an order for "errors". Tax adjustment is not even in the line item snapshot.

Craft CMS version

4.5.13

Craft Commerce version

4.3.3

PHP version

No response

Operating system and version

No response

Database type and version

No response

Image driver and version

No response

Installed plugins and versions

@jonleverrier jonleverrier added commerce4 Issues related to Commerce v4 bug labels Dec 19, 2023
@jonleverrier jonleverrier changed the title [4.x]: Validating an order removes tax from line item [4.x]: validate() function removes tax from line item Dec 19, 2023
@jonleverrier jonleverrier changed the title [4.x]: validate() function removes tax from line item [4.x]: validate() function removes tax adjustment from line item Dec 21, 2023
@nfourtythree
Copy link
Contributor

Hi @jonleverrier

Thank you for your message, I was unable to replicate this issue with the following event code:

Event::on(Order::class, Order::EVENT_BEFORE_SAVE, function(ModelEvent $event) {
    $event->sender->validate();
});

Here is a video of the result:

CleanShot.2024-01-04.at.17.16.19.mp4

Is there any other custom code running in your project that could be making a difference to the process?

Thanks

@nfourtythree
Copy link
Contributor

Closing this issue for now due to not being able to replicate and no further information.

Please let us know if you have any more info and we can re-open the issue.

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug commerce4 Issues related to Commerce v4
Projects
None yet
Development

No branches or pull requests

2 participants