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.

CartController.php 3.0KB

4 vuotta sitten
4 vuotta sitten
4 vuotta sitten
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. <?php
  2. namespace Lc\ShopBundle\Controller\Frontend ;
  3. use App\Form\Frontend\OrderProductsType;
  4. use App\Services\OrderUtils;
  5. use Doctrine\ORM\EntityManagerInterface;
  6. use Lc\ShopBundle\Context\MerchantUtilsInterface;
  7. use Lc\ShopBundle\Context\OrderProductInterface;
  8. use Lc\ShopBundle\Context\OrderUtilsInterface;
  9. use Lc\ShopBundle\Context\ProductFamilyInterface;
  10. use Symfony\Component\HttpFoundation\JsonResponse;
  11. use Symfony\Component\HttpFoundation\Request;
  12. use Symfony\Component\Security\Core\Security;
  13. class CartController extends BaseController
  14. {
  15. protected $orderUtils ;
  16. protected $productFamilyRepository ;
  17. protected $productFamily ;
  18. protected $orderProducts = [] ;
  19. public function __construct(EntityManagerInterface $em, Security $security, MerchantUtilsInterface $merchantUtils, OrderUtilsInterface $orderUtils)
  20. {
  21. parent::__construct($em, $security, $merchantUtils);
  22. $this->orderUtils = $orderUtils ;
  23. $this->productFamilyRepository = $this->em->getRepository($this->em->getClassMetaData(ProductFamilyInterface::class)->getName()) ;
  24. }
  25. public function addProductFamily(Request $request)
  26. {
  27. $return = [] ;
  28. $data = $request->request->all() ;
  29. if(isset($data['order_products']['id_product_family'])) {
  30. $idProductFamily = $data['order_products']['id_product_family'] ;
  31. $this->productFamily = $this->productFamilyRepository->find($idProductFamily) ;
  32. if($this->productFamily) {
  33. $form = $this->createForm(OrderProductsType::class, ['id_product_family' => $this->productFamily->getId()]);
  34. $form->handleRequest($request);
  35. if ($form->isSubmitted() && $form->isValid()) {
  36. $orderShop = $this->orderUtils->getOrderShopCurrent() ;
  37. $data = $form->getData() ;
  38. foreach($data as $orderProduct) {
  39. if($orderProduct instanceof OrderProductInterface) {
  40. $this->orderUtils->addOrderProduct($orderShop, $orderProduct) ;
  41. if($orderProduct->getQuantity() > 0) {
  42. $this->orderProducts[] = $orderProduct ;
  43. }
  44. }
  45. }
  46. }
  47. }
  48. }
  49. return new JsonResponse($return) ;
  50. }
  51. public function addProduct()
  52. {
  53. }
  54. public function editProduct()
  55. {
  56. }
  57. public function deleteProduct()
  58. {
  59. }
  60. public function summary()
  61. {
  62. }
  63. }