src/Components/ShoppingCartComponent.php line 12

Open in your IDE?
  1. <?php
  2. namespace App\Components;
  3. use App\Dto\CartItem;
  4. use App\Service\ShoppingCartService;
  5. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  6. use Symfony\UX\LiveComponent\Attribute\AsLiveComponent;
  7. use Symfony\UX\LiveComponent\DefaultActionTrait;
  8. #[AsLiveComponent('shopping_cart')]
  9. final class ShoppingCartComponent extends AbstractController {
  10. use DefaultActionTrait;
  11. /** @var ShoppingCartService */
  12. private $shoppingCartService;
  13. public function __construct(ShoppingCartService $shoppingCartService) {
  14. $this->shoppingCartService = $shoppingCartService;
  15. }
  16. /**
  17. * @return array<int, CartItem>
  18. */
  19. public function getCartItems(): array {
  20. return $this->shoppingCartService->getCartItems();
  21. }
  22. public function getNumberOfItems(): int {
  23. return $this->shoppingCartService->getNumberOfItems();
  24. }
  25. public function getTotalPrice(): float {
  26. return $this->shoppingCartService->getTotalPrice();
  27. }
  28. public function getTotalRecurringPrice(): float {
  29. return $this->shoppingCartService->getTotalRecurringPrice();
  30. }
  31. }