You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

47 line
1.4KB

  1. <?php
  2. namespace Lc\ShopBundle\Controller;
  3. use Doctrine\ORM\EntityManager;
  4. use Doctrine\ORM\EntityManagerInterface;
  5. use Lc\ShopBundle\Context\ProductInterface;
  6. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  7. use Symfony\Component\HttpFoundation\JsonResponse;
  8. use Symfony\Component\Security\Core\Security;
  9. class ApiController extends AbstractController
  10. {
  11. protected $security;
  12. protected $userManager;
  13. protected $em ;
  14. protected $utils ;
  15. public function __construct(EntityManagerInterface $entityManager)
  16. {
  17. $this->em = $entityManager;
  18. }
  19. public function getEntity($entity, $id)
  20. {
  21. if($entity == 'product'){
  22. $repo = $this->em->getRepository(ProductInterface::class);
  23. $data = $repo->find($id);
  24. $data= array(
  25. 'id' => $data->getId(),
  26. 'title' => $data->getTitleInherited(),
  27. 'price' => $data->getPriceInherited(),
  28. 'unit' => $data->getUnitInherited(),
  29. 'availableQuantity' => $data->getAvailableQuantityInherited(),
  30. 'taxRate' => $data->getTaxRateInherited(),
  31. );
  32. }
  33. return new JsonResponse($data);
  34. }
  35. }