src/OfficeBrain/Bundle/WishListBundle/Controller/WishListController.php line 152

Open in your IDE?
  1. <?php
  2. namespace App\OfficeBrain\Bundle\WishListBundle\Controller;
  3. // use Symfony\Bundle\FrameworkBundle\Controller\Controller;
  4. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  5. use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
  6. use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
  7. use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;
  8. use Symfony\Component\HttpFoundation\Session\Session;
  9. use Symfony\Component\HttpFoundation\Session\Flash\FlashBag;
  10. use Symfony\Component\HttpFoundation\JsonResponse;
  11. use Symfony\Component\Translation\Translator;
  12. use Symfony\Component\HttpFoundation\Request;
  13. use Symfony\Component\DependencyInjection\ContainerInterface;
  14. use App\OfficeBrain\Bundle\WishListBundle\Manager\Service\WishListService;
  15. use App\OfficeBrain\Bundle\CoreBundle\Service\OBCommon;
  16. use Symfony\Component\HttpFoundation\RequestStack;
  17. use Symfony\Component\Routing\RouterInterface;
  18. use Symfony\Component\Validator\Validator\ValidatorInterface;
  19. use App\OfficeBrain\Bundle\CoreBundle\Service\SessionManager;
  20. /**
  21.  *
  22.  * @author OfficeBrain 4074 <info@officebrain.com>
  23.  *
  24.  * Desciption: This controller help user to manage his/her wish list
  25.  * 
  26.  * @package: OfficeBrain eCommerce Product Web Client
  27.  * 
  28.  * @subpackage: Wish List
  29.  *
  30.  * @version 1.0
  31.  * 
  32.  */
  33. class WishListController extends AbstractController
  34. {
  35.     /**
  36.      *
  37.      * @author Employee Id: 4074
  38.      *
  39.      * Desciption: Define member variables with thier default value
  40.      *
  41.      * @param NULL
  42.      * 
  43.      * @return NULL
  44.      * 
  45.      * @throws NULL
  46.      * 
  47.      */
  48.     public function __construct(ContainerInterface $containerRequestStack $requestStackRouterInterface $routerValidatorInterface $validatorInterfaceWishListService $wishListServiceSessionManager $session)
  49.     {
  50.         $commonLibraryManager = new OBCommon($router$validatorInterface$requestStack);
  51.         $this->request null;
  52.         $this->userId null;
  53.         $this->productId null;
  54.         $this->refererUrl null;
  55.         $this->wishListManager $wishListService->getWishlistManagerExtended();
  56.         $this->responseArray = array();
  57.         $this->projectSetting null;
  58.         $this->cultureProductId null;
  59.         $this->commonLibraryManager $commonLibraryManager;
  60.         $this->inlineViewProductMaxLimit null;
  61.         $this->sessionManager $session;
  62.         $this->serviceContainer $container;
  63.     }
  64.     
  65.     /**
  66.      *
  67.      * @author Employee Id: 4074
  68.      *
  69.      * Desciption: Unset member variables
  70.      *
  71.      * @param NULL
  72.      * 
  73.      * @return NULL
  74.      * 
  75.      * @throws NULL
  76.      * 
  77.      */
  78.     public function __destruct()
  79.     {
  80.         unset($this->userId);
  81.         unset($this->request);
  82.         unset($this->productId);
  83.         unset($this->refererUrl);
  84.         unset($this->responseArray);
  85.         unset($this->projectSetting);
  86.         unset($this->wishListManager);
  87.         unset($this->cultureProductId);
  88.         unset($this->commonLibraryManager);
  89.         unset($this->inlineViewProductMaxLimit);
  90.         unset($this->sessionManager);
  91.     }
  92.     
  93.     /**
  94.      *
  95.      * @author Employee Id: 4074
  96.      *
  97.      * Desciption: Create and initialize various required object and member variables
  98.      *
  99.      * @param NULL
  100.      *
  101.      * @return NULL
  102.      *
  103.      * @throws NULL
  104.      *
  105.      */
  106.     public function initAction(Request $request)
  107.     {
  108.         $this->request $request;
  109.         $this->page $this->request->get('page'1);
  110.         $this->productId $this->request->get('productId'null);
  111.         $this->cultureProductId $this->request->get('cultureProductId'null);
  112.         
  113.         $this->projectSetting $this->request->get('project_setting');
  114.         $this->userId $this->projectSetting['user_id'];
  115.         $this->inlineViewProductMaxLimit $this->projectSetting['configuration_rule']['transaction']['wish_list']['inline_view']['option']['no_of_product'];
  116.         $this->responseArray['product_id'] = $this->productId;
  117.         $this->responseArray['status'] = 'error';
  118.         // $this->wishListManager = $this->serviceContainer->get('office_brain_wish_list_manager'); // symfony 4
  119.         $this->wishListManager $this->wishListManager;
  120.         // $this->wishListManager = $this->container->get('office_brain_wish_list_guest_extended');
  121.         // $this->commonLibraryManager = $this->serviceContainer->get('office_brain_common_library');
  122.         $this->commonLibraryManager $this->commonLibraryManager;
  123.         // $this->sessionManager = $this->serviceContainer->get('office_brain_session_manager');
  124.         $this->sessionManager $this->sessionManager;
  125.     }
  126.     /**
  127.      *
  128.      * @author Employee Id: 4014
  129.      *
  130.      * Desciption: This function allow user to see his/her wish list page wise 
  131.      *
  132.      * @param integer page
  133.      *
  134.      * @return Html Response 
  135.      *
  136.      * @throws NULL
  137.      *
  138.      * @Route("/{_locale}/wish-list",
  139.      *     name="office_brain_wishlistbundle_wishlist_wishlist"
  140.      * )
  141.      * 
  142.      * @Method({"GET", "POST"})
  143.      * 
  144.      * @Template("OfficeBrain/Bundle/WishListBundle/WishList/wishList.html.twig")
  145.      * 
  146.      */
  147.     public function wishListAction(Request $request)
  148.     {
  149.         $this->initAction($request);
  150.         $this->responseArray['record_set'] = $this->wishListManager->getWishListPage($this->page);
  151.         $this->responseArray['total_record'] = $this->wishListManager->getTotalCount();
  152.         if ($this->request->isXmlHttpRequest() && !count($this->responseArray['record_set']->getItems())) {
  153.             return new JsonResponse(array('status'=>'error''error_code'=>'END_OF_PAGINATION'));
  154.         }
  155.         return $this->responseArray;
  156.     }
  157.     
  158.     /**
  159.      *
  160.      * @author Employee Id: 4014
  161.      *
  162.      * Desciption: This function allow user to add desire prooduct to his/her wish list. 
  163.      *
  164.      *  @param integer productId
  165.      *  @param integer cultureProductId
  166.      *
  167.      * @return Html Response 
  168.      *
  169.      * @throws NULL
  170.      *
  171.      * @Route("/{_locale}/add-to-wishlist-product",
  172.      * name="office_brain_wishlistbundle_wishlist_addproducttowishlist",
  173.      *  options={"expose"=true}
  174.      * )
  175.      *
  176.      * @Method({"POST"})
  177.      * 
  178.      * @Template()
  179.      * 
  180.      */
  181.     public function addProductToWishlistAction(Request $request)
  182.     {
  183.         $this->initAction($request);
  184.         
  185.         if ($this->productId && $this->cultureProductId) {
  186.             $status $this->wishListManager->setWishList($this->productId$this->cultureProductId);
  187.             switch ($status) {
  188.                 case 'ERROR_PRODUCT_ALREADY_EXISTS':
  189.                     $this->responseArray['error_message'] = $this->serviceContainer->get('translator')->trans('wishlist_product.product_already_exists');
  190.                     break;
  191.                 case 'SUCCESS':
  192.                     $this->responseArray['status'] = 'success';
  193.                     $this->responseArray['success_message'] = $this->serviceContainer->get('translator')->trans('wishlist_product.add_success_message');
  194.                     
  195.                     $this->refererUrl $this->commonLibraryManager->getRefererRouteName();
  196.                     break;
  197.             }
  198.         }
  199.         if ($this->refererUrl=='office_brain_wishlistbundle_wishlist_wishlist') {
  200.             $this->responseArray['page_url'] = $this->generateUrl('office_brain_wishlistbundle_wishlist_wishlist');
  201.         } else {
  202.             $this->responseArray['total_record'] = $this->wishListManager->getTotalCount();
  203.         }
  204.         
  205.         return new JsonResponse($this->responseArray);
  206.     }
  207.   
  208.     /* public function addToWishListAction(Request $request)
  209.     {
  210.         $this->initAction($request);
  211.         // To check wishlist enable or not
  212.         $this->checkEnableWishList();
  213.         $productId = $this->request->get('productId', null);
  214.         $cultureProductId = $this->request->get('cultureProductId', null);
  215.         if($productId &&  $cultureProductId){
  216.             $wishListCount = $this->entityManager->getRepository('OfficeBrainWishListBundle:WishList')->addToWishList($productId, $cultureProductId, $this->userId, $this->cultureId);
  217.             if($wishListCount===false) {
  218.                 return new JsonResponse ( array( 'product_id'=>$productId, 'status'=>'error', 'error_message'=>$this->get('translator')->trans('wish_list.product_already_exists')) );
  219.             }
  220.             else {
  221.                 return new JsonResponse ( array( 'product_id'=>$productId, 'status'=>'success', 'success_message'=>$this->get('translator')->trans('wish_list.add_success_message'), 'total'=>$wishListCount ) );
  222.             }
  223.         }
  224.         return new JsonResponse();
  225.     } */
  226.     
  227.     /**
  228.      *
  229.      * @author Employee Id: 4014
  230.      *
  231.      * Desciption: This function allow user to view recently added prooduct to his/her wish list. 
  232.      *
  233.      * @param integer productId
  234.      * @param integer cultureProductId
  235.      *
  236.      * @return Html Response 
  237.      *
  238.      * @throws NULL
  239.      *
  240.      * @Route("/{_locale}/recent-wish-list",
  241.      *     name="office_brain_wishlistbundle_wishlist_recentwishlist",
  242.      *  options={"expose"=true}
  243.      * )
  244.      *
  245.      * @Method({"GET"})
  246.      * 
  247.      * @Template("OfficeBrain/Bundle/WishListBundle/WishList/recentWishList.html.twig")
  248.      * 
  249.      */
  250.     public function recentWishListAction(Request $request)
  251.     {
  252.         $this->initAction($request);
  253.         $this->responseArray['record_set'] = $this->wishListManager->getMaxNoOfWishList($this->inlineViewProductMaxLimit);
  254.         $this->responseArray['total_record'] = $this->wishListManager->getTotalCount();
  255.         return $this->responseArray;
  256.     }
  257.     
  258.     /**
  259.      *
  260.      * @author Employee Id: 4471
  261.      *
  262.      * Desciption: This function allow user to delete prooduct from his/her wish list. 
  263.      *
  264.      * @param integer productId
  265.      * @param integer cultureProductId
  266.      *
  267.      * @return Json Response 
  268.      *
  269.      * @throws NULL
  270.      *
  271.      * @Route("/{_locale}/wish-list-delete",
  272.      *     name="office_brain_wishlistbundle_wishlist_deletewishlist",
  273.      *  options={"expose"=true}
  274.      * )
  275.      *
  276.      * @Method({"POST"})
  277.      * 
  278.      * @Template()
  279.      * 
  280.      */
  281.     public function deleteWishListAction(Request $request)
  282.     {
  283.         $this->initAction($request);
  284.         if ($this->productId && $this->cultureProductId) {
  285.             $status $this->wishListManager->deleteWishList($this->productId$this->cultureProductId);
  286.             switch ($status) {
  287.                 case 'ERROR_NOT_FOUND':
  288.                     $this->responseArray['error_message'] = $this->serviceContainer->get('translator')->trans('wish_list.product_not_found');
  289.                     break;
  290.                 case 'SUCCESS':
  291.                     $this->responseArray['status'] = 'success';
  292.                     $this->responseArray['success_message'] = $this->serviceContainer->get('translator')->trans('wish_list.remove_success_message');
  293.     
  294.                     $this->refererUrl $this->commonLibraryManager->getRefererRouteName();
  295.                     break;
  296.             }
  297.         }
  298.     
  299.         if ($this->refererUrl=='office_brain_wishlistbundle_wishlist_wishlist') {
  300.             $this->sessionManager->set('wishlist_success_deleted',$this->serviceContainer->get('translator')->trans('wish_list.remove_success_message'));
  301.             $this->responseArray['page_url'] = $this->generateUrl('office_brain_wishlistbundle_wishlist_wishlist');
  302.         } else {
  303.             $this->responseArray['total_record'] = $this->wishListManager->getTotalCount();
  304.         }
  305.     
  306.         return new JsonResponse($this->responseArray);
  307.     }
  308.     
  309.     /**
  310.      *
  311.      * @author Employee Id: 4471
  312.      *
  313.      * Desciption: This function allow user to delete all prooduct from his/her wish list. 
  314.      *
  315.      * @param integer productId
  316.      * @param integer cultureProductId
  317.      *
  318.      * @return Html Response 
  319.      *
  320.      * @throws NULL
  321.      *
  322.      * @Route("/{_locale}/wish-list-delete-all",
  323.      *     name="office_brain_wishlistbundle_wishlist_deleteallwishlist"
  324.      * )
  325.      *
  326.      * @Method({"POST"})
  327.      * 
  328.      * @Template()
  329.      * 
  330.      */
  331.     public function deleteAllWishListAction(Request $request)
  332.     { 
  333.         $this->initAction($request);
  334.         $status $this->wishListManager->deleteAllWishList();
  335.         switch ($status
  336.         {
  337.             case 'ERROR_NOT_FOUND':
  338.                 $this->responseArray['error_message'] = $this->serviceContainer->get('translator')->trans('wish_list.product_not_found');
  339.                 break;
  340.             case 'SUCCESS':
  341.                 $this->responseArray['status'] = 'success';
  342.                 $this->responseArray['success_message'] = $this->serviceContainer->get('translator')->trans('wish_list.remove_success_message');
  343.                 $this->refererUrl $this->commonLibraryManager->getRefererRouteName();
  344.                 break;
  345.         }
  346.         if ($this->refererUrl=='office_brain_wishlistbundle_wishlist_wishlist') {
  347.             $this->sessionManager->set('wishlist_success_deleted',$this->serviceContainer->get('translator')->trans('wish_list.remove_success_message'));
  348.             $this->responseArray['total_record'] = $this->wishListManager->getTotalCount();
  349.             $this->responseArray['page_url'] = $this->generateUrl('office_brain_wishlistbundle_wishlist_wishlist');
  350.         } else {
  351.             $this->responseArray['total_record'] = $this->wishListManager->getTotalCount();
  352.         }
  353.     
  354.         return new JsonResponse($this->responseArray);
  355.                 
  356.     }
  357. }