Skip to content

[New routing] Refactoring update product variant positions#18882

Open
loic425 wants to merge 1 commit intoSylius:new-routingfrom
loic425:update-product-variant-positions
Open

[New routing] Refactoring update product variant positions#18882
loic425 wants to merge 1 commit intoSylius:new-routingfrom
loic425:update-product-variant-positions

Conversation

@loic425
Copy link
Copy Markdown
Member

@loic425 loic425 commented Mar 3, 2026

Q A
Branch? new-routing
Bug fix? no
New feature? yes
BC breaks? no
Deprecations? no
Related tickets partially #18212
License MIT

@loic425 loic425 requested review from a team as code owners March 3, 2026 12:14
@probot-autolabeler probot-autolabeler bot added the Admin AdminBundle related issues and PRs. label Mar 3, 2026
@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Mar 3, 2026

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Tip

Try Coding Plans. Let us write the prompt for your AI agent so you can ship faster (with fewer bugs).
Share your feedback on Discord.


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.

@github-actions
Copy link
Copy Markdown

github-actions bot commented Mar 3, 2026

❗ Preview Environment deployment failed on Bunnyshell

See: Environment Details | Pipeline Logs

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

Available commands:

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

Copy link
Copy Markdown
Member

@diimpp diimpp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Request changes is due missing not found check on product variants

Comment on lines +43 to +44
$csrfToken = new CsrfToken(self::CSRF_TOKEN_NAME, $data['_csrf_token'] ?? '');
$this->validateCsrfProtection($csrfToken);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
$csrfToken = new CsrfToken(self::CSRF_TOKEN_NAME, $data['_csrf_token'] ?? '');
$this->validateCsrfProtection($csrfToken);
$this->validateCsrfProtection(
new CsrfToken(self::CSRF_TOKEN_NAME, $data['_csrf_token'] ?? '')
);


$productVariantsToUpdate = $data['productVariants'] ?? [];

if (in_array($request->getMethod(), ['POST', 'PUT', 'PATCH'], true)) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why this check is necessary? Cannot route have these definitions?

But if necessary, then would be better to avoid wrapping logic with if

        if (!in_array($request->getMethod(), ['POST', 'PUT', 'PATCH'], true)) {
            throw new BadRequestException();
        }

Comment on lines +58 to +59
$productVariant = $this->productVariantRepository->findOneBy(['id' => $productVariantToUpdate['id']]);
$productVariant->setPosition((int) $productVariantToUpdate['position']);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing check that productVariant is found with NotFoundException

/** @var ProductVariantInterface $productVariant */
$productVariant = $this->productVariantRepository->findOneBy(['id' => $productVariantToUpdate['id']]);
$productVariant->setPosition((int) $productVariantToUpdate['position']);
$this->manager->flush();
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe worth adding comment, that in-loop flush is necessary due how gedmo/sortable works otherwise it doesn't look like good code.

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