您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

80 行
2.9KB

  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. class CartController extends BaseController
  13. {
  14. protected $orderUtils ;
  15. protected $productFamilyRepository ;
  16. protected $productFamily ;
  17. protected $orderProducts = [] ;
  18. public function __construct(EntityManagerInterface $em, MerchantUtilsInterface $merchantUtils, OrderUtilsInterface $orderUtils)
  19. {
  20. parent::__construct($em, $merchantUtils);
  21. $this->orderUtils = $orderUtils ;
  22. $this->productFamilyRepository = $this->em->getRepository($this->em->getClassMetaData(ProductFamilyInterface::class)->getName()) ;
  23. }
  24. public function addProductFamily(Request $request)
  25. {
  26. $return = [] ;
  27. $data = $request->request->all() ;
  28. if(isset($data['order_products']['id_product_family'])) {
  29. $idProductFamily = $data['order_products']['id_product_family'] ;
  30. $this->productFamily = $this->productFamilyRepository->find($idProductFamily) ;
  31. if($this->productFamily) {
  32. $form = $this->createForm(OrderProductsType::class, ['id_product_family' => $this->productFamily->getId()]);
  33. $form->handleRequest($request);
  34. if ($form->isSubmitted() && $form->isValid()) {
  35. $orderShop = $this->orderUtils->getOrderShopCurrent() ;
  36. $data = $form->getData() ;
  37. foreach($data as $orderProduct) {
  38. if($orderProduct instanceof OrderProductInterface) {
  39. $this->orderUtils->addOrderProduct($orderShop, $orderProduct) ;
  40. if($orderProduct->getQuantity() > 0) {
  41. $this->orderProducts[] = $orderProduct ;
  42. }
  43. }
  44. }
  45. }
  46. }
  47. }
  48. return new JsonResponse($return) ;
  49. }
  50. public function addProduct()
  51. {
  52. }
  53. public function editProduct()
  54. {
  55. }
  56. public function deleteProduct()
  57. {
  58. }
  59. public function summary()
  60. {
  61. }
  62. }