Skip to content

Commit

Permalink
[TASK] Improve implementation of Event
Browse files Browse the repository at this point in the history
Improve `ProcessOrderCheckStockEvent`:
* better naming
* remove interface

Related: #309
  • Loading branch information
rintisch committed May 30, 2024
1 parent c08f3dd commit c18c432
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 52 deletions.
4 changes: 2 additions & 2 deletions Classes/Controller/Cart/OrderController.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,8 @@ public function createAction(
$processOrderCheckStockEvent = new ProcessOrderCheckStockEvent($this->cart);
$this->eventDispatcher->dispatch($processOrderCheckStockEvent);

if (!$processOrderCheckStockEvent->allProductsAreAvailable()) {
$errors = $processOrderCheckStockEvent->getMessages();
if (!$processOrderCheckStockEvent->isEveryProductAvailable()) {
$errors = $processOrderCheckStockEvent->getInsufficientStockMessages();

$messageBody = '';
$messageTitle = '';
Expand Down
33 changes: 11 additions & 22 deletions Classes/Event/ProcessOrderCheckStockEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@
use Extcode\Cart\Domain\Model\Cart\Cart;
use TYPO3\CMS\Core\Messaging\FlashMessage;

final class ProcessOrderCheckStockEvent implements ProcessOrderCheckStockEventInterface
final class ProcessOrderCheckStockEvent
{
private bool $allProductsAvailable = true;
private bool $everyProductAvailable = true;

/**
* @var FlashMessage[]
*/
protected array $messages = [];
protected array $insufficientStockMessages = [];

public function __construct(
private readonly Cart $cart
Expand All @@ -32,37 +32,26 @@ public function getCart(): Cart
return $this->cart;
}

public function allProductsAreAvailable(): bool
public function isEveryProductAvailable(): bool
{
return $this->allProductsAvailable;
return $this->everyProductAvailable;
}

public function setNotAllProductsAreAvailable(): void
public function setNotEveryProductAvailable(): void
{
$this->allProductsAvailable = false;
$this->everyProductAvailable = false;
}

/**
* @return FlashMessage[]
*/
public function getMessages(): array
public function getInsufficientStockMessages(): array
{
return $this->messages;
return $this->insufficientStockMessages;
}

/**
* @param FlashMessage[] $messages
*/
public function setMessages(array $messages): void
{
$this->messages = $messages;
}

/**
* @param FlashMessage $message
*/
public function addMessage(FlashMessage $message): void
public function addMessage(FlashMessage $insufficientStockMessage): void
{
$this->messages[] = $message;
$this->insufficientStockMessages[] = $insufficientStockMessage;
}
}
28 changes: 0 additions & 28 deletions Classes/Event/ProcessOrderCheckStockEventInterface.php

This file was deleted.

0 comments on commit c18c432

Please sign in to comment.