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

Wrong sorting of products in taxon after saving #15954

Open
delyriand opened this issue Mar 6, 2024 · 2 comments · May be fixed by #15955
Open

Wrong sorting of products in taxon after saving #15954

delyriand opened this issue Mar 6, 2024 · 2 comments · May be fixed by #15955
Assignees

Comments

@delyriand
Copy link
Contributor

delyriand commented Mar 6, 2024

Sylius version affected: 1.2.11 and higher

Description

The position of the last products in a taxon is not correctly saved when there are more products than the taxon of the 1st productTaxon.

Because the getMaxPosition method in Sylius\Bundle\CoreBundle\Controller\ProductTaxonController class returns the wrong maximum position.
This is because when we load the "productTaxon" via the line $productTaxon = $this->findOr404($configuration); we have no criteria. So the SingleResourceProvider does a findOneBy with an empty array and returns the 1st "productTaxon".

Steps to reproduce

  • with the default fixutres
  • try to reorder all products in the Jeans taxon /admin/products/taxon/9
  • position of 2 last product is "-1"

image

Possible Solution

We could define the criteria in the requestConfiguration before calling the getMaxPosition method. For example:

$firstProductTaxonId = array_key_first($productTaxonsPositions);
$configuration->getParameters()->set('criteria', ['id' => $firstProductTaxonId]);
$maxPosition = $this->getMaxPosition($configuration);
@jakubtobiasz
Copy link
Member

Hi @delyriand,
can you tell use what values did you provide? We aren't able to reproduce your issue. It'd be great if you could record your screen 🙏🏻.

@delyriand
Copy link
Contributor Author

Hi @jakubtobiasz,

I can't reproduce the -1 positions… But if you look at the "maxPosition" (via xdebug or similar) when saving product positions in Jeans taxon, you'll see that it's 5 but not 7.

And if you try to save these positions:

image

I should have:

  • 666F
  • 111F
  • 000F

Products are saved in the wrong order:

image

Does it help you reproduce my issue?

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 a pull request may close this issue.

2 participants