Dont change the original collection when calling getOrderdetails with $hide_obsolete = true

This caused the orderdetails tab to be hidden on part info, when the orderdetail was obsolete
This commit is contained in:
Jan Böhmer 2022-09-08 00:35:39 +02:00
parent 28c09eb51d
commit b0d29eaeaf

View file

@ -44,6 +44,7 @@ namespace App\Entity\Parts\PartTraits;
use App\Entity\PriceInformations\Orderdetail; use App\Entity\PriceInformations\Orderdetail;
use App\Security\Annotations\ColumnSecurity; use App\Security\Annotations\ColumnSecurity;
use Doctrine\Common\Collections\ArrayCollection;
use Symfony\Component\Validator\Constraints as Assert; use Symfony\Component\Validator\Constraints as Assert;
use function count; use function count;
use Doctrine\Common\Collections\Collection; use Doctrine\Common\Collections\Collection;
@ -129,14 +130,9 @@ trait OrderTrait
{ {
//If needed hide the obsolete entries //If needed hide the obsolete entries
if ($hide_obsolete) { if ($hide_obsolete) {
$orderdetails = $this->orderdetails; return $this->orderdetails->filter(function (Orderdetail $orderdetail) {
foreach ($orderdetails as $key => $details) { return ! $orderdetail->getObsolete();
if ($details->getObsolete()) { });
unset($orderdetails[$key]);
}
}
return $orderdetails;
} }
return $this->orderdetails; return $this->orderdetails;