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

Fix crash when adding a package to a package set where a package was previously deleted #4877

Merged
merged 2 commits into from
Feb 11, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/Doctrine/EventSubscriber/TaskSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,7 @@ private function handleStateChangesForTasks(EntitymanagerInterface $em, array $t
continue;
}

// if all tasks of a delivery are cancelled, cancel the linked order
$tasks = $delivery->getTasks();
$cancelOrder = true;
foreach ($tasks as $task) {
Expand All @@ -233,7 +234,8 @@ private function handleStateChangesForTasks(EntitymanagerInterface $em, array $t
}
}

if ($cancelOrder && $order->getState() !== OrderInterface::STATE_CANCELLED) {
// do not cancel order if order is "refused"
if ($cancelOrder && $order->getState() !== OrderInterface::STATE_CANCELLED && $order->getState() !== OrderInterface::STATE_REFUSED) {
$this->orderManager->cancel($order, 'All tasks were cancelled');
$em->flush();
}
Expand Down
5 changes: 4 additions & 1 deletion src/Entity/PackageSet.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,11 +88,14 @@ public function setName($name)
*/
public function getPackages()
{
return $this->packages->filter(
$filtered = $this->packages->filter(
function ($package) {
return !$package->isDeleted();
}
);

// reset index after filtering
return new ArrayCollection(array_values($filtered->toArray()));
}

/**
Expand Down
12 changes: 6 additions & 6 deletions src/Entity/Store.php
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ class Store extends LocalBusiness implements TaggableInterface, OrganizationAwar
/**
* The deliveries of this store will be linked by default to this rider
* @var User
*/
*/
private $defaultCourier;

protected string $billingMethod = 'unit';
Expand All @@ -219,7 +219,8 @@ class Store extends LocalBusiness implements TaggableInterface, OrganizationAwar
*/
protected ?string $storeGLN = null;

public function __construct() {
public function __construct()
{
$this->deliveries = new ArrayCollection();
$this->owners = new ArrayCollection();
$this->addresses = new ArrayCollection();
Expand Down Expand Up @@ -552,7 +553,7 @@ public function setMultiDropEnabled($multiDropEnabled)

public function getTimeSlots()
{
return $this->timeSlots->map(fn (StoreTimeSlot $sts): TimeSlot => $sts->getTimeSlot());
return $this->timeSlots->map(fn(StoreTimeSlot $sts): TimeSlot => $sts->getTimeSlot());
}

public function setTimeSlots($timeSlots): void
Expand Down Expand Up @@ -611,13 +612,13 @@ public function setTimeSlots($timeSlots): void
public function getPackages()
{
if (null !== $this->packageSet) {
return array_values($this->packageSet->getPackages()->toArray());
return $this->packageSet->getPackages();
}

return [];
}

public function isTransporterEnabled(): bool
public function isTransporterEnabled(): bool
{
return !is_null($this->transporter);
}
Expand Down Expand Up @@ -672,5 +673,4 @@ public function getStoreGLN(): ?string
{
return $this->storeGLN;
}

}
Loading