Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

58 rindas
2.2KB

  1. <?php
  2. namespace Lc\ShopBundle\Controller;
  3. use Doctrine\ORM\EntityManager;
  4. use Doctrine\ORM\EntityManagerInterface;
  5. use Lc\ShopBundle\Context\ProductCategoryInterface;
  6. use Lc\ShopBundle\Context\ProductInterface;
  7. use Lc\ShopBundle\Services\PriceUtils;
  8. use Lc\ShopBundle\Services\ProductFamilyUtils;
  9. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  10. use Symfony\Component\HttpFoundation\JsonResponse;
  11. use Symfony\Component\HttpFoundation\Response;
  12. use Symfony\Component\Security\Core\Security;
  13. class ApiController extends AbstractController
  14. {
  15. protected $security;
  16. protected $userManager;
  17. protected $em ;
  18. protected $utils ;
  19. protected $priceUtils ;
  20. protected $productFamilyUtils;
  21. public function __construct(EntityManagerInterface $entityManager, PriceUtils $priceUtils, ProductFamilyUtils $productFamilyUtils)
  22. {
  23. $this->em = $entityManager;
  24. $this->priceUtils = $priceUtils;
  25. $this->productFamilyUtils = $productFamilyUtils;
  26. }
  27. public function getEntity($entity, $id)
  28. {
  29. $repo = $this->em->getRepository(ProductCategoryInterface::class);
  30. $data = $repo->findBy(array());
  31. if($entity == 'product'){
  32. $repo = $this->em->getRepository(ProductInterface::class);
  33. $data = $repo->find($id);
  34. $data= array(
  35. 'id' => $data->getId(),
  36. 'title' => $data->getTitleInherited(),
  37. 'price' => $this->priceUtils->getPrice($data),
  38. 'priceWithTax' => $this->priceUtils->getPriceWithTax($data),
  39. 'priceWithTaxAndReduction' => $this->priceUtils->getPriceWithTaxAndReduction($data),
  40. 'unit' => $data->getUnitInherited(),
  41. 'availableQuantity' => $data->getAvailableQuantityInherited(),
  42. 'taxRate' => $data->getTaxRateInherited(),
  43. );
  44. }
  45. return new Response(json_encode($data));
  46. }
  47. }