<?php
namespace App\OfficeBrain\Bundle\WishListBundle\Controller;
// use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;
use Symfony\Component\HttpFoundation\Session\Session;
use Symfony\Component\HttpFoundation\Session\Flash\FlashBag;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\Translation\Translator;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\DependencyInjection\ContainerInterface;
use App\OfficeBrain\Bundle\WishListBundle\Manager\Service\WishListService;
use App\OfficeBrain\Bundle\CoreBundle\Service\OBCommon;
use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\Component\Routing\RouterInterface;
use Symfony\Component\Validator\Validator\ValidatorInterface;
use App\OfficeBrain\Bundle\CoreBundle\Service\SessionManager;
/**
*
* @author OfficeBrain 4074 <info@officebrain.com>
*
* Desciption: This controller help user to manage his/her wish list
*
* @package: OfficeBrain eCommerce Product Web Client
*
* @subpackage: Wish List
*
* @version 1.0
*
*/
class WishListController extends AbstractController
{
/**
*
* @author Employee Id: 4074
*
* Desciption: Define member variables with thier default value
*
* @param NULL
*
* @return NULL
*
* @throws NULL
*
*/
public function __construct(ContainerInterface $container, RequestStack $requestStack, RouterInterface $router, ValidatorInterface $validatorInterface, WishListService $wishListService, SessionManager $session)
{
$commonLibraryManager = new OBCommon($router, $validatorInterface, $requestStack);
$this->request = null;
$this->userId = null;
$this->productId = null;
$this->refererUrl = null;
$this->wishListManager = $wishListService->getWishlistManagerExtended();
$this->responseArray = array();
$this->projectSetting = null;
$this->cultureProductId = null;
$this->commonLibraryManager = $commonLibraryManager;
$this->inlineViewProductMaxLimit = null;
$this->sessionManager = $session;
$this->serviceContainer = $container;
}
/**
*
* @author Employee Id: 4074
*
* Desciption: Unset member variables
*
* @param NULL
*
* @return NULL
*
* @throws NULL
*
*/
public function __destruct()
{
unset($this->userId);
unset($this->request);
unset($this->productId);
unset($this->refererUrl);
unset($this->responseArray);
unset($this->projectSetting);
unset($this->wishListManager);
unset($this->cultureProductId);
unset($this->commonLibraryManager);
unset($this->inlineViewProductMaxLimit);
unset($this->sessionManager);
}
/**
*
* @author Employee Id: 4074
*
* Desciption: Create and initialize various required object and member variables
*
* @param NULL
*
* @return NULL
*
* @throws NULL
*
*/
public function initAction(Request $request)
{
$this->request = $request;
$this->page = $this->request->get('page', 1);
$this->productId = $this->request->get('productId', null);
$this->cultureProductId = $this->request->get('cultureProductId', null);
$this->projectSetting = $this->request->get('project_setting');
$this->userId = $this->projectSetting['user_id'];
$this->inlineViewProductMaxLimit = $this->projectSetting['configuration_rule']['transaction']['wish_list']['inline_view']['option']['no_of_product'];
$this->responseArray['product_id'] = $this->productId;
$this->responseArray['status'] = 'error';
// $this->wishListManager = $this->serviceContainer->get('office_brain_wish_list_manager'); // symfony 4
$this->wishListManager = $this->wishListManager;
// $this->wishListManager = $this->container->get('office_brain_wish_list_guest_extended');
// $this->commonLibraryManager = $this->serviceContainer->get('office_brain_common_library');
$this->commonLibraryManager = $this->commonLibraryManager;
// $this->sessionManager = $this->serviceContainer->get('office_brain_session_manager');
$this->sessionManager = $this->sessionManager;
}
/**
*
* @author Employee Id: 4014
*
* Desciption: This function allow user to see his/her wish list page wise
*
* @param integer page
*
* @return Html Response
*
* @throws NULL
*
* @Route("/{_locale}/wish-list",
* name="office_brain_wishlistbundle_wishlist_wishlist"
* )
*
* @Method({"GET", "POST"})
*
* @Template("OfficeBrain/Bundle/WishListBundle/WishList/wishList.html.twig")
*
*/
public function wishListAction(Request $request)
{
$this->initAction($request);
$this->responseArray['record_set'] = $this->wishListManager->getWishListPage($this->page);
$this->responseArray['total_record'] = $this->wishListManager->getTotalCount();
if ($this->request->isXmlHttpRequest() && !count($this->responseArray['record_set']->getItems())) {
return new JsonResponse(array('status'=>'error', 'error_code'=>'END_OF_PAGINATION'));
}
return $this->responseArray;
}
/**
*
* @author Employee Id: 4014
*
* Desciption: This function allow user to add desire prooduct to his/her wish list.
*
* @param integer productId
* @param integer cultureProductId
*
* @return Html Response
*
* @throws NULL
*
* @Route("/{_locale}/add-to-wishlist-product",
* name="office_brain_wishlistbundle_wishlist_addproducttowishlist",
* options={"expose"=true}
* )
*
* @Method({"POST"})
*
* @Template()
*
*/
public function addProductToWishlistAction(Request $request)
{
$this->initAction($request);
if ($this->productId && $this->cultureProductId) {
$status = $this->wishListManager->setWishList($this->productId, $this->cultureProductId);
switch ($status) {
case 'ERROR_PRODUCT_ALREADY_EXISTS':
$this->responseArray['error_message'] = $this->serviceContainer->get('translator')->trans('wishlist_product.product_already_exists');
break;
case 'SUCCESS':
$this->responseArray['status'] = 'success';
$this->responseArray['success_message'] = $this->serviceContainer->get('translator')->trans('wishlist_product.add_success_message');
$this->refererUrl = $this->commonLibraryManager->getRefererRouteName();
break;
}
}
if ($this->refererUrl=='office_brain_wishlistbundle_wishlist_wishlist') {
$this->responseArray['page_url'] = $this->generateUrl('office_brain_wishlistbundle_wishlist_wishlist');
} else {
$this->responseArray['total_record'] = $this->wishListManager->getTotalCount();
}
return new JsonResponse($this->responseArray);
}
/* public function addToWishListAction(Request $request)
{
$this->initAction($request);
// To check wishlist enable or not
$this->checkEnableWishList();
$productId = $this->request->get('productId', null);
$cultureProductId = $this->request->get('cultureProductId', null);
if($productId && $cultureProductId){
$wishListCount = $this->entityManager->getRepository('OfficeBrainWishListBundle:WishList')->addToWishList($productId, $cultureProductId, $this->userId, $this->cultureId);
if($wishListCount===false) {
return new JsonResponse ( array( 'product_id'=>$productId, 'status'=>'error', 'error_message'=>$this->get('translator')->trans('wish_list.product_already_exists')) );
}
else {
return new JsonResponse ( array( 'product_id'=>$productId, 'status'=>'success', 'success_message'=>$this->get('translator')->trans('wish_list.add_success_message'), 'total'=>$wishListCount ) );
}
}
return new JsonResponse();
} */
/**
*
* @author Employee Id: 4014
*
* Desciption: This function allow user to view recently added prooduct to his/her wish list.
*
* @param integer productId
* @param integer cultureProductId
*
* @return Html Response
*
* @throws NULL
*
* @Route("/{_locale}/recent-wish-list",
* name="office_brain_wishlistbundle_wishlist_recentwishlist",
* options={"expose"=true}
* )
*
* @Method({"GET"})
*
* @Template("OfficeBrain/Bundle/WishListBundle/WishList/recentWishList.html.twig")
*
*/
public function recentWishListAction(Request $request)
{
$this->initAction($request);
$this->responseArray['record_set'] = $this->wishListManager->getMaxNoOfWishList($this->inlineViewProductMaxLimit);
$this->responseArray['total_record'] = $this->wishListManager->getTotalCount();
return $this->responseArray;
}
/**
*
* @author Employee Id: 4471
*
* Desciption: This function allow user to delete prooduct from his/her wish list.
*
* @param integer productId
* @param integer cultureProductId
*
* @return Json Response
*
* @throws NULL
*
* @Route("/{_locale}/wish-list-delete",
* name="office_brain_wishlistbundle_wishlist_deletewishlist",
* options={"expose"=true}
* )
*
* @Method({"POST"})
*
* @Template()
*
*/
public function deleteWishListAction(Request $request)
{
$this->initAction($request);
if ($this->productId && $this->cultureProductId) {
$status = $this->wishListManager->deleteWishList($this->productId, $this->cultureProductId);
switch ($status) {
case 'ERROR_NOT_FOUND':
$this->responseArray['error_message'] = $this->serviceContainer->get('translator')->trans('wish_list.product_not_found');
break;
case 'SUCCESS':
$this->responseArray['status'] = 'success';
$this->responseArray['success_message'] = $this->serviceContainer->get('translator')->trans('wish_list.remove_success_message');
$this->refererUrl = $this->commonLibraryManager->getRefererRouteName();
break;
}
}
if ($this->refererUrl=='office_brain_wishlistbundle_wishlist_wishlist') {
$this->sessionManager->set('wishlist_success_deleted',$this->serviceContainer->get('translator')->trans('wish_list.remove_success_message'));
$this->responseArray['page_url'] = $this->generateUrl('office_brain_wishlistbundle_wishlist_wishlist');
} else {
$this->responseArray['total_record'] = $this->wishListManager->getTotalCount();
}
return new JsonResponse($this->responseArray);
}
/**
*
* @author Employee Id: 4471
*
* Desciption: This function allow user to delete all prooduct from his/her wish list.
*
* @param integer productId
* @param integer cultureProductId
*
* @return Html Response
*
* @throws NULL
*
* @Route("/{_locale}/wish-list-delete-all",
* name="office_brain_wishlistbundle_wishlist_deleteallwishlist"
* )
*
* @Method({"POST"})
*
* @Template()
*
*/
public function deleteAllWishListAction(Request $request)
{
$this->initAction($request);
$status = $this->wishListManager->deleteAllWishList();
switch ($status)
{
case 'ERROR_NOT_FOUND':
$this->responseArray['error_message'] = $this->serviceContainer->get('translator')->trans('wish_list.product_not_found');
break;
case 'SUCCESS':
$this->responseArray['status'] = 'success';
$this->responseArray['success_message'] = $this->serviceContainer->get('translator')->trans('wish_list.remove_success_message');
$this->refererUrl = $this->commonLibraryManager->getRefererRouteName();
break;
}
if ($this->refererUrl=='office_brain_wishlistbundle_wishlist_wishlist') {
$this->sessionManager->set('wishlist_success_deleted',$this->serviceContainer->get('translator')->trans('wish_list.remove_success_message'));
$this->responseArray['total_record'] = $this->wishListManager->getTotalCount();
$this->responseArray['page_url'] = $this->generateUrl('office_brain_wishlistbundle_wishlist_wishlist');
} else {
$this->responseArray['total_record'] = $this->wishListManager->getTotalCount();
}
return new JsonResponse($this->responseArray);
}
}