|
- <?php
-
- namespace Lc\ShopBundle\Controller;
-
- use Doctrine\ORM\EntityManager;
- use Doctrine\ORM\EntityManagerInterface;
- use Lc\ShopBundle\Context\ProductInterface;
- use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
- use Symfony\Component\HttpFoundation\JsonResponse;
- use Symfony\Component\Security\Core\Security;
-
- class ApiController extends AbstractController
- {
- protected $security;
- protected $userManager;
- protected $em ;
- protected $utils ;
-
- public function __construct(EntityManagerInterface $entityManager)
- {
- $this->em = $entityManager;
-
- }
-
- public function getEntity($entity, $id)
- {
-
-
- if($entity == 'product'){
- $repo = $this->em->getRepository(ProductInterface::class);
- $data = $repo->find($id);
- $data= array(
- 'id' => $data->getId(),
- 'title' => $data->getTitleInherited(),
- 'price' => $data->getPriceInherited(),
- 'unit' => $data->getUnitInherited(),
- 'availableQuantity' => $data->getAvailableQuantityInherited(),
- 'taxRate' => $data->getTaxRateInherited(),
- );
- }
-
- return new JsonResponse($data);
- }
-
- }
|