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

Doctrine error on removeAdjustement (A managed+dirty entity) #16347

Open
Jgrasp opened this issue Jun 5, 2024 · 0 comments
Open

Doctrine error on removeAdjustement (A managed+dirty entity) #16347

Jgrasp opened this issue Jun 5, 2024 · 0 comments

Comments

@Jgrasp
Copy link

Jgrasp commented Jun 5, 2024

Sylius version affected: 1.12.14

Description
When removing adjustments, if two $entityManager->flush() are played in succession, the following doctrine message appears:

A managed+dirty entity App\Entity\Order\Adjustment@11699 cannot be scheduled for insertion.

This is because shipping adjustments are not removed from the shipment when removing adjustments at the order level.

Steps to reproduce

Use the endpoint /shop/orders/{tokenValue}/complete
Add a new callback on complete transition & send an email.

Email will be send via messenger, an a flush() will be played a first time.
ApiPlatform will also use messenger for this action and will flush() too.

Possible Solution

public function removeAdjustment(AdjustmentInterface $adjustment): void
    {
        if (!$adjustment->isLocked() && $this->hasAdjustment($adjustment)) {
            $this->adjustments->removeElement($adjustment);
            $this->subtractFromAdjustmentsTotal($adjustment);
            $adjustment->setAdjustable(null);
           
             // Here the fix
            $adjustment->setShipment(null);
            
            $this->recalculateAdjustmentsTotal();
        }
    }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant