Skip to content

[UPMERGE] 1.14 -> 2.0#17583

Merged
mpysiak merged 5 commits into2.0from
upmerge/1.14_2.0
Jan 3, 2025
Merged

[UPMERGE] 1.14 -> 2.0#17583
mpysiak merged 5 commits into2.0from
upmerge/1.14_2.0

Conversation

@SyliusBot
Copy link
Copy Markdown
Contributor

@SyliusBot SyliusBot commented Dec 19, 2024

This PR has been generated automatically.
For more details see upmerge_pr.yaml.

Remember! The upmerge should always be merged with using Merge pull request button.

In case of conflicts, please resolve them manually with usign the following commands:

git fetch upstream
gh pr checkout <this-pr-number>
git merge upstream/2.0 -m "Resolve conflicts between 1.14 and 2.0"

If you use other name for the upstream remote, please replace upstream with the name of your remote pointing to the Sylius/Sylius repository.

Once the conflicts are resolved, please run git merge --continue and push the changes to this PR.

Summary by CodeRabbit

  • Bug Fixes
    • Improved URL generation logic to handle empty link URLs more effectively, ensuring a fallback mechanism is in place.
    • Enhanced control flow for determining paths in the catalog promotion and default action views.
  • New Features
    • Introduced a new service for resetting cart changes, improving the handling of shopping cart updates.
    • Added a new interface and class for cart changes resetting functionality.
  • Data Updates
    • Updated statistics responses to reflect a decrease in new customer counts across daily, monthly, and yearly reports.

@SyliusBot SyliusBot requested review from a team as code owners December 19, 2024 02:28
@probot-autolabeler probot-autolabeler bot added the Admin AdminBundle related issues and PRs. label Dec 19, 2024
@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Dec 19, 2024

Walkthrough

The pull request introduces modifications to two Twig template files in the Sylius Admin and UI bundles, focusing on the logic for generating URL paths in grid action templates. The updates enhance the handling of the options.link.url variable by implementing explicit checks for empty strings before assigning or generating paths. Additionally, changes are made in the OrderBundle, where a new service for resetting cart changes is introduced, along with the removal of an old method and the addition of a new interface and class to encapsulate this functionality.

Changes

File Change Summary
src/Sylius/Bundle/.../AdminBundle/Resources/views/Grid/deleteCatalogPromotion.html.twig Modified path variable assignment with explicit empty string check
src/Sylius/Bundle/.../UiBundle/Resources/views/Grid/Action/default.html.twig Updated path generation logic with conditional URL handling
src/Sylius/Bundle/.../OrderBundle/Controller/OrderController.php Removed resetChangesOnCart method; added getCartResetter method; introduced CartChangesResetterInterface dependency
src/Sylius/Bundle/.../OrderBundle/Resetter/CartChangesResetter.php Added CartChangesResetter class implementing CartChangesResetterInterface with resetChanges method
src/Sylius/Bundle/.../OrderBundle/Resetter/CartChangesResetterInterface.php Added CartChangesResetterInterface with resetChanges method
src/Sylius/Bundle/.../OrderBundle/Resources/config/services.xml Introduced new service definition for sylius.resetter.cart_changes
src/Sylius/Bundle/.../OrderBundle/spec/Resetter/CartChangesResetterSpec.php Added specification tests for CartChangesResetter class
tests/Api/Responses/admin/statistics/get_day_statistics_response.json Updated newCustomersCount from 1 to 0
tests/Api/Responses/admin/statistics/get_month_statistics_response.json Updated newCustomersCount from 1 to 0
tests/Api/Responses/admin/statistics/get_year_statistics_response.json Updated newCustomersCount from 1 to 0

Poem

🐰 Hop, hop, through Twig's twisty lane,
Where URLs dance and paths refrain,
A rabbit's logic, clean and bright,
Checks empty strings with all its might!
Grid actions now more robust and clear,
No more wandering without a steer! 🔗


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Copy Markdown

@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

🧹 Nitpick comments (1)
src/Sylius/Bundle/UiBundle/Resources/views/Grid/Action/default.html.twig (1)

3-3: Consider documenting the URL resolution behavior.

Since this is a breaking change in how empty URLs are handled, it would be helpful to document this behavior in the grid configuration documentation.

Would you like me to help draft documentation for this URL resolution behavior?

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between d3293b3 and 88dce18.

📒 Files selected for processing (2)
  • src/Sylius/Bundle/AdminBundle/Resources/views/Grid/deleteCatalogPromotion.html.twig (1 hunks)
  • src/Sylius/Bundle/UiBundle/Resources/views/Grid/Action/default.html.twig (1 hunks)
🔇 Additional comments (2)
src/Sylius/Bundle/UiBundle/Resources/views/Grid/Action/default.html.twig (1)

3-3: LGTM! The URL handling is now more robust.

The explicit empty string check improves the URL resolution logic, making it more defensive.

Let's verify if any grid configurations might be affected by this change:

✅ Verification successful

LGTM! The URL handling change is safe to use

The explicit empty string check in the default grid action template is a defensive improvement that doesn't impact existing configurations. The search results show:

  1. No grid configurations directly specify empty URLs
  2. The template is used consistently across the codebase
  3. The change aligns with Sylius's defensive programming patterns
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for grid configurations that might use empty URLs
rg -g "*.{yaml,yml}" -A 5 "link:\s*\n\s*url:" src/

Length of output: 244


Script:

#!/bin/bash
# Search for grid configurations that might use empty URLs, with multiline support
rg -U -g "*.{yaml,yml}" "link:\s*\n\s+url:" src/

# Also search for grid action configurations in general
rg -g "*.{yaml,yml}" "actions:" -A 10 src/

# Look for other grid action templates that might be affected
fd -e twig "action" src/ --exec grep -l "options.link"

Length of output: 66443


Script:

#!/bin/bash
# Search for grid action templates that might be affected
fd -e twig "action" src/ --exec grep -l "options.link"

# Search for grid configurations that use URL in actions
rg -U -g "*.{yaml,yml}" "actions:(?s).*?url:" src/

# Look for other templates that might include this template
rg -g "*.twig" "include.*default.html.twig" src/

Length of output: 1732

src/Sylius/Bundle/AdminBundle/Resources/views/Grid/deleteCatalogPromotion.html.twig (1)

1-1: LGTM! URL handling is consistent with the default template.

The change maintains consistency with the default grid action template while preserving all security features.

Let's verify the impact on catalog promotion configurations:

✅ Verification successful

The verification results show that the catalog promotion grid configuration is properly set up:

  1. It uses the custom template @SyliusAdmin/Grid/deleteCatalogPromotion.html.twig
  2. The delete action is configured with a proper route sylius_admin_catalog_promotion_delete
  3. The route parameters are correctly mapped using resource.code

Let me verify if there are any custom URL configurations that might be affected by this change.


URL handling change in catalog promotion deletion is safe

The verification confirms that:

  • The route is properly configured with a standard DELETE endpoint
  • The template is only referenced in the catalog promotion grid configuration
  • No custom URL configurations or overrides are present that could be affected by the URL handling change
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for catalog promotion grid configurations
rg -g "*.{yaml,yml}" -A 10 "catalog_promotion.*grid:" src/

# Check for any custom delete action configurations
rg -g "*.{yaml,yml}" -A 5 "delete_catalog_promotion" src/

Length of output: 1554


Script:

#!/bin/bash
# Check for any custom URL configurations in catalog promotion routes
rg -g "*.{yaml,yml}" -A 5 "sylius_admin_catalog_promotion_delete" src/

# Check if there are any other templates extending or including the delete template
rg -l "@SyliusAdmin/Grid/deleteCatalogPromotion.html.twig" src/

Length of output: 1411

Copy link
Copy Markdown

@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

🧹 Nitpick comments (5)
src/Sylius/Bundle/OrderBundle/Resetter/CartChangesResetterInterface.php (1)

18-21: Consider adding basic PHPDoc.
It may be helpful to add a brief PHPDoc description clarifying the purpose of the resetChanges method and when it should be called, which could guide future maintainers.

src/Sylius/Bundle/OrderBundle/Resetter/CartChangesResetter.php (1)

26-43: Optional: Log or debug newly removed units.
When removing units in a production system, it can be helpful to log or debug the removal, especially for auditing or troubleshooting issues involving partial cart updates.

src/Sylius/Bundle/OrderBundle/spec/Resetter/CartChangesResetterSpec.php (1)

1-74: Nice coverage and clarity in tests.
The spec thoroughly checks both the unmanaged-cart scenario and the correct removal of new units. Consider adding a test for edge cases with zero items, ensuring no unintended side effects.

src/Sylius/Bundle/OrderBundle/Controller/OrderController.php (1)

223-227: Prefer dependency injection in the constructor.
Accessing the service via $this->get() is typical in older Symfony code, but consider injecting CartChangesResetterInterface directly through the constructor or dedicated methods for improved testability.

src/Sylius/Bundle/OrderBundle/Resources/config/services.xml (1)

90-93: LGTM! Clean service definition following Symfony best practices.

The new cart changes resetter service is well-structured with proper dependency injection and interface binding.

Consider making this service private since it appears to be an internal service that should not be accessed directly from the service container. Apply this diff:

-        <service id="sylius.resetter.cart_changes" class="Sylius\Bundle\OrderBundle\Resetter\CartChangesResetter">
+        <service id="sylius.resetter.cart_changes" class="Sylius\Bundle\OrderBundle\Resetter\CartChangesResetter" public="false">
             <argument type="service" id="sylius.manager.order" />
         </service>
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 88dce18 and a5fb686.

📒 Files selected for processing (8)
  • src/Sylius/Bundle/OrderBundle/Controller/OrderController.php (3 hunks)
  • src/Sylius/Bundle/OrderBundle/Resetter/CartChangesResetter.php (1 hunks)
  • src/Sylius/Bundle/OrderBundle/Resetter/CartChangesResetterInterface.php (1 hunks)
  • src/Sylius/Bundle/OrderBundle/Resources/config/services.xml (1 hunks)
  • src/Sylius/Bundle/OrderBundle/spec/Resetter/CartChangesResetterSpec.php (1 hunks)
  • tests/Api/Responses/admin/statistics/get_day_statistics_response.json (1 hunks)
  • tests/Api/Responses/admin/statistics/get_month_statistics_response.json (1 hunks)
  • tests/Api/Responses/admin/statistics/get_year_statistics_response.json (1 hunks)
🔇 Additional comments (7)
tests/Api/Responses/admin/statistics/get_year_statistics_response.json (1)

19-19: LGTM! Verify related test cases.

The update to newCustomersCount is consistent with the changes in other statistics response fixtures. However, since this modifies test data, ensure that:

  1. The related test cases have been updated to expect this new value
  2. The change reflects the correct business logic in the main codebase
✅ Verification successful

Change is consistent across all statistics response fixtures

The verification shows that newCustomersCount is consistently set to 0 across all related statistics response fixtures:

  • get_year_statistics_response.json
  • get_month_statistics_response.json
  • get_day_statistics_response.json

Since we found no test assertions expecting the old value of 1, and all related response fixtures are aligned with the new value of 0, this change appears to be correctly implemented across the test suite.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for any test cases that might still expect newCustomersCount to be 1

# Search for test assertions related to newCustomersCount
rg -A 5 "newCustomersCount.*1" "tests/"

Length of output: 39


Script:

#!/bin/bash
# Let's try a broader search for newCustomersCount in tests
rg "newCustomersCount" "tests/" -B 2 -A 2

# Also search for any test files that might be using this response fixture
fd ".*test.*\.(php|js|ts|py)$" | xargs rg "get_year_statistics_response"

Length of output: 1576

tests/Api/Responses/admin/statistics/get_month_statistics_response.json (1)

151-151: LGTM! Change is consistent with other fixtures.

The update to newCustomersCount maintains consistency with the changes in the yearly statistics response fixture.

tests/Api/Responses/admin/statistics/get_day_statistics_response.json (1)

4391-4391: LGTM! Verify the business logic change.

The update to newCustomersCount completes the consistent pattern of changes across all statistics response fixtures (yearly, monthly, and daily). Since this appears to be a deliberate change across all granularities, we should verify:

  1. The business logic change in the main codebase that necessitated these test updates
  2. The impact on any statistics-related features that might depend on this value
✅ Verification successful

Test fixtures updated to match actual business logic implementation

The test fixtures were correctly updated to reflect the actual implementation. The newCustomersCount value is derived from CustomerRepositoryInterface::countCustomersInPeriod() which counts customers within a specific time period. The test fixtures (yearly, monthly, and daily statistics responses) were updated for consistency with this implementation.

Looking at the implementation in BusinessActivitySummaryProvider.php, we can see that:

  1. The value comes directly from the customer repository's count method
  2. The test spec confirms this behavior, showing it's an expected part of the business logic
  3. The change in test fixtures from 1 to 0 aligns with this implementation
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Look for the business logic change that modified how newCustomersCount is calculated

# Search for relevant business logic in statistics-related files
rg -l "newCustomersCount" "src/" | while read -r file; do
  echo "=== $file ==="
  git log -p "$file"
done

# Search for any remaining references to the old value
rg "newCustomersCount.*1" "src/"

Length of output: 636


Script:

#!/bin/bash
# Let's examine the content of the identified files to understand the business logic

# Check BusinessActivitySummary.php
echo "=== BusinessActivitySummary.php ==="
cat "src/Sylius/Component/Core/Statistics/ValueObject/BusinessActivitySummary.php"

# Check StatisticsDocumentationModifier.php
echo -e "\n=== StatisticsDocumentationModifier.php ==="
cat "src/Sylius/Bundle/ApiBundle/OpenApi/Documentation/StatisticsDocumentationModifier.php"

# Check DashboardContext.php
echo -e "\n=== DashboardContext.php ==="
cat "src/Sylius/Behat/Context/Api/Admin/DashboardContext.php"

# Let's also check for any test files that might provide context
echo -e "\n=== Test files containing newCustomersCount ==="
rg -l "newCustomersCount" "tests/"

Length of output: 12353


Script:

#!/bin/bash
# Let's check for any recent changes in the business logic implementation

# Look for the statistics provider/calculator implementation
echo "=== Looking for statistics provider implementation ==="
rg -l "BusinessActivitySummary" "src/"

# Check for any test implementations that might provide context
echo -e "\n=== Looking for related test implementations ==="
rg -l "newCustomersCount.*assert" "tests/"

# Check for any recent commits related to statistics
echo -e "\n=== Recent commits related to statistics ==="
git log --grep="statistic" --grep="customer" -n 5 --oneline

Length of output: 1037


Script:

#!/bin/bash
# Let's check the implementation of the business logic

# Check the statistics provider implementation
echo "=== BusinessActivitySummaryProvider.php ==="
cat "src/Sylius/Component/Core/Statistics/Provider/BusinessActivitySummaryProvider.php"

# Check the spec file for insights into the expected behavior
echo -e "\n=== BusinessActivitySummaryProviderSpec.php ==="
cat "src/Sylius/Component/Core/spec/Statistics/Provider/BusinessActivitySummaryProviderSpec.php"

# Check the statistics provider
echo -e "\n=== StatisticsProvider.php ==="
cat "src/Sylius/Component/Core/Statistics/Provider/StatisticsProvider.php"

Length of output: 5497

src/Sylius/Bundle/OrderBundle/Resetter/CartChangesResetter.php (1)

20-24: Good use of final and constructor injection.
This approach adheres to best practices in modern PHP, preventing class extension and ensuring dependencies are clearly declared.

src/Sylius/Bundle/OrderBundle/Controller/OrderController.php (2)

17-17: Importing the interface is appropriate.
Bringing in CartChangesResetterInterface aligns with the newly introduced service, ensuring the controller stays decoupled from implementation details.


126-126: Verify cart reset behavior upon invalid form submission.
Resetting carts after form validation fails may be correct, but carefully review whether this is expected from a user perspective, e.g., should unsaved new items always be discarded?

src/Sylius/Bundle/OrderBundle/Resources/config/services.xml (1)

90-93: Verify the integration of the new cart changes resetter service.

Let's ensure all the related changes are properly implemented:

✅ Verification successful

The cart changes resetter service is properly integrated and implemented

The verification shows that:

  • Both the interface and implementation classes exist and are properly implemented
  • The OrderController has been updated to use the new service through getCartResetter() method
  • The old resetChangesOnCart method has been completely removed
  • The implementation correctly handles cart changes using Doctrine's EntityManager

The service implementation looks solid with proper:

  • Type declarations and null safety
  • Error handling for non-managed entities
  • Proper cleanup of new units and refresh of affected entities
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the complete implementation of the cart changes resetter

# Check if the new classes exist
echo "Checking for new class files..."
fd CartChangesResetter.php
fd CartChangesResetterInterface.php

# Check if OrderController has been updated to use the new service
echo -e "\nChecking OrderController updates..."
rg -A 5 "getCartResetter|resetChanges.*resource" --type php

# Check for any remaining usages of the old method
echo -e "\nChecking for any remaining usages of the old method..."
rg "resetChangesOnCart" --type php

Length of output: 1835


Script:

#!/bin/bash
# Let's verify the implementation details of the new classes

# Check the interface definition
echo "Checking CartChangesResetterInterface implementation..."
cat src/Sylius/Bundle/OrderBundle/Resetter/CartChangesResetterInterface.php

echo -e "\nChecking CartChangesResetter implementation..."
cat src/Sylius/Bundle/OrderBundle/Resetter/CartChangesResetter.php

# Check for any tests
echo -e "\nChecking for related tests..."
fd -e php -g "*CartChangesResetter*Test.php"

Length of output: 2072

mpysiak
mpysiak previously approved these changes Jan 2, 2025
@github-actions
Copy link
Copy Markdown

github-actions bot commented Jan 2, 2025

Bunnyshell Preview Environment deleted

Available commands:

  • /bns:deploy to redeploy the environment

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Admin AdminBundle related issues and PRs.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants