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