-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
[FIX] Fixing action clear cart after added address on shipping step #18427
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
[FIX] Fixing action clear cart after added address on shipping step #18427
Conversation
WalkthroughAfter clearing the cart resource, the Cart FormComponent now recreates the resource, resets the form, and clears validation state (isValidated = false, validatedFields = []) to avoid stale references and EntityNotFound errors when an address was present. Changes
Sequence Diagram(s)sequenceDiagram
autonumber
actor User
participant CartForm as Cart FormComponent
participant Repo as Repository / EntityManager
participant FormState as Form State
participant Validation as Validation State
User->>CartForm: clearCart()
CartForm->>Repo: remove(resource)
Repo-->>CartForm: removed
CartForm->>Repo: flush()
Repo-->>CartForm: flushed
rect rgba(46,117,182,0.08)
note right of CartForm: Reinitialization (new)
CartForm->>CartForm: createResource()
CartForm->>FormState: resetForm()
CartForm->>Validation: set isValidated = false
CartForm->>Validation: clear validatedFields
end
CartForm-->>User: cart cleared and reinitialized
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Poem
Pre-merge checks and finishing touches✅ Passed checks (5 passed)
✨ Finishing touches🧪 Generate unit tests (beta)
📜 Recent review detailsConfiguration used: CodeRabbit UI Review profile: CHILL Plan: Pro 📒 Files selected for processing (2)
🚧 Files skipped from review as they are similar to previous changes (2)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
❌ Preview Environment deleted from BunnyshellAvailable commands:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (1)
src/Sylius/Bundle/ShopBundle/Twig/Component/Cart/FormComponent.php (1)
92-107: Consider adding test coverage for this edge case.Given that this bug involved a specific sequence (cart with address → clear cart), consider adding an integration or functional test that:
- Creates a cart with items
- Associates an address (simulating checkout progress)
- Calls
clearCart()- Verifies no exception occurs and a fresh cart is created
This would prevent regression and document the expected behavior.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
src/Sylius/Bundle/ShopBundle/Twig/Component/Cart/FormComponent.php(1 hunks)
🧰 Additional context used
📓 Path-based instructions (2)
**/*.{php,yaml,yml,xml,twig}
📄 CodeRabbit inference engine (AGENTS.md)
Use 4 spaces for indentation in PHP, YAML, XML, and Twig files
Files:
src/Sylius/Bundle/ShopBundle/Twig/Component/Cart/FormComponent.php
**/*.php
📄 CodeRabbit inference engine (AGENTS.md)
**/*.php: Use modern PHP 8.2+ syntax and features
Declare strict_types=1 in all PHP files
Follow the Sylius Coding Standard
Do not use deprecated features from PHP, Symfony, or Sylius
Use final for all classes, except entities and repositories
Use readonly for immutable services and value objects
Add type declarations for all properties, arguments, and return values
Use camelCase for variables and method names
Use SCREAMING_SNAKE_CASE for constants
Use fast returns instead of unnecessary nesting
Use trailing commas in multi-line arrays and argument lists
Order array keys alphabetically where applicable
Use PHPDoc only when necessary (e.g., @var Collection)
Group class elements in order: constants, properties, constructor, public, protected, private methods
Group getter and setter methods for the same properties together
Suffix interfaces with Interface and traits with Trait
Use use statements for all non-global classes
Sort use imports alphabetically and group by type (classes, functions, constants)
Files:
src/Sylius/Bundle/ShopBundle/Twig/Component/Cart/FormComponent.php
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (16)
- GitHub Check: End-to-end tests (MariaDB) / Non-JS, PHP 8.4, Symfony ^7.3, MariaDB 11.4.7, State Machine Adapter symfony_workflow
- GitHub Check: End-to-end tests (MariaDB) / Non-JS, PHP 8.2, Symfony ^6.4, MariaDB 10.11.13, State Machine Adapter winzou_state_machine
- GitHub Check: End-to-end tests (MySQL) / JS with Panther, PHP 8.2, Symfony ^6.4 (test_cached), MySQL 8.0, Twig ^3.3
- GitHub Check: End-to-end tests (MySQL) / JS with Panther, PHP 8.3, Symfony ^7.3 (test_cached), MySQL 8.4, Twig ^3.3
- GitHub Check: End-to-end tests (MySQL) / JS with Chromedriver, PHP 8.4, Symfony ^7.3 (test_cached), MySQL 8.4, Twig ^3.3
- GitHub Check: End-to-end tests (MySQL) / JS with Chromedriver, PHP 8.3, Symfony ^7.3 (test_cached), MySQL 8.4, Twig ^3.3
- GitHub Check: End-to-end tests (MySQL) / JS with Panther, PHP 8.4, Symfony ^7.3 (test_cached), MySQL 8.4, Twig ^3.3
- GitHub Check: End-to-end tests (MySQL) / Non-JS, PHP 8.2, Symfony ^6.4 (test_cached), MySQL 8.0, Twig ^3.3
- GitHub Check: End-to-end tests (MySQL) / JS with Chromedriver, PHP 8.2, Symfony ^6.4 (test_cached), MySQL 8.0, Twig ^3.3
- GitHub Check: End-to-end tests (MySQL) / Non-JS, PHP 8.4, Symfony ^7.3 (test_cached), MySQL 8.4, Twig ^3.3
- GitHub Check: End-to-end tests (MySQL) / Non-JS, PHP 8.3, Symfony ^7.3 (test_cached), MySQL 8.4, Twig ^3.3
- GitHub Check: Frontend / NodeJS 24.x
- GitHub Check: Packages / PHP 8.3, Symfony ^7.3, ORM ^3.3
- GitHub Check: Packages / PHP 8.2, Symfony ^6.4
- GitHub Check: Packages / PHP 8.4, Symfony ^7.3
- GitHub Check: End-to-end tests (PostgreSQL) / Get matrix
🔇 Additional comments (1)
src/Sylius/Bundle/ShopBundle/Twig/Component/Cart/FormComponent.php (1)
99-102: LGTM! Fix correctly addresses the EntityNotFoundException.The addition of these lines properly resolves the issue described in #18421. By creating a fresh cart resource and resetting all associated state after removing the old cart, you prevent Doctrine from attempting to reference deleted entities (such as Address entities that were associated with the cleared cart). This ensures the component returns to a clean initial state.
The sequence is correct:
- Old cart removed and flushed (lines 96-97)
- Fresh cart resource created (line 99)
- Form reset to bind to new resource (line 100)
- Validation state cleared (lines 101-102)
- Form submitted with new resource (line 105)
Please verify that this fix resolves the reproduction steps from issue #18421:
- Add product to cart
- Go to checkout/address and enter address
- Return to cart page
- Click "Clear cart" — should now succeed without EntityNotFoundException
8383cd4 to
b0e5f0d
Compare
Summary by CodeRabbit
Bug Fixes
Tests