Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Conversation

rust-le
Copy link
Contributor

@rust-le rust-le commented Oct 13, 2025

Q A
Branch? 2.1
Bug fix? no
New feature? no
BC breaks? no
Deprecations? no
Related tickets #18405
License MIT

Summary by CodeRabbit

  • Bug Fixes

    • Stock levels now correctly increase when an order is partially refunded, ensuring inventory is accurately restored.
  • Improvements

    • Enhanced reliability of resource creation in UI forms, enabling more flexible and consistent behavior across different configurations.

@rust-le rust-le requested review from a team as code owners October 13, 2025 13:16
Copy link

coderabbitai bot commented Oct 13, 2025

Walkthrough

Adds optional factory-based resource instantiation to ResourceFormComponentTrait via new initialize parameters and adjusted createResource logic. Modifies OrderInventoryOperator::cancel to treat PARTIALLY_REFUNDED like PAID/REFUNDED for inventory return, altering the control path for that payment state.

Changes

Cohort / File(s) Summary
UI Resource Form Factory Support
src/Sylius/Bundle/UiBundle/Twig/Component/ResourceFormComponentTrait.php
Adds optional FactoryInterface and factoryMethod to initialize; createResource now uses factory when provided; imports FactoryInterface; updates PHPDoc and method signature.
Inventory Cancel Flow Adjustment
src/Sylius/Component/Core/Inventory/Operator/OrderInventoryOperator.php
Extends cancel logic: PARTIALLY_REFUNDED now triggers giveBack() alongside PAID and REFUNDED.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  actor T as Twig Component
  participant R as ResourceFormComponentTrait
  participant F as Factory (optional)

  T->>R: initialize(repository, formFactory, resourceClass, formClass, factory?, factoryMethod?)
  Note over R: Store factory and method if provided
  T->>R: createResource()
  alt factory provided
    R->>F: factoryMethod() -> resource
    F-->>R: New Resource
  else no factory
    R->>R: new resourceClass()
  end
  R-->>T: Resource instance
Loading
sequenceDiagram
  autonumber
  participant S as OrderInventoryOperator
  participant O as Order
  participant I as Inventory

  S->>O: cancel(order)
  O-->>S: getPaymentState()
  alt state in {PAID, REFUNDED, PARTIALLY_REFUNDED}
    S->>I: giveBack(order)
    I-->>S: inventory returned
  else other states
    S->>I: release(order)
    I-->>S: inventory released
  end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Poem

I twitch my whiskers at new lines of lore,
A factory hops in—resources galore!
Partials refunded? I bounce and I pivot,
Inventory returns—just the right rivet.
Carrots compiled, CI lights green—
Ship it, and nibble the changelog clean. 🥕✨

Pre-merge checks and finishing touches

❌ Failed checks (2 warnings)
Check name Status Explanation Resolution
Title Check ⚠️ Warning The title “[WIP] Custom factory configuration fix” includes a development marker that should be removed and only references the factory configuration change, omitting the update to handle the partially refunded state in OrderInventoryOperator::cancel. It does not clearly summarize the primary set of changes in the pull request. Remove the “[WIP]” prefix and use a concise title that reflects both key changes, for example: “Allow optional factory for ResourceFormComponentTrait and handle partially refunded state in OrderInventoryOperator::cancel.”
Docstring Coverage ⚠️ Warning Docstring coverage is 60.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (1 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

github-actions bot commented Oct 13, 2025

❗ Preview Environment deployment failed on Bunnyshell

See: Environment Details | Pipeline Logs

Check https://github.com/Sylius/Sylius/actions/runs/18467059344 for details.

Available commands:

  • 🚀 /bns:deploy to redeploy the environment
  • /bns:delete to remove the environment

Copy link

@coderabbitai coderabbitai bot left a 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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
src/Sylius/Component/Core/Inventory/Operator/OrderInventoryOperator.php (1)

24-37: Prevent over-returning stock on partial refunds
In cancel(), STATE_PARTIALLY_REFUNDED still calls giveBack(), which returns all items. No per-item refund tracking exists—implement tracking (e.g., refundedQuantity on OrderItem) and adjust cancel() to return only actually refunded items.

🧹 Nitpick comments (1)
src/Sylius/Bundle/UiBundle/Twig/Component/ResourceFormComponentTrait.php (1)

96-106: Validate factory method exists before dynamic invocation.

The trait’s createResource() unconditionally calls $this->factory->$factoryMethod() which can fail at runtime if a custom $factoryMethod is invalid or requires parameters. Add a method_exists($this->factory, $factoryMethod) check (for example in initialize()) or constrain allowed methods to guarantee safety.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 7dcdad3 and 0c28cd2.

📒 Files selected for processing (2)
  • src/Sylius/Bundle/UiBundle/Twig/Component/ResourceFormComponentTrait.php (5 hunks)
  • src/Sylius/Component/Core/Inventory/Operator/OrderInventoryOperator.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/Component/Core/Inventory/Operator/OrderInventoryOperator.php
  • src/Sylius/Bundle/UiBundle/Twig/Component/ResourceFormComponentTrait.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/Component/Core/Inventory/Operator/OrderInventoryOperator.php
  • src/Sylius/Bundle/UiBundle/Twig/Component/ResourceFormComponentTrait.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). (19)
  • GitHub Check: End-to-end tests (PostgreSQL) / Non-JS, PHP 8.4, Symfony ^7.3, PostgreSQL 17.5
  • GitHub Check: End-to-end tests (PostgreSQL) / Non-JS, PHP 8.2, Symfony ^6.4, PostgreSQL 15.13
  • GitHub Check: Frontend / NodeJS 24.x
  • GitHub Check: End-to-end tests (MariaDB) / Non-JS, PHP 8.4, Symfony ^7.3, MariaDB 11.4.7, State Machine Adapter symfony_workflow, ApiPlatform ~4.1.7
  • 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: Packages / PHP 8.3, Symfony ^7.3, ORM ^3.3
  • GitHub Check: Packages / PHP 8.4, Symfony ^7.3
  • GitHub Check: Packages / PHP 8.2, Symfony ^6.4
  • 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) / Non-JS, 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 Panther, 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) / 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) / JS with Panther, PHP 8.3, Symfony ^7.3 (test_cached), MySQL 8.4, Twig ^3.3
  • GitHub Check: WIP
🔇 Additional comments (4)
src/Sylius/Bundle/UiBundle/Twig/Component/ResourceFormComponentTrait.php (3)

17-17: LGTM!

The import is correctly added and necessary for the new factory-based functionality.


48-51: LGTM with minor note.

The properties are well-typed with appropriate defaults. The $factoryMethod = 'createNew' default on line 51 is redundant since it's always set via initialize(), but this doesn't cause issues and maintains consistency.


75-89: LGTM!

The signature change maintains backward compatibility with optional parameters and appropriate defaults. The PHPDoc correctly documents the generic factory type.

src/Sylius/Component/Core/Inventory/Operator/OrderInventoryOperator.php (1)

24-37: Confirm inventory return logic for partially refunded orders
In OrderInventoryOperator::cancel() (line 28), adding STATE_PARTIALLY_REFUNDED routes cancellation through giveBack(), which restocks all items.

  • Should cancelling a partially-refunded order restock every item or only the refunded ones?
  • No test covers cancel() for STATE_PARTIALLY_REFUNDED—please add one to OrderInventoryOperatorTest.
  • This inventory change isn’t related to “[WIP] Custom factory configuration fix”; consider splitting it into a dedicated PR or updating the title.

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

Successfully merging this pull request may close these issues.

1 participant

Morty Proxy This is a proxified and sanitized view of the page, visit original site.