[go: nahoru, domu]

Skip to content

Commit

Permalink
bug #16477 Fix ProductTaxons' positioning logic (NoResponseMate)
Browse files Browse the repository at this point in the history
This PR was merged into the 1.12 branch.

Discussion
----------

| Q               | A
|-----------------|-----
| Branch?         | 1.12
| Bug fix?        | yes
| New feature?    | no
| BC breaks?      | no
| Deprecations?   | no
| Related tickets | outlined in #15225 (comment)
| License         | MIT

The second issue:
>The other error is smaller, the count should not be reduced by 1 because the positioner will check for $newPosition >= $maxPosition. If you move a product to the last one in the taxon it will change it to the second-last position.

does not occur since when the `$newPosition >= $maxPosition` check is true, the position is set to `-1` instead of being reduced by 1. After that, the default Gedmo logic kicks in and `-1` gets converted into the last position.

Commits
-------

4fa32f3 Fix ProductTaxons' positioning logic
  • Loading branch information
GSadee committed Jul 1, 2024
2 parents bd3e203 + 4fa32f3 commit f63e2a3
Showing 1 changed file with 7 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public function updateProductTaxonsPositionsAction(Request $request): Response
return $this->redirectHandler->redirectToReferer($configuration);
}

$maxPosition = $this->getMaxPosition($configuration);
$maxPosition = $this->getMaxPosition($productTaxonsPositions);

try {
$this->updatePositions($productTaxonsPositions, $maxPosition);
Expand Down Expand Up @@ -120,14 +120,17 @@ private function updatePositions(array $productTaxonPositions, int $maxPosition)
}
}

private function getMaxPosition(RequestConfiguration $configuration): int
/** @param array<int, string> $productTaxonsPositions */
private function getMaxPosition(array $productTaxonsPositions): int
{
/** @var ProductTaxonInterface $productTaxon */
$productTaxon = $this->findOr404($configuration);
$firstProductTaxonId = array_keys($productTaxonsPositions)[0];

/** @var EntityRepository&RepositoryInterface $repository */
$repository = $this->repository;

/** @var ProductTaxonInterface $productTaxon */
$productTaxon = $repository->find($firstProductTaxonId);

return $repository->count(['taxon' => $productTaxon->getTaxon()]) - 1;
}

Expand Down

0 comments on commit f63e2a3

Please sign in to comment.