src/Controller/EshopController.php line 1556

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use Doctrine\Persistence\ManagerRegistry;
  4. use Symfony\Component\HttpKernel\KernelInterface;
  5. use Symfony\Component\Routing\Annotation\Route;
  6. use Symfony\Bundle\FrameworkBundle\Controller\Controller;
  7. use Symfony\Component\HttpFoundation\Request;
  8. use Symfony\Component\HttpFoundation\Response
  9. use Symfony\Component\HttpFoundation\JsonResponse
  10. use Symfony\Component\Form\Extension\Core\Type\TextType
  11. use Symfony\Component\Form\Extension\Core\Type\PasswordType;
  12. use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
  13. use Symfony\Component\Form\Extension\Core\Type\TextareaType;
  14. use Symfony\Component\Form\Extension\Core\Type\EmailType;
  15. use Symfony\Component\Form\Extension\Core\Type\FileType;
  16. use Symfony\Component\Form\Extension\Core\Type\SubmitType;
  17. use Symfony\Component\Form\Extension\Core\Type\HiddenType;
  18. use Symfony\Component\Console\Input\ArrayInput;
  19. use Symfony\Bundle\FrameworkBundle\Console\Application;
  20. use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
  21. use Symfony\Component\Validator\Constraints\DateTime;
  22. use Symfony\Component\Serializer\Normalizer\DateTimeNormalizer;
  23. use Symfony\Component\Serializer\Serializer;
  24. use Symfony\Component\Mailer\MailerInterface;
  25. use Symfony\Component\Mime\Email;
  26. use App\Entity\Address;
  27. use App\Entity\Category;
  28. use App\Entity\Consent;
  29. use App\Entity\Currency;
  30. use App\Entity\CssDesign;
  31. use App\Entity\Delivery;
  32. use App\Entity\Eshop3D;
  33. use App\Entity\Gallery;
  34. use App\Entity\GalleryItem;
  35. use App\Entity\Gallery3D;
  36. use App\Entity\Language;
  37. use App\Entity\Module;
  38. use App\Entity\Payment;
  39. use App\Entity\Paypal;
  40. use App\Entity\Product;
  41. use App\Entity\ProductParameter;
  42. use App\Entity\ProductParameterGroup;
  43. use App\Entity\ProductParameterValue;
  44. use App\Entity\Price;
  45. use App\Entity\PriceLevel;
  46. use App\Entity\Eshop;
  47. use App\Entity\EshopDelivery;
  48. use App\Entity\EshopPayment;
  49. use App\Entity\Order;
  50. use App\Entity\OrderItem;
  51. use App\Entity\Contact;
  52. use App\Entity\Service;
  53. use App\Entity\ServiceExample;
  54. use App\Entity\ReCaptcha;
  55. use App\Entity\User;
  56. use App\Entity\WebPage;
  57. use App\Entity\WireFrame;
  58. use FOS\RestBundle\Controller\Annotations as Rest;
  59. use Psr\Log\LoggerInterface;
  60. use Symfony\Contracts\Translation\TranslatorInterface;
  61. use Twig\Environment;
  62. class EshopController extends DefaultController
  63. {
  64.     protected $dynamicEntityManager;
  65.     protected $currentEshop;
  66.     protected ManagerRegistry $doctrine;
  67.     protected TranslatorInterface $translator;
  68.     protected $appKernel;
  69.     protected MailerInterface $mailer;
  70.     protected Environment $twig;
  71.     public function __construct(ManagerRegistry $doctrine,
  72.                                 TranslatorInterface $translator,
  73.                                 KernelInterface $appKernel,
  74.                                 MailerInterface $mailer,
  75.                                 Environment $twig)
  76.     {
  77.         $this->doctrine $doctrine;
  78.         $this->translator $translator;
  79.         $this->appKernel $appKernel;
  80.         $this->mailer $mailer;
  81.         $this->twig $twig;
  82.     }
  83.     
  84.     /** 
  85.      * @Route("/eshop", name="eshopHome")
  86.      */
  87.     public function indexAction(Request $request)
  88.     {
  89.         /* we load session data */
  90.         parent::init($request);
  91.         $session $request->getSession();
  92.         /* we load entity managers */
  93.         $em $this->doctrine->getManager();
  94.         $dem $this->doctrine->getManager('dynamic_em');
  95.         
  96.         /* we get demo e-shop */
  97.         $eshopId 1;
  98.         $eshop $em->getRepository(Eshop::class)->getEshop($eshopId);
  99.         
  100.         /* we get current 3D eshop */
  101.         $eshop3D $dem->getRepository(Eshop3D::class)->getEshop3DByEshopId($eshopId);
  102.         $user $em->getRepository(User::class)->getUser($eshop->getUserId());
  103.         $userDirs $this->getUserFolderPathsFromUserId($user->getUserId());
  104.         
  105.         /* we load list of modules for connector service */
  106.         $service $em->getRepository(Service::class)->getService(1);
  107.         /* we load examples */
  108.         $exampleCollection $em->getRepository(ServiceExample::class)->getServiceExampleListByService(13);
  109.         shuffle($exampleCollection);   
  110.         
  111.         //isModule Pack Sale
  112.         $module $em->getRepository(Module::class)->getModule(42);
  113.         $isPackSaleModule $em->getRepository(User::class)->userHasModule($user$module);
  114.         //print('<br>qqw eshop: ');
  115.         //\Doctrine\Common\Util\Debug::dump($eshop);    
  116.         
  117.         $logger $this->getLogger(null'e-shop 3D'); 
  118.         
  119.         // we get the gallery
  120.         $gallery3DId 7;
  121.         $gallery3D $em->getRepository(Gallery3D::class)->getGallery3D($gallery3DId);
  122.         
  123.         // we get parent gallery items
  124.         $galleryItemCollection null;
  125.         if(!empty($gallery3D) and !empty($gallery3D->getGallery())) {
  126.             $galId $gallery3D->getGallery()->getGalleryId();
  127.             $galleryItemCollection $em->getRepository(GalleryItem::class)->getGalleryItemList($galId);
  128.         }           
  129.         $rootNodes $dem->getRepository(Category::class)->getRootNodes();
  130.         $childNodes = array();
  131.         $childNodeImages = array();
  132.         $categoryImages = array();
  133.         $products = array();
  134.         $categoryProducts = array();
  135.         $categoryProductImages = array();
  136.         $productListTitles = array();
  137.         $productDescriptions = array();
  138.         $categoryProductPrices = array();
  139.         /* we get parent gallery items */
  140.         $textureItemCollection null;
  141.         if(!empty($eshop3D) && !empty($eshop3D->getTextureGallery())) {
  142.             $textureItemCollection $dem->getRepository(GalleryItem::class)->getGalleryItemList($eshop3D->getTextureGallery()->getGalleryId());
  143.         }         
  144.         foreach($rootNodes as $cat) {
  145.             if($cat->getEshopId() == $eshopId && $cat->getIsActive()) {
  146.                 $catId $cat->getCategoryId();
  147.                 $productList = array();
  148.                 $childNodes[] = $cat;
  149.                 $childNodeImages[$catId] = $this->getImageFromText($cat->getCategoryName(), 'orange-black'$userDirs['images'], $userDirs['web'].'/images'30'category_'.$catId400604048);
  150.                 //getImageFromText($text="", $colorType="default", $imagePath, $imageWebPath, $countCharactersInLine = 30, $imageName="image_name", $imageWidth=400, $imageHeight=60, $fontSize=40, $positionY = 40)
  151.                 if($cat->getImage1() != "") {
  152.                     $categoryImagePath $userDirs['web'].'/images/'.$cat->getImage1();  
  153.                 } else {
  154.                     $categoryImagePath '';
  155.                 }
  156.                 $categoryImages[$catId] = $categoryImagePath;
  157.                 /* we get products in the cateory */
  158.                 $productList $dem->getRepository(Product::class)->getProductListByCategory($catId);
  159.                 /* we generate images for product titles */
  160.                 foreach($productList as $product) {
  161.                     $productId $product->getProductId();
  162.                     $title $this->getImageFromText($product->getProductName(), 'orange-black'$userDirs['images'], $userDirs['web'].'/images'30'product_'.$productId.'_title'500402530);    
  163.                     $description $this->getImageFromText($product->getProductDescription(), 'orange-black'$userDirs['images'], $userDirs['web'].'/images'50'product_'.$productId.'_description'500271240);
  164.                     $productListTitles[$productId] = $title;
  165.                     $productDescriptions[$productId] = $description;
  166.                     $products[$productId] = $product;
  167.                 }   
  168.                 /*
  169.                 print('<br>QQW productList in category: '.$cat->getCategoryName());
  170.                 \Doctrine\Common\Util\Debug::dump($productList);        
  171.                 */
  172.                 /* we display products from subfolders */
  173.                 if(!empty($eshop->isDisplayProductsFromSubfolders()) && $eshop->isDisplayProductsFromSubfolders() == true) {
  174.   
  175.                     $catChildNodes $cat->getChildren();
  176.                     foreach($catChildNodes as $catChild) {
  177.                          $subCatId $catChild->getCategoryId();
  178.                         $nodeProductList $dem->getRepository(Product::class)->getProductListByCategory($catChild->getCategoryId());
  179.                         //$productList = array_merge($productList, $nodeProductList);
  180.                         $categoryProducts[$catChild->getCategoryId()] = $nodeProductList
  181.                         
  182.                         $productIds = [];
  183.                         foreach($nodeProductList as $product) {
  184.                             $productId $product->getProductId();
  185.                             $title $this->getImageFromText($product->getProductName(), 'orange-black'$userDirs['images'], $userDirs['web'].'/images'30'product_'.$productId.'_title'500402530);    
  186.                             $description $this->getImageFromText($product->getProductDescription(), 'orange-black'$userDirs['images'], $userDirs['web'].'/images'50'product_'.$productId.'_description'500271240);
  187.                             $productListTitles[$productId] = $title;
  188.                             $productDescriptions[$productId] = $description;
  189.                             $products[$productId] = $product;
  190.                             $productIds[] = $productId;
  191.                         }
  192.                         
  193.                        /* we load prices */
  194.             $productPriceList $dem->getRepository(Product::class)->getProductPriceList($productIds);
  195.             $defaultCurrency $em->getRepository(Currency::class)->getCurrency($eshop->getPreferredCurrencyId());
  196.             $targetCurrency $session->get('eshopCurrency');
  197.             
  198.             /* we load currency rated prices */
  199.             $productPriceList $dem->getRepository(Product::class)->getCurrencyRatedProductPriceList($productPriceList$defaultCurrency$targetCurrency);
  200.             /* we get price(s) to display */
  201.             $displayPrice null;
  202.             foreach($productPriceList as $price) {
  203.                 if($price->getProductId() == $product->getProductId()) {
  204.                 /* we get default price level */
  205.                 if($price->getPriceLevelId() == 1) {
  206.                     //$displayPrice = round($price->getBruttoValue(),$eshop->getRoundPrice());
  207.                     $displayPrice round($price->getNettoValue(),$eshop->getRoundPrice());
  208.                 }
  209.                 
  210.                 }
  211.             } 
  212.             
  213.             $categoryProductPrices[$subCatId] = $productPriceList;
  214.             
  215.             //$logger->notice('QQW subCatId: '.,;
  216.             //$logger->notice('QQW subCat '.$catChild->getCategoryName().' prices:', ['subCatPrices' => count($productPriceList)]);        
  217.                         
  218.   
  219.                     }
  220.                     
  221.                     
  222.                     
  223.                     /*
  224.                     print('<br>-------------------QQW DisplayProductsFromSubfolders: ');
  225.                     \Doctrine\Common\Util\Debug::dump($productList);
  226.                     */
  227.                 
  228.                 $categoryProducts[$cat->getCategoryId()] = $productList
  229.                 /* we generate images for product titles */
  230.                 $productIds = [];
  231.                 foreach($productList as $product) {
  232.                     $productId $product->getProductId();
  233.                     $productIds[] = $productId;
  234.                     $title $this->getImageFromText($product->getProductName(), 'orange-black'$userDirs['images'], $userDirs['web'].'/images'30'product_'.$productId.'_title'500402530);    
  235.                     $description $this->getImageFromText($product->getProductDescription(), 'orange-black'$userDirs['images'], $userDirs['web'].'/images'50'product_'.$productId.'_description'500271240);
  236.                     
  237.                     $productListTitles[$productId] = $title;
  238.                     $productDescriptions[$productId] = $description;
  239.                     $products[$productId] = $product;
  240.                 }  
  241.                 
  242.                 /* we load prices */
  243.         $productPriceList $dem->getRepository(Product::class)->getProductPriceList($productIds);
  244.         $defaultCurrency $em->getRepository(Currency::class)->getCurrency($eshop->getPreferredCurrencyId());
  245.         $targetCurrency $session->get('eshopCurrency');
  246. //        print('targetCurrency: ');
  247. //        print_r($targetCurrency);
  248. //        die();
  249.         if(empty($targetCurrency)) {
  250.             $targetCurrency $defaultCurrency;
  251.         }
  252.         /* we load currency rated prices */
  253.         $productPriceList $dem->getRepository(Product::class)->getCurrencyRatedProductPriceList($productPriceList$defaultCurrency$targetCurrency);
  254.         /* we get price(s) to display */
  255.         $displayPrice null;
  256.         foreach($productPriceList as $price) {
  257.             if($price->getProductId() == $product->getProductId()) {
  258.                 /* we get default price level */
  259.                 if($price->getPriceLevelId() == 1) {
  260.                     //$displayPrice = round($price->getBruttoValue(),$eshop->getRoundPrice());
  261.                     $displayPrice round($price->getNettoValue(),$eshop->getRoundPrice());
  262.                 }
  263.                 
  264.             }
  265.         } 
  266.         
  267.         $categoryProductPrices[$cat->getCategoryId()] = $productPriceList;
  268.         
  269.         //$logger->notice('QQW Cat '.$cat->getCategoryName().' prices:', ['catPrices' => count($productPriceList)]);      
  270.             }
  271.           
  272.         } 
  273.         
  274.         /*
  275.         print('<hr>QQW categoryProductPrices: ');
  276.         \Doctrine\Common\Util\Debug::dump($categoryProductPrices); 
  277.         
  278.         $logger->notice('QQW Hallo logger e-shop 3D: ');        
  279.         foreach($productListTitles as $tit){ 
  280.           $logger->notice('tit: '.$tit);  
  281.         }
  282.         */
  283.         /*
  284.         print('<hr>QQW productList: ');
  285.         \Doctrine\Common\Util\Debug::dump($categoryProducts);     
  286.         print('<hr>');
  287.         */
  288.         //die();
  289.         if($_SERVER['HTTP_HOST'] != 'localhost') {
  290.             $urlPattern "https://www.virtualrealitycommerce.org/";
  291.         } else {
  292.             $urlPattern "http://localhost/webexciter/public/";
  293.         }
  294.         $debug 1;
  295.         if($request->request->get('header')==='false') {  
  296.             $isHeader false;
  297.         } else {
  298.             $isHeader true;
  299.         }        
  300.         if(!empty($request->request->get('is_footer')) && $request->request->get('footer')=='false') {  
  301.             $isFooter false;
  302.         } else {
  303.             $isFooter true;
  304.         }
  305.         /* we load list of modules for connector service */
  306.         $service $em->getRepository(Service::class)->getService(1);
  307.         /* we load examples */
  308.         $exampleCollection $em->getRepository(ServiceExample::class)->getServiceExampleListByService(13);
  309.         shuffle($exampleCollection);   
  310.         
  311.         /* we render data */
  312.         return $this->render('eshopHome.html.twig',
  313.                     array(
  314.                            'headerData' => $this -> getPageHeader($request),
  315.                            'moduleList' => $service->getModules(),
  316.                            'exampleCollection' => $exampleCollection,
  317.                            'service' => $service,
  318.                             'menu' => $this -> adminMenu($request),
  319.                             'mainMenu' => $this -> adminMainMenu($request),
  320.                             'eshop' => $eshop,
  321.                             'user' => $user,
  322.                             'userDirs' => $userDirs,
  323.                             'childNodes' => $childNodes,
  324.                             'childNodeImages' => $childNodeImages,
  325.                             'categoryImages' => $categoryImages,
  326.                             'productListTitles' => $productListTitles,
  327.                             'productDescriptions' => $productDescriptions,
  328.                             'products' => $products,
  329.                             'categoryProducts' => $categoryProducts,
  330.                             'categoryTreeMenu' => $this->categoryTreeMenu($eshop$request),    
  331.                             'categoryTopMenu' => $this->categoryTopMenu($eshop$request),                
  332.                             'logger' => $logger,
  333.                             'urlPattern' => $urlPattern
  334.                             'textureItemCollection' => $textureItemCollection,
  335.                             'categoryProductPrices' => $categoryProductPrices,
  336.                             'isPackSaleModule' => $isPackSaleModule,
  337.                             'eshop3D' => $eshop3D,
  338.                             'gallery3D' => $gallery3D,
  339.                             'galleryItemCollection' => $galleryItemCollection                                                  
  340.                 )
  341.         );           
  342.     }
  343.     
  344.     /**
  345.      * @Route("/eshop/{eshopId}", name="eshop")
  346.      */
  347.     public function eshopAction(Request $request$eshopId)
  348.     {
  349.     
  350.         /* we load session data */
  351.         parent::init($request);
  352.         $session $request->getSession();
  353.         $logger $this->getLogger(null'e-shop');
  354.         $logger->notice('E-shop id '.$eshopId.' - logger init');
  355.         //print('<br>QQW eshop ID: '.$eshopId); 
  356.         //\Doctrine\Common\Util\Debug::dump($category);
  357.         //print('<br>QQW getLocale: '.$request->getLocale());
  358.         //$product->setLocale($lang->getLangKey());
  359.     
  360.         /* we load entity managers */
  361.         $em $this->doctrine->getManager();
  362.         $dem $this->doctrine->getManager('dynamic_em');
  363.         
  364.         /* we get current e-shop */
  365.         $eshop $em->getRepository(Eshop::class)->getEshop($eshopId);
  366.         $user $em->getRepository(User::class)->getUser($eshop->getUserId());
  367.             
  368.         /* we check if eshop exists */
  369.         if($eshop === null) {
  370.             $this->addFlash('error''E-shop with this ID does not exist.');
  371.             return $this->redirectToRoute('eshopHome');
  372.         }    
  373.         try {
  374.             //print('<br>Twig - adds php functions ...');
  375.             $this->twig->addFunction(new \Twig\TwigFunction('deg2rad''deg2rad'));
  376.             $this->twig->addFunction(new \Twig\TwigFunction('sin''sin'));
  377.             $this->twig->addFunction(new \Twig\TwigFunction('imagecreatefromstring''imagecreatefromstring'));
  378.             $this->twig->addFunction(new \Twig\TwigFunction('file_get_contents''file_get_contents'));
  379.             $this->twig->addFunction(new \Twig\TwigFunction('ImageSX''ImageSX'));
  380.             $this->twig->addFunction(new \Twig\TwigFunction('ImageSY''ImageSY')); 
  381.         } catch(Exception $e) {
  382.             $this->addFlash('error'"Twig functions init error");
  383.         }
  384.       
  385.         /* we load header for the current website */
  386.         //$product->setLocale($lang->getLangKey());
  387.         $eshopHeader $dem->getRepository(Eshop::class)->getEshopHeader($eshopId);
  388.         if(!empty($eshopHeader)) {
  389.           $eshopHeader->setLocale($session->get('lang')->getLangKey());
  390.           $dem->refresh($eshopHeader);            
  391.         }
  392.         /* we load footer for the current website */
  393.         $eshopFooter $dem->getRepository(Eshop::class)->getEshopFooter($eshopId);
  394.         if(!empty($eshopFooter)) {         
  395.           $eshopFooter->setLocale($session->get('lang')->getLangKey());
  396.           $dem->refresh($eshopFooter);  
  397.         }      
  398.       
  399.         /* we load home page for the current website */
  400.         $homePage $dem->getRepository(Eshop::class)->getHomePage($eshopId);
  401.         if(!empty($homePage)) { 
  402.           $homePage->setLocale($session->get('lang')->getLangKey());
  403.           $dem->refresh($homePage);          
  404.         }
  405. //        print('<br>qqw homePage: ');
  406. //        \Doctrine\Common\Util\Debug::dump($homePage);
  407.         $seoData = array();
  408.         $seoData['seoTitle'] = '';
  409.         $seoData['seoDescription'] = '';   
  410.         
  411.         /* we parse the page content for placeholders */
  412.         if(!empty($homePage)) {
  413.            $homePageContent $this->parseContent($request$homePage->getWebPageContent()); 
  414.            $homePage->setWebPageContent($homePageContent);
  415.            $seoData['seoTitle'] = $homePage->getSeoTitle();
  416.            $seoData['seoDescription'] = $homePage->getSeoDescription(); 
  417.         } 
  418.         /* we add product(s) to basket - POST form action */
  419.         if(!empty($request->request->get('basket'))) {
  420.             /* we call method to add to basket */
  421.             $this->addToBasket($request$eshopId$request->request->get('productId'));
  422.         }        
  423.         /* we get wireframe */
  424.         $wireFrame $em->getRepository(WireFrame::class)->getWireFrame($eshop->getWireFrameId());
  425.         $rootNodes $dem->getRepository(Category::class)->getRootNodes();
  426.         $childNodes = array();
  427.         $subCats = array();
  428.         foreach($rootNodes as $cat) {
  429.             if($cat->getEshopId() == $eshopId && $cat->getIsActive()) {
  430.                 $cat->setLocale($session->get('lang')->getLangKey());
  431.                 $dem->refresh($cat);
  432.                 $childNodes[] = $cat;
  433.                 $subNodes $cat->getChildren();
  434.                 $rootCatId $cat->getCategoryId(); 
  435.                 foreach($subNodes as $subNode) {
  436.                     if($subNode->getEshopId() == $eshop->getEshopId() && $subNode->getIsActive()) {
  437.                         $subNode->setLocale($session->get('lang')->getLangKey());
  438.                         $dem->refresh($subNode);
  439.                         //print('<br>qqw subNode: '.$subNode->getCategoryName());
  440.                         //\Doctrine\Common\Util\Debug::dump($subNode);  
  441.                         $subCats[$rootCatId][] = $subNode;
  442.                     }
  443.                 }
  444.             }
  445.         }      
  446.         //we prepare sub categories thumbnails
  447.         $categoryThumbs = array();
  448.         foreach($childNodes as $cat) {
  449.             //print('<hr>QQW cat: '.$cat->getImage1());
  450.             $catId $cat->getCategoryId();
  451.             if(!empty($cat->getImage1()) && $cat->getImage1() != "") {     
  452.                 //$imagePath = 'users/'.$user->getUserName().'/images/'.$product->getImage1();   
  453.                   if (strpos($cat->getImage1(), 'http') === false) {
  454.                     $imagePath 'users/'.$user->getUserName().'/images/'.$cat->getImage1();
  455.                     $imageThumbPath 'users/'.$user->getUserName().'/images/thumb_'.$cat->getImage1();
  456.                   } else {
  457.                     $imagePath $cat->getImage1();
  458.                     $path parse_url($imagePathPHP_URL_PATH);
  459.                     $imageThumbPath 'users/'.$user->getUserName().'/images/thumb_'.basename($path);
  460.                   } 
  461.                 /*
  462.                 print('<br>qqw imagePath: '.$imagePath);
  463.                 print('<br>qqw imageThumbPath: '.$imageThumbPath);   
  464.                 */
  465.                 $imageThumb $this->getEshopImageThumb($eshop$imagePath$imageThumbPathtrue);
  466.                 $categoryThumbs[$catId] = $imageThumb;
  467.               }            
  468.             //\Doctrine\Common\Util\Debug::dump($cat);
  469.         }    
  470.    
  471.         /* we render data */
  472.         return $this->render('eshop.html.twig',
  473.                 array(  'headerData' => $this -> getPageHeader($request),
  474.                         'seoData' => $seoData,
  475.                         'menu' => $this -> adminMenu($request),'mainMenu' => $this -> adminMainMenu($request),'mainMenu' => $this -> adminMainMenu($request),
  476.                         'eshop' => $eshop,
  477.                         'user' => $user,
  478.                         'wireFrame' => $wireFrame,
  479.                         'childNodes' => $childNodes,
  480.                         'categoryTreeMenu' => $this->categoryTreeMenu($eshop$request),    
  481.                         'categoryTopMenu' => $this->categoryTopMenu($eshop$request),   
  482.                         'eshopHeader' => $eshopHeader,
  483.                         'eshopFooter' => $eshopFooter,  
  484.                         'homePage' => $homePage,  
  485.                         'topProducts' => $this->getTopProducts($request$eshop7),
  486.                         //'topProducts' => $topProducts,
  487.                         'routeName' => 'eshop'           
  488.                 )
  489.                 );
  490.          
  491.     }   
  492.   
  493.     /**
  494.      * @Route("/eshop/{eshopId}/category/{categoryId}", name="eshopCategory")
  495.      */
  496.     public function eshopCategoryAction(Request $request$eshopId$categoryId)
  497.     {
  498.     
  499.         /* we load session data */
  500.         parent::init($request); 
  501.         $session $request->getSession();
  502.         //print('<br>QQW eshop ID: '.$eshopId);
  503.         //\Doctrine\Common\Util\Debug::dump($category);   
  504.         /* we load entity managers */
  505.         $em $this->doctrine->getManager();
  506.         $dem $this->doctrine->getManager('dynamic_em');
  507.          
  508.         /* we get current e-shop */
  509.         $eshop $em->getRepository(Eshop::class)->getEshop($eshopId);
  510.         $user $em->getRepository(User::class)->getUser($eshop->getUserId());
  511.         $priceLevelList $dem->getRepository(PriceLevel::class)->getPriceLevelList();
  512.         foreach ($priceLevelList as $priceLevel) {
  513.             //print('<br>qqw priceLevel: ');
  514.             $priceLevel->setLocale($session->get('lang')->getLangKey());
  515.             $dem->refresh($priceLevel);
  516.         } 
  517.         /* we check if eshop exists */
  518.         if($eshop === null) {
  519.             $this->addFlash('error''E-shop with this ID does not exist.');
  520.             return $this->redirectToRoute('eshopHome');
  521.         }       
  522.         
  523.         $category $dem->getRepository(Eshop::class)->getCategory($categoryId);
  524.         $categoryPath $dem->getRepository(Category::class)->getPath($category);
  525.         $childNodes $category->getChildren();
  526.         //print('<br>categoryPath: '); 
  527.         //\Doctrine\Common\Util\Debug::dump($categoryPath);
  528.         foreach($categoryPath as $cat) {
  529.             $cat->setLocale($session->get('lang')->getLangKey());
  530.             $dem->refresh($cat);
  531.         }
  532.         $seoData = array();
  533.         $seoData['seoTitle'] = $category->getCategoryName().' - '.$eshop->getEshopName();
  534.         $seoData['seoDescription'] = $eshop->getEshopName().', '.$category->getCategoryName().(!empty($category->getCategoryDescription())?(' - '.$category->getCategoryDescription()):'');       
  535.         
  536.         //we prepare sub categories thumbnails
  537.         $categoryThumbs = array();
  538.         foreach($childNodes as $cat) {
  539.             //print('<hr>QQW cat: '.$cat->getImage1());
  540.             $catId $cat->getCategoryId();
  541.             $cat->setLocale($session->get('lang')->getLangKey());
  542.             $dem->refresh($cat);
  543.             if(!empty($cat->getImage1()) && $cat->getImage1() != "") {     
  544.                 //$imagePath = 'users/'.$user->getUserName().'/images/'.$product->getImage1();   
  545.                   if (strpos($cat->getImage1(), 'http') === false) {
  546.                     $imagePath 'users/'.$user->getUserName().'/images/'.$cat->getImage1();
  547.                     $imageThumbPath 'users/'.$user->getUserName().'/images/thumb_'.$cat->getImage1();
  548.                   } else {
  549.                     $imagePath $cat->getImage1();
  550.                     $path parse_url($imagePathPHP_URL_PATH);
  551.                     $imageThumbPath 'users/'.$user->getUserName().'/images/thumb_'.basename($path);
  552.                   } 
  553.                 /*
  554.                 print('<br>qqw imagePath: '.$imagePath);
  555.                 print('<br>qqw imageThumbPath: '.$imageThumbPath);   
  556.                 */
  557.                 $imageThumb $this->getEshopImageThumb($eshop$imagePath$imageThumbPathtrue);
  558.                 $categoryThumbs[$catId] = $imageThumb;
  559.               }            
  560.             //\Doctrine\Common\Util\Debug::dump($cat);
  561.         }
  562.         $categoryArray = array();
  563.         $categoryArray[] = $category;
  564.         if(!empty($eshop->isDisplayProductsFromSubfolders()) && $eshop->isDisplayProductsFromSubfolders() == true) {
  565.             if ($eshop->getDisplayProductsFromSubfoldersLevel() > 0) {
  566.                 foreach($childNodes as $cat) {
  567.                     if($cat->getIsActive()) {
  568.                         $categoryArray[] = $cat;
  569.                         if ($eshop->getDisplayProductsFromSubfoldersLevel() > 1) {
  570.                             $childNodesLevel2 $cat->getChildren();
  571.                             foreach($childNodesLevel2 as $catLevel2) {
  572.                                 $categoryArray[] = $catLevel2;
  573.                                 if ($eshop->getDisplayProductsFromSubfoldersLevel() > 2) {
  574.                                     $childNodesLevel3 $catLevel2->getChildren();
  575.                                     foreach($childNodesLevel3 as $catLevel3) {
  576.                                         $categoryArray[] = $catLevel3;
  577.                                     }
  578.                                 }
  579.                             }
  580.                         }
  581.                     }
  582.                 } 
  583.             }
  584.        
  585.         }
  586.         /* we get product list */
  587.         $productPerPage $eshop->getCountPerPage();
  588.         $page $request->query->get('page');
  589.         $firstRecord = ($page $productPerPage) - $productPerPage;
  590.         if($firstRecord 1) {
  591.             $firstRecord 0;
  592.         }
  593.         if(!empty($request->get('sort'))) {
  594.             /* we call method to setup sort in session */
  595.             $session->set('sort'$request->get('sort'));
  596.         } elseif(empty($session->get('sort'))) {
  597.             $session->set('sort''default');
  598.         }
  599.         // filters
  600.         // add brand filter
  601.         $brandFilters null;
  602.         if(!empty($request->get('addBrandFilter'))) {
  603.             
  604.             if(empty($session->get('brandFilters'))) {
  605.                 $brandFilters = [];
  606.                 $brandFilters[] = $request->get('addBrandFilter');
  607.             } else {
  608.                 $brandFilters $session->get('brandFilters');
  609.                 if (!in_array($request->get('addBrandFilter'), $brandFilters)) {
  610.                     $brandFilters[] = $request->get('addBrandFilter');
  611.                 }
  612.             }
  613.             $session->set('brandFilters'$brandFilters);
  614.             // print('<br>QQW adding brand filter: '.$request->get('addBrandFilter'));
  615.             // print('<br>QQW brandFilters: ');
  616.             // \Doctrine\Common\Util\Debug::dump($brandFilters);             
  617.         
  618.         // remove brand filter
  619.         if(!empty($request->get('removeBrandFilter'))) {
  620.             $brandFilters $session->get('brandFilters');
  621.             if (in_array($request->get('removeBrandFilter'), $brandFilters)) {
  622.                 foreach ($brandFilters as $key => $brand) {
  623.                     if ($brand == $request->get('removeBrandFilter')) {
  624.                         unset($brandFilters[$key]);
  625.                         print('<br>QQW brandFilters X: ');
  626.                     }
  627.                 }
  628.             }  
  629.             $session->set('brandFilters'$brandFilters);
  630.             // print('<br>QQW removing brand filter: '.$request->get('removeBrandFilter'));
  631.             // print('<br>QQW brandFilters: ');
  632.             // \Doctrine\Common\Util\Debug::dump($brandFilters); 
  633.         }
  634.         //isModule Pack Sale
  635.         $module $em->getRepository(Module::class)->getModule(42);
  636.         $isPackSaleModule $em->getRepository(User::class)->userHasModule($user$module);
  637.         $productList $dem->getRepository(Product::class)->getProductListByCategory($categoryArray$firstRecord$productPerPagefalse$session->get('sort'), $brandFilters);
  638.         $productCount $dem->getRepository(Product::class)->getProductCountByCategory($categoryArray);
  639.         //print('<br>QQW productCount: '.$productCount);
  640.         $manufacturerList $dem->getRepository(Product::class)->getManufacturerListByCategory($categoryArray);
  641.         // print('<br>QQW productList: ');
  642.         // \Doctrine\Common\Util\Debug::dump($productList);        
  643.         
  644.         /* we display products from subfolders */
  645.         /*
  646.         if(!empty($eshop->getDisplayProductsFromSubfolders()) && $eshop->getDisplayProductsFromSubfolders() == true) {
  647.             foreach($childNodes as $cat) {
  648.                 $nodeProductList = $dem->getRepository(Product::class)->getProductListByCategory($cat->getCategoryId());
  649.                 $productList = array_merge($productList, $nodeProductList);
  650.             }
  651.         }
  652.         */
  653.         /* we load product ids into array */
  654.         /* we setup and validate images */
  655.       $productIds = [];
  656.       $productImages = [];
  657.       $productThumbs = [];
  658.       $productVariants = [];
  659.       $manufacturers = [];
  660.         foreach($productList as $product) {
  661.         $pId $product->getProductId();
  662.             $productIds[] = $pId;
  663.             if($product->getImage1() != "") {     
  664.                 //$imagePath = 'users/'.$user->getUserName().'/images/'.$product->getImage1();   
  665.                   if (strpos($product->getImage1(), 'http') === false) {
  666.                     $imagePath 'users/'.$user->getUserName().'/images/'.$product->getImage1();
  667.                     $imageThumbPath 'users/'.$user->getUserName().'/images/'.$product->getImage1();
  668.                   } else {
  669.                     $imagePath $product->getImage1();
  670.                     $path parse_url($imagePathPHP_URL_PATH);
  671.                     $imageThumbPath 'users/'.$user->getUserName().'/images/'.basename($path);
  672.                   } 
  673.                 /*
  674.                 print('<br>qqw imagePath: '.$imagePath);
  675.                 print('<br>qqw imageThumbPath: '.$imageThumbPath);   
  676.                 */
  677.                 $imageThumb $this->getEshopImageThumb($eshop$imagePath$imageThumbPathfalse$category);
  678.                 $productThumbs[$pId] = $imageThumb;
  679.               }
  680.             //print('<br>qqw productName: '.$product->getProductName());
  681.             
  682.             /* we setup product names - if empty then we load multilingual values */
  683.             $productName '';
  684.             if(!empty($product->getProductName()) && $product->getProductName() != '') {
  685.                 $productName $product->getProductName();
  686.                 //int('<br>qqw pname 0: '.$productName);
  687.             } else {
  688.                 //we try to get the product name from multilangual fields 
  689.                 foreach($eshop->getLanguages() as $lang) {
  690.                     $product->setLocale($lang->getLangKey());
  691.                     $dem->refresh($product);
  692.                     if(!empty($product->getProductName()) && $product->getProductName() != '') {
  693.                         $productName $product->getProductName();
  694.                     }
  695.                 }
  696.             }
  697.             //print('<br>qqw pname 1: '.$productName);
  698.             $product->setProductName($productName);
  699.             $dem->flush();
  700.             
  701.             //print('<br>qqw pname 2: '.$product->getProductName());
  702.             /* we setup product descriptions - if empty then we load multilingual values */
  703.             $productDescription '';
  704.             if(!empty($product->getProductDescription()) && $product->getProductDescription() != '') {
  705.                 $productDescription $product->getProductDescription();
  706.             } else {
  707.                 //we try to get the product description from multilangual fields 
  708.                 foreach($eshop->getLanguages() as $lang) {
  709.                     $product->setLocale($lang->getLangKey());
  710.                     $dem->refresh($product);
  711.                     if(!empty($product->getProductDescription()) && $product->getProductDescription() != '') {
  712.                         $productDescription $product->getProductDescription();
  713.                     }
  714.                 }
  715.             }
  716.             //print('<br>qqw pDescription: '.$productDescription);
  717.             $product->setProductDescription($productDescription);      
  718.             $dem->flush();      
  719.             // we setup brands
  720.             if(!empty($product->getManufacturer())) {
  721.                 if(!in_array($product->getManufacturer(),$manufacturers)) {
  722.                     $manufacturers[] = $product->getManufacturer();
  723.                 }
  724.             }
  725.             //we check variants
  726.             $parentProduct null;
  727.             if(!empty($product->getParentProductId())) {
  728.                 print('<hr>QQW parent product: '.$product->getParentProductId()); 
  729.                 $parentProduct $dem->getRepository(Product::class)->getProduct($product->getParentProductId());    
  730.                 // we load variants of master product
  731.                 $productVariantList $dem->getRepository(Product::class)->getProductVariantList($product->getParentProductId());           
  732.             } else {
  733.                 
  734.                 // we load variants of master product
  735.                 if(is_numeric($pId)) { 
  736.                     $productVariantList $dem->getRepository(Product::class)->getProductVariantList($pId); 
  737.                 } else {
  738.                     $productVariantList $dem->getRepository(Product::class)->getProductVariantListSeo($pId);
  739.                 }
  740.                 
  741.             }
  742.             $productVariants[$pId] = $productVariantList;
  743.       
  744.       }
  745.         /* we load prices */
  746.         $productPriceList $dem->getRepository(Product::class)->getProductPriceList($productIds);
  747.         $defaultCurrency $em->getRepository(Currency::class)->getCurrency($eshop->getPreferredCurrencyId());
  748.         $targetCurrency $session->get('eshopCurrency');
  749.         
  750.         /* we load currency rated prices */
  751.         $productPriceList $dem->getRepository(Product::class)->getCurrencyRatedProductPriceList($productPriceList$defaultCurrency$targetCurrency);
  752.         /* we get price(s) to display */
  753.         $displayPrice null;
  754.         foreach($productPriceList as $price) {
  755.             if($price->getProductId() == $product->getProductId()) {
  756.                 /* we get default price level */
  757.                 if($price->getPriceLevelId() == 1) {
  758.                     //$displayPrice = round($price->getBruttoValue(),$eshop->getRoundPrice());
  759.                     $displayPrice round($price->getNettoValue(),$eshop->getRoundPrice());
  760.                 }
  761.                 
  762.             }
  763.         }
  764.         /* we load pack prices */
  765.         $productPackPriceList = array();
  766.         if($isPackSaleModule) {
  767.             $productPackPriceList $dem->getRepository(Product::class)->getProductPackPriceList($productIds);
  768.             
  769.             /* we load currency rated prices */
  770.             $productPackPriceList $dem->getRepository(Product::class)->getCurrencyRatedProductPriceList($productPackPriceList$defaultCurrency$targetCurrency);
  771.             /* we get package price(s) to display */
  772.             $displayPackPrice null;
  773.             foreach($productPackPriceList as $price) {
  774.                 if($price->getProductId() == $product->getProductId()) {
  775.                     /* we get default price level */
  776.                     if($price->getPriceLevelId() == 1) {
  777.                         //$displayPrice = round($price->getBruttoValue(),$eshop->getRoundPrice());
  778.                         $displayPackPrice round($price->getNettoValue(),$eshop->getRoundPrice());
  779.                     }
  780.                     
  781.                 }
  782.             }   
  783.         }     
  784.         /* we add product(s) to basket - POST form action */
  785.         if(!empty($request->request->get('basket'))) {
  786.             /* we call method to add to basket */
  787.             $this->addToBasket($request$eshopId$request->request->get('productId'));
  788.         }
  789.         
  790.         $productView $eshop->getProductView();
  791.         
  792.         /*
  793.         print('<br>qqw eshop: '.$eshop->getWireFrameId());
  794.         \Doctrine\Common\Util\Debug::dump($eshop);
  795.         */
  796.         
  797.         /* we load header for the current website */
  798.         $eshopHeader $dem->getRepository(Eshop::class)->getEshopHeader($eshopId);
  799.         if(!empty($eshopHeader)) {
  800.           $eshopHeader->setLocale($session->get('lang')->getLangKey());
  801.           $dem->refresh($eshopHeader);            
  802.         }
  803.         /* we load footer for the current website */
  804.         $eshopFooter $dem->getRepository(Eshop::class)->getEshopFooter($eshopId);
  805.         if(!empty($eshopFooter)) {         
  806.           $eshopFooter->setLocale($session->get('lang')->getLangKey());
  807.           $dem->refresh($eshopFooter);  
  808.         }   
  809.       
  810.         /* we load home page for the current website */
  811.         $homePage $dem->getRepository(Eshop::class)->getHomePage($eshopId);
  812.       
  813.         $wireFrame $em->getRepository(WireFrame::class)->getWireFrame($eshop->getProductListWireFrameId());
  814.         //$childNodes = $category->getChildren();
  815.         /*
  816.         print('<br>qqw childNodes: ');
  817.         \Doctrine\Common\Util\Debug::dump($childNodes);
  818.         */     
  819.         if(!empty($request->query->get('simpleview'))) { 
  820.             $simpleView true;
  821.         } else {
  822.             $simpleView false;
  823.         }
  824.         /* we prepare data for view */
  825.         $viewData = array(  'headerData' => $this -> getPageHeader($request),
  826.                         'menu' => $this -> adminMenu($request),'mainMenu' => $this -> adminMainMenu($request),'mainMenu' => $this -> adminMainMenu($request),
  827.                         'eshop' => $eshop,
  828.                         'user' => $user,
  829.                         'productView' => $productView,
  830.                         'productList' => $productList,
  831.                         'productPriceList' => $productPriceList,
  832.                         'productThumbs' => $productThumbs,
  833.                         'productCount' => $productCount,
  834.                         'wireFrame' => $wireFrame,
  835.                         'category' => $category,
  836.                         'childNodes' => $childNodes,
  837.                         'categoryPath' => $categoryPath,
  838.                         'categoryTreeMenu' => $this->categoryTreeMenu($eshop$request),
  839.                         'categoryTopMenu' => $this->categoryTopMenu($eshop$request),
  840.                         'eshopHeader' => $eshopHeader,
  841.                         'eshopFooter' => $eshopFooter,  
  842.                         'homePage' => $homePage,          
  843.                         'seoData' => $seoData,  
  844.                         'productPackPriceList' => $productPackPriceList,
  845.                         'isPackSaleModule' => $isPackSaleModule,     
  846.                         'priceLevelList' => $priceLevelList,
  847.                         'topProducts' => $this->getTopProducts($request$eshop7),
  848.                         'manufacturers' => $manufacturerList,
  849.                         'simpleView' => $simpleView,
  850.                         'productVariants' => $productVariants                                                                                      
  851.                 );    
  852.         if(!empty($request->query->get('REST')) OR !empty($request->query->get('api'))) {
  853.             // we output json
  854.             return new JsonResponse($viewData);
  855.         } else {
  856.             // we render template
  857.             return $this->render('eshopCategory.html.twig'$viewData);
  858.         }                    
  859.     
  860.     
  861.     }  
  862.     public function addToBasket(Request $request$eshopId$productId$isFlashMessage true)
  863.     {
  864.         /* we load session data */ 
  865.         parent::init($request);
  866.         $session $request->getSession();
  867.         //print('<br>QQW eshop ID: '.$eshopId);
  868.         //\Doctrine\Common\Util\Debug::dump($category);
  869.     
  870.         /* we load entity managers */
  871.         $em $this->doctrine->getManager();
  872.         $dem $this->doctrine->getManager('dynamic_em');
  873.         /* we get current e-shop */
  874.         $eshop $em->getRepository(Eshop::class)->getEshop($eshopId);
  875.         $user $em->getRepository(User::class)->getUser($eshop->getUserId());
  876.         $targetCurrency $session->get('eshopCurrency');
  877.             /* we load product */
  878.             $product $dem->getRepository(Product::class)->getProduct($productId);
  879.             $product->setLocale($session->get('lang')->getLangKey());
  880.             $dem->refresh($product);
  881.             /* if there is no order in basket then we create new order */
  882.             if(empty($session->get('order'))) {
  883.                 //print('<br>QQW Creating New Order');
  884.                 $order = new Order;
  885.                 $order->setEshopId($eshopId);
  886.                 $order->setCurrencyKey($targetCurrency->getCurrencyKey());
  887.                 $session->set('order'$order);
  888.                 $session->get('order')->setIp($request->getClientIp());
  889.             }    
  890.             /* we set product units */ 
  891.             $units 1;
  892.             if(!empty($request->request->get('units'))) {
  893.                 $unitInt intval($request->request->get('units'));
  894.                 if($unitInt 0) {
  895.                   $units $request->request->get('units');  
  896.                 } else {
  897.                   $units 1;  
  898.                 }
  899.             } 
  900.             //isModule Pack Sale
  901.             $module $em->getRepository(Module::class)->getModule(42);
  902.             $isPackSaleModule $em->getRepository(User::class)->userHasModule($user$module);
  903.             //we set totalprice for order item
  904.             $totalOrderItemPrice $this->getTotalOrderItemPrice($request$product$units$isPackSaleModule);
  905.             /* we check if we have this order item in basket already */     
  906.             $isInBasket false;
  907.             foreach($session->get('order')->getOrderItems() as $orderItem) {
  908.               if($orderItem->getProductId() == $product->getProductId()) {
  909.                 //print('<br>qqw item exists in basket');
  910.                 $totalOrderItemPrice $this->getTotalOrderItemPrice($request$product, ($orderItem->getOrderItemUnits() + $units), $isPackSaleModule);
  911.                 $orderItem->setOrderItemUnits($orderItem->getOrderItemUnits() + $units); 
  912.                 $orderItem->setOrderItemTotalPrice($totalOrderItemPrice);
  913.                 $isInBasket true;
  914.               } 
  915.             }  
  916.             
  917.             if(!$isInBasket) {
  918.               /* we create order item and load it with product data */
  919.               //print('<br>qqw product is NOT in basket yet');
  920.               $orderItem = new OrderItem;
  921.               $orderItem->setOrderItemTitle($product->getProductName());
  922.               //print('<br>qqw units: '.$units);
  923.               $orderItem->setOrderItemUnits($units);
  924.               $orderItem->setProductId($product->getProductId());
  925.               //$itemPrice = $units * $request->request->get('productPrice');
  926.               $orderItem->setOrderItemPrice($request->request->get('productPrice'));
  927.               $orderItem->setOrderItemTotalPrice($totalOrderItemPrice); 
  928.                        
  929.   
  930.               //we set brutto price
  931.               if(!empty($request->request->get('orderItemPriceBrutto')) && $request->request->get('orderItemPriceBrutto') > 0) {
  932.                 $orderItem->setOrderItemPriceBrutto($request->request->get('orderItemPriceBrutto'));
  933.               }
  934.               //we set order item VAT
  935.               if(!empty($request->request->get('orderItemVAT')) && $request->request->get('orderItemVAT') > 0) {
  936.                 $orderItem->setOrderItemVAT($request->request->get('orderItemVAT'));
  937.               }              
  938.               $orderItem->setCurrencyKey($request->request->get('currencyKey'));
  939.               $session->get('order')->addOrderItem($orderItem);
  940.             }
  941.             $orderItemId $dem->getRepository(Order::class)->getMaxOrderItemId($session->get('order'));
  942.             if ($isFlashMessage) {
  943.                 $this->addFlash('notice'$this->translator->trans('product.added_to_basket').'<a href="/eshop/'.$eshopId.'/basket" class="viewBasket">'.$this->translator->trans('eshop.basket_view').'</a>');
  944.             }
  945.             
  946.             /*
  947.             print('<br>qqw basket items: ');
  948.             \Doctrine\Common\Util\Debug::dump($session->get('order')->getOrderItems());
  949.             */
  950.             
  951.     }  
  952.     /**
  953.      * @Route("/api/eshop/{eshopId}/product/{productId}", name="apiEshopProduct")
  954.      */
  955.     public function getEshopProduct(Request $request$eshopId$productId)
  956.     {
  957.         /* we load session data */
  958.         parent::init($request);     
  959.         $session $request->getSession(); 
  960.         /* we load users entity manager */
  961.         $em $this->doctrine->getManager();
  962.         $dem $this->doctrine->getManager('dynamic_em');
  963.         // we get current e-shop 
  964.         $eshop $em->getRepository(Eshop::class)->getEshop($eshopId);
  965.         $priceLevelList $dem->getRepository(PriceLevel::class)->getPriceLevelList();
  966.         /*
  967.         print('<br>qqw eshop: '.$eshop->getEshopId());
  968.         \Doctrine\Common\Util\Debug::dump($eshop);
  969.         */
  970.         if(!empty($request->request->get('productId'))) {
  971.             // we call method to add to basket 
  972.             $productId $request->request->get('productId');
  973.         } elseif (!empty($request->get('productId'))) {
  974.             $productId $request->get('productId');
  975.         } elseif (!empty($request->attributes->get('productId'))) {
  976.             $productId $request->attributes->get('productId');
  977.         }        
  978.         $product $dem->getRepository(Product::class)->getProduct($productId);
  979.         $product->setLocale($session->get('lang')->getLangKey());
  980.         $dem->refresh($product);
  981.         //$apiProduct = get_object_vars($product);
  982.         //$apiProduct = $product->toArray();
  983.         try {
  984.             //print('<br>Twig - adds php functions ...');
  985.             $this->twig->addFunction(new \Twig\TwigFunction('deg2rad''deg2rad'));
  986.             $this->twig->addFunction(new \Twig\TwigFunction('sin''sin'));
  987.             $this->twig->addFunction(new \Twig\TwigFunction('imagecreatefromstring''imagecreatefromstring'));
  988.             $this->twig->addFunction(new \Twig\TwigFunction('file_get_contents''file_get_contents'));
  989.             $this->twig->addFunction(new \Twig\TwigFunction('ImageSX''ImageSX'));
  990.             $this->twig->addFunction(new \Twig\TwigFunction('ImageSY''ImageSY')); 
  991.         } catch(Exception $e) {
  992.             $this->addFlash('error'"Twig functions init error");
  993.         }
  994.         
  995.     //loads prices
  996.     $productIds = [$productId];
  997.     $productPriceList $dem->getRepository(Product::class)->getProductPriceList($productIds);    
  998.     $defaultCurrency $em->getRepository(Currency::class)->getCurrency($eshop->getPreferredCurrencyId());
  999.     $targetCurrency $session->get('eshopCurrency');
  1000.     // loads currency rated prices
  1001.     $productPriceList $dem->getRepository(Product::class)->getCurrencyRatedProductPriceList($productPriceList$defaultCurrency$targetCurrency);
  1002.     //gets price(s) to display
  1003.     $displayPrice null;
  1004.     foreach($productPriceList as $price) {
  1005.         if($price->getProductId() == $product->getProductId()) {
  1006.             /* we get default price level */
  1007.             if($price->getPriceLevelId() == 1) {
  1008.             //$displayPrice = round($price->getBruttoValue(),$eshop->getRoundPrice());
  1009.             $displayPrice round($price->getNettoValue(),$eshop->getRoundPrice());
  1010.             }
  1011.             
  1012.         }
  1013.     }        
  1014.         
  1015.         $apiProduct = [
  1016.             'productName' => $product->getProductName(),
  1017.             'productKey' => $product->getProductKey(),
  1018.             'ERPKey' => $product->getERPKey(),
  1019.             'image1' => $product->getImage1(),
  1020.             'displayPrice' => $displayPrice,
  1021.             'productDescription' => $product->getProductDescription(),
  1022.         ];
  1023.         
  1024.         $limit 300;
  1025.         $offset 0;
  1026.         $count 0;      
  1027.         $pages 10;
  1028.         $page 1;
  1029.         $system = array('code' => 200'message' => 'OK');
  1030.         $metadata = array('count' => $count'limit' => 100'pages' => $pages'page' => $page);
  1031.         //die(); 
  1032.          
  1033.         /* we prepare data for view */
  1034.         $viewData = array('system' => $system,
  1035.                           'product' => $apiProduct
  1036.                           'metadata' => $metadata,
  1037.                 );           
  1038.         // we output json
  1039.         return new JsonResponse($viewData);
  1040.     }
  1041.     /**
  1042.      * @Route("/api/eshop/{eshopId}/getbasket", name="getBasket")
  1043.      */
  1044.     public function getBasket(Request $request$eshopId)
  1045.     {
  1046.         /* we load session data */
  1047.         parent::init($request);     
  1048.         $session $request->getSession(); 
  1049.         /* we load users entity manager */
  1050.         $em $this->doctrine->getManager();
  1051.         $dem $this->doctrine->getManager('dynamic_em');
  1052.         // we get current e-shop 
  1053.         $eshop $em->getRepository(Eshop::class)->getEshop($eshopId);
  1054.         /*
  1055.         print('<br>qqw eshop: '.$eshop->getEshopId());
  1056.         \Doctrine\Common\Util\Debug::dump($eshop);
  1057.         */
  1058.         $limit 300;
  1059.         $offset 0;
  1060.         $defaultCurrency $em->getRepository(Currency::class)->getCurrency($eshop->getPreferredCurrencyId());
  1061.         
  1062.         $count 0;      
  1063.         $pages 10;
  1064.         $page 1;
  1065.         $system = array('code' => 200'message' => 'OK');
  1066.         $metadata = array('count' => $count'limit' => 100'pages' => $pages'page' => $page);
  1067.         $basketItems = [];
  1068.         if(!empty($session->get('order'))) {
  1069.             foreach($session->get('order')->getOrderItems() as $orderItem) {
  1070.                 $basketItem = [];
  1071.                 if(!empty($orderItem->getOrderItemPriceBrutto())) {
  1072.                     $productPriceVAT $orderItem->getOrderItemPriceBrutto() * $orderItem->getOrderItemUnits();
  1073.                 } else {
  1074.                     $productPriceVAT $orderItem->getOrderItemPrice() * $orderItem->getOrderItemUnits();
  1075.                 }
  1076.                 $basketItem['productId'] = $orderItem->getProductId();
  1077.                 $basketItem['title'] = $orderItem->getOrderItemTitle();                
  1078.                 $basketItem['units'] = $orderItem->getOrderItemUnits();
  1079.                 $basketItem['price'] = $productPriceVAT;                
  1080.                 $basketItems[] = $basketItem;
  1081.             }
  1082.         }
  1083.          
  1084.         /* we prepare data for view */
  1085.         $viewData = array('system' => $system,
  1086.                           'basketItems' => $basketItems
  1087.                           'metadata' => $metadata,
  1088.                 );           
  1089.         // we output json
  1090.         return new JsonResponse($viewData);
  1091.     }
  1092.     /**
  1093.      * @Route("/api/eshop/{eshopId}/addbasket", name="addBasket", methods={"POST", "PUT"})
  1094.      */
  1095.      public function addBasket(Request $request$eshopId)
  1096.      {
  1097.         /* we load session data */ 
  1098.         parent::init($request);
  1099.         $session $request->getSession();
  1100.         $message 'Adding product to basket.';
  1101.         //print('<br>QQW eshop ID: '.$eshopId);
  1102.         //\Doctrine\Common\Util\Debug::dump($category);
  1103.     
  1104.         // we load entity managers 
  1105.         $em $this->doctrine->getManager();
  1106.         $dem $this->doctrine->getManager('dynamic_em');
  1107.         
  1108.         // we get current e-shop and user
  1109.         $eshop $em->getRepository(Eshop::class)->getEshop($eshopId);
  1110.         $user $em->getRepository(User::class)->getUser($eshop->getUserId());
  1111.         $productId 102;
  1112.         // we add product(s) to basket - POST form action 
  1113.         if(!empty($request->request->get('productId'))) {
  1114.             // we call method to add to basket 
  1115.             $productId $request->request->get('productId');
  1116.             $this->addToBasket($request$eshopId$request->request->get('productId'), false);
  1117.             
  1118.             if(!empty($session->get('order')) && $session->get('order')->getEshopId() == $eshopId) {
  1119.                 $basketCount count($session->get('order')->getOrderItems());
  1120.             }
  1121.             
  1122.             $message $this->translator->trans('eshop.product_inserted');
  1123.         }
  1124.         $count 0;      
  1125.         $pages 10;
  1126.         $page 1;
  1127.         $system = array('code' => 200'message' => $message);
  1128.         $metadata = array('count' => $count'limit' => 100'pages' => $pages'page' => $page);
  1129.         //die(); 
  1130.          
  1131.         /* we prepare data for view */
  1132.         $viewData = array('system' => $system,
  1133.                           'basketCount' => $basketCount
  1134.                           'metadata' => $metadata,
  1135.                 );           
  1136.         // we output json
  1137.         return new JsonResponse($viewData);
  1138.      }    
  1139.     /**
  1140.      * @Route("/eshop/{eshopId}/product/{productId}", name="eshopProduct")
  1141.      */
  1142.     public function eshopProductDetailAction(Request $request$eshopId$productId)
  1143.     {
  1144.     
  1145.         /* we load session data */
  1146.         parent::init($request);
  1147.         $session $request->getSession();
  1148.         //print('<br>QQW eshop ID: '.$eshopId);
  1149.         //\Doctrine\Common\Util\Debug::dump($category);
  1150.         /* we load entity managers */
  1151.         $em $this->doctrine->getManager();
  1152.         $dem $this->doctrine->getManager('dynamic_em');
  1153.     
  1154.         /* we get current e-shop */
  1155.         $eshop $em->getRepository(Eshop::class)->getEshop($eshopId);
  1156.         $priceLevelList $dem->getRepository(PriceLevel::class)->getPriceLevelList();
  1157.         /* we check if eshop exists */
  1158.         if($eshop === null) {
  1159.             $this->addFlash('error''E-shop with this ID does not exist.');
  1160.             return $this->redirectToRoute('eshopHome');
  1161.         }          
  1162.         $user $em->getRepository(User::class)->getUser($eshop->getUserId());
  1163.         $userDirs $this->getUserFolderPathsFromUserId($eshop->getUserId());
  1164.         if(is_numeric($productId)) {
  1165.             $product $dem->getRepository(Product::class)->getProduct($productId);    
  1166.         } else {
  1167.             $product $dem->getRepository(Product::class)->findOneBy(['titleSEO'=> $productId]);
  1168.         }
  1169.         if(!$product) {
  1170.             $this->addFlash('error''Product does not exists.');
  1171.             return $this->redirectToRoute('eshop', array('eshopId' => $eshopId));          
  1172.         }
  1173.         $product->setLocale($session->get('lang')->getLangKey());
  1174.         $dem->refresh($product);
  1175.         try {
  1176.             //print('<br>Twig - adds php functions ...');
  1177.             $this->twig->addFunction(new \Twig\TwigFunction('deg2rad''deg2rad'));
  1178.             $this->twig->addFunction(new \Twig\TwigFunction('sin''sin'));
  1179.             $this->twig->addFunction(new \Twig\TwigFunction('imagecreatefromstring''imagecreatefromstring'));
  1180.             $this->twig->addFunction(new \Twig\TwigFunction('file_get_contents''file_get_contents'));
  1181.             $this->twig->addFunction(new \Twig\TwigFunction('ImageSX''ImageSX'));
  1182.             $this->twig->addFunction(new \Twig\TwigFunction('ImageSY''ImageSY')); 
  1183.         } catch(Exception $e) {
  1184.             $this->addFlash('error'"Twig functions init error");
  1185.         }
  1186.         /* we load VAT */   
  1187.         $productVAT null;
  1188.         if(!empty($product) && !empty($product->getProductVAT()) && $product->getProductVAT() > 0) {
  1189.             /* VAT is derived from productVAT */
  1190.             $productVAT $product->getProductVAT();
  1191.         } elseif(!empty($eshop->getPreferredVAT()) && $eshop->getPreferredVAT() > 0) {
  1192.             /* VAT is derived from eshop VAT */
  1193.             $productVAT $eshop->getPreferredVAT();            
  1194.         }
  1195.         /* we setup product name - if empty then we load multilingual values */
  1196.         $productName '';
  1197.         if(!empty($product->getProductName()) && $product->getProductName() != '') {
  1198.             $productName $product->getProductName();
  1199.         } else {
  1200.             //we try to get the product name from multilangual fields 
  1201.             foreach($eshop->getLanguages() as $lang) {
  1202.                 $product->setLocale($lang->getLangKey());
  1203.                 $dem->refresh($product);
  1204.                 if(!empty($product->getProductName()) && $product->getProductName() != '') {
  1205.                     $productName $product->getProductName();
  1206.                 }
  1207.             }
  1208.         }
  1209.         //print('<br>qqw pname: '.$productName);
  1210.         $product->setProductName($productName);
  1211.         $dem->flush();
  1212.         /* we setup product description - if empty then we load multilingual values */
  1213.         
  1214.         $productDescription '';
  1215.         if(!empty($product->getProductDescription()) && $product->getProductDescription() != '') {
  1216.             $productDescription $product->getProductDescription();
  1217.         } else {
  1218.             //we try to get the product description from multilangual fields 
  1219.             foreach($eshop->getLanguages() as $lang) {
  1220.                 $product->setLocale($lang->getLangKey());
  1221.                 $dem->refresh($product);
  1222.                 if(!empty($product->getProductDescription()) && $product->getProductDescription() != '') {
  1223.                     $productDescription $product->getProductDescription();
  1224.                 }
  1225.             }
  1226.         }
  1227.         //print('<br>qqw pdescription: '.$productDescription);
  1228.         $product->setProductDescription($productDescription);
  1229.         $dem->flush();
  1230.         $seoData = array();
  1231.         $seoData['seoTitle'] = $product->getProductName().' - '.$eshop->getEshopName();
  1232.         $seoData['seoDescription'] = $eshop->getEshopName().', '.$product->getProductName().(!empty($product->getProductShortDescription())?(' - '.$product->getProductShortDescription()):'');    
  1233.         //isModule Pack Sale
  1234.         $module $em->getRepository(Module::class)->getModule(42);
  1235.         $isPackSaleModule $em->getRepository(User::class)->userHasModule($user$module);
  1236.         /* we load prices */
  1237.         $productIds = array();
  1238.         $productIds[] = $productId;  
  1239.         // we load parent product
  1240.         $parentProduct null;
  1241.         if(!empty($product->getParentProductId())) {
  1242.             //print('<hr>QQW parent product: '.$product->getParentProductId()); 
  1243.             $parentProduct $dem->getRepository(Product::class)->getProduct($product->getParentProductId());    
  1244.             // we load variants of master product
  1245.             $productVariantList $dem->getRepository(Product::class)->getProductVariantList($product->getParentProductId());             
  1246.         } else {
  1247.             // we load variants of master product
  1248.             if(is_numeric($productId)) { 
  1249.                 $productVariantList $dem->getRepository(Product::class)->getProductVariantList($productId); 
  1250.             } else {
  1251.                 $productVariantList $dem->getRepository(Product::class)->getProductVariantListSeo($productId);
  1252.             }
  1253.             
  1254.         }
  1255.         
  1256.         // we get 3D gallery
  1257.         $gallery3d '';
  1258.         if(!empty($product->getGallery3dId()) && $product->getGallery3dId() > 0) {
  1259.             $gallery3d $this->getGallery3D($product->getGallery3dId(), $request);
  1260.         }
  1261.         $galleryItemCollection = [];
  1262.         if(!empty($product->getImageGallery())) {
  1263.             foreach($product->getImageGallery() as $imageGallery) {
  1264.                 $galleryId $imageGallery->getGalleryId();
  1265.                 $galleryItems $dem->getRepository(GalleryItem::class)->getGalleryItemList($galleryId);
  1266.                 $galleryItemCollection[$galleryId] = $galleryItems;
  1267.                 
  1268.             }
  1269.         }
  1270.         /*
  1271.         print('<hr>QQW productVariantList: '.$productId);
  1272.         \Doctrine\Common\Util\Debug::dump($productVariantList);
  1273.         */
  1274.         // we get variants parameters
  1275.         $productVariantParameters = array();
  1276.         $productVariantParameterValues = array();
  1277.         $variantTexts = [];
  1278.         
  1279.         $productParameterList $dem->getRepository(ProductParameter::class)->getProductParameterList();
  1280.         //print('<hr>QQW productParameterList : '); 
  1281.         //\Doctrine\Common\Util\Debug::dump($productParameterList);
  1282.         if(!empty($productVariantList)) {
  1283.             foreach($productVariantList as $productVariant) {
  1284.                 $productVariant->setLocale($session->get('lang')->getLangKey());
  1285.                 $dem->refresh($productVariant); 
  1286.                 $productVariantId $productVariant->getProductId();
  1287.                 $productIds[] = $productVariantId
  1288.                 
  1289.                 $variantText '';
  1290.                 $variantParamCount 0;
  1291.                 
  1292.                 foreach($productParameterList as $productParameter) {
  1293.                     $productParameter->setLocale($session->get('lang')->getLangKey());
  1294.                     $dem->refresh($productParameter); 
  1295.                     $parameterValue $dem->getRepository(ProductParameterValue::class)->getProductParameterValueByProduct($productParameter->getProductParameterId(), $productVariantId);
  1296.                     if (!empty($parameterValue) && $parameterValue->getProductParameterValue() !== '') {
  1297.                         $parameterValue->setLocale($session->get('lang')->getLangKey());
  1298.                         $dem->refresh($parameterValue); 
  1299.                     
  1300.                         if ($variantParamCount 0) {
  1301.                             $variantText .= ', ';
  1302.                         }
  1303.                         $variantText .= $productParameter->getProductParameterName().': '.$parameterValue->getProductParameterValue();
  1304.             //             print('<hr>QQW productParameter: '.$productParameter->getProductParameterId()); 
  1305.             //             print('<br>QQW name: '.$productParameter->getProductParameterName()); 
  1306.                         // print('<br>QQW parameterValue: '.$parameterValue->getProductParameterValue());
  1307.                         // print_r($parameterValue);
  1308.                         //print('<br>QQW parameterValue: '.$variantText);
  1309.                         $variantParamCount++;
  1310.                      }
  1311.                 }
  1312.                 
  1313.                 $variantTexts[$productVariantId] = $variantText;
  1314.                 
  1315.                 //print('<hr>qqw productVariant (id '.$productVariantId.'): '.$productVariant->getERPKey().' - '.$productVariant->getProductKey());
  1316.                 $productVariantParameterValueList $dem->getRepository(ProductParameterValue::class)->getProductParameterValueList($productVariantId);
  1317.                 foreach($productVariantParameterValueList as $variantParamVal) {
  1318.                     $variantParamVal->setLocale($session->get('lang')->getLangKey());
  1319.                     $dem->refresh($variantParamVal); 
  1320.                 }
  1321.                 $productVariantParameterValues[$productVariantId] = $productVariantParameterValueList
  1322.                 
  1323.                 foreach($productVariantParameterValues as $productVariantParameterValue) {
  1324.                     foreach($productVariantParameterValue as $pvp) {
  1325.                         $pvp->setLocale($session->get('lang')->getLangKey());
  1326.                         $dem->refresh($pvp); 
  1327.                         $parameter $dem->getRepository(ProductParameter::class)->getProductParameter($pvp->getProductParameterId());
  1328.                         $parameter->setLocale($session->get('lang')->getLangKey());
  1329.                         $dem->refresh($parameter); 
  1330.                         if(!in_array($parameter$productVariantParameters)) {
  1331.                             $parameterId $parameter->getProductParameterId();
  1332.                             $productVariantParameters[$parameterId] = $parameter
  1333.                         }                        
  1334.                     }
  1335.  
  1336.                 }  
  1337.             }
  1338.         }
  1339.         $productPriceList $dem->getRepository(Product::class)->getProductPriceList($productIds);     
  1340.         $defaultCurrency $em->getRepository(Currency::class)->getCurrency($eshop->getPreferredCurrencyId());
  1341.         $targetCurrency $session->get('eshopCurrency');
  1342.         
  1343.         /* we load currency rated prices */
  1344.         $productPriceList $dem->getRepository(Product::class)->getCurrencyRatedProductPriceList($productPriceList$defaultCurrency$targetCurrency);        
  1345.         /* we load pack prices */
  1346.         $productPackPriceList = array();
  1347.         if($isPackSaleModule) {
  1348.             $productPackPriceList $dem->getRepository(Product::class)->getProductPackPriceList($productIds);
  1349.             
  1350.             /* we load currency rated prices */
  1351.             $productPackPriceList $dem->getRepository(Product::class)->getCurrencyRatedProductPriceList($productPackPriceList$defaultCurrency$targetCurrency);
  1352.             /* we get package price(s) to display */
  1353.             /*
  1354.             $displayPackPrice = null;
  1355.             foreach($productPackPriceList as $price) {
  1356.                 if($price->getProductId() == $product->getProductId()) {
  1357.                     // we get default price level
  1358.                     if($price->getPriceLevelId() == 1) {
  1359.                         //$displayPrice = round($price->getBruttoValue(),$eshop->getRoundPrice());
  1360.                         $displayPackPrice = round($price->getNettoValue(),$eshop->getRoundPrice());
  1361.                     }
  1362.                     
  1363.                 }
  1364.             }  
  1365.             */ 
  1366.         }            
  1367.         /*
  1368.         print('<br>qqw defaultCurrency: '.$defaultCurrency->getCurrencyKey());
  1369.         print('<br>qqw targetCurrency: '.$targetCurrency->getCurrencyKey());      
  1370.         */  
  1371.         //print('<hr>qqw productIds: ');
  1372.         //\Doctrine\Common\Util\Debug::dump($productIds);        
  1373.         //print('<hr>qqw productPriceList: ');
  1374.         //\Doctrine\Common\Util\Debug::dump($productPriceList);
  1375.         
  1376.         /* we add product(s) to basket - POST form action */
  1377.         if(!empty($request->request->get('basket'))) {
  1378.             /* we call method to add to basket */
  1379.             $this->addToBasket($request$eshopId$request->request->get('productId'));
  1380.         }    
  1381.         $eshopHeader $dem->getRepository(Eshop::class)->getEshopHeader($eshopId);
  1382.         if(!empty($eshopHeader)) {
  1383.           $eshopHeader->setLocale($session->get('lang')->getLangKey());
  1384.           $dem->refresh($eshopHeader);            
  1385.         }
  1386.         /* we load footer for the current website */
  1387.         $eshopFooter $dem->getRepository(Eshop::class)->getEshopFooter($eshopId);
  1388.         if(!empty($eshopFooter)) {         
  1389.           $eshopFooter->setLocale($session->get('lang')->getLangKey());
  1390.           $dem->refresh($eshopFooter);  
  1391.         }  
  1392.       
  1393.         /* we load home page for the current website */
  1394.         $homePage $dem->getRepository(Eshop::class)->getHomePage($eshopId);
  1395.         $wireFrame $em->getRepository(WireFrame::class)->getWireFrame($eshop->getProductDetailWireFrameId());
  1396.         
  1397.         $categoryPath null;
  1398.         if(!empty($product->getParentProductId())) {
  1399.             //variant of product - we need to get master product path
  1400.             //print('<hr>QQW parent product: '.$product->getParentProductId()); 
  1401.             $parentProduct $dem->getRepository(Product::class)->getProduct($product->getParentProductId());  
  1402.             
  1403.             foreach($parentProduct->getCategories() as $cat) {
  1404.                 $categoryPath $dem->getRepository(Category::class)->getPath($cat);
  1405.             }
  1406.         }
  1407.         else {
  1408.             
  1409.             foreach($product->getCategories() as $cat) {
  1410.                 $cat->setLocale($session->get('lang')->getLangKey());
  1411.                 $dem->refresh($cat); 
  1412.                 $categoryPath $dem->getRepository(Category::class)->getPath($cat);
  1413.             }            
  1414.         } 
  1415.         //print('<hr>qqw categoryPath: ');
  1416.         //\Doctrine\Common\Util\Debug::dump($categoryPath); 
  1417.         
  1418.         $parameterList $dem->getRepository(ProductParameter::class)->getProductParameterList();
  1419.         // we load ProductParameterValueList
  1420.         if(!empty($product->getParentProductId())) {
  1421.             //print('<br>QQW variant 69: ');  
  1422.              $productParameterValueList $dem->getRepository(ProductParameterValue::class)->getProductParameterValueList($product->getParentProductId());
  1423.         } else {
  1424.             //print('<br>QQW master 69: '); 
  1425.             $productParameterValueList $dem->getRepository(ProductParameterValue::class)->getProductParameterValueList($productId);
  1426.                
  1427.         }        
  1428.         //$productParameterValueList = $dem->getRepository(ProductParameterValue::class)->getProductParameterValueList($productId);
  1429.         $productParameterList = array();
  1430.         foreach($productParameterValueList as $productParameterValue) {
  1431.             $parameter $dem->getRepository(ProductParameter::class)->getProductParameter($productParameterValue->getProductParameterId());
  1432.             $parameter->setLocale($session->get('lang')->getLangKey());
  1433.             $dem->refresh($parameter); 
  1434.             $productParameterValue->setLocale($session->get('lang')->getLangKey());
  1435.             $dem->refresh($productParameterValue); 
  1436.             if(!in_array($parameter$productParameterList)) {
  1437.                 $productParameterList[] = $parameter;
  1438.             }
  1439.         }  
  1440.         /*
  1441.         print('<hr>QQW productParameterList 2: ');
  1442.         \Doctrine\Common\Util\Debug::dump($productParameterList);
  1443.         
  1444.         print('<hr>QQW productParameterValueList: ');
  1445.         \Doctrine\Common\Util\Debug::dump($productParameterValueList);
  1446.         */
  1447.         /* we load parameter groups */
  1448.         $productParameterGroupList $dem->getRepository(ProductParameterGroup::class)->getProductParameterGroupList();
  1449.         /* we filter only groups with any parameters */
  1450.         $groupList = array();
  1451.         foreach($productParameterList as $param) {
  1452.             //print('<br>QQW param: '.$param->getProductParameterName());
  1453.             foreach($param->getProductParameterGroups() as $group) {
  1454.                 //print('<br>QQW group: '.$group->getProductParameterGroupName());
  1455.                 if(!in_array($group$groupList)) {
  1456.                     $groupList[] = $group;
  1457.                 }
  1458.             }
  1459.         } 
  1460.         /*
  1461.         print('<hr>QQW groupList: ');
  1462.         \Doctrine\Common\Util\Debug::dump($groupList);  
  1463.         */
  1464.         /* we remove empty parameter groups from list */
  1465.         foreach($productParameterGroupList as $key => $group) {
  1466.                 if(!in_array($group$groupList)) {
  1467.                     unset($productParameterGroupList[$key]);
  1468.                 }
  1469.         }
  1470.         // print('<br>QQW topProducts: ');
  1471.         // \Doctrine\Common\Util\Debug::dump($topProducts);     
  1472.         
  1473.         //$productParameterGroupList = $groupList;   
  1474.         
  1475.         /* we render data */
  1476.         return $this->render('eshopProduct.html.twig',
  1477.                 array(  'headerData' => $this -> getPageHeader($request),
  1478.                         'menu' => $this -> adminMenu($request),'mainMenu' => $this -> adminMainMenu($request),'mainMenu' => $this -> adminMainMenu($request),
  1479.                         'user' => $user,
  1480.                         'userDirs' => $userDirs,
  1481.                         'eshop' => $eshop,
  1482.                         'product' => $product,
  1483.                         'productVAT' => $productVAT,                        
  1484.                         'productPriceList' => $productPriceList,
  1485.                         'wireFrame' => $wireFrame,
  1486.                         'categoryPath' => $categoryPath,
  1487.                         'categoryTreeMenu' => $this->categoryTreeMenu($eshop$request),
  1488.                         'categoryTopMenu' => $this->categoryTopMenu($eshop$request),
  1489.                         'eshopHeader' => $eshopHeader,
  1490.                         'eshopFooter' => $eshopFooter,  
  1491.                         'productParameterList' => $productParameterList,
  1492.                         'productParameterValueList' => $productParameterValueList,
  1493.                         'productParameterGroupList' => $productParameterGroupList,
  1494.                         'homePage' => $homePage,   
  1495.                         'seoData' => $seoData,  
  1496.                         'productVariantList' => $productVariantList
  1497.                         'productVariantParameters' => $productVariantParameters,                         
  1498.                         'productVariantParameterValues' => $productVariantParameterValues,                                                
  1499.                         'parentProduct' => $parentProduct,
  1500.                         'productPackPriceList' => $productPackPriceList,
  1501.                         'isPackSaleModule' => $isPackSaleModule,
  1502.                         'topProducts' => $this->getTopProducts($request$eshop7),    
  1503.                         'priceLevelList' => $priceLevelList,
  1504.                         'gallery3d' => $gallery3d,
  1505.                         'galleryItemCollection' => $galleryItemCollection,
  1506.                         'variantTexts' => $variantTexts                                                                                       
  1507.                 )
  1508.                 );
  1509.     
  1510.     }    
  1511.   
  1512.     /**
  1513.      * @Route("/eshop/{eshopId}/register", name="eshopRegister")
  1514.      */
  1515.     public function eshopRegisterAction(Request $request$eshopId)
  1516.     {
  1517.     
  1518.         /* we load session data */
  1519.         parent::init($request);
  1520.         $session $request->getSession();
  1521.         /* we load entity managers */
  1522.         $em $this->doctrine->getManager();
  1523.         $dem $this->doctrine->getManager('dynamic_em');
  1524.     
  1525.         /* we get current e-shop */
  1526.         $eshop $em->getRepository(Eshop::class)->getEshop($eshopId);
  1527.     
  1528.         $user $em->getRepository(User::class)->getUser($eshop->getUserId());
  1529.          
  1530.         /* we check if eshop exists */
  1531.         if($eshop === null) {
  1532.             $this->addFlash('error''E-shop with this ID does not exist.');
  1533.             return $this->redirectToRoute('eshopHome');
  1534.         }
  1535.     
  1536.         $eshopHeader $dem->getRepository(Eshop::class)->getEshopHeader($eshopId);
  1537.         if(!empty($eshopHeader)) {
  1538.           $eshopHeader->setLocale($session->get('lang')->getLangKey());
  1539.           $dem->refresh($eshopHeader);            
  1540.         }
  1541.         /* we load footer for the current website */
  1542.         $eshopFooter $dem->getRepository(Eshop::class)->getEshopFooter($eshopId);
  1543.         if(!empty($eshopFooter)) {         
  1544.           $eshopFooter->setLocale($session->get('lang')->getLangKey());
  1545.           $dem->refresh($eshopFooter);  
  1546.         }  
  1547.       
  1548.         /* we load home page for the current website */
  1549.         $homePage $dem->getRepository(Eshop::class)->getHomePage($eshopId);
  1550.         $wireFrame $em->getRepository(WireFrame::class)->getWireFrame($eshop->getProductDetailWireFrameId());
  1551.         /* we prepare data for the form */
  1552.         if(!empty($request->request->get('lastName'))) {
  1553.             $lastName $request->request->get('lastName');
  1554.         } else {
  1555.             $lastName '';
  1556.         }   
  1557.         if(!empty($request->request->get('firstName'))) {
  1558.             $firstName $request->request->get('firstName');
  1559.         } else {
  1560.             $firstName '';
  1561.         }              
  1562.         if(!empty($request->request->get('company'))) {
  1563.             $company $request->request->get('company');
  1564.         } else {
  1565.             $company '';
  1566.         }
  1567.         if(!empty($request->request->get('email'))) {
  1568.             $email $request->request->get('email');
  1569.         } else {
  1570.             $email '';
  1571.         }
  1572.         if(!empty($request->request->get('telefon'))) {
  1573.             $telefon $request->request->get('telefon');
  1574.         } else {
  1575.             $telefon '';
  1576.         }
  1577.         if(!empty($request->request->get('addressStreet'))) {
  1578.             $addressStreet $request->request->get('addressStreet');
  1579.         } else {
  1580.             $addressStreet '';
  1581.         } 
  1582.         if(!empty($request->request->get('addressStreetNumber'))) {
  1583.             $addressStreetNumber $request->request->get('addressStreetNumber')[''];
  1584.         } else {
  1585.             $addressStreetNumber '';
  1586.         }   
  1587.         if(!empty($request->request->get('addressCity'))) {
  1588.             $addressCity $request->request->get('addressCity');
  1589.         } else {
  1590.             $addressCity '';
  1591.         } 
  1592.         if(!empty($request->request->get('addressZipCode'))) {
  1593.             $addressZipCode $request->request->get('addressZipCode');
  1594.         } else {
  1595.             $addressZipCode '';
  1596.         }          
  1597.         if(!empty($request->request->get('addressCountry'))) {
  1598.             $addressCountry $request->request->get('addressCountry');
  1599.         } else {
  1600.             $addressCountry '';
  1601.         }                             
  1602.         if(!empty($request->request->get('address'))) {
  1603.             $address $request->request->get('address');
  1604.         } else {
  1605.             $address '';
  1606.         }
  1607.         if(!empty($request->request->get('username'))) {
  1608.             $username $request->request->get('username');
  1609.         } else {
  1610.             $username '';
  1611.         }
  1612.         if(!empty($request->request->get('password'))) {
  1613.             $password $request->request->get('password');
  1614.         } else {
  1615.             $password '';
  1616.         }
  1617.         if(!empty($request->request->get('password_retype'))) {
  1618.             $password_retype $request->request->get('password_retype');
  1619.         } else {
  1620.             $password_retype '';
  1621.         }    
  1622.         if(!empty($request->request->get('businessId'))) {
  1623.             $businessId $request->request->get('businessId');
  1624.         } else {
  1625.             $businessId '';
  1626.         }     
  1627.         if(!empty($request->request->get('DICId'))) {
  1628.             $DICId $request->request->get('DICId');
  1629.         } else {
  1630.             $DICId '';
  1631.         }               
  1632.         
  1633.         /* we build register form */
  1634.         $contact = new Contact;
  1635.         $formBuilder $this->createFormBuilder($contact);
  1636.         $formBuilder->add('lastName'TextType::class, array(
  1637.                 'required' => true,
  1638.                 'label' => $this->translator->trans('knowledgebase.last_name'),
  1639.                 'attr' => array('class' => 'text_form''size' => 35'value' => $lastName),
  1640.                 'label_attr' => array('class' => 'form_field_label_required')
  1641.         ));
  1642.         $formBuilder->add('firstName'TextType::class, array(
  1643.                 'required' => true,
  1644.                 'label' => $this->translator->trans('knowledgebase.first_name'),
  1645.                 'attr' => array('class' => 'text_form''size' => 35'value' => $firstName),
  1646.                 'label_attr' => array('class' => 'form_field_label_required')
  1647.         )); 
  1648.         $formBuilder->add('email'EmailType::class, array(
  1649.                 'required' => true,
  1650.                 'attr' => array('class' => 'text_form''size' => 35'value' => $email),
  1651.                 'label_attr' => array('class' => 'form_field_label_required'),
  1652.         ));  
  1653.         $formBuilder->add('contactUserName'TextType::class, array(
  1654.                 'required' => true,
  1655.                 'label' => $this->translator->trans('user.username'),
  1656.                 'empty_data'  => '',
  1657.                 'attr' => array('class' => 'text_form''size' => 20'value' => $username),
  1658.                 'label_attr' => array('class' => 'form_field_label_required'),
  1659.         ));
  1660.         $formBuilder->add('contactUserPassword'PasswordType::class, array(
  1661.                 'required' => true,
  1662.                 'label' => $this->translator->trans('user.password'),
  1663.                 'attr' => array('class' => 'text_form''size' => 20'value' => $password),
  1664.                 'label_attr' => array('class' => 'form_field_label_required'),
  1665.         ));                     
  1666.         /*
  1667.         $formBuilder->add('password_retype', PasswordType::class, array(
  1668.                 'required' => true,
  1669.                 'label' => $this->translator->trans('user.password_retype'),
  1670.                 'attr' => array('class' => 'text_form', 'size' => 35, 'value' => $password_retype),
  1671.                 'label_attr' => array('class' => 'form_field_label_required'),
  1672.         )); 
  1673.         */ 
  1674.         $formBuilder->add('phone'TextType::class, array(
  1675.                 'required' => false,
  1676.                 'label' => $this->translator->trans('user.telephone'),
  1677.                 'attr' => array('class' => 'text_form''size' => 20'value' => $telefon),
  1678.                 'label_attr' => array('class' => 'form_field_label'),
  1679.         ));
  1680.         /* we add address */
  1681.         $formBuilder->add('addressStreet'TextType::class, array(
  1682.                 'required' => true,
  1683.                 'mapped' => false,
  1684.                 'label' => $this->translator->trans('address.street'),
  1685.                 'attr' => array('class' => 'text_form''size' => 35'value' => $addressStreet),
  1686.                 'label_attr' => array('class' => 'form_field_label_required'),
  1687.         ));
  1688.         $formBuilder->add('addressStreetNumber'TextType::class, array(
  1689.                 'required' => true,
  1690.                 'mapped' => false,
  1691.                 'label' => $this->translator->trans('address.street_number'),
  1692.                 'attr' => array('class' => 'text_form''size' => 10'value' => $addressStreetNumber),
  1693.                 'label_attr' => array('class' => 'form_field_label_required'),
  1694.         ));     
  1695.         $formBuilder->add('addressZipCode'TextType::class, array(
  1696.                 'required' => true,
  1697.                 'mapped' => false,
  1698.                 'label' => $this->translator->trans('address.zip_code'),
  1699.                 'attr' => array('class' => 'text_form''size' => 10'value' => $addressZipCode),
  1700.                 'label_attr' => array('class' => 'form_field_label_required'),
  1701.         ));   
  1702.         $formBuilder->add('addressCity'TextType::class, array(
  1703.                 'required' => true,
  1704.                 'mapped' => false,
  1705.                 'label' => $this->translator->trans('address.city'),
  1706.                 'attr' => array('class' => 'text_form''size' => 35'value' => $addressCity),
  1707.                 'label_attr' => array('class' => 'form_field_label_required'),
  1708.         ));       
  1709.         $formBuilder->add('addressCountry'TextType::class, array(
  1710.                 'required' => true,
  1711.                 'mapped' => false,
  1712.                 'label' => $this->translator->trans('address.country'),
  1713.                 'attr' => array('class' => 'text_form''size' => 35'value' => $addressCountry),
  1714.                 'label_attr' => array('class' => 'form_field_label_required'),
  1715.         ));
  1716.         $formBuilder->add('companyName'TextType::class, array(
  1717.                 'required' => false,
  1718.                 'label' => $this->translator->trans('user.company'),
  1719.                 'attr' => array('class' => 'text_form''size' => 35'value' => $company),
  1720.                 'label_attr' => array('class' => 'form_field_label')
  1721.         ));
  1722.         $formBuilder->add('businessId'TextType::class, array(
  1723.                 'required' => false,
  1724.                 'label' => $this->translator->trans('user.business_number'),
  1725.                 'attr' => array('class' => 'text_form''size' => 20'value' => $businessId),
  1726.                 'label_attr' => array('class' => 'form_field_label')
  1727.         ));        
  1728.         $formBuilder->add('DICId'TextType::class, array(
  1729.                 'required' => false,
  1730.                 'label' => $this->translator->trans('user.DIC_number'),
  1731.                 'attr' => array('class' => 'text_form''size' => 20'value' => $DICId),
  1732.                 'label_attr' => array('class' => 'form_field_label')
  1733.         ));  
  1734.         $formBuilder->add('form_control_question'TextType::class, array(
  1735.                 'required' => false,
  1736.                 'mapped' => false,
  1737.                 'label' => $this->translator->trans('system.control_question').' 11 + 6 =',
  1738.                 'attr' => array('class' => 'text_form''size' => 20'value' => $DICId),
  1739.                 'label_attr' => array('class' => 'form_field_label')
  1740.         )); 
  1741.         /*
  1742.         $formBuilder->add('address', TextareaType::class, array(
  1743.                 'required' => false,
  1744.                 'label' => $this->translator->trans('user.address'),
  1745.                 'attr' => array('class' => 'textarea_form', 'cols' => 33, 'rows' => 2, 'value' => $address),
  1746.                 'label_attr' => array('class' => 'form_textarea_label'),
  1747.         ));
  1748.         */
  1749.         //isModule e-Privacy Consent
  1750.         $module $em->getRepository(Module::class)->getModule(30);
  1751.         $isConsentModule $em->getRepository(User::class)->userHasModule($user$module);
  1752.         $consentList null;
  1753.         $consentDescriptions = array();
  1754.         if($isConsentModule) {
  1755.             //print('<br>qqw is module e-Privacy Consent');
  1756.  
  1757.             $consentList $dem->getRepository(Consent::class)->getConsentList();
  1758.             $consents = array();
  1759.             $consentRequired false;
  1760.             foreach($consentList as $consent) {
  1761.                 $consent->setLocale($session->get('lang')->getLangKey());
  1762.                 $dem->refresh($consent);  
  1763.                 //print('<br>Consent: '.$consent->getConsentName());
  1764.                 if($consent->isBlockOrder()) {
  1765.                     $consentRequired true;
  1766.                 }
  1767.                 $consents[$consent->getConsentName()] = $consent->getConsentId();
  1768.                 $consentDescriptions[$consent->getConsentId()] = $consent->getConsentDescription();
  1769.             }
  1770.             $selectedConsents = array();
  1771.             $formBuilder->add('consents'ChoiceType::class, array(
  1772.                     'choices' => $consents,
  1773.                     'required' => $consentRequired,
  1774.                     'mapped' => false,
  1775.                     'multiple' => true,
  1776.                     'expanded' => true,
  1777.                     'label_attr' => array('class' => 'consent_label'),
  1778.                     'attr' => array('class' => 'form_field_text'),
  1779.                     'choice_attr' => function($val$key$index) {
  1780.                         // adds a class like attending_yes, attending_no, etc
  1781.                         return ['class' => 'choiceBlock5''required' => 'required']; 
  1782.                     },   
  1783.                     'data' => $selectedConsents
  1784.             ));             
  1785.         }            
  1786.         
  1787.         $formBuilder->add('save'SubmitType::class, array('label' => $this->translator->trans('system.create_account'),
  1788.                 'attr' => array('class' => 'butt_big')));
  1789.         
  1790.         $form $formBuilder->getForm();
  1791.         //isModule ReCaptcha
  1792.         $module $em->getRepository(Module::class)->getModule(41);
  1793.         $isReCaptchaModule $em->getRepository(User::class)->userHasModule($user$module);
  1794.         $reCaptcha null;
  1795.         if($isReCaptchaModule) {
  1796.             //we load re-captcha
  1797.             $reCaptcha $dem->getRepository(ReCaptcha::class)->findOneBy(['reCaptchaId'=> 1]);
  1798.         } 
  1799.         
  1800.         $form->handleRequest($request);
  1801.         
  1802.         if ($request->getMethod() == 'POST') {
  1803.         
  1804.             //$form->bindRequest($request);
  1805.             //$this->captchaverify($request->get('g-recaptcha-response')
  1806.             /*
  1807.             print('<br>recaptcha-response verify: ');
  1808.             var_dump($this->captchaVerify($request->get('g-recaptcha-response')));
  1809.   
  1810.             print('<hr>recaptcha-response: ');
  1811.             print_r($request->get('g-recaptcha-response'));
  1812.             var_dump($request->get('g-recaptcha-response'));
  1813.             */
  1814.             
  1815.             //die();
  1816.             //if ($form->isValid() && $this->captchaVerify($request->get('g-recaptcha-response')) != null) {
  1817.             if(!$isReCaptchaModule) {
  1818.                 //we load re-captcha
  1819.                 $captchaResponse "noCaptcha";
  1820.             } else {
  1821.                 $captchaResponse $request->get('g-recaptcha-response');
  1822.             }
  1823.             //print('<br>Captcha qqw: '.$captchaResponse);
  1824.             //die();
  1825.             //if ($form->isValid() && $this->captchaVerify($request->get('g-recaptcha-response')) != null) {
  1826.             if ($form->isValid() && $captchaResponse && (int)$form['form_control_question']->getData() == 17) {
  1827.                 // perform some action, such as save the object to the database
  1828.                 $formData $form->getData();
  1829.         
  1830.                 /* we check if this contact already exists */
  1831.                 $contactExist $dem->getRepository(Contact::class)->getContactFromUsername($formData->getContactUserName());
  1832.         
  1833. //                print('<br>qqw contact exists: ');
  1834. //                \Doctrine\Common\Util\Debug::dump($contactExist);
  1835.                 if($contactExist === null) {
  1836.         
  1837.                     /* we check if the password fields are the same */
  1838.                     //$password = $request->request->get('form')['password'];
  1839.                     //$retypePassword = $request->request->get('form')['password_retype'];
  1840.                         //print('<br>We create new contact');
  1841.         
  1842.                         $password md5($formData->getContactUserPassword());
  1843.         
  1844.                         /* we load contact data from register form into contact object */
  1845.                         $contact->setFirstName($formData->getFirstName());
  1846.                         $contact->setLastName($formData->getLastName());
  1847.                         $contact->setCompanyName($formData->getCompanyName());
  1848.                         $contact->setContactUserName($formData->getContactUserName());
  1849.                         $contact->setEmail($formData->getEmail());
  1850.                         $contact->setPhone($formData->getPhone());
  1851.                         //$contact->setAddress1($request->request->get('form')['address']);
  1852.                         $contact->setContactUserPassword($password);
  1853.                         $address $contact->getAddress();
  1854.                         if(empty($address)) {
  1855.                            $address = new Address
  1856.                         }
  1857.                         $address->setStreet($form['addressStreet']->getData());
  1858.                         $address->setStreetNumber($form['addressStreetNumber']->getData());
  1859.                         $address->setCity($form['addressCity']->getData());
  1860.                         $address->setZipCode($form['addressZipCode']->getData());
  1861.                         $address->setCountry($form['addressCountry']->getData());
  1862.                         $contact->setAddress($address);      
  1863.                         $contact->setBusinessId($formData->getBusinessId());
  1864.                         $contact->setDICId($formData->getDICId());
  1865.                         /*
  1866.                         print('<br>qqw user exists: ');
  1867.                         \Doctrine\Common\Util\Debug::dump($contact);
  1868.                         */
  1869.          
  1870.                         /* we remove old consents */
  1871.                         if(!empty($contact->getConsents())) {
  1872.                             foreach($contact->getConsents() as $consent) {
  1873.                                 $contact->removeConsent($consent);
  1874.                                 //$dem->refresh($product);
  1875.                                 //$dem->persist($cat);
  1876.                             }
  1877.                         }
  1878.                         /* we save consents */
  1879.                         if(!empty($form['consents']->getData())) {
  1880.                             foreach($form['consents']->getData() as $consentId) {
  1881.                                 $consent $dem->getRepository(Consent::class)->getConsent($consentId);
  1882.                                 $contact->addConsent($consent);                
  1883.                             }
  1884.                         } 
  1885.                         /* we persist and save contact */
  1886.                         $dem->persist($contact);
  1887.                         $dem->flush();
  1888.         
  1889.                         $this->addFlash('notice'$this->translator->trans('eshop.contact_new_created'));
  1890.                         
  1891.                         /* we load logged contact into session */
  1892.                         $session $request->getSession();
  1893.                         $session->set('contact'$contact);    
  1894.                          /* we prepare emailing about registration */
  1895.                         $name $eshop->getEshopName();
  1896.                         $to      $user->getEmail(); 
  1897.                         $subject $name.' - '.$this->translator->trans('eshop.email_register_subject').': #'.$contact->getContactId();
  1898.                         $message $this->translator->trans('eshop.email_register_text');
  1899.                         /* we load order email cms text for the current eshop */
  1900.                         $orderEmail $dem->getRepository(WebPage::class)->getEmailRegister($eshopId);
  1901.                         if(!empty($orderEmail)) {
  1902.                             $message .= $orderEmail->getWebPageContent();
  1903.                         }                          
  1904.                         /* we load register email cms text for the current eshop */
  1905.                         $emailText $this->getRegisterEmail($request$eshop$contact);
  1906.                         $message .= $emailText;
  1907.                         $from 'noreply@easycommerc.com';
  1908.                         /*
  1909.                         $headers  = "MIME-Version: 1.0\r\n";
  1910.                         $headers .= "Content-type: text/html; charset=UTF-8\r\n";
  1911.                         $headers .= "From: {$name} <{$from}>\r\n";
  1912.                         $headers .= "Reply-To: <{$from}>\r\n";
  1913.                         $headers .= "Subject: {$subject}\r\n";
  1914.                         $headers .= "X-Mailer: PHP/".phpversion()."\r\n";
  1915.                         */
  1916.                         // we send email to eshop owner
  1917.                         if($this->sendEmail($to$subject$from$message)) {
  1918.                             if(!empty($user->getContactPersonEmail())) {
  1919.                                 $this->sendEmail($user->getContactPersonEmail(), $subject$from$message);
  1920.                             }
  1921.                             $mailToAdminStatus $this->translator->trans('eshop.email_admin_order_ok').': '.$to;
  1922.                         } else {
  1923.                             $mailToAdminStatus $this->translator->trans('eshop.email_admin_order_error'.': '.$to);
  1924.                         }
  1925.                         // we send email to customer 
  1926.                         $to      $contact->getEmail();    
  1927.                         if($this->sendEmail($to$subject$from$message)) {
  1928.                             $mailToCustomerStatus $this->translator->trans('eshop.email_customer_order_ok').': '.$to;
  1929.                         } else {   
  1930.                             $mailToCustomerStatus $this->translator->trans('eshop.email_customer_order_error'.': '.$to);
  1931.                         }
  1932.                         
  1933.                         /*
  1934.                         // we send email to e-shop admin 
  1935.                         if(@mail($to, $subject, $message, $headers)) {
  1936.                             //print('<br>Email was sent.');
  1937.                             //we send email to users contact person
  1938.                             if(!empty($user->getContactPersonEmail())) {
  1939.                                 mail($user->getContactPersonEmail(), $subject, $message, $headers);
  1940.                                 //die('<br>qqw register email to: '.$user->getContactPersonEmail());
  1941.                             }
  1942.                             $mailToAdminStatus = $this->translator->trans('eshop.email_admin_order_ok').': '.$to;
  1943.                         } else {
  1944.                             //print('<br>Email was not sent.');
  1945.                             $mailToAdminStatus = $this->translator->trans('eshop.email_admin_order_error'.': '.$to);
  1946.                         }   
  1947.   
  1948.                         // we send email to customer 
  1949.                         $to      = $contact->getEmail();    
  1950.                         if(@mail($to, $subject, $message, $headers)) {
  1951.                             //print('<br>Email was sent.');
  1952.                             $mailToCustomerStatus = $this->translator->trans('eshop.email_customer_order_ok').': '.$to;
  1953.                         } else {
  1954.                             //print('<br>Email was not sent.');
  1955.                             $mailToCustomerStatus = $this->translator->trans('eshop.email_customer_order_error'.': '.$to);
  1956.                         }         
  1957.                         */                                  
  1958.                         
  1959.                         return $this->redirectToRoute('eshopHomeContact', array('eshopId' => $eshopId));
  1960.         
  1961.                 }
  1962.                 else {
  1963.                     $this->addFlash('error'$this->translator->trans('eshop.contact_already_exist')); 
  1964.                 }
  1965.         
  1966.             } else {
  1967.                 $this->addFlash('error'$this->translator->trans('system.form_not_valid')); 
  1968.             }
  1969.         
  1970.         }       
  1971.         
  1972.         /* we render data */
  1973.         return $this->render('eshopRegister.html.twig',
  1974.                 array(  'headerData' => $this -> getPageHeader($request),
  1975.                         'form' => $formBuilder->getForm()->createView(),
  1976.                         'menu' => $this -> adminMenu($request),'mainMenu' => $this -> adminMainMenu($request),'mainMenu' => $this -> adminMainMenu($request),
  1977.                         'eshop' => $eshop,
  1978.                         'user' => $user,
  1979.                         'wireFrame' => $wireFrame,
  1980.                         'categoryTreeMenu' => $this->categoryTreeMenu($eshop$request),
  1981.                         'categoryTopMenu' => $this->categoryTopMenu($eshop$request),
  1982.                         'eshopHeader' => $eshopHeader,
  1983.                         'eshopFooter' => $eshopFooter,  
  1984.                         'homePage' => $homePage,  
  1985.                         'consentList' => $consentList
  1986.                         'consentDescriptions' => $consentDescriptions,    
  1987.                         'reCaptcha' => $reCaptcha,                                                  
  1988.                 )
  1989.                 );
  1990.     
  1991.     }    
  1992.     
  1993.     /**
  1994.      * @Route("/eshop/{eshopId}/editContact", name="eshopEditContact")
  1995.      */
  1996.     public function eshopEditContactAction(Request $request$eshopId)
  1997.     {
  1998.     
  1999.         /* we load session data */
  2000.         parent::init($request);
  2001.         $session $request->getSession();
  2002.         /* we load entity managers */
  2003.         $em $this->doctrine->getManager();
  2004.         $dem $this->doctrine->getManager('dynamic_em');
  2005.     
  2006.         /* we get current e-shop */
  2007.         $eshop $em->getRepository(Eshop::class)->getEshop($eshopId);
  2008.     
  2009.         $user $em->getRepository(User::class)->getUser($eshop->getUserId());
  2010.          
  2011.         /* we check if eshop exists */
  2012.         if($eshop === null) {
  2013.             $this->addFlash('error''E-shop with this ID does not exist.');
  2014.             return $this->redirectToRoute('eshopHome');
  2015.         }
  2016.         /* we check if customer exists */
  2017.         if(empty($session->get('contact'))) {
  2018.             $this->addFlash('error''Customer does not exists.');
  2019.             return $this->redirectToRoute('eshopHome');
  2020.         } else {
  2021.            //$contact = $session->get('contact');
  2022.            //$contact = $dem->getRepository(Contact::class)->getContactFromUsername($session->get('contact')->getContactUserName());
  2023.             $contact $dem->getRepository(Contact::class)->getContact($session->get('contact')->getContactId());
  2024.         }
  2025.         $eshopHeader $dem->getRepository(Eshop::class)->getEshopHeader($eshopId);
  2026.         if(!empty($eshopHeader)) {
  2027.           $eshopHeader->setLocale($session->get('lang')->getLangKey());
  2028.           $dem->refresh($eshopHeader);            
  2029.         }
  2030.         /* we load footer for the current website */
  2031.         $eshopFooter $dem->getRepository(Eshop::class)->getEshopFooter($eshopId);
  2032.         if(!empty($eshopFooter)) {         
  2033.           $eshopFooter->setLocale($session->get('lang')->getLangKey());
  2034.           $dem->refresh($eshopFooter);  
  2035.         }  
  2036.       
  2037.         /* we load home page for the current website */
  2038.         $homePage $dem->getRepository(Eshop::class)->getHomePage($eshopId);
  2039.         $wireFrame $em->getRepository(WireFrame::class)->getWireFrame($eshop->getProductDetailWireFrameId());
  2040.         /*
  2041.         print('<br>qqw c address: ');
  2042.         \Doctrine\Common\Util\Debug::dump($contact->getAddress());
  2043.         */
  2044.         /* we prepare data for the form */
  2045.         if(!empty($contact->getLastName())) {
  2046.             $lastName $contact->getLastName();
  2047.         } else {
  2048.             $lastName '';
  2049.         }   
  2050.         if(!empty($contact->getFirstName())) {
  2051.             $firstName $contact->getFirstName();
  2052.         } else {
  2053.             $firstName '';
  2054.         }              
  2055.         if(!empty($contact->getCompanyName())) {
  2056.             $company $contact->getCompanyName();
  2057.         } else {
  2058.             $company '';
  2059.         }
  2060.         if(!empty($contact->getEmail())) {
  2061.             $email $contact->getEmail();
  2062.         } else {
  2063.             $email '';
  2064.         }
  2065.         if(!empty($contact->getPhone())) {
  2066.             $telefon $contact->getPhone();
  2067.         } else {
  2068.             $telefon '';
  2069.         }
  2070.         if(!empty($contact->getAddress()) && !empty($contact->getAddress()->getStreet())) {
  2071.             $addressStreet $contact->getAddress()->getStreet();
  2072.         } else {
  2073.             $addressStreet '';
  2074.         } 
  2075.         if(!empty($contact->getAddress()) && !empty($contact->getAddress()->getStreetNumber())) {
  2076.             $addressStreetNumber $contact->getAddress()->getStreetNumber();
  2077.         } else {
  2078.             $addressStreetNumber '';
  2079.         }   
  2080.         if(!empty($contact->getAddress()) && !empty($contact->getAddress()->getCity())) {
  2081.             $addressCity $contact->getAddress()->getCity();
  2082.         } else {
  2083.             $addressCity '';
  2084.         } 
  2085.         if(!empty($contact->getAddress()) && !empty($contact->getAddress()->getZipCode())) {
  2086.             $addressZipCode $contact->getAddress()->getZipCode();
  2087.         } else {
  2088.             $addressZipCode '';
  2089.         }          
  2090.         if(!empty($contact->getAddress()) && !empty($contact->getAddress()->getCountry())) {
  2091.             $addressCountry $contact->getAddress()->getCountry();
  2092.         } else {
  2093.             $addressCountry '';
  2094.         }                             
  2095.         if(!empty($contact->getContactUserName())) {
  2096.             $username $contact->getContactUserName();
  2097.         } else {
  2098.             $username '';
  2099.         }
  2100.         /*
  2101.         if(!empty($contact->getContactUserPassword())) {
  2102.             $password = $contact->getContactUserPassword();
  2103.         } else {
  2104.             $password = '';
  2105.         }   
  2106.         */
  2107.         if(!empty($contact->getBusinessId())) {
  2108.             $businessId $contact->getBusinessId();
  2109.         } else {
  2110.             $businessId '';
  2111.         }     
  2112.         if(!empty($contact->getDICId())) {
  2113.             $DICId $contact->getDICId();
  2114.         } else {
  2115.             $DICId '';
  2116.         }               
  2117.         
  2118.         /* we build register form */
  2119.         $formBuilder $this->createFormBuilder();
  2120.         $formBuilder->add('contactId'HiddenType::class, [
  2121.             'data' => $contact->getContactId(),
  2122.         ]);
  2123.         
  2124.         $formBuilder->add('lastName'TextType::class, array(
  2125.                 'required' => true,
  2126.                 'label' => $this->translator->trans('knowledgebase.last_name'),
  2127.                 'attr' => array('class' => 'text_form''size' => 35'value' => $lastName),
  2128.                 'label_attr' => array('class' => 'form_field_label_required')
  2129.         ));
  2130.         $formBuilder->add('firstName'TextType::class, array(
  2131.                 'required' => true,
  2132.                 'label' => $this->translator->trans('knowledgebase.first_name'),
  2133.                 'attr' => array('class' => 'text_form''size' => 35'value' => $firstName),
  2134.                 'label_attr' => array('class' => 'form_field_label_required')
  2135.         )); 
  2136.         $formBuilder->add('email'EmailType::class, array(
  2137.                 'required' => true,
  2138.                 'attr' => array('class' => 'text_form''size' => 35'value' => $email),
  2139.                 'label_attr' => array('class' => 'form_field_label_required'),
  2140.         ));  
  2141.         /*
  2142.         $formBuilder->add('username', TextType::class, array(
  2143.                 'required' => true,
  2144.                 'label' => $this->translator->trans('user.username'),
  2145.                 'empty_data'  => '',
  2146.                 'attr' => array('class' => 'text_form', 'size' => 35, 'value' => $username),
  2147.                 'label_attr' => array('class' => 'form_field_label_required'),
  2148.         ));          
  2149.         */
  2150.         /*
  2151.         $formBuilder->add('password', PasswordType::class, array(
  2152.                 'required' => true,
  2153.                 'label' => $this->translator->trans('user.password'),
  2154.                 'attr' => array('class' => 'text_form', 'size' => 35, 'value' => $password),
  2155.                 'label_attr' => array('class' => 'form_field_label_required'),
  2156.         ));   
  2157.         */                 
  2158.         /*
  2159.         $formBuilder->add('password_retype', PasswordType::class, array(
  2160.                 'required' => true,
  2161.                 'label' => $this->translator->trans('user.password_retype'),
  2162.                 'attr' => array('class' => 'text_form', 'size' => 35, 'value' => $password_retype),
  2163.                 'label_attr' => array('class' => 'form_field_label_required'),
  2164.         )); 
  2165.         */ 
  2166.         $formBuilder->add('telefon'TextType::class, array(
  2167.                 'required' => false,
  2168.                 'label' => $this->translator->trans('user.telephone'),
  2169.                 'attr' => array('class' => 'text_form''size' => 35'value' => $telefon),
  2170.                 'label_attr' => array('class' => 'form_field_label'),
  2171.         ));
  2172.         /* we add address */
  2173.         $formBuilder->add('addressStreet'TextType::class, array(
  2174.                 'required' => true
  2175.                 'label' => $this->translator->trans('address.street'),
  2176.                 'attr' => array('class' => 'text_form''size' => 35'value' => $addressStreet),
  2177.                 'label_attr' => array('class' => 'form_field_label_required'),
  2178.         ));
  2179.         $formBuilder->add('addressStreetNumber'TextType::class, array(
  2180.                 'required' => true
  2181.                 'label' => $this->translator->trans('address.street_number'),
  2182.                 'attr' => array('class' => 'text_form''size' => 10'value' => $addressStreetNumber),
  2183.                 'label_attr' => array('class' => 'form_field_label_required'),
  2184.         ));     
  2185.         $formBuilder->add('addressZipCode'TextType::class, array(
  2186.                 'required' => true
  2187.                 'label' => $this->translator->trans('address.zip_code'),
  2188.                 'attr' => array('class' => 'text_form''size' => 10'value' => $addressZipCode),
  2189.                 'label_attr' => array('class' => 'form_field_label_required'),
  2190.         ));   
  2191.         $formBuilder->add('addressCity'TextType::class, array(
  2192.                 'required' => true
  2193.                 'label' => $this->translator->trans('address.city'),
  2194.                 'attr' => array('class' => 'text_form''size' => 35'value' => $addressCity),
  2195.                 'label_attr' => array('class' => 'form_field_label_required'),
  2196.         ));       
  2197.         $formBuilder->add('addressCountry'TextType::class, array(
  2198.                 'required' => true
  2199.                 'label' => $this->translator->trans('address.country'),
  2200.                 'attr' => array('class' => 'text_form''size' => 35'value' => $addressCountry),
  2201.                 'label_attr' => array('class' => 'form_field_label_required'),
  2202.         ));
  2203.         $formBuilder->add('company'TextType::class, array(
  2204.                 'required' => false,
  2205.                 'label' => $this->translator->trans('user.company'),
  2206.                 'attr' => array('class' => 'text_form''size' => 35'value' => $company),
  2207.                 'label_attr' => array('class' => 'form_field_label')
  2208.         ));
  2209.         $formBuilder->add('businessId'TextType::class, array(
  2210.                 'required' => false,
  2211.                 'label' => $this->translator->trans('user.business_number'),
  2212.                 'attr' => array('class' => 'text_form''size' => 35'value' => $businessId),
  2213.                 'label_attr' => array('class' => 'form_field_label')
  2214.         ));        
  2215.         $formBuilder->add('DICId'TextType::class, array(
  2216.                 'required' => false,
  2217.                 'label' => $this->translator->trans('user.DIC_number'),
  2218.                 'attr' => array('class' => 'text_form''size' => 35'value' => $DICId),
  2219.                 'label_attr' => array('class' => 'form_field_label')
  2220.         ));  
  2221.         /*
  2222.         $formBuilder->add('address', TextareaType::class, array(
  2223.                 'required' => false,
  2224.                 'label' => $this->translator->trans('user.address'),
  2225.                 'attr' => array('class' => 'textarea_form', 'cols' => 33, 'rows' => 2, 'value' => $address),
  2226.                 'label_attr' => array('class' => 'form_textarea_label'),
  2227.         ));
  2228.         */
  2229.         
  2230.         $formBuilder->add('save'SubmitType::class, array('label' => $this->translator->trans('form.button.save'),
  2231.                 'attr' => array('class' => 'butt_big')));
  2232.         
  2233.         $form $formBuilder->getForm();
  2234.         
  2235.         $form->handleRequest($request);
  2236.         
  2237.         if ($request->getMethod() == 'POST') {
  2238.         
  2239.             //$form->bindRequest($request);
  2240.         
  2241.             if ($form->isValid()) {
  2242.                 // perform some action, such as save the object to the database
  2243.                 //print('<br>qqw post form 2: ');
  2244.         
  2245.                 /* we check if this contact already exists */
  2246.                 $contact $dem->getRepository(Contact::class)->getContact($request->request->get('form')['contactId']);
  2247.         
  2248.                         /* we load contact data from register form into contact object */
  2249.                         $contact->setFirstName($request->request->get('form')['firstName']);
  2250.                         $contact->setLastName($request->request->get('form')['lastName']);
  2251.                         $contact->setCompanyName($request->request->get('form')['company']);
  2252.                         //$contact->setContactUserName($request->request->get('form')['username']);
  2253.                         $contact->setEmail($request->request->get('form')['email']);
  2254.                         //$contact->setAddress1($request->request->get('form')['address']);
  2255.                         //$contact->setContactUserPassword($password);
  2256.                         $address $contact->getAddress();
  2257.                         if(empty($address)) {
  2258.                            $address = new Address
  2259.                         }
  2260.                         $address->setStreet($request->request->get('form')['addressStreet']);
  2261.                         $address->setStreetNumber($request->request->get('form')['addressStreetNumber']);
  2262.                         $address->setCity($request->request->get('form')['addressCity']);
  2263.                         $address->setZipCode($request->request->get('form')['addressZipCode']);
  2264.                         $address->setCountry($request->request->get('form')['addressCountry']);
  2265.                         $contact->setAddress($address);                        
  2266.                         $contact->setBusinessId($request->request->get('form')['businessId']);
  2267.                         $contact->setDICId($request->request->get('form')['DICId']);
  2268.          
  2269.                         /* we persist and save contact */
  2270.                         $dem->persist($contact);
  2271.                         $dem->flush();
  2272.         
  2273.                         $this->addFlash('notice'$this->translator->trans('eshop.contact_updated'));
  2274.                         
  2275.                         /* we load logged contact into session */
  2276.                         $session $request->getSession();
  2277.                         $session->set('contact'$contact);                                        
  2278.                         
  2279.                         return $this->redirectToRoute('eshopHomeContact', array('eshopId' => $eshopId));
  2280.         
  2281.         
  2282.             }
  2283.         
  2284.         }       
  2285.         
  2286.         /* we render data */
  2287.         return $this->render('eshopEditContact.html.twig',
  2288.                 array(  'headerData' => $this -> getPageHeader($request),
  2289.                         'form' => $formBuilder->getForm()->createView(),
  2290.                         'menu' => $this -> adminMenu($request),'mainMenu' => $this -> adminMainMenu($request),'mainMenu' => $this -> adminMainMenu($request),
  2291.                         'eshop' => $eshop,
  2292.                         'user' => $user,
  2293.                         'wireFrame' => $wireFrame,
  2294.                         'categoryTreeMenu' => $this->categoryTreeMenu($eshop$request),
  2295.               'categoryTopMenu' => $this->categoryTopMenu($eshop$request),
  2296.               'eshopHeader' => $eshopHeader,
  2297.                         'eshopFooter' => $eshopFooter,  
  2298.               'homePage' => $homePage,      
  2299.                 )
  2300.                 );
  2301.     
  2302.     }    
  2303.     /**
  2304.      * @Route("/eshop/{eshopId}/logout", name="eshopLogout")
  2305.      */
  2306.     public function eshopLogoutAction(Request $request$eshopId) {
  2307.     
  2308.         /* we load session data */
  2309.         parent::init($request);
  2310.     
  2311.         /* we unload logged user session */
  2312.         $session $request->getSession();
  2313.         $session->set('contact'null);
  2314.         $this->addFlash('notice'$this->translator->trans('eshop.customer_logged_out'));
  2315.     
  2316.         return $this->redirectToRoute('eshop', array('eshopId' => $eshopId));
  2317.     
  2318.     }    
  2319.     
  2320.     /**
  2321.      * @Route("/eshop/{eshopId}/login", name="eshopLogin")
  2322.      */
  2323.     public function eshopLoginAction(Request $request$eshopId)
  2324.     {
  2325.     
  2326.         /* we load session data */
  2327.         parent::init($request);
  2328.         $session $request->getSession();
  2329.     
  2330.         /* we load entity managers */
  2331.         $em $this->doctrine->getManager();
  2332.         $dem $this->doctrine->getManager('dynamic_em');
  2333.     
  2334.         /* we get current e-shop */
  2335.         $eshop $em->getRepository(Eshop::class)->getEshop($eshopId);
  2336.     
  2337.         $user $em->getRepository(User::class)->getUser($eshop->getUserId());
  2338.          
  2339.         /* we check if eshop exists */
  2340.         if($eshop === null) {
  2341.             $this->addFlash('error''E-shop with this ID does not exist.');
  2342.             return $this->redirectToRoute('eshopHome');
  2343.         }
  2344.     
  2345.         $eshopHeader $dem->getRepository(Eshop::class)->getEshopHeader($eshopId);
  2346.         if(!empty($eshopHeader)) {
  2347.           $eshopHeader->setLocale($session->get('lang')->getLangKey());
  2348.           $dem->refresh($eshopHeader);            
  2349.         }
  2350.         /* we load footer for the current website */
  2351.         $eshopFooter $dem->getRepository(Eshop::class)->getEshopFooter($eshopId);
  2352.         if(!empty($eshopFooter)) {         
  2353.           $eshopFooter->setLocale($session->get('lang')->getLangKey());
  2354.           $dem->refresh($eshopFooter);  
  2355.         }  
  2356.       
  2357.         /* we load home page for the current website */
  2358.         $homePage $dem->getRepository(Eshop::class)->getHomePage($eshopId);
  2359.         $wireFrame $em->getRepository(WireFrame::class)->getWireFrame($eshop->getProductDetailWireFrameId());
  2360.     
  2361.         /* we build login form */
  2362.         $formBuilder $this->createFormBuilder();
  2363.         
  2364.         $formBuilder->add('username'TextType::class, array(
  2365.                 'required' => true,
  2366.                 'mapped' => false,
  2367.                 'label' => $this->translator->trans('user.username'),
  2368.                 'attr' => array('class' => 'text_form''size' => 22),
  2369.                 'label_attr' => array('class' => 'form_field_label'),
  2370.         ));
  2371.         
  2372.         $formBuilder->add('password'PasswordType::class, array(
  2373.                 'required' => true,
  2374.                 'mapped' => false,
  2375.                 'label' => $this->translator->trans('user.password'),
  2376.                 'attr' => array('class' => 'text_form''size' => 22),
  2377.                 'label_attr' => array('class' => 'form_field_label'),
  2378.         ));
  2379.         
  2380.         $formBuilder->add('save'SubmitType::class, array('label' => 'Login',
  2381.                 'attr' => array('class' => 'butt_big')));
  2382.         
  2383.         $form $formBuilder->getForm();
  2384.         
  2385.         $form->handleRequest($request);
  2386.         
  2387.         if ($request->getMethod() == 'POST') {
  2388.         
  2389.             //$form->bindRequest($request);
  2390.             //print('<br>qqw post dude');
  2391.         
  2392.             //if ($form->isValid()) {
  2393.                 // perform some action, such as save the object to the database
  2394.                 /* we check if this username exists */
  2395.                 $em $this->doctrine->getManager();
  2396.         
  2397.                 $userName $form['username']->getData();
  2398.         
  2399.                 $contactExist $dem->getRepository(Contact::class)->getContactFromLogin($userName$form['password']->getData());
  2400.                  /*        
  2401.                  print('<br>qqw contact exists: ');
  2402.                  \Doctrine\Common\Util\Debug::dump($contactExist);
  2403.                  */
  2404.                 
  2405.                 //die();
  2406.                 if(!empty($contactExist)) {
  2407.                     $contact $dem->getRepository(Contact::class)->getContact($contactExist->getContactId());
  2408.                     /* we load logged contact into session */
  2409.                     $session $request->getSession();
  2410.                     //$session->set('contact', $contactExist);
  2411.                     $session->set('contact'$contact);                    
  2412.                     //print('<br>qqw x contact: ');
  2413.                     //\Doctrine\Common\Util\Debug::dump($contact);
  2414.                     //print('<br>qqw x Street: '.$session->get('contact')->getAddress()->getStreet());
  2415.                     
  2416.                     //die(); 
  2417.         
  2418.                     /*
  2419.                      print('<hr>we set session contact: ');
  2420.                      \Doctrine\Common\Util\Debug::dump($session->get('contact'));
  2421.                      */
  2422.         
  2423.                     $this->addFlash('notice'$this->translator->trans('system.welcome').' '.$userName.'. '.$this->translator->trans('eshop.customer_logged_in'));
  2424.         
  2425.                     if(!empty($request->request->get('returnRoute'))) {
  2426.                         return $this->redirectToRoute($request->request->get('returnRoute'), array('eshopId' => $eshopId));
  2427.                     } else {
  2428.                         return $this->redirectToRoute('eshopHomeContact', array('eshopId' => $eshopId));
  2429.                     }
  2430.                 }
  2431.                 else {
  2432.                     $this->addFlash('error''Login error.');
  2433.                 }
  2434.         
  2435.             //}
  2436.         
  2437.         }       
  2438.         
  2439.         /* we render data */
  2440.         return $this->render('eshopLogin.html.twig',
  2441.                 array(  'headerData' => $this -> getPageHeader($request),
  2442.                         'form' => $formBuilder->getForm()->createView(),
  2443.                         'menu' => $this -> adminMenu($request),'mainMenu' => $this -> adminMainMenu($request),'mainMenu' => $this -> adminMainMenu($request),
  2444.                         'eshop' => $eshop,
  2445.                         'user' => $user,
  2446.                         'wireFrame' => $wireFrame,
  2447.                         'categoryTreeMenu' => $this->categoryTreeMenu($eshop$request),
  2448.                         'categoryTopMenu' => $this->categoryTopMenu($eshop$request),
  2449.                         'eshopHeader' => $eshopHeader,
  2450.                         'eshopFooter' => $eshopFooter,  
  2451.                         'homePage' => $homePage,
  2452.                 )
  2453.                 );
  2454.         
  2455.         }    
  2456.         
  2457.     /**
  2458.      * @Route("/eshop/{eshopId}/forgottenpassword", name="eshopForgottenPassword")
  2459.      */ 
  2460.     public function eshopForgottenPasswordAction(Request $request$eshopId)
  2461.     {
  2462.     
  2463.         /* we load session data */
  2464.         parent::init($request);
  2465.         $session $request->getSession();
  2466.     
  2467.         /* we load entity managers */
  2468.         $em $this->doctrine->getManager();
  2469.         $dem $this->doctrine->getManager('dynamic_em');
  2470.     
  2471.         /* we get current e-shop */
  2472.         $eshop $em->getRepository(Eshop::class)->getEshop($eshopId);
  2473.     
  2474.         $user $em->getRepository(User::class)->getUser($eshop->getUserId());
  2475.          
  2476.         /* we check if eshop exists */
  2477.         if($eshop === null) {
  2478.             $this->addFlash('error''E-shop with this ID does not exist.');
  2479.             return $this->redirectToRoute('eshopHome');
  2480.         }
  2481.     
  2482.         $eshopHeader $dem->getRepository(Eshop::class)->getEshopHeader($eshopId);
  2483.         if(!empty($eshopHeader)) {
  2484.           $eshopHeader->setLocale($session->get('lang')->getLangKey());
  2485.           $dem->refresh($eshopHeader);            
  2486.         }
  2487.         /* we load footer for the current website */
  2488.         $eshopFooter $dem->getRepository(Eshop::class)->getEshopFooter($eshopId);
  2489.         if(!empty($eshopFooter)) {         
  2490.           $eshopFooter->setLocale($session->get('lang')->getLangKey());
  2491.           $dem->refresh($eshopFooter);  
  2492.         }  
  2493.       
  2494.         /* we load home page for the current website */
  2495.         $homePage $dem->getRepository(Eshop::class)->getHomePage($eshopId);
  2496.         $wireFrame $em->getRepository(WireFrame::class)->getWireFrame($eshop->getProductDetailWireFrameId());
  2497.     
  2498.         /* we build login form */
  2499.         $formBuilder $this->createFormBuilder();
  2500.         
  2501.         $formBuilder->add('email'EmailType::class, array(
  2502.                 'required' => true,
  2503.                 'label' => $this->translator->trans('knowledgebase.email'),
  2504.                 'attr' => array('class' => 'text_form''size' => 22),
  2505.                 'label_attr' => array('class' => 'form_field_label'),
  2506.         ));
  2507.         
  2508.         $formBuilder->add('save'SubmitType::class, array('label' => $this->translator->trans('form.send'),
  2509.                 'attr' => array('class' => 'butt_big')));
  2510.         
  2511.         $form $formBuilder->getForm();
  2512.         
  2513.         $form->handleRequest($request);
  2514.         //phpinfo();
  2515.         
  2516.         if ($request->getMethod() == 'POST') {
  2517.         
  2518.             //$form->bindRequest($request);
  2519.             //print('<br>qqw post dude');
  2520.             //$email = $request->request->get('form')['email'];
  2521.             $emailAddress $form['email']->getData();
  2522.             $contact $dem->getRepository(Contact::class)->getContactFromEmail($emailAddress);
  2523.             if(!empty($contact)) {
  2524.             //if ($form->isValid()) {
  2525.                 // send emails
  2526.                 /* we check if this username exists */
  2527.                 $em $this->doctrine->getManager();
  2528.                 /* we prepare emailing */
  2529.                 //print('from: '.$user->getEmail());
  2530.                 //print('<br>to: '.$emailAddress);
  2531.                 $name $eshop->getEshopName();
  2532.                 $subject $name.' - '.$this->translator->trans('user.forgotten_password').': '.$eshop->getEshopName();
  2533.                 $messageBody $this->translator->trans('user.forgotten_password');
  2534.                 $emailText $this->getForgottenPasswordEmail($request$eshop$emailAddress);
  2535.                 $messageBody .= $emailText;
  2536.                 
  2537.                 if($this->sendEmail($emailAddress$subject$user->getEmail(), $messageBody)) {
  2538.                     $this->addFlash('notice'$this->translator->trans('user.forgotten_password_sent').': '.$emailAddress);
  2539.                 } else {
  2540.                     $this->addFlash('error'$this->translator->trans('user.forgotten_password_sent_error').': '.$emailAddress);
  2541.                 }
  2542.                 //return $this->redirectToRoute('eshopForgottenPassword', array('eshopId' => $eshopId));
  2543.                  /*        
  2544.                  print('<br>qqw contact exists: ');
  2545.                  \Doctrine\Common\Util\Debug::dump($contactExist);
  2546.                  */
  2547.             } else {
  2548.                 $this->addFlash('error'$this->translator->trans('eshop.contact_new_psw_fields').': '.$email);
  2549.             }
  2550.             //}
  2551.         
  2552.         }       
  2553.         
  2554.         /* we render data */
  2555.         return $this->render('eshopForgottenPassword.html.twig',
  2556.                 array(  'headerData' => $this -> getPageHeader($request),
  2557.                         'form' => $formBuilder->getForm()->createView(),
  2558.                         'menu' => $this -> adminMenu($request),'mainMenu' => $this -> adminMainMenu($request),'mainMenu' => $this -> adminMainMenu($request),
  2559.                         'eshop' => $eshop,
  2560.                         'user' => $user,
  2561.                         'wireFrame' => $wireFrame,
  2562.                         'categoryTreeMenu' => $this->categoryTreeMenu($eshop$request),
  2563.                         'categoryTopMenu' => $this->categoryTopMenu($eshop$request),
  2564.                         'eshopHeader' => $eshopHeader,
  2565.                         'eshopFooter' => $eshopFooter,  
  2566.                         'homePage' => $homePage,     
  2567.                 )
  2568.                 );
  2569.         
  2570.         }    
  2571.         /**
  2572.          * @Route("/eshop/{eshopId}/forgottenpasswordupdate/{customerEmail}", name="eshopForgottenPasswordUpdate")
  2573.          */ 
  2574.         public function eshopForgottenPasswordUpdateAction(Request $request$eshopId$customerEmail)
  2575.         {     
  2576.         
  2577.             /* we load session data */
  2578.             parent::init($request);
  2579.             $session $request->getSession();
  2580.         
  2581.             /* we load entity managers */
  2582.             $em $this->doctrine->getManager();
  2583.             $dem $this->doctrine->getManager('dynamic_em');
  2584.         
  2585.             /* we get current e-shop */
  2586.             $eshop $em->getRepository(Eshop::class)->getEshop($eshopId);
  2587.         
  2588.             $user $em->getRepository(User::class)->getUser($eshop->getUserId());
  2589.              
  2590.             /* we check if eshop exists */
  2591.             if($eshop === null) {
  2592.                 $this->addFlash('error''E-shop with this ID does not exist.');
  2593.                 return $this->redirectToRoute('eshopHome');
  2594.             }
  2595.             $contact $dem->getRepository(Contact::class)->getContactFromEmail($customerEmail);
  2596.         
  2597.             $eshopHeader $dem->getRepository(Eshop::class)->getEshopHeader($eshopId);
  2598.             if(!empty($eshopHeader)) {
  2599.               $eshopHeader->setLocale($session->get('lang')->getLangKey());
  2600.               $dem->refresh($eshopHeader);            
  2601.             }
  2602.             /* we load footer for the current website */
  2603.             $eshopFooter $dem->getRepository(Eshop::class)->getEshopFooter($eshopId);
  2604.             if(!empty($eshopFooter)) {         
  2605.               $eshopFooter->setLocale($session->get('lang')->getLangKey());
  2606.               $dem->refresh($eshopFooter);  
  2607.             }  
  2608.           
  2609.             /* we load home page for the current website */
  2610.             $homePage $dem->getRepository(Eshop::class)->getHomePage($eshopId);
  2611.             $wireFrame $em->getRepository(WireFrame::class)->getWireFrame($eshop->getProductDetailWireFrameId());
  2612.         
  2613.             /* we build login form */
  2614.             $formBuilder $this->createFormBuilder();
  2615.             
  2616.             $formBuilder->add('password_new'TextType::class, array(
  2617.                     'required' => true,
  2618.                     'label' => $this->translator->trans('user.password_new'),
  2619.                     'attr' => array('class' => 'text_form''size' => 22),
  2620.                     'label_attr' => array('class' => 'form_field_label'),
  2621.             ));
  2622.             $formBuilder->add('password_new_retype'TextType::class, array(
  2623.                     'required' => true,
  2624.                     'label' => $this->translator->trans('user.password_new'),
  2625.                     'attr' => array('class' => 'text_form''size' => 22),
  2626.                     'label_attr' => array('class' => 'form_field_label'),
  2627.             ));            
  2628.             
  2629.             $formBuilder->add('save'SubmitType::class, array('label' => $this->translator->trans('form.send'),
  2630.                     'attr' => array('class' => 'butt_big')));
  2631.             
  2632.             $form $formBuilder->getForm();
  2633.             
  2634.             $form->handleRequest($request);
  2635.             
  2636.             if ($request->getMethod() == 'POST') {
  2637.                 //print('<br>qqw post dude');
  2638.                 $psw $request->request->get('form')['password_new'];
  2639.                 $psw_retype $request->request->get('form')['password_new_retype'];
  2640.                 if($psw === $psw_retype) {
  2641.                     //print('<br>qqw we change password');
  2642.                     $password md5($psw);
  2643.                     $contact->setContactUserPassword($password);
  2644.                     
  2645.                     $dem->persist($contact);
  2646.                     $dem->flush();
  2647.                     $this->addFlash('notice'$this->translator->trans('user.password_changed'));
  2648.                 } else {
  2649.                     $this->addFlash('error'$this->translator->trans('eshop.contact_new_psw_fields'));
  2650.                 }
  2651.             }    
  2652.             /* we render data */
  2653.             return $this->render('eshopForgottenPasswordUpdate.html.twig',
  2654.                     array(  'headerData' => $this -> getPageHeader($request),
  2655.                             'form' => $formBuilder->getForm()->createView(),
  2656.                             'menu' => $this -> adminMenu($request),'mainMenu' => $this -> adminMainMenu($request),'mainMenu' => $this -> adminMainMenu($request),
  2657.                             'eshop' => $eshop,
  2658.                             'user' => $user,
  2659.                             'wireFrame' => $wireFrame,
  2660.                             'categoryTreeMenu' => $this->categoryTreeMenu($eshop$request),
  2661.                   'categoryTopMenu' => $this->categoryTopMenu($eshop$request),
  2662.                   'eshopHeader' => $eshopHeader,
  2663.                             'eshopFooter' => $eshopFooter,  
  2664.                   'homePage' => $homePage,     
  2665.                     )
  2666.                     );        
  2667.         }   
  2668.         
  2669.         /**
  2670.          * @Route("/eshop/{eshopId}/eshopHomeContact", name="eshopHomeContact")
  2671.          */
  2672.         public function eshopHomeContactAction(Request $request$eshopId) {
  2673.         
  2674.             /* we load session data */
  2675.             parent::init($request);
  2676.         
  2677.             $session $request->getSession();
  2678.         
  2679.             /* we load entity managers */
  2680.             $em $this->doctrine->getManager();
  2681.             $dem $this->doctrine->getManager('dynamic_em');
  2682.         
  2683.             /* we get current e-shop */
  2684.             $eshop $em->getRepository(Eshop::class)->getEshop($eshopId);
  2685.             $defaultCurrency $em->getRepository(Currency::class)->getCurrency($eshop->getPreferredCurrencyId());
  2686.             $user $em->getRepository(User::class)->getUser($eshop->getUserId());
  2687.             $eshopHeader $dem->getRepository(Eshop::class)->getEshopHeader($eshopId);
  2688.             if(!empty($eshopHeader)) {
  2689.               $eshopHeader->setLocale($session->get('lang')->getLangKey());
  2690.               $dem->refresh($eshopHeader);            
  2691.             }
  2692.             /* we load footer for the current website */
  2693.             $eshopFooter $dem->getRepository(Eshop::class)->getEshopFooter($eshopId);
  2694.             if(!empty($eshopFooter)) {         
  2695.               $eshopFooter->setLocale($session->get('lang')->getLangKey());
  2696.               $dem->refresh($eshopFooter);  
  2697.             }  
  2698.             $wireFrame $em->getRepository(WireFrame::class)->getWireFrame($eshop->getProductDetailWireFrameId());
  2699.             // no contact logged in - we redirect to eshop login
  2700.             if(empty($session->get('contact'))) {
  2701.                 return $this->redirectToRoute('eshopLogin', array('eshopId' => $eshopId));
  2702.             }            
  2703.             $contactId $session->get('contact')->getContactId();
  2704.             $contact $dem->getRepository(Contact::class)->getContact($contactId);
  2705.             /* we load orders */
  2706.             $orderList $dem->getRepository(Order::class)->getOrderListByCustomer($contact,'orderId','DESC');
  2707.             /* we load order prices */
  2708.             $orderPrices = array();
  2709.             foreach($orderList as $order) {
  2710.                 if(!empty($order->getCurrencyKey())) {
  2711.                     $targetCurrency $em->getRepository(Currency::class)->getCurrencyByKey($order->getCurrencyKey());
  2712.                 } else {
  2713.                     $targetCurrency $defaultCurrency;
  2714.                 }
  2715.                 $orderPrices[$order->getOrderId()] = $dem->getRepository(Order::class)->getOrderPrice($order->getOrderId(), $targetCurrencyfalse$eshop$defaultCurrency);
  2716.             }              
  2717.             /*
  2718.             print('<hr>QQW orderList: ');
  2719.             \Doctrine\Common\Util\Debug::dump($orderList);  
  2720.             */          
  2721.             $topProductContent $this->getProductGroup(1$request);
  2722.             //isModule Price Levels
  2723.             $module $em->getRepository(Module::class)->getModule(22);
  2724.             $isPriceLevelModule $em->getRepository(User::class)->userHasModule($user$module);
  2725.             $priceLevelName null;
  2726.             if($isPriceLevelModule) {
  2727.                 $priceLevel $contact->getPriceLevel();
  2728.                 if(!empty($priceLevel)) {
  2729.                     $priceLevel->setLocale($session->get('lang')->getLangKey());
  2730.                     $dem->refresh($priceLevel);
  2731.                     $priceLevelName $priceLevel->getPriceLevelName();
  2732.                 }
  2733.                 //print('<br>Price Level Id: '.$priceLevel->getPriceLevelId());
  2734.                 //print('<br>qqw is module Price Level: '.$priceLevel->getPriceLevelName());
  2735.             }
  2736.             /* we add product(s) to basket - POST form action */
  2737.             if(!empty($request->request->get('basket'))) {
  2738.                 /* we call method to add to basket */
  2739.                 $this->addToBasket($request$eshopId$request->request->get('productId'));
  2740.             }
  2741.             //print('<hr>QQW topProductContent: ');
  2742.             //\Doctrine\Common\Util\Debug::dump($topProductContent); 
  2743.             /* we render data */
  2744.             return $this->render('eshopHomeContact.html.twig',
  2745.                     array('headerData' => $this -> getPageHeader($request),
  2746.                             'contact' => $contact,
  2747.                             'eshop' => $eshop,
  2748.                             'wireFrame' => $wireFrame,
  2749.                             'categoryTreeMenu' => $this->categoryTreeMenu($eshop$request),
  2750.                             'categoryTopMenu' => $this->categoryTopMenu($eshop$request),   
  2751.                             'eshopHeader' => $eshopHeader,
  2752.                             'eshopFooter' => $eshopFooter,  
  2753.                             'orderList' => $orderList
  2754.                             'orderPrices' => $orderPrices
  2755.                             'topProductContent' => $topProductContent
  2756.                             'priceLevelName' => $priceLevelName
  2757.                     )
  2758.                     );
  2759.         
  2760.         }       
  2761.         /**
  2762.          * @Route("/eshop/{eshopId}/eshopOrderContact/{orderId}", name="eshopOrderContact")
  2763.          */
  2764.         public function eshopOrderContactAction(Request $request$eshopId$orderId) {
  2765.         
  2766.             /* we load session data */
  2767.             parent::init($request);
  2768.         
  2769.             $session $request->getSession();
  2770.         
  2771.             /* we load entity managers */
  2772.             $em $this->doctrine->getManager();
  2773.             $dem $this->doctrine->getManager('dynamic_em');
  2774.         
  2775.             /* we get current e-shop */
  2776.             $eshop $em->getRepository(Eshop::class)->getEshop($eshopId);
  2777.             $eshopCurrency $em->getRepository(Currency::class)->getCurrency($eshop->getPreferredCurrencyId());
  2778.             $eshopHeader $dem->getRepository(Eshop::class)->getEshopHeader($eshopId);
  2779.             if(!empty($eshopHeader)) {
  2780.               $eshopHeader->setLocale($session->get('lang')->getLangKey());
  2781.               $dem->refresh($eshopHeader);            
  2782.             }
  2783.             /* we load footer for the current website */
  2784.             $eshopFooter $dem->getRepository(Eshop::class)->getEshopFooter($eshopId);
  2785.             if(!empty($eshopFooter)) {         
  2786.               $eshopFooter->setLocale($session->get('lang')->getLangKey());
  2787.               $dem->refresh($eshopFooter);  
  2788.             }  
  2789.             $wireFrame $em->getRepository(WireFrame::class)->getWireFrame($eshop->getProductDetailWireFrameId());
  2790.             $contactId $session->get('contact')->getContactId();
  2791.             $contact $dem->getRepository(Contact::class)->getContact($contactId);
  2792.             /* we load order */
  2793.             $order $dem->getRepository(Order::class)->getOrder($orderId);
  2794.             if(!empty($order->getCurrencyKey())) {
  2795.                 $targetCurrency $em->getRepository(Currency::class)->getCurrencyByKey($order->getCurrencyKey());
  2796.             } else {
  2797.                 $targetCurrency $eshopCurrency;
  2798.             }    
  2799.             $orderPrice $dem->getRepository(Order::class)->getOrderPrice($order->getOrderId(), $targetCurrencyfalse$eshop$eshopCurrency);
  2800.             $orderPriceVAT $dem->getRepository(Order::class)->getOrderPrice($order->getOrderId(), $targetCurrencytrue$eshop$eshopCurrency);
  2801.             if(!empty($order->getEshopDelivery())) {
  2802.                 //we set delivery cost in selected currency
  2803.                 $deliveryCost $dem->getRepository(Price::class)->getCurrencyRatedPrice($order->getEshopDelivery()->getCost(), $eshopCurrency$targetCurrency);
  2804.                 $order->getEshopDelivery()->setCost(round($deliveryCost2));
  2805.             }    
  2806.             if(!empty($order->getEshopDelivery())) {
  2807.                 //we set payment cost in selected currency
  2808.                 $paymentCost $dem->getRepository(Price::class)->getCurrencyRatedPrice($order->getEshopPayment()->getCost(), $eshopCurrency$targetCurrency);
  2809.                 $order->getEshopPayment()->setCost(round($paymentCost2));  
  2810.             }  
  2811.             
  2812.             //print('<hr>QQW order '.$orderId.': ');
  2813.             //\Doctrine\Common\Util\Debug::dump($order);                        
  2814.             /* we render data */
  2815.             return $this->render('eshopOrderContact.html.twig',
  2816.                     array('headerData' => $this -> getPageHeader($request),
  2817.                             'contact' => $contact,
  2818.                             'eshop' => $eshop,
  2819.                             'wireFrame' => $wireFrame,
  2820.                             'categoryTreeMenu' => $this->categoryTreeMenu($eshop$request),
  2821.                             'categoryTopMenu' => $this->categoryTopMenu($eshop$request),   
  2822.                             'eshopHeader' => $eshopHeader,
  2823.                             'eshopFooter' => $eshopFooter,  
  2824.                             'order' => $order
  2825.                             'orderPrice' => $orderPrice,    
  2826.                             'orderPriceVAT' => $orderPriceVAT,                                                      
  2827.                     )
  2828.                     );
  2829.         
  2830.         }               
  2831.    
  2832.         /**
  2833.          * @Route("/eshop/{eshopId}/basket", name="eshopBasket")
  2834.          */
  2835.         public function eshopBasketAction(Request $request$eshopId) {
  2836.              
  2837.             /* we load session data */
  2838.             parent::init($request);
  2839.              
  2840.             $session $request->getSession();
  2841.              
  2842.             /* we load entity managers */
  2843.             $em $this->doctrine->getManager();
  2844.             $dem $this->doctrine->getManager('dynamic_em');
  2845.              
  2846.             /* we get current e-shop */
  2847.             $eshop $em->getRepository(Eshop::class)->getEshop($eshopId);
  2848.         
  2849.             $user $em->getRepository(User::class)->getUser($eshop->getUserId());
  2850.         
  2851.             $userDirs $this->getUserFolderPathsFromUserId($eshop->getUserId());
  2852.         
  2853.             $eshopHeader $dem->getRepository(Eshop::class)->getEshopHeader($eshopId);
  2854.             if(!empty($eshopHeader)) {
  2855.               $eshopHeader->setLocale($session->get('lang')->getLangKey());
  2856.               $dem->refresh($eshopHeader);            
  2857.             }
  2858.             /* we load footer for the current website */
  2859.             $eshopFooter $dem->getRepository(Eshop::class)->getEshopFooter($eshopId);
  2860.             if(!empty($eshopFooter)) {         
  2861.               $eshopFooter->setLocale($session->get('lang')->getLangKey());
  2862.               $dem->refresh($eshopFooter);  
  2863.             }  
  2864.       
  2865.             /* we load home page for the current website */
  2866.             $homePage $dem->getRepository(Eshop::class)->getHomePage($eshopId);
  2867.             //$wireFrame = $em->getRepository(WireFrame::class)->getWireFrame($eshop->getProductDetailWireFrameId());
  2868.         
  2869.             /* removing basket item */
  2870.             if(!empty($request->query->get('removeBasketItem'))) {
  2871.                 //print('<br>qqw removing item: '.$request->query->get('removeBasketItem'));
  2872.                 
  2873.                 $processResult false;
  2874.                 foreach($session->get('order')->getOrderItems() as $orderItem) {
  2875.                   if($orderItem->getProductId() == $request->query->get('removeBasketItem')) {
  2876.                     //print('<br>qqw item exists in basket');
  2877.                     $session->get('order')->removeOrderItem($orderItem);
  2878.                     $processResult true;
  2879.                   } 
  2880.                 }
  2881.                 
  2882.                 if($processResult) {
  2883.                     $this->addFlash('notice'$this->translator->trans('eshop.basket_item_removed'));
  2884.                 }
  2885.                 
  2886.             }    
  2887.             /* we update product(s) in basket - POST form action */
  2888.             if(!empty($request->request->get('updateBasket'))) {
  2889. //                print('<br>qqw updating basket:');
  2890.                 $newUnits $request->request->all('basketItemUnit');
  2891.                 $processResult true;
  2892.                 foreach($session->get('order')->getOrderItems() as $orderItem) {
  2893.                     $productId $orderItem->getProductId();
  2894.                     $productUnits $orderItem->getOrderItemUnits();
  2895.                     //print('<br>qqw product id: '.$productId.' :: units: '.$productUnits);
  2896.                     if(!empty($newUnits[$productId])) {
  2897.                         //print(' :: qqw new units: '.$newUnits[$productId]);
  2898.                         $orderItem->setOrderItemUnits($newUnits[$productId]);
  2899.                     }
  2900.     
  2901.                 }
  2902.                 
  2903.                 if($processResult) {
  2904.                     $this->addFlash('notice'$this->translator->trans('eshop.basket_item_updated'));
  2905.                 }                
  2906.             }  
  2907.             //print('<br>qqw session order: ');
  2908.             //\Doctrine\Common\Util\Debug::dump($session->get('order'));  
  2909.             /* we remove session order if it exists and if basket is empty */
  2910.             if(!empty($session->get('order')) && count($session->get('order')->getOrderItems()) == 0) {
  2911.                 $session->remove('order');
  2912.             }                      
  2913.         
  2914.             $productThumbs = array();
  2915.             $products = array();
  2916.             if(!empty($session->get('order')) && $session->get('order')->getEshopId() == $eshopId) {
  2917.                 foreach($session->get('order')->getOrderItems() as $orderItem) {
  2918.                     $pId $orderItem->getProductId();
  2919.                     $product $dem->getRepository(Product::class)->getProduct($pId);
  2920.                     if(!empty($product)) {  
  2921.                         $products[$pId] = $product;
  2922.                     }   
  2923.                     if(!empty($product) && $product->getImage1() != "") {     
  2924.                         //$imagePath = 'users/'.$user->getUserName().'/images/'.$product->getImage1();    
  2925.                         if (strpos($product->getImage1(), 'http') === false) {
  2926.                             $imagePath 'users/'.$user->getUserName().'/images/'.$product->getImage1();
  2927.                             $imageThumbPath 'users/'.$user->getUserName().'/images/thumb_'.$product->getImage1();
  2928.                         } else {
  2929.                             $imagePath $product->getImage1();
  2930.                             $path parse_url($imagePathPHP_URL_PATH);
  2931.                             $imageThumbPath 'users/'.$user->getUserName().'/images/thumb_'.basename($path);
  2932.                         } 
  2933.                         //$imageThumbPath = 'users/'.$user->getUserName().'/images/thumb_'.$product->getImage1();
  2934.                         $imageThumb $this->getEshopImageThumb($eshop$imagePath$imageThumbPath);
  2935.                         $productThumbs[$pId] = $imageThumb;
  2936.                     }
  2937.                 }   
  2938.             }
  2939.             
  2940.             /* we render data */
  2941.             return $this->render('eshopBasket.html.twig',
  2942.                     array('headerData' => $this -> getPageHeader($request),
  2943.                             'eshop' => $eshop,
  2944.                             'wireFrame' => null,
  2945.                             'categoryTreeMenu' => $this->categoryTreeMenu($eshop$request),
  2946.                             'categoryTopMenu' => $this->categoryTopMenu($eshop$request), 
  2947.                             'eshopHeader' => $eshopHeader,
  2948.                             'eshopFooter' => $eshopFooter,  
  2949.                             'homePage' => $homePage,  
  2950.                             'products' => $products,                             
  2951.                             'productThumbs' => $productThumbs,   
  2952.                             'userDirs' => $userDirs,   
  2953.                     )
  2954.                     );
  2955.              
  2956.         }       
  2957.  
  2958.         /**
  2959.          * @Route("/eshop/{eshopId}/payment", name="payment")
  2960.          */        
  2961.         public function eshopPaymentAction(Request $request$eshopId) {
  2962.              
  2963.             /* we load session data */
  2964.             parent::init($request);
  2965.              
  2966.             $session $request->getSession();
  2967.              
  2968.             /* we load entity managers */
  2969.             $em $this->doctrine->getManager();
  2970.             $dem $this->doctrine->getManager('dynamic_em');
  2971.             /* we get current e-shop */
  2972.             $eshop $em->getRepository(Eshop::class)->getEshop($eshopId);
  2973.             $userId $eshop->getUserId();
  2974.             $user $em->getRepository(User::class)->getUser($userId);
  2975.             $defaultCurrency $em->getRepository(Currency::class)->getCurrency($eshop->getPreferredCurrencyId());
  2976.             $targetCurrency $session->get('eshopCurrency');
  2977.             $eshopHeader $dem->getRepository(Eshop::class)->getEshopHeader($eshopId);
  2978.             if(!empty($eshopHeader)) {
  2979.               $eshopHeader->setLocale($session->get('lang')->getLangKey());
  2980.               $dem->refresh($eshopHeader);            
  2981.             }
  2982.             /* we load footer for the current website */
  2983.             $eshopFooter $dem->getRepository(Eshop::class)->getEshopFooter($eshopId);
  2984.             if(!empty($eshopFooter)) {         
  2985.               $eshopFooter->setLocale($session->get('lang')->getLangKey());
  2986.               $dem->refresh($eshopFooter);  
  2987.             }  
  2988.  
  2989.             /* we add delivery to order - POST form action */;
  2990.             if(!empty($request->request->get('delivery'))) {
  2991.                 //print("<br>qqw setting order delivery 2: ".$request->request->get('delivery'));
  2992.                 $eshopDelivery $dem->getRepository(EshopDelivery::class)->getEshopDelivery($request->request->get('delivery'));
  2993.                 $session->get('order')->setEshopDelivery($eshopDelivery);
  2994.                 /*
  2995.                 print('<br>qqw orderEshopDelivery 0: ');
  2996.                 \Doctrine\Common\Util\Debug::dump($eshopDelivery);
  2997.                 */
  2998.             }     
  2999.             /* we add payment to order - POST form action */;
  3000.             if(!empty($request->request->get('paymentSubmit'))) {
  3001.                 //print('<br>qqw payment submit: '.$request->request->get('payment'));
  3002.                 
  3003.                 //$eshopPayment = $dem->getRepository(EshopPayment::class)->getEshopPayment($request->request->get('payment'));
  3004.                 $eshopPayment $dem->getRepository(EshopPayment::class)->getEshopPaymentFromPayment($request->request->get('payment'));
  3005.                 //$eshopPayment = $dem->getRepository(EshopPayment::class)->getEshopPayment(1);
  3006.                 //\Doctrine\Common\Util\Debug::dump($eshopPayment);
  3007.                 $session->get('order')->setEshopPayment($eshopPayment);
  3008.                 if(!empty($eshopPayment)) {
  3009.                     return $this->redirectToRoute('customer', array('eshopId' => $eshopId));
  3010.                 } else {
  3011.                     $this->addFlash('error'$this->translator->trans('eshop.select_payment'));  
  3012.                 }
  3013.             }                       
  3014.             //$wireFrame = $em->getRepository(WireFrame::class)->getWireFrame($eshop->getProductDetailWireFrameId());
  3015.             //$orderPrice = $dem->getRepository(Order::class)->getOrderPrice($session->get('order')->getOrderId());
  3016.              $totalPrice 0;
  3017.                 foreach($session->get('order')->getOrderItems() as $orderItem) {
  3018.                     
  3019.                     //print('<br>qqw basket order item: ');
  3020.                     //\Doctrine\Common\Util\Debug::dump($orderItem);
  3021.                     
  3022.                     if(empty($orderItem->getOrderItemPrice())) {
  3023.                         $orderItem->setOrderItemPrice(0);
  3024.                     }       
  3025.                 
  3026.                     $productPrice $orderItem->getOrderItemPrice() * $orderItem->getOrderItemUnits();
  3027.                     if(empty($productPrice)) {
  3028.                         $productPrice 0;
  3029.                     }
  3030.                     $totalPrice $totalPrice $productPrice;
  3031.                 }     
  3032.             //print('<br>qqw totalPrice 0: '.$totalPrice);       
  3033.             /* we get delivery list from master db */
  3034.             $deliveryList $em->getRepository(Delivery::class)->getDeliveryList();
  3035.             /* we get delivery list of this e-shop */
  3036.             $eshopDeliveryList = array();
  3037.             foreach($deliveryList as $delivery) {
  3038.                 $eshopDelivery $dem->getRepository(EshopDelivery::class)->getEshopDeliveryFromDelivery($delivery->getDeliveryId());  
  3039.                 if(!empty($eshopDelivery)) {
  3040.                     $eshopDelivery->setLocale($session->get('lang')->getLangKey());
  3041.                     $dem->refresh($eshopDelivery); 
  3042.                     //print('<br>QQW delivery 2: ');
  3043.                     //\Doctrine\Common\Util\Debug::dump($deshopDelivery); 
  3044.                     //we check limits from and to order price
  3045.                     if(!empty($eshopDelivery->getEnableFromOrderPrice())) {
  3046.                        $fromLimit $eshopDelivery->getEnableFromOrderPrice();
  3047.                     } else {
  3048.                         $fromLimit 0;
  3049.                     }
  3050.                     if(!empty($eshopDelivery->getEnableToOrderPrice())) {
  3051.                        $toLimit $eshopDelivery->getEnableToOrderPrice();
  3052.                     } else {
  3053.                         $toLimit 999999999;
  3054.                     }   
  3055.                     //print('<br>QQW totalPrice: '.$totalPrice);                  
  3056.                     
  3057.                     if(($totalPrice $fromLimit && $totalPrice $toLimit) || $totalPrice == 0) {
  3058.                         //we set cost in selected currency
  3059.                         $deliveryCost $dem->getRepository(Price::class)->getCurrencyRatedPrice($eshopDelivery->getCost(), $defaultCurrency$targetCurrency);
  3060.                         $eshopDelivery->setCost(round($deliveryCost2));
  3061.                         $eshopDeliveryList[$delivery->getDeliveryId()] = $eshopDelivery;
  3062.                     }
  3063.                     //print('<br>qqw '.$eshopDelivery->getEshopDeliveryName().' limit from: '.$eshopDelivery->getEnableFromOrderPrice());
  3064.                     
  3065.                     //print('<br>qqw deliveryCost: '.$deliveryCost);
  3066.                 }
  3067.             }
  3068.             /* we get payment list from master db */
  3069.             $paymentList $em->getRepository(Payment::class)->getPaymentList();
  3070.             /* we get payment list of this e-shop */
  3071.             $eshopPaymentList = array();
  3072.             foreach($paymentList as $payment) {
  3073.                 $eshopPayment $dem->getRepository(EshopPayment::class)->getEshopPaymentFromPayment($payment->getPaymentId());
  3074.                 if(!empty($eshopPayment)) {
  3075.                     $eshopPayment->setLocale($session->get('lang')->getLangKey());
  3076.                     $dem->refresh($eshopPayment); 
  3077.                     //we set cost in selected currency
  3078.                     $paymentCost $dem->getRepository(Price::class)->getCurrencyRatedPrice($eshopPayment->getCost(), $defaultCurrency$targetCurrency);
  3079.                     $eshopPayment->setCost(round($paymentCost2));                    
  3080.                     if(!empty($session->get('order')->getEshopDelivery())) {
  3081.                         /* we add to payment list only if it is payment associated with selected delivery */
  3082.                         foreach($session->get('order')->getEshopDelivery()->getEshopPayments() as $orderEshopPayment) {
  3083.                             if($orderEshopPayment->getEshopPaymentId() == $eshopPayment->getEshopPaymentId()) {
  3084.                                 $eshopPaymentList[$payment->getPaymentId()] = $eshopPayment;
  3085.                             }
  3086.                         }
  3087.                     } else {
  3088.                         $eshopPaymentList[$payment->getPaymentId()] = $eshopPayment
  3089.                     }
  3090.                 }
  3091.             }   
  3092.             /* we render data */
  3093.             return $this->render('eshopPayment.html.twig',
  3094.                     array('headerData' => $this -> getPageHeader($request),
  3095.                             'eshop' => $eshop,
  3096.                             'user' => $user,
  3097.                             'wireFrame' => null,
  3098.                             'deliveryList' => $deliveryList,
  3099.                             'eshopDeliveryList' => $eshopDeliveryList,    
  3100.                             'paymentList' => $paymentList,
  3101.                             'eshopPaymentList' => $eshopPaymentList,   
  3102.                             'orderEshopDelivery' => $session->get('order')->getEshopDelivery(),  
  3103.                             'orderEshopPayment' => $session->get('order')->getEshopPayment(), 
  3104.                             'categoryTreeMenu' => $this->categoryTreeMenu($eshop$request),
  3105.                             'categoryTopMenu' => $this->categoryTopMenu($eshop$request), 
  3106.                             'eshopHeader' => $eshopHeader,
  3107.                             'eshopFooter' => $eshopFooter,    
  3108.                     )
  3109.                     );
  3110.              
  3111.         }    
  3112.         /**
  3113.          * @Route("/eshop/{eshopId}/search", name="search")
  3114.          */        
  3115.         public function eshopSearchAction(Request $request$eshopId) {
  3116.              
  3117.             /* we load session data */
  3118.             parent::init($request);
  3119.              
  3120.             $session $request->getSession();
  3121.              
  3122.             /* we load entity managers */
  3123.             $em $this->doctrine->getManager();
  3124.             $dem $this->doctrine->getManager('dynamic_em');
  3125.             /* we get current e-shop */
  3126.             $eshop $em->getRepository(Eshop::class)->getEshop($eshopId);
  3127.             $eshopHeader $dem->getRepository(Eshop::class)->getEshopHeader($eshopId);
  3128.             if(!empty($eshopHeader)) {
  3129.               $eshopHeader->setLocale($session->get('lang')->getLangKey());
  3130.               $dem->refresh($eshopHeader);            
  3131.             }
  3132.             /* we load footer for the current website */
  3133.             $eshopFooter $dem->getRepository(Eshop::class)->getEshopFooter($eshopId);
  3134.             if(!empty($eshopFooter)) {         
  3135.               $eshopFooter->setLocale($session->get('lang')->getLangKey());
  3136.               $dem->refresh($eshopFooter);  
  3137.             }  
  3138.             $user $em->getRepository(User::class)->getUser($eshop->getUserId());
  3139.             $productList = [];   
  3140.             $displayPrice null;    
  3141.             $productPriceList = [];     
  3142.             $productThumbs null;    
  3143.             $productCount 0;
  3144.             $categoryList = [];                                            
  3145.  
  3146.             /* we search according to searchString */;
  3147.             $searchString '';
  3148.             if(!empty($request->get('searchstring'))) {
  3149.                 $searchString $request->get('searchstring');
  3150.             } elseif(!empty($request->request->get('searchstring'))) {
  3151.                 $searchString $request->request->get('searchstring');
  3152.             } 
  3153.             
  3154.             if ($searchString != '') {
  3155.             
  3156.                 /* we get category list */    
  3157.                 $categoryList $dem->getRepository(Eshop::class)->getCategoryListBySearch($eshopIdtrim($searchString));
  3158.                 /* we get product list */
  3159.                 $productPerPage $eshop->getCountPerPage();
  3160.                 $page $request->query->get('page');
  3161.                 $firstRecord = ($page $productPerPage) - $productPerPage;
  3162.                 if($firstRecord 1) {
  3163.                     $firstRecord 0;
  3164.                 }
  3165.                 $productList $dem->getRepository(Product::class)->getProductListBySearch($eshopIdtrim($searchString));
  3166.                 /*
  3167.                 foreach($productList as $product) {
  3168.                     print('<br>QQW product: ');
  3169.                     \Doctrine\Common\Util\Debug::dump($product->getProductName()); 
  3170.                 }    
  3171.                 */       
  3172.                 $productCount count($productList);            
  3173.                 /* we load product ids into array */
  3174.                 /* we setup and validate images */
  3175.               $productIds = array();
  3176.               $productImages = array();
  3177.               $productThumbs = array();
  3178.               foreach($productList as $product) {
  3179.                 $pId $product->getProductId();
  3180.                     $productIds[] = $pId;
  3181.                     if($product->getImage1() != "") {     
  3182.                         //$imagePath = 'users/'.$user->getUserName().'/images/'.$product->getImage1();   
  3183.                           if (strpos($product->getImage1(), 'http') === false) {
  3184.                             $imagePath 'users/'.$user->getUserName().'/images/'.$product->getImage1();
  3185.                             $imageThumbPath 'users/'.$user->getUserName().'/images/thumb_'.$product->getImage1();
  3186.                           } else {
  3187.                             $imagePath $product->getImage1();
  3188.                             $path parse_url($imagePathPHP_URL_PATH);
  3189.                             $imageThumbPath 'users/'.$user->getUserName().'/images/thumb_'.basename($path);
  3190.                           } 
  3191.                         /*
  3192.                         print('<br>qqw imagePath: '.$imagePath);
  3193.                         print('<br>qqw imageThumbPath: '.$imageThumbPath);   
  3194.                         */
  3195.                         $imageThumb $this->getEshopImageThumb($eshop$imagePath$imageThumbPath);
  3196.                         $productThumbs[$pId] = $imageThumb;
  3197.                       }
  3198.                     //print('<br>qqw productName: '.$product->getProductName());
  3199.                     
  3200.                     /* we setup product names - if empty then we load multilingual values */
  3201.                     $productName '';
  3202.                     if(!empty($product->getProductName()) && $product->getProductName() != '') {
  3203.                         $productName $product->getProductName();
  3204.                     } else {
  3205.                         //we try to get the product name from multilangual fields 
  3206.                         foreach($eshop->getLanguages() as $lang) {
  3207.                             $product->setLocale($lang->getLangKey());
  3208.                             $dem->refresh($product);
  3209.                             if(!empty($product->getProductName()) && $product->getProductName() != '') {
  3210.                                 $productName $product->getProductName();
  3211.                             }
  3212.                         }
  3213.                     }
  3214.                     //print('<br>qqw pname 1: '.$productName);
  3215.                     $product->setProductName($productName);
  3216.                     $dem->flush();
  3217.                     
  3218.                     //print('<br>qqw pname 2: '.$product->getProductName());
  3219.                     /* we setup product descriptions - if empty then we load multilingual values */
  3220.                     $productDescription '';
  3221.                     if(!empty($product->getProductDescription()) && $product->getProductDescription() != '') {
  3222.                         $productDescription $product->getProductDescription();
  3223.                     } else {
  3224.                         //we try to get the product description from multilangual fields 
  3225.                         foreach($eshop->getLanguages() as $lang) {
  3226.                             $product->setLocale($lang->getLangKey());
  3227.                             $dem->refresh($product);
  3228.                             if(!empty($product->getProductDescription()) && $product->getProductDescription() != '') {
  3229.                                 $productDescription $product->getProductDescription();
  3230.                             }
  3231.                         }
  3232.                     }
  3233.                     //print('<br>qqw pDescription: '.$productDescription);
  3234.                     $product->setProductDescription($productDescription);      
  3235.                     $dem->flush();      
  3236.               }
  3237.                 /* we load prices */
  3238.                 $productPriceList $dem->getRepository(Product::class)->getProductPriceList($productIds);
  3239.                 $defaultCurrency $em->getRepository(Currency::class)->getCurrency($eshop->getPreferredCurrencyId());
  3240.                 $targetCurrency $session->get('eshopCurrency');
  3241.                 
  3242.                 /* we load currency rated prices */
  3243.                 $productPriceList $dem->getRepository(Product::class)->getCurrencyRatedProductPriceList($productPriceList$defaultCurrency$targetCurrency);
  3244.                 /* we get price(s) to display */
  3245.                 $displayPrice null;
  3246.                 foreach($productPriceList as $price) {
  3247.                     if($price->getProductId() == $product->getProductId()) {
  3248.                         /* we get default price level */
  3249.                         if($price->getPriceLevelId() == 1) {
  3250.                             //$displayPrice = round($price->getBruttoValue(),$eshop->getRoundPrice());
  3251.                             $displayPrice round($price->getNettoValue(),$eshop->getRoundPrice());
  3252.                         }
  3253.                         
  3254.                     }
  3255.                 }         
  3256.             }    
  3257.             /* we add product(s) to basket - POST form action */
  3258.             if(!empty($request->request->get('basket'))) {
  3259.                 /* we call method to add to basket */
  3260.                 $this->addToBasket($request$eshopId$request->request->get('productId'));
  3261.                 return $this->redirectToRoute('eshopBasket', array('eshopId' => $eshopId));
  3262.             }
  3263.             $productView $eshop->getProductView();
  3264.             //isModule Pack Sale
  3265.             $module $em->getRepository(Module::class)->getModule(42);
  3266.             $isPackSaleModule $em->getRepository(User::class)->userHasModule($user$module);
  3267.             /* we render data */
  3268.             return $this->render('eshopSearch.html.twig',
  3269.                     array('headerData' => $this -> getPageHeader($request),
  3270.                             'eshop' => $eshop,
  3271.                             'user' => $user,
  3272.                             'productView' => $productView,
  3273.                             'productList' => $productList,
  3274.                             'displayPrice' => $displayPrice,
  3275.                             'productPriceList' => $productPriceList,
  3276.                             'productThumbs' => $productThumbs,  
  3277.                             'productCount' => $productCount,                          
  3278.                             'wireFrame' => null,
  3279.                             'categoryTreeMenu' => $this->categoryTreeMenu($eshop$request),
  3280.                             'categoryTopMenu' => $this->categoryTopMenu($eshop$request), 
  3281.                             'eshopHeader' => $eshopHeader,
  3282.                             'eshopFooter' => $eshopFooter,    
  3283.                             'searchString' => $searchString,  
  3284.                             'categoryList' => $categoryList,    
  3285.                             'isPackSaleModule' => false,                                                
  3286.                     )
  3287.                     );
  3288.              
  3289.         }    
  3290.         /**
  3291.          * @Route("/eshop/{eshopId}/customer", name="customer")
  3292.          */        
  3293.         public function eshopCustomerAction(Request $request$eshopId) {
  3294.              
  3295.             /* we load session data */
  3296.             parent::init($request);
  3297.              
  3298.             $session $request->getSession();
  3299.              
  3300.             /* we load entity managers */
  3301.             $em $this->doctrine->getManager();
  3302.             $dem $this->doctrine->getManager('dynamic_em');
  3303.             
  3304.             /* we get current e-shop */
  3305.             $eshop $em->getRepository(Eshop::class)->getEshop($eshopId);
  3306.             $eshopHeader $dem->getRepository(Eshop::class)->getEshopHeader($eshopId);
  3307.             if(!empty($eshopHeader)) {
  3308.               $eshopHeader->setLocale($session->get('lang')->getLangKey());
  3309.               $dem->refresh($eshopHeader);            
  3310.             }
  3311.             /* we load footer for the current website */
  3312.             $eshopFooter $dem->getRepository(Eshop::class)->getEshopFooter($eshopId);
  3313.             if(!empty($eshopFooter)) {         
  3314.               $eshopFooter->setLocale($session->get('lang')->getLangKey());
  3315.               $dem->refresh($eshopFooter);  
  3316.             }  
  3317.             $user $em->getRepository(User::class)->getUser($eshop->getUserId());
  3318.             //we set contact from db to session
  3319.             if(!empty($session->get('contact'))) {
  3320.                 $contact $dem->getRepository(Contact::class)->getContactFromUsername($session->get('contact')->getContactUserName());
  3321.                 $session->set('contact'$contact);
  3322.             }
  3323.             //isModule PayPal
  3324.             $module $em->getRepository(Module::class)->getModule(9);
  3325.             $isPayPalModule $em->getRepository(User::class)->userHasModule($user$module);
  3326.             /* we prepare data for the form */
  3327.             if(!empty($request->request->get('firstName'))) {
  3328.                 $firstName $request->request->get('firstName');
  3329.             } elseif(!empty($session->get('contact'))) {
  3330.                 $firstName $session->get('contact')->getFirstName();
  3331.             } else {
  3332.                 $firstName '';
  3333.             }
  3334.             if(!empty($request->request->get('lastName'))) {
  3335.                 $lastName $request->request->get('lastName');
  3336.             } elseif(!empty($session->get('contact'))) {
  3337.                 $lastName $session->get('contact')->getLastName();
  3338.             } else {
  3339.                 $lastName '';
  3340.             }            
  3341.             if(!empty($request->request->get('companyName'))) {
  3342.                 $company $request->request->get('companyName');
  3343.             } elseif(!empty($session->get('contact'))) {
  3344.                 $company $session->get('contact')->getCompanyName();
  3345.             } else {
  3346.                 $company '';
  3347.             }
  3348.             if(!empty($request->request->get('email'))) {
  3349.                 $email $request->request->get('email');
  3350.             } elseif(!empty($session->get('contact'))) {
  3351.                 $email $session->get('contact')->getEmail();
  3352.             } else {
  3353.                 $email '';
  3354.             }
  3355.             if(!empty($request->request->get('phone'))) {
  3356.                 $telefon $request->request->get('phone');
  3357.             } elseif(!empty($session->get('contact'))) {
  3358.                 $telefon $session->get('contact')->getPhone();
  3359.             } else {
  3360.                 $telefon '';
  3361.             }
  3362.             if(!empty($request->request->get('addressStreet'))) {
  3363.                 $addressStreet $request->request->get('addressStreet');
  3364.             } elseif(!empty($session->get('contact')) && !empty($session->get('contact')->getAddress())) {
  3365.                 $addressStreet $session->get('contact')->getAddress()->getStreet();
  3366.             } else {
  3367.                 $addressStreet '';
  3368.             }
  3369.             if(!empty($request->request->get('addressStreetNumber'))) {
  3370.                 $addressStreetNumber $request->request->get('addressStreetNumber');
  3371.             } elseif(!empty($session->get('contact')) && !empty($session->get('contact')->getAddress())) {
  3372.                 $addressStreetNumber $session->get('contact')->getAddress()->getStreetNumber();
  3373.             } else {
  3374.                 $addressStreetNumber '';
  3375.             }     
  3376.             if(!empty($request->request->get('addressCity'))) {
  3377.                 $addressCity $request->request->get('addressCity');
  3378.             } elseif(!empty($session->get('contact')) && !empty($session->get('contact')->getAddress())) {
  3379.                 $addressCity $session->get('contact')->getAddress()->getCity();
  3380.             } else {
  3381.                 $addressCity '';
  3382.             }   
  3383.             
  3384.             if(!empty($request->request->get('addressZipCode'))) {
  3385.                 $addressZipCode $request->request->get('addressZipCode');
  3386.             } elseif(!empty($session->get('contact')) && !empty($session->get('contact')->getAddress())) {
  3387.                 $addressZipCode $session->get('contact')->getAddress()->getZipCode();
  3388.             } else {
  3389.                 $addressZipCode '';
  3390.             }   
  3391.             
  3392.             if(!empty($request->request->get('addressCountry'))) {
  3393.                 $addressCountry $request->request->get('addressCountry');
  3394.             } elseif(!empty($session->get('contact')) && !empty($session->get('contact')->getAddress())) {
  3395.                 $addressCountry $session->get('contact')->getAddress()->getCountry();
  3396.             } else {
  3397.                 $addressCountry '';
  3398.             }                                        
  3399.             if(!empty($request->request->get('address'))) {
  3400.                 $address $request->request->get('address');
  3401.             } elseif(!empty($session->get('contact'))) {
  3402.                 $address $session->get('contact')->getAddress1();
  3403.             } else {
  3404.                 $address '';
  3405.             }
  3406.             if(!empty($request->request->get('contactUserName'))) {
  3407.                 $username $request->request->get('contactUserName');
  3408.             } elseif(!empty($session->get('contact'))) {
  3409.                 $username $session->get('contact')->getContactUserName();
  3410.             } else {
  3411.                 $username '';
  3412.             }
  3413.             if(!empty($request->request->get('contactUserPassword'))) {
  3414.                 $password $request->request->get('contactUserPassword');
  3415.             } elseif(!empty($session->get('contact'))) {
  3416.                 $password $session->get('contact')->getContactUserPassword();
  3417.             } else {
  3418.                 $password '';
  3419.             }
  3420.             if(!empty($request->request->get('password_retype'))) {
  3421.                 $password_retype $request->request->get('password_retype');
  3422.             } elseif(!empty($session->get('contact'))) {
  3423.                 $password_retype $session->get('contact')->getContactUserPassword();
  3424.             } else {
  3425.                 $password_retype '';
  3426.             }   
  3427.             if(!empty($request->request->get('businessId'))) {
  3428.                 $businessId $request->request->get('businessId');
  3429.             } elseif(!empty($session->get('contact'))) {
  3430.                 $businessId $session->get('contact')->getBusinessId();
  3431.             } else {
  3432.                 $businessId '';
  3433.             }
  3434.              if(!empty($request->request->get('DICId'))) {
  3435.                 $DICId $request->request->get('DICId');
  3436.             } elseif(!empty($session->get('contact'))) {
  3437.                 $DICId $session->get('contact')->getDICId();
  3438.             } else {
  3439.                 $DICId '';
  3440.             }                           
  3441.             /* we build register form */
  3442.             $contact = new Contact;
  3443.             $formBuilder $this->createFormBuilder($contact);
  3444.             $formBuilder->add('lastName'TextType::class, array(
  3445.                     'required' => true,
  3446.                     'label' => $this->translator->trans('knowledgebase.last_name'),
  3447.                     'attr' => array('class' => 'text_form''size' => 35'value' => $lastName),
  3448.                     'label_attr' => array('class' => 'form_field_label_required')
  3449.             ));  
  3450.             $formBuilder->add('firstName'TextType::class, array(
  3451.                     'required' => true,
  3452.                     'label' => $this->translator->trans('knowledgebase.first_name'),
  3453.                     'attr' => array('class' => 'text_form''size' => 35'value' => $firstName),
  3454.                     'label_attr' => array('class' => 'form_field_label_required')
  3455.             ));
  3456.             $formBuilder->add('email'EmailType::class, array(
  3457.                     'required' => true,
  3458.                     'attr' => array('class' => 'text_form''size' => 35'value' => $email),
  3459.                     'label_attr' => array('class' => 'form_field_label_required'),
  3460.             ));
  3461.             $formBuilder->add('contactUserName'TextType::class, array(
  3462.                     'required' => true,
  3463.                     'label' => $this->translator->trans('user.username'),
  3464.                     'empty_data'  => '',
  3465.                     'attr' => array('class' => 'text_form''size' => 35'value' => $username),
  3466.                     'label_attr' => array('class' => 'form_field_label_required'),
  3467.             ));
  3468.             $formBuilder->add('contactUserPassword'PasswordType::class, array(
  3469.                     'required' => true,
  3470.                     'label' => $this->translator->trans('user.password'),
  3471.                     'attr' => array('class' => 'text_form''size' => 35'value' => $password),
  3472.                     'label_attr' => array('class' => 'form_field_label_required'),
  3473.             ));
  3474.             $formBuilder->add('phone'TextType::class, array(
  3475.                     'required' => false,
  3476.                     'label' => $this->translator->trans('user.telephone'),
  3477.                     'attr' => array('class' => 'text_form''size' => 35'value' => $telefon),
  3478.                     'label_attr' => array('class' => 'form_field_label'),
  3479.             ));
  3480.             /* we add address */
  3481.             $formBuilder->add('addressStreet'TextType::class, array(
  3482.                     'required' => true,
  3483.                     'mapped' => false,
  3484.                     'label' => $this->translator->trans('address.street'),
  3485.                     'attr' => array('class' => 'text_form''size' => 35'value' => $addressStreet),
  3486.                     'label_attr' => array('class' => 'form_field_label_required'),
  3487.             ));
  3488.             $formBuilder->add('addressStreetNumber'TextType::class, array(
  3489.                     'required' => true,
  3490.                     'mapped' => false,
  3491.                     'label' => $this->translator->trans('address.street_number'),
  3492.                     'attr' => array('class' => 'text_form''size' => 10'value' => $addressStreetNumber),
  3493.                     'label_attr' => array('class' => 'form_field_label_required'),
  3494.             ));
  3495.             $formBuilder->add('addressZipCode'TextType::class, array(
  3496.                     'required' => true,
  3497.                     'mapped' => false,
  3498.                     'label' => $this->translator->trans('address.zip_code'),
  3499.                     'attr' => array('class' => 'text_form''size' => 10'value' => $addressZipCode),
  3500.                     'label_attr' => array('class' => 'form_field_label_required'),
  3501.             ));
  3502.             $formBuilder->add('addressCity'TextType::class, array(
  3503.                     'required' => true,
  3504.                     'mapped' => false,
  3505.                     'label' => $this->translator->trans('address.city'),
  3506.                     'attr' => array('class' => 'text_form''size' => 35'value' => $addressCity),
  3507.                     'label_attr' => array('class' => 'form_field_label_required'),
  3508.             ));
  3509.             $formBuilder->add('addressCountry'TextType::class, array(
  3510.                     'required' => true,
  3511.                     'mapped' => false,
  3512.                     'label' => $this->translator->trans('address.country'),
  3513.                     'attr' => array('class' => 'text_form''size' => 35'value' => $addressCountry),
  3514.                     'label_attr' => array('class' => 'form_field_label_required'),
  3515.             ));
  3516.             $formBuilder->add('companyName'TextType::class, array(
  3517.                     'required' => false,
  3518.                     'label' => $this->translator->trans('user.company'),
  3519.                     'attr' => array('class' => 'text_form''size' => 35'value' => $company),
  3520.                     'label_attr' => array('class' => 'form_field_label')
  3521.             ));
  3522.             $formBuilder->add('businessId'TextType::class, array(
  3523.                     'required' => false,
  3524.                     'label' => $this->translator->trans('user.business_number'),
  3525.                     'attr' => array('class' => 'text_form''size' => 35'value' => $businessId),
  3526.                     'label_attr' => array('class' => 'form_field_label')
  3527.             ));
  3528.             $formBuilder->add('DICId'TextType::class, array(
  3529.                     'required' => false,
  3530.                     'label' => $this->translator->trans('user.DIC_number'),
  3531.                     'attr' => array('class' => 'text_form''size' => 35'value' => $DICId),
  3532.                     'label_attr' => array('class' => 'form_field_label')
  3533.             ));
  3534.             
  3535.             /*
  3536.             $formBuilder->add('address', TextareaType::class, array(
  3537.                     'required' => false,
  3538.                     'label' => $this->translator->trans('user.address'),
  3539.                     'attr' => array('class' => 'textarea_form', 'cols' => 33, 'rows' => 2, 'value' => $address),
  3540.                     'label_attr' => array('class' => 'form_textarea_label'),
  3541.                     'data' => $address,
  3542.             ));
  3543.             */
  3544.             /*
  3545.             $formBuilder->add('password_retype', PasswordType::class, array(
  3546.                     'required' => true,
  3547.                     'label' => $this->translator->trans('user.password_retype'),
  3548.                     'attr' => array('class' => 'text_form', 'size' => 35, 'value' => $password_retype),
  3549.                     'label_attr' => array('class' => 'form_field_label_required'),
  3550.             ));    
  3551.             */  
  3552.         
  3553.         //isModule e-Privacy Consent
  3554.         $module $em->getRepository(Module::class)->getModule(30);
  3555.         $isConsentModule $em->getRepository(User::class)->userHasModule($user$module);
  3556.         $consentList null;
  3557.         $consentDescriptions = array();
  3558.         if($isConsentModule) {
  3559.             //print('<br>qqw is module e-Privacy Consent');
  3560.  
  3561.             $consentList $dem->getRepository(Consent::class)->getConsentList();
  3562.             $consents = array();
  3563.             $consentRequired false;
  3564.             foreach($consentList as $consent) {
  3565.                 //print('<br>Consent: '.$consent->getConsentName());
  3566.                 $consent->setLocale($session->get('lang')->getLangKey());
  3567.                 $dem->refresh($consent); 
  3568.                 if($consent->isBlockOrder()) {
  3569.                     $consentRequired true;
  3570.                 }
  3571.                 $consents[$consent->getConsentName()] = $consent->getConsentId();
  3572.                 $consentDescriptions[$consent->getConsentId()] = $consent->getConsentDescription();
  3573.             }
  3574.             $selectedConsents = array();
  3575.             $formBuilder->add('consents'ChoiceType::class, array(
  3576.                     'choices' => $consents,
  3577.                     'required' => $consentRequired,
  3578.                     'mapped' => false,
  3579.                     'multiple' => true,
  3580.                     'expanded' => true,
  3581.                     'label_attr' => array('class' => 'consent_label'),
  3582.                     'attr' => array('class' => 'form_field_text'),
  3583.                     'choice_attr' => function($val$key$index) {
  3584.                         // adds a class like attending_yes, attending_no, etc
  3585.                         return ['class' => 'choiceBlock5''required' => 'required'];
  3586.                     },
  3587.                     'data' => $selectedConsents
  3588.             ));
  3589.         }    
  3590.         $formBuilder->add('save'SubmitType::class, array('label' => $this->translator->trans('eshop.complete_order'),
  3591.                 'attr' => array('class' => 'completeOrderButton')));
  3592.         $form $formBuilder->getForm();
  3593.         
  3594.             $form->handleRequest($request);
  3595.             
  3596.             if ($request->getMethod() == 'POST') {
  3597.             
  3598.                 //$form->bindRequest($request);
  3599.             
  3600.                 if ($form->isValid()) {
  3601.                     $formData $form->getData();
  3602.             
  3603.                     /* we check if this contact already exists */
  3604.                     $contactExist $dem->getRepository(Contact::class)->getContactFromUsername($formData->getContactUsername());
  3605.             
  3606.                     /*
  3607.                     print('<br>qqw contact exists: ');
  3608.                     \Doctrine\Common\Util\Debug::dump($contactExist);
  3609.                     */
  3610.                     /* we create new contact
  3611.                     if($contactExist === null) {
  3612.             
  3613.                         /* we check if the password fields are the same */
  3614.                         $password $formData->getContactUserPassword();
  3615.                         //$retypePassword = $request->request->get('form')['password_retype'];
  3616.                             if(!empty($session->get('contact'))) {
  3617.                                 /* */
  3618.                                 $contact $dem->getRepository(Contact::class)->getContactFromUsername($formData->getContactUsername());
  3619.                                 $password $formData->getContactUserPassword();
  3620.                             } else {
  3621.                                 print('<br>We create new contact');
  3622.                                 //$contact = new Contact;
  3623.                                 $password md5($formData->getContactUserPassword());
  3624.                             }
  3625.                             /* we load contact data from register form into contact object */
  3626.                             $contact->setFirstName($formData->getFirstName());
  3627.                             $contact->setLastName($formData->getLastName());
  3628.                             $contact->setCompanyName($formData->getCompanyName());
  3629.                             $contact->setContactUserName($formData->getContactUserName());
  3630.                             $contact->setEmail($formData->getEmail());
  3631.                             $contact->setPhone($formData->getPhone());
  3632.                             $contact->setContactUserPassword($password);
  3633.                             //$address = $contact->getAddress();
  3634.                             if(empty($contact->getAddress())) {
  3635.                                $address = new Address;
  3636.                             } else {
  3637.                                $address $contact->getAddress();
  3638.                             }
  3639.                             $address->setStreet($form['addressStreet']->getData());
  3640.                             $address->setStreetNumber($form['addressStreetNumber']->getData());
  3641.                             $address->setCity($form['addressCity']->getData());
  3642.                             $address->setZipCode($form['addressZipCode']->getData());
  3643.                             $address->setCountry($form['addressCountry']->getData());
  3644.                             $contact->setAddress($address);
  3645.                             $contact->setBusinessId($formData->getBusinessId());
  3646.                             $contact->setDICId($formData->getDICId());
  3647.                             /* we remove old consents */
  3648.                             if(!empty($contact->getConsents())) {
  3649.                                 foreach($contact->getConsents() as $consent) {
  3650.                                     $contact->removeConsent($consent);
  3651.                                     //$dem->refresh($product);
  3652.                                     //$dem->persist($cat);
  3653.                                 }
  3654.                             }
  3655.                             /* we save consents */
  3656.                             if(!empty($form['consents']->getData())) {
  3657.                                 foreach($form['consents']->getData() as $consentId) {
  3658.                                     $consent $dem->getRepository(Consent::class)->getConsent($consentId);
  3659.                                     $contact->addConsent($consent);
  3660.                                 }
  3661.                             }
  3662.                             /* we persist and save contact */
  3663.                             $dem->persist($contact);
  3664.                             $dem->flush();
  3665.             
  3666.                             //$this->addFlash('notice', $this->translator->trans('eshop.contact_new_created'));
  3667.                             
  3668.                             /* we load logged contact into session */
  3669.                             $session $request->getSession();
  3670.                             $session->set('contact'$contact);    
  3671.                             
  3672.                             /* we load logged user into order 
  3673.                             //$session->get('order')->setEshopContact($contact); 
  3674.                             /*
  3675.                             print('<br>qqw contact: ');
  3676.                             \Doctrine\Common\Util\Debug::dump($session->get('contact'));        
  3677.                             */
  3678.                             return $this->redirectToRoute('thankyou', array('eshopId' => $eshopId));
  3679.             
  3680.                     }
  3681.                     else {
  3682.                         $this->addFlash('error''E-shop account with this username already exists.');
  3683.                     }
  3684.             
  3685.                 }
  3686.             /* we setup wireframe and layout extensoin */
  3687.             if(!empty($wireFrame)) {
  3688.                 $wireFrameFile $wireFrame->getWireFrameFile();
  3689.             } else {
  3690.                 $wireFrameFile 'eshopLayoutFlat.html.twig';
  3691.             }
  3692.             $currentUserId $eshop->getUserId();
  3693.             $paypalList $dem->getRepository(Paypal::class)->getPaypalListByUser($currentUserId);
  3694.             $userPaypal null;
  3695.             foreach($paypalList as $paypal) {
  3696.                 $userPaypal $dem->getRepository(Paypal::class)->getPaypal($paypal->getPaypalId());
  3697.             }
  3698.             
  3699.             /*
  3700.             print('<br>qqw paypalList: ');
  3701.             \Doctrine\Common\Util\Debug::dump($paypalList);            
  3702.             print('<br>qqw paypal: ');
  3703.             \Doctrine\Common\Util\Debug::dump($userPaypal);
  3704.             */
  3705.             
  3706.             /* we render data */
  3707.             return $this->render('eshopCustomer.html.twig',
  3708.                     array('headerData' => $this -> getPageHeader($request),
  3709.                             'form' => $formBuilder->getForm()->createView(),
  3710.                             'formRaw' => $formBuilder->getForm(),
  3711.                             'eshop' => $eshop,
  3712.                             'wireFrame' => null,
  3713.                             'wireFrameFile' => $wireFrameFile,                            
  3714.                             'categoryTreeMenu' => $this->categoryTreeMenu($eshop$request),
  3715.                             'categoryTopMenu' => $this->categoryTopMenu($eshop$request), 
  3716.                             'eshopHeader' => $eshopHeader,
  3717.                             'eshopFooter' => $eshopFooter,    
  3718.                             'isConsentModule' => $isConsentModule,    
  3719.                             'consentList' => $consentList
  3720.                             'consentDescriptions' => $consentDescriptions
  3721.                             'isPayPalModule' => $isPayPalModule,
  3722.                             'paypal' => $userPaypal                                                       
  3723.                     )
  3724.                     );
  3725.              
  3726.         }   
  3727.         /**
  3728.          * @Route("/eshop/{eshopId}/thankyou", name="thankyou")
  3729.          */        
  3730.         public function thankyouAction(Request $request$eshopId) {
  3731.               
  3732.             /* we load session data */
  3733.             parent::init($request);
  3734.              
  3735.             $session $request->getSession();
  3736.              
  3737.             /* we load entity managers */
  3738.             $em $this->doctrine->getManager();
  3739.             $dem $this->doctrine->getManager('dynamic_em');
  3740.             
  3741.             /* we get current e-shop */
  3742.             $eshop $em->getRepository(Eshop::class)->getEshop($eshopId);
  3743.             $eshopHeader $dem->getRepository(Eshop::class)->getEshopHeader($eshopId);
  3744.             if(!empty($eshopHeader)) {
  3745.               $eshopHeader->setLocale($session->get('lang')->getLangKey());
  3746.               $dem->refresh($eshopHeader);            
  3747.             }
  3748.             /* we load footer for the current website */
  3749.             $eshopFooter $dem->getRepository(Eshop::class)->getEshopFooter($eshopId);
  3750.             if(!empty($eshopFooter)) {         
  3751.               $eshopFooter->setLocale($session->get('lang')->getLangKey());
  3752.               $dem->refresh($eshopFooter);  
  3753.             }  
  3754.             /* we get user */
  3755.             $user $em->getRepository(User::class)->getUser($eshop->getUserId());
  3756.             if(empty($session->get('order'))) {
  3757.                     $this->addFlash('error''Order session timed out.');
  3758.                     return $this->redirectToRoute('eshopHome'); 
  3759.             }
  3760.             
  3761.             /* we setup order fields */
  3762.             $dateTimeNow = new \DateTime("now");            
  3763.             $session->get('order')->setDateCreated($dateTimeNow);
  3764.             $order $session->get('order');
  3765.             /* we get new order id */
  3766.             $getMaxOrderId $dem->getRepository(Order::class)->getMaxOrderId() + 1;
  3767.             /* we persist order items into db */
  3768.             $orderItems $session->get('order')->getOrderItems();
  3769.             foreach($orderItems as $orderItem) {
  3770.                 $orderItem->setOrderId($getMaxOrderId);
  3771.                 $dem->persist($orderItem);
  3772.             }
  3773.             //print('<br>qqw del id: '.$session->get('order')->getEshopDelivery()->getDeliveryId());
  3774.             /* we persist delivery */
  3775.             //$orderDelivery = $em->getRepository(Delivery::class)->getDelivery($session->get('order')->getEshopDelivery()->getDeliveryId());
  3776.             $orderDelivery $dem->getRepository(EshopDelivery::class)->getEshopDelivery($session->get('order')->getEshopDelivery()->getEshopDeliveryId());
  3777.             $order->setEshopDelivery($orderDelivery);
  3778.             $orderPayment $dem->getRepository(EshopPayment::class)->getEshopPayment($session->get('order')->getEshopPayment()->getEshopPaymentId());
  3779.             $order->setEshopPayment($orderPayment);
  3780.             //$dem->persist($orderDelivery);
  3781.             /*
  3782.              print('<br>qqw orderDelivery: ');
  3783.             \Doctrine\Common\Util\Debug::dump($orderDelivery);
  3784.             */
  3785.             //die('<br>qqw Delivery x');  
  3786.             //$orderDelivery = $session->get('order')->getEshopDelivery();
  3787.             //$dem->persist($orderDelivery);
  3788.             //$orderPayment = $session->get('order')->getEshopPayment();
  3789.             //$dem->persist($orderPayment);
  3790.             
  3791.             /* we persist customer */
  3792.             if(!empty($session->get('contact'))) {
  3793.                 //print('<br>qqw existing customer');
  3794.                 $orderContact $dem->getRepository(Contact::class)->getContact($session->get('contact')->getContactId());
  3795.                 if(empty($orderContact)) {
  3796.                     $orderContact $session->get('contact');
  3797.                 }
  3798.                 $order->setEshopContact($orderContact);
  3799.             } else {
  3800.                 $orderContact $session->get('order')->getEshopContact();
  3801.             }
  3802.              
  3803.             /*          
  3804.             print('<br>qqw orderContact: ');
  3805.             \Doctrine\Common\Util\Debug::dump($orderContact);
  3806.             
  3807.             
  3808.              print('<br>qqw contact: ');
  3809.              \Doctrine\Common\Util\Debug::dump($session->get('contact'));    
  3810.              */  
  3811.             $order->setIp($request->getClientIp());        
  3812.             $dem->persist($orderContact);          
  3813.             /* we persist order into db */
  3814.             $dem->persist($order);
  3815.             $dem->flush();
  3816.             /* we remove the order from session */
  3817.             $session->remove('order');
  3818.             /* we prepare emailing */
  3819.             $name $eshop->getEshopName();
  3820.             $to      $user->getEmail();
  3821.             $subject $name.' - '.$this->translator->trans('eshop.email_order_subject').': #'.$order->getOrderId();
  3822.             $message $this->translator->trans('eshop.email_order_text');
  3823.             /* we load order email cms text for the current eshop */
  3824.             $orderEmail $dem->getRepository(WebPage::class)->getEmailOrder($eshopId);
  3825.             if(!empty($orderEmail)) {
  3826.                 $message .= $orderEmail->getWebPageContent();
  3827.             } 
  3828.             /* we load order email cms text for the current eshop */
  3829.             /* we get order prices */
  3830.             $eshopCurrency $em->getRepository(Currency::class)->getCurrency($eshop->getPreferredCurrencyId());
  3831.             if(!empty($order->getCurrencyKey())) {
  3832.                 $targetCurrency $em->getRepository(Currency::class)->getCurrencyByKey($order->getCurrencyKey());
  3833.             } else {
  3834.                 $targetCurrency $eshopCurrency;
  3835.             }
  3836.             $orderPrice $dem->getRepository(Order::class)->getOrderPrice($order->getOrderId(), $targetCurrencyfalse$eshop$eshopCurrency);
  3837.             $orderPriceVAT $dem->getRepository(Order::class)->getOrderPrice($order->getOrderId(), $targetCurrencytrue$eshop$eshopCurrency);
  3838.             $orderEmailText $this->getOrderEmail($request$eshop$order$orderPrice$orderPriceVAT);
  3839.             $message .= $orderEmailText;
  3840.             $from 'noreply@virtualrealitycommerce.cz';
  3841.             /*
  3842.             $headers  = "MIME-Version: 1.0\r\n";
  3843.             $headers .= "Content-type: text/html; charset=UTF-8\r\n";
  3844.             $headers .= "From: {$name} <{$from}>\r\n";
  3845.             $headers .= "Reply-To: <{$from}>\r\n";
  3846.             $headers .= "Subject: {$subject}\r\n";
  3847.             $headers .= "X-Mailer: PHP/".phpversion()."\r\n";
  3848.             */
  3849.             // we send email to eshop owner
  3850.             if($this->sendEmail($to$subject$from$message)) {
  3851.                 if(!empty($user->getContactPersonEmail())) {
  3852.                     $this->sendEmail($user->getContactPersonEmail(), $subject$from$message);
  3853.                 }
  3854.                 $mailToAdminStatus $this->translator->trans('eshop.email_admin_order_ok').': '.$to;
  3855.             } else {
  3856.                 $mailToAdminStatus $this->translator->trans('eshop.email_admin_order_error'.': '.$to);
  3857.             }
  3858.             // we send email to customer 
  3859.             $to      $orderContact->getEmail();    
  3860.             if($this->sendEmail($to$subject$from$message)) {
  3861.                 $mailToCustomerStatus $this->translator->trans('eshop.email_customer_order_ok').': '.$to;
  3862.             } else {   
  3863.                 $mailToCustomerStatus $this->translator->trans('eshop.email_customer_order_error'.': '.$to);
  3864.             }
  3865.             
  3866.             /*
  3867.             // we send email to e-shop admin - sendmail, sendemail 
  3868.             if(@mail($to, $subject, $message, $headers)) {
  3869.                 //print('<br>Email was sent.');
  3870.                 //we send email to users contact person
  3871.                 if(!empty($user->getContactPersonEmail())) {
  3872.                     mail($user->getContactPersonEmail(), $subject, $message, $headers);
  3873.                 }
  3874.                 
  3875.             } else {
  3876.                 //print('<br>Email was not sent.');
  3877.                 $mailToAdminStatus = $this->translator->trans('eshop.email_admin_order_error'.': '.$to);
  3878.             }   
  3879.             // we send email to customer 
  3880.             $to      = $orderContact->getEmail();    
  3881.             if(@mail($to, $subject, $message, $headers)) {
  3882.                 //print('<br>Email was sent.');
  3883.                 $mailToCustomerStatus = $this->translator->trans('eshop.email_customer_order_ok').': '.$to;
  3884.             } else {
  3885.                 //print('<br>Email was not sent.');
  3886.                 $mailToCustomerStatus = $this->translator->trans('eshop.email_customer_order_error'.': '.$to);
  3887.             }     
  3888.             */             
  3889.             /* we render data */
  3890.             return $this->render('eshopThankYou.html.twig',
  3891.                     array('headerData' => $this -> getPageHeader($request),
  3892.                             'eshop' => $eshop,
  3893.                             'order' => $order,
  3894.                             'user' => $user,
  3895.                             'wireFrame' => null,
  3896.                             'categoryTreeMenu' => $this->categoryTreeMenu($eshop$request),
  3897.                             'categoryTopMenu' => $this->categoryTopMenu($eshop$request), 
  3898.                             'eshopHeader' => $eshopHeader,
  3899.                             'eshopFooter' => $eshopFooter,   
  3900.                             'mailToAdminStatus' => $mailToAdminStatus,  
  3901.                             'mailToCustomerStatus' => $mailToCustomerStatus,    
  3902.                     )
  3903.                     );
  3904.     }
  3905.       
  3906.     public function getOrderEmail(Request $request$eshop$order$orderPrice=null$orderPriceVAT=null)
  3907.     {
  3908.         /* we load session data */
  3909.         parent::init($request);
  3910.          
  3911.         $session $request->getSession();
  3912.          
  3913.         /* we load entity managers */
  3914.         $em $this->doctrine->getManager();
  3915.         $dem $this->doctrine->getManager('dynamic_em');
  3916.         /* we get user */
  3917.         $user $em->getRepository(User::class)->getUser($eshop->getUserId());
  3918.         $defaultCurrency $em->getRepository(Currency::class)->getCurrency($eshop->getPreferredCurrencyId());
  3919.         if(!empty($order->getCurrencyKey())) {
  3920.             $targetCurrency $em->getRepository(Currency::class)->getCurrencyByKey($order->getCurrencyKey());
  3921.         } else {
  3922.             $targetCurrency $session->get('eshopCurrency');        
  3923.         }
  3924.  
  3925.         if(!empty($order->getDateCreated())) {
  3926.           $dateCreated $order->getDateCreated()->format('Y\-m\-d\ H:i:s');
  3927.         } else {
  3928.           $dateCreated '';
  3929.         }
  3930.         $emailText '<h3>'.$this->translator->trans('eshop.order_detail').'</h3>';
  3931.         $emailText .= '<table width="100%" style="background-color: #EFEFEF; color: Black;font-family: Arial;font-size: 14px;border:Gray solid 1px;" cellspacing="0" cellpadding="3">
  3932.             <tr>
  3933.               <td><strong>'.$this->translator->trans('eshop.order').':</strong></td> 
  3934.               <td>'.$order->getOrderId().'</td> 
  3935.             </tr>
  3936.             <tr>
  3937.               <td><strong>'.$this->translator->trans('system.date_created').':</strong></td> 
  3938.               <td>'.$dateCreated.'</td>                 
  3939.             </tr></table> '
  3940.         $emailText .= '<h3>'.$this->translator->trans('eshop.order_items').'</h3>
  3941.         <table width="100%" style="background-color: #EFEFEF; color: Black;font-family: Arial;font-size: 14px;border:Gray solid 1px;" cellspacing="0" cellpadding="3">
  3942.             <tr>
  3943.                 <th style="text-align:left;background-color: LightGray;">id#</th> 
  3944.                 <th style="text-align:left;background-color: LightGray;">'.$this->translator->trans('product.name').'</th> 
  3945.                 <th style="text-align:left;background-color: LightGray;">'.$this->translator->trans('product.key').'</th>
  3946.                 <th style="text-align:left;background-color: LightGray;">'.$this->translator->trans('system.units').'</th> 
  3947.                 <th style="text-align:left;background-color: LightGray;">'.$this->translator->trans('eshop.price_piece').'</th>   
  3948.                 <th style="text-align:left;background-color: LightGray;">'.$this->translator->trans('eshop.price').'</th>         
  3949.             </tr>  '
  3950.             $totalPrice 0;
  3951.             $totalPriceVAT 0;
  3952.             foreach($order->getOrderItems() as $orderItem) {
  3953.                 if(empty($orderItem->getOrderItemPrice())) {
  3954.                     $orderItem->setOrderItemPrice(0);
  3955.                 }      
  3956.                 $productKey "";
  3957.                 if(!empty($orderItem->getProductId())) {
  3958.                     $product $dem->getRepository(Product::class)->getProduct($orderItem->getProductId());
  3959.                     $productKey $product->getERPKey();
  3960.                 }
  3961.             
  3962.                 $productPrice $orderItem->getOrderItemPrice() * $orderItem->getOrderItemUnits();
  3963.                 if(!empty($orderItem->getOrderItemPriceBrutto())) {
  3964.                     $productPriceVAT $orderItem->getOrderItemPriceBrutto() * $orderItem->getOrderItemUnits();
  3965.                 } else {
  3966.                     $productPriceVAT $orderItem->getOrderItemPrice() * $orderItem->getOrderItemUnits();
  3967.                 }
  3968.                 if(empty($productPrice)) { 
  3969.                     $productPrice 0;
  3970.                 }
  3971.                 $totalPrice $totalPrice $productPrice;
  3972.                 $totalPriceVAT $totalPriceVAT $productPriceVAT;                
  3973.                 $emailText .= '<tr>
  3974.                   <td>'.$orderItem->getOrderItemId().'</td>
  3975.                   <td>
  3976.                     <strong>'.$orderItem->getOrderItemTitle().'</strong>
  3977.                   </td>
  3978.                   <td>'.$productKey.'</td>
  3979.                   <td>'.$orderItem->getOrderItemUnits().'</td>
  3980.                   <td>'.$orderItem->getOrderItemPrice().' '.$orderItem->getCurrencyKey().'</td>
  3981.                   <td>'.($orderItem->getOrderItemUnits()*$orderItem->getOrderItemPrice()).' '.$orderItem->getCurrencyKey().'</td>
  3982.                 </tr>';
  3983.             }
  3984.         $emailText .= '</table>';
  3985.         $emailText .= '<h3>'.$this->translator->trans('eshop.customer').'</h3>
  3986.         <table width="100%" style="background-color: #EFEFEF; color: Black;font-family: Arial;font-size: 14px;border:Gray solid 1px;" cellspacing="0" cellpadding="3">
  3987.             <tr>
  3988.                 <th style="text-align:left;background-color: LightGray;">id#</th> 
  3989.                 <th style="text-align:left;background-color: LightGray;">'.$this->translator->trans('knowledgebase.first_name').'</th>  
  3990.                 <th style="text-align:left;background-color: LightGray;">'.$this->translator->trans('knowledgebase.last_name').'</th>
  3991.                 <th style="text-align:left;background-color: LightGray;">'.$this->translator->trans('knowledgebase.company_name').'</th>
  3992.                 <th style="text-align:left;background-color: LightGray;">'.$this->translator->trans('knowledgebase.email').'</th>  
  3993.                 <th style="text-align:left;background-color: LightGray;">'.$this->translator->trans('knowledgebase.phone').'</th>         
  3994.                 <th style="text-align:left;background-color: LightGray;">'.$this->translator->trans('address.street').'</th> 
  3995.                 <th style="text-align:left;background-color: LightGray;">'.$this->translator->trans('address.street_number').'</th>
  3996.                 <th style="text-align:left;background-color: LightGray;">'.$this->translator->trans('address.city').'</th> 
  3997.                 <th style="text-align:left;background-color: LightGray;">'.$this->translator->trans('address.zip_code').'</th>
  3998.                 <th style="text-align:left;background-color: LightGray;">'.$this->translator->trans('address.country').'</th>
  3999.             </tr> 
  4000.             <tr>
  4001.                 <td>'.$order->getEshopContact()->getContactId().'</td>
  4002.                 <td>'.$order->getEshopContact()->getFirstName().'</td>
  4003.                 <td>'.$order->getEshopContact()->getLastName().'</td>
  4004.                 <td>'.$order->getEshopContact()->getCompanyName().'</td>
  4005.                 <td>'.$order->getEshopContact()->getEmail().'</td>
  4006.                 <td>'.$order->getEshopContact()->getPhone().'</td>
  4007.                 <td>'.(!empty($order->getEshopContact()->getAddress())?$order->getEshopContact()->getAddress()->getStreet():"").'</td>
  4008.                 <td>'.(!empty($order->getEshopContact()->getAddress())?$order->getEshopContact()->getAddress()->getStreetNumber():"").'</td>                
  4009.                 <td>'.(!empty($order->getEshopContact()->getAddress())?$order->getEshopContact()->getAddress()->getCity():"").'</td>
  4010.                 <td>'.(!empty($order->getEshopContact()->getAddress())?$order->getEshopContact()->getAddress()->getZipCode():"").'</td>
  4011.                 <td>'.(!empty($order->getEshopContact()->getAddress())?$order->getEshopContact()->getAddress()->getCountry():"").'</td>
  4012.     
  4013.             </tr>     
  4014.         </table>';
  4015.         if($order->getEshopContact()->getBusinessId()) {
  4016.             $emailText .= '<div style="padding: 2px;"><strong>'.$this->translator->trans('user.business_number').': </strong>'.$order->getEshopContact()->getBusinessId().'</div>';
  4017.         }
  4018.         if($order->getEshopContact()->getDICId()) {
  4019.             $emailText .= '<div style="padding: 2px;"><strong>'.$this->translator->trans('user.DIC_number').': </strong>'.$order->getEshopContact()->getDICId().'</div>';
  4020.         }        
  4021.         /* we display delivery and price */
  4022.         $emailText .= '<h3>'.$this->translator->trans('eshop.delivery_payment').'</h3>';
  4023.         $emailText .= '<table width="100%" style="background-color: #EFEFEF; color: Black;font-family: Arial;font-size: 14px;border:Gray solid 1px;" cellspacing="0" cellpadding="3">';
  4024.         $emailText .= '<tr><td><strong>'.$this->translator->trans('eshop.delivery').':</strong>';
  4025.         $emailText .= '</td><td>';
  4026.             
  4027.             if(!empty($order->getEshopDelivery())) {
  4028.                 //we set cost in selected currency
  4029.                 $deliveryCost $dem->getRepository(Price::class)->getCurrencyRatedPrice($order->getEshopDelivery()->getCost(), $defaultCurrency$targetCurrency);
  4030.                 $order->getEshopDelivery()->setCost(round($deliveryCost2));
  4031.                 $emailText .= $order->getEshopDelivery()->getEshopDeliveryName();
  4032.                 $emailText .= '<span> [ '.$order->getEshopDelivery()->getCost().' '.$targetCurrency->getCurrencyKey().' ]</span>';
  4033.             }
  4034.         $emailText .= '</td></tr>
  4035.         <tr><td><strong>'.$this->translator->trans('eshop.payment').':</strong>';
  4036.         $emailText .= '</td><td>';
  4037.             if(!empty($order->getEshopPayment())) {
  4038.                 //we set cost in selected currency
  4039.                 $paymentCost $dem->getRepository(Price::class)->getCurrencyRatedPrice($order->getEshopPayment()->getCost(), $defaultCurrency$targetCurrency);
  4040.                 $order->getEshopPayment()->setCost(round($paymentCost2));
  4041.                 $emailText .= $order->getEshopPayment()->getEshopPaymentName();
  4042.                 $emailText .= '<span> [ '.$order->getEshopPayment()->getCost().' '.$targetCurrency->getCurrencyKey().' ]</span>';
  4043.                 if ($order->getEshopPayment()->getPaymentId() == 2) {
  4044.                     // we add sellers bank account info into email
  4045.                     $bankAccountInfo $user->getBankAccount();
  4046.                     $emailText .= '<br>'.$this->translator->trans('eshop.email_bank_account').': '.$bankAccountInfo;
  4047.                 }
  4048.             }
  4049.         $emailText .= '</td></tr>
  4050.         </table>';      
  4051.         /* we display total price */
  4052.         $emailText .= '<br>
  4053.         <table width="100%" style="background-color: #EFEFEF; color: Black;font-family: Arial;font-size: 14px;border:Gray solid 1px;" cellspacing="0" cellpadding="3">
  4054.         <tr><td>'.$this->translator->trans('eshop.price_product_total').':</td><td>'.$totalPrice.' '.$targetCurrency->getCurrencyKey().'</td></tr>
  4055.         <tr><td>'.$this->translator->trans('product.price_with_VAT').':</td><td>'.$totalPriceVAT.' '.$targetCurrency->getCurrencyKey().'</td></tr>';
  4056.         if(!empty($orderPrice)) {
  4057.             $emailText .= '<tr><td><strong>'.$this->translator->trans('eshop.price_total').':</strong></td>';
  4058.             $emailText .= '<td><strong>'.$orderPrice.' '.$targetCurrency->getCurrencyKey().'</strong></td>';
  4059.             $emailText .= '</tr>';  
  4060.         } 
  4061.         if(!empty($orderPriceVAT)) {
  4062.             $emailText .= '<tr><td><strong>'.$this->translator->trans('eshop.price_total_VAT').':</strong></td>';
  4063.             $emailText .= '<td><strong>'.$orderPriceVAT.' '.$targetCurrency->getCurrencyKey().'</strong></td>';
  4064.             $emailText .= '</tr>';  
  4065.         } 
  4066.         $emailText .= '</table>';            
  4067.         return $emailText;
  4068.     }
  4069.     public function getRegisterEmail(Request $request$eshop$contact)
  4070.     {
  4071.         $emailText '<h1>'.$this->translator->trans('eshop.register').' #'.$contact->getContactId().'</h1>';
  4072.         $emailText .= '<h3>'.$this->translator->trans('eshop.customer').'</h3>
  4073.         <table style="color: Black;font-family: Arial;font-size: 14px;border-top:DarkGray solid 2px;border-bottom: DarkGray solid 2px;" cellspacing="0" cellpadding="0">
  4074.             <tr>
  4075.                 <th style="padding: 3px;text-align:left;background-color: LightGray;">id</th> 
  4076.                 <th style="padding: 3px;text-align:left;background-color: LightGray;">'.$this->translator->trans('knowledgebase.first_name').'</th>  
  4077.                 <th style="padding: 3px;text-align:left;background-color: LightGray;">'.$this->translator->trans('knowledgebase.last_name').'</th>
  4078.                 <th style="padding: 3px;text-align:left;background-color: LightGray;">'.$this->translator->trans('knowledgebase.company_name').'</th>
  4079.                 <th style="padding: 3px;text-align:left;background-color: LightGray;">'.$this->translator->trans('knowledgebase.email').'</th>  
  4080.                 <th style="padding: 3px;text-align:left;background-color: LightGray;">'.$this->translator->trans('knowledgebase.phone').'</th>         
  4081.                 <th style="padding: 3px;text-align:left;background-color: LightGray;">'.$this->translator->trans('knowledgebase.user_name').'</th>         
  4082.             </tr> 
  4083.             <tr>
  4084.                 <td style="padding: 3px;">'.$contact->getContactId().'</td>
  4085.                 <td style="padding: 3px;">'.$contact->getFirstName().'</td>
  4086.                 <td style="padding: 3px;">'.$contact->getLastName().'</td>
  4087.                 <td style="padding: 3px;">'.$contact->getCompanyName().'</td>
  4088.                 <td style="padding: 3px;">'.$contact->getEmail().'</td>
  4089.                 <td style="padding: 3px;">'.$contact->getPhone().'</td>
  4090.                 <td style="padding: 3px;">'.$contact->getContactUserName().'</td>          
  4091.             </tr>     
  4092.         </table>';            
  4093.         return $emailText;
  4094.     }
  4095.     public function getEshopRequestEmail(Request $request$eshop$eshopRequestEmail$eshopRequestSubject$eshopRequestMessage$eshopRequestTelephone)
  4096.     {
  4097.         $emailText '<h1>'.$this->translator->trans('eshop.request').'</h1>';
  4098.         $dateTimeNow = new \DateTime("now");
  4099.         $dateCreated $dateTimeNow->format('Y\-m\-d\ H:i:s');
  4100.  
  4101.         $emailText '<h3>'.$this->translator->trans('eshop.request_detail').'</h3>';
  4102.         $emailText .= '<table width="100%" style="background-color: #EFEFEF; color: Black;font-family: Arial;font-size: 14px;border:Gray solid 1px;" cellspacing="0" cellpadding="3">
  4103.             <tr>
  4104.               <td><strong>'.$this->translator->trans('system.date_created').':</strong></td> 
  4105.               <td>'.$dateCreated.'</td>                 
  4106.             </tr>        
  4107.             <tr>
  4108.               <td><strong>Email:</strong></td> 
  4109.               <td>'.$eshopRequestEmail.'</td> 
  4110.             </tr>
  4111.             <tr>
  4112.               <td><strong>'.$this->translator->trans('user.telephone').':</strong></td> 
  4113.               <td>'.$eshopRequestTelephone.'</td> 
  4114.             </tr>            
  4115.             <tr>
  4116.               <td><strong>'.$this->translator->trans('eshop.request_subject').':</strong></td> 
  4117.               <td>'.$eshopRequestSubject.'</td> 
  4118.             </tr>
  4119.             <tr>
  4120.               <td><strong>'.$this->translator->trans('eshop.request_message').':</strong></td> 
  4121.               <td>'.$eshopRequestMessage.'</td> 
  4122.             </tr>            
  4123.             </table> ';    
  4124.         return $emailText;
  4125.     }
  4126.     public function getForgottenPasswordEmail(Request $request$eshop$email)
  4127.     {
  4128.         $link 'https://'.$_SERVER['HTTP_HOST'].'/eshop/'.$eshop->getEshopId().'/forgottenpasswordupdate/'.$email;
  4129.         $emailText '<h1>'.$this->translator->trans('user.forgotten_password').'</h1>';
  4130.         $emailText .= $this->translator->trans('user.forgotten_password_link').'
  4131.        
  4132.                 <a href="'.$link.'" target="_blank" style="padding: 3px;">'.$link.'</a>
  4133.      
  4134.                         ';            
  4135.         return $emailText;
  4136.     }    
  4137.     /**
  4138.      * @Route("/eshopAdmin", name="eshopAdmin")
  4139.      */
  4140.     public function eshopAdminAction(Request $request)
  4141.     {
  4142.         /* we load session data */
  4143.         parent::init($request);
  4144.         
  4145.         $session $request->getSession();
  4146.         // we check if any user is logged in
  4147.         if(!$this->isLoggedUser($request)) {
  4148.             return $this->redirectToRoute('login');
  4149.         }    
  4150.         /* we load entity managers */
  4151.         $em $this->doctrine->getManager();
  4152.         $dem $this->doctrine->getManager('dynamic_em');
  4153.         
  4154.         /* we get current user */
  4155.         $currentUserId $session->get('user')->getUserId();
  4156.         $user $em->getRepository(User::class)->getUser($currentUserId);
  4157.         /* setting current eshop */
  4158.         if(!empty($request->query->get('setCurrent'))) {
  4159.             $eshop $em->getRepository(Eshop::class)->getEshop($request->query->get('setCurrent'));
  4160.             $em->getRepository(Eshop::class)->setCurrentEshop($currentUserId$request->query->get('setCurrent'));
  4161.             $session->set('eshop'$eshop);
  4162.             
  4163.             $this->addFlash('notice''The eshop '.$eshop->getEshopName().' was set as current one.');
  4164.             return $this->redirectToRoute('eshopAdmin');
  4165.             
  4166.         }
  4167.         
  4168.         /* we get current e-shop */
  4169. //        print('<br>qqw currentUserId: '.$currentUserId);
  4170.         $currentEshop $em->getRepository(Eshop::class)->getCurrentEshop($currentUserId);
  4171.         if(!empty($currentEshop)) {
  4172.             $defaultCurrency $em->getRepository(Currency::class)->getCurrency($currentEshop->getPreferredCurrencyId());
  4173.         } else {
  4174.             $defaultCurrency null;
  4175.         }
  4176.       
  4177.       /*
  4178.         print('<br>qqw currentEshop: ');
  4179.         \Doctrine\Common\Util\Debug::dump($currentEshop->getEshopId());
  4180.       */      
  4181.       
  4182.         /* we load list of eshops for logged user */
  4183.         $eshopList $em->getRepository(Eshop::class)->getEshopListByUser($currentUserId);
  4184.         //we create new e-shop if there is none
  4185.         if(count($eshopList) == 0) {
  4186.             $this->eshopCreate($request);
  4187.             return $this->redirectToRoute('eshopAdmin'); 
  4188.         }
  4189.         
  4190.         if(!empty($currentEshop)) {
  4191.             /* we load list of web pages for the current eshop */
  4192.             $webPageList $dem->getRepository(WebPage::class)->getWebPageListByEshop($currentEshop->getEshopId());
  4193.      
  4194.             $eshopHeader $dem->getRepository(Eshop::class)->getEshopHeader($currentEshop->getEshopId());
  4195.             if(!empty($eshopHeader)) {
  4196.               $eshopHeader->setLocale($session->get('lang')->getLangKey());
  4197.               $dem->refresh($eshopHeader);            
  4198.             }
  4199.             /* we load footer for the current website */
  4200.             $eshopFooter $dem->getRepository(Eshop::class)->getEshopFooter($currentEshop->getEshopId());
  4201.             if(!empty($eshopFooter)) {         
  4202.               $eshopFooter->setLocale($session->get('lang')->getLangKey());
  4203.               $dem->refresh($eshopFooter);  
  4204.             }  
  4205.         } else {
  4206.             $webPageList = array();
  4207.             //$webMenuList = array();
  4208.             $eshopHeader null;
  4209.             $eshopFooter null;
  4210.         }      
  4211.         
  4212.       
  4213.         /* we load list of wireframes */
  4214.         $wireFrameList $em->getRepository(WireFrame::class)->getWireFrameList();
  4215.         
  4216.         /* we prepare array of wireframes */
  4217.         $wireFrameArray = array();
  4218.         foreach($wireFrameList as $wireFrame) {
  4219.             $wireFrameArray[$wireFrame->getWireFrameId()] = $wireFrame;
  4220.         }
  4221.          
  4222.         /* we prepare array of count(products) */
  4223.         $productCountArray = array();
  4224.         /*
  4225.         foreach($websiteList as $website) {
  4226.             $productCountArray[$website->getWebsiteId()] = $dem->getRepository(WebPage::class)->getWebPageCountByWebsite($website->getWebsiteId());
  4227.         } 
  4228.         */      
  4229.         
  4230.         /* we load list of modules for e-shop service */
  4231.         $service $em->getRepository(Service::class)->getService(1);
  4232.         /* we load recent orders */
  4233.         $orderList $dem->getRepository(Order::class)->getOrderList("orderId""DESC"10);
  4234.         /* we load order prices */
  4235.         $orderPrices = array();
  4236.         if(!empty($defaultCurrency)) {
  4237.             foreach($orderList as $order) {
  4238.                 if(!empty($order->getCurrencyKey())) {
  4239.                     $targetCurrency $em->getRepository(Currency::class)->getCurrencyByKey($order->getCurrencyKey());
  4240.                 } else {
  4241.                     $targetCurrency $defaultCurrency;
  4242.                 }
  4243.                 
  4244.                 
  4245.                 $orderPrices[$order->getOrderId()] = $dem->getRepository(Order::class)->getOrderPrice($order->getOrderId(), $targetCurrencyfalse$currentEshop$defaultCurrency);
  4246.                 
  4247.             }
  4248.         }
  4249.         //$moduleCollection = $em->getRepository(Module::class)->getModuleList();
  4250.         
  4251.         /*
  4252.         print('<br>qqw moduleCollection: ');
  4253.         \Doctrine\Common\Util\Debug::dump($moduleCollection);
  4254.         
  4255.         print('<hr>qqw userModuleCollection: ');
  4256.         \Doctrine\Common\Util\Debug::dump($user->getModules());   ());      
  4257.         */
  4258.         /* we render data */
  4259.         return $this->render('eshopAdmin.html.twig',
  4260.                 array('headerData' => $this -> getPageHeader($request),
  4261.                       'eshopList' => $eshopList,
  4262.                       'eshopHeader' => $eshopHeader,
  4263.                       'eshopFooter' => $eshopFooter,
  4264.                       'webPageList' => $webPageList,
  4265.                       'moduleList' => $service->getModules(),
  4266.                       'userModuleList' => $user->getModules(),
  4267.                       'wireFrameArray' => $wireFrameArray,
  4268.                       'productCountArray' => $productCountArray,
  4269.                       'orderList' => $orderList,
  4270.                       'orderPrices' => $orderPrices,
  4271.                       'user' => $user,
  4272.                       'menu' => $this -> adminMenu($request),
  4273.                       'mainMenu' => $this -> adminMainMenu($request)
  4274.                 )
  4275.                 );
  4276.     
  4277.     }
  4278.     
  4279.     /**
  4280.      * @Route("/categorynew", name="categoryNew")
  4281.      */
  4282.     public function categoryNewAction(Request $request)
  4283.     {
  4284.         /* we load session data */
  4285.         parent::init($request);
  4286.     
  4287.         $session $request->getSession();
  4288.     
  4289.         $em $this->doctrine->getManager();
  4290.         $dem $this->doctrine->getManager('dynamic_em');
  4291.         
  4292.         $currentUserId $session->get('user')->getUserId();
  4293.         $user $em->getRepository(User::class)->getUser($currentUserId);
  4294.         
  4295.         /* we get current e-shop */
  4296.         $eshop $em->getRepository(Eshop::class)->getCurrentEshop($currentUserId);
  4297.          
  4298.         $categoryCollection $dem->getRepository(Eshop::class)->getCategoryListByEshop($eshop->getEshopId());
  4299.          
  4300.          
  4301.         /* we build login form */
  4302.         $category = new Category;
  4303.         $formBuilder $this->createFormBuilder($category);
  4304.          
  4305.         $formBuilder->add('categoryName'TextType::class, array(
  4306.                 'required' => true,
  4307.                 'label' => $this->translator->trans('eshop.category_name'),
  4308.                 'attr' => array('class' => 'text_form''size' => 22),
  4309.                 'label_attr' => array('class' => 'form_field_label'),
  4310.         ));
  4311.         /* we add category list */
  4312.         $categories = array();
  4313.         $categories['RootX'] = 0;
  4314.         foreach($categoryCollection as $cat)
  4315.         {
  4316.             $catId $cat->getCategoryId();
  4317.             //print('<br>qqw cat: '.$catId);
  4318.             $cat->setLocale($session->get('lang')->getLangKey());
  4319.             $dem->refresh($cat);
  4320.             $catName $cat->getCategoryName();
  4321.             $categories[$catName] = $catId;
  4322.         }  
  4323.         
  4324.         /*
  4325.         print('<hr>qqw categories ');
  4326.         \Doctrine\Common\Util\Debug::dump($categories);
  4327.         
  4328.         print('<hr>qqw categories 2');
  4329.         \Doctrine\Common\Util\Debug::dump($categories2);
  4330.         */      
  4331.         
  4332.         $formBuilder->add('categories'ChoiceType::class, array(
  4333.                 'choices' => $categories,
  4334.                 'mapped' => false,
  4335.                 'attr' => array('class' => 'selector'),
  4336.                 'label' => $this->translator->trans('eshop.parent_category'),
  4337.                 'label_attr' => array('class' => 'form_field_label')
  4338.         ));     
  4339.         
  4340.         $formBuilder->add('save'SubmitType::class, array('label' => $this->translator->trans('form.button.save'),
  4341.                 'attr' => array('class' => 'butt_big')));
  4342.          
  4343.         $form $formBuilder->getForm();
  4344.         $form->handleRequest($request);
  4345.          
  4346.         if ($request->getMethod() == 'POST') {
  4347.     
  4348.             if ($form->isValid()) {
  4349.                 $formData $form->getData();
  4350.                  
  4351.                 /* we load users entity manager */
  4352.                 $dem $this->doctrine->getManager('dynamic_em');
  4353.                  
  4354.                 //$userName = $request->request->get('form')['username'];
  4355.                 //$userExist = $em->getRepository(User::class)->getUserFromLogin($userName, $request->request->get('form')['password']);
  4356.                 
  4357.                 $root $dem->getRepository(Eshop::class)->getCategory(1);
  4358.                 $dem->persist($eshop);
  4359.                 $category->setCategoryName($formData->getCategoryName());
  4360.                 $category->setIsActive(1);
  4361.                 $category->setEshopId($eshop->getEshopId());
  4362.                 if(intval($form['categories']->getData()) == 0) {
  4363.                     $parentCategory null;
  4364.                 } else {
  4365.                     $parentCategory $dem->getRepository(Eshop::class)->getCategory(intval($form['categories']->getData()));
  4366.                 }
  4367.                 $category->setParent($parentCategory);
  4368.                  
  4369.                 /* we persist and save category */
  4370.                 $dem->persist($category);
  4371.                 $dem->flush();
  4372.                  
  4373.                 $this->addFlash('notice''New category was created.');
  4374.                 
  4375.                 return $this->redirectToRoute('categoryEdit', array('categoryId' => $category->getCategoryId()));
  4376.                  
  4377.             }
  4378.              
  4379.         }
  4380.     
  4381.         /* we render data */
  4382.         return $this->render('categoryNew.html.twig',
  4383.                 array('form' => $formBuilder->getForm()->createView(),
  4384.                         'headerData' => $this -> getPageHeader($request),
  4385.                         'user' => $user,
  4386.                         'menu' => $this -> adminMenu($request),'mainMenu' => $this -> adminMainMenu($request),'mainMenu' => $this -> adminMainMenu($request),
  4387.                 )
  4388.                 );
  4389.     
  4390.     }
  4391.         
  4392.     /**
  4393.      * @Route("/categories", name="categories")
  4394.      */
  4395.     public function categoriesAction(Request $request)
  4396.     {
  4397.         /* we load session data */
  4398.         parent::init($request);
  4399.         $session $request->getSession();
  4400.         // we check if any user is logged in
  4401.         if(!$this->isLoggedUser($request)) {
  4402.             return $this->redirectToRoute('login');
  4403.         }            
  4404.          
  4405.         /* we load entity managers */
  4406.         $em $this->doctrine->getManager();
  4407.         $dem $this->doctrine->getManager('dynamic_em');
  4408.     
  4409.         $currentUserId $session->get('user')->getUserId();
  4410.         $user $em->getRepository(User::class)->getUser($currentUserId);
  4411.          
  4412.         /* we get current e-shop */
  4413.         $eshop $em->getRepository(Eshop::class)->getCurrentEshop($currentUserId);
  4414.         /* we do a action with selected products */
  4415.         if (!empty($request->request->get('selectCategoriesSubmit'))) {
  4416. //            print('<br>qqw selectedCategories:');
  4417.             set_time_limit(60);
  4418.             $productIds = [];
  4419.             foreach ($request->request->all('selectedCategories') as $cId) {
  4420. //                print('<br>qqw cID: '.$cId);
  4421.                 $categoryIds[] = $cId;
  4422.                 /* we get product and remove it */
  4423. //                $category = $dem->getRepository(Eshop::class)->getCategory($cId);
  4424.                 $category $dem->getRepository(Category::class)->findOneBy(['categoryId'=> $cId]);
  4425.                 if (!empty($category)) {
  4426.                     $dem->remove($category);
  4427.                     $em->persist($category);
  4428.                     $dem->flush();
  4429.                 }
  4430.             }
  4431.             /* we remove product prices */
  4432.             $productPriceList $dem->getRepository(Product::class)->getProductPriceList($productIds);
  4433.             foreach($productPriceList as $price) {
  4434.                 //print('<br>qqw removing price: ');
  4435.                 $dem->remove($price);
  4436.                 $dem->flush();
  4437.             }
  4438.             $this->addFlash('notice'$this->translator->trans('category.removed'));
  4439.         }
  4440.         $categoryList $dem->getRepository(Eshop::class)->getCategoryListByEshop($eshop->getEshopId());
  4441.          
  4442.         $root $dem->getRepository(Eshop::class)->getCategory(1);
  4443.         if(isset($GLOBALS['request']) && $GLOBALS['request']) {
  4444.             $locale $GLOBALS['request']->getLocale();    
  4445.             //print('<br>qqw locale: '.$locale);
  4446.         }
  4447.         foreach($categoryList as $cat) {
  4448.             $cat->setLocale('en');
  4449.             //$cat->setLocale($locale);
  4450.             $dem->refresh($cat);
  4451.             //print('<br>qqw cat (id '.$cat->getCategoryId().'): '.$cat->getCategoryName());
  4452.         }
  4453.         /* category name - multilangual fields */
  4454.         /*
  4455.         foreach($eshop->getLanguages() as $lang) {
  4456.         
  4457.             //$fieldLabel = $this->translator->trans('eshop.category_name').' ['.$lang->getLangKey().']';
  4458.             $category->setLocale($lang->getLangKey());
  4459.             $dem->refresh($category);
  4460.             $fieldValue = $category->getCategoryName();
  4461.  
  4462.         } 
  4463.         */  
  4464.         
  4465.         //$vegetables = $dem->getRepository(Eshop::class)->getCategory(9);
  4466.         
  4467.         /*
  4468.         $food = new Category();
  4469.         $food->setCategoryName('Food');
  4470.         $food->setParent($root);
  4471.         
  4472.         $fruits = new Category();
  4473.         $fruits->setCategoryName('Fruits');
  4474.         $fruits->setParent($food);      
  4475.         
  4476.         $vegetables = new Category();
  4477.         $vegetables->setCategoryName('Vegetables');
  4478.         $vegetables->setParent($food);
  4479.          
  4480.         $carrots = new Category();
  4481.         $carrots->setCategoryName('Carrots');
  4482.         $carrots->setParent($vegetables);       
  4483.         
  4484.         $dem->persist($fruits);
  4485.         $dem->persist($vegetables);
  4486.         $dem->persist($carrots);        
  4487.         $dem->persist($food);
  4488.         $dem->flush();
  4489.         */
  4490.         
  4491.         
  4492.         //$repo = $em->getRepository('Entity\Category');
  4493.         
  4494.         $repo $dem->getRepository(Category::class);
  4495.         
  4496.         $this->dynamicEntityManager $dem;
  4497.         $this->currentEshop $eshop;
  4498.         
  4499.         $options = array(
  4500.                 'decorate' => true,             
  4501.                 'rootOpen' => '<ul>',
  4502.                 'rootClose' => '</ul>',
  4503.                 'childOpen' => function($node) {
  4504.                     
  4505.                     
  4506.                     //print('<br>QQW node: ');
  4507.                     //\Doctrine\Common\Util\Debug::dump($node);
  4508.                         
  4509.                     
  4510.                     if($node['eshopId'] == $this->currentEshop->getEshopId()) {
  4511.                         return '<li>';
  4512.                     } else {
  4513.                         return '<li class="treeItemHidden">';
  4514.                     }                   
  4515.                     
  4516.                     /*
  4517.                     print('<br>QQW getEshop: '.$cat->getEshop()->getEshopId());
  4518.                     print('<br>QQW currentEshop: '.$this->currentEshop->getEshopId());
  4519.                     
  4520.                     if($cat->getEshop()->getEshopId() == $this->currentEshop->getEshopId()) {
  4521.                         return '<li>currShop'; 
  4522.                     } else {
  4523.                         return '<li>';
  4524.                     }
  4525.                     
  4526.                     print('<hr>QQW cat: ');
  4527.                     
  4528.                     
  4529.                     print('<hr>QQW cat: ');
  4530.                     \Doctrine\Common\Util\Debug::dump($cat);    
  4531.                     */              
  4532.                     /*
  4533.                     if($node['categoryName'] == "Nokia") {
  4534.                         return '<h1>QQW NOKIA</h1><ul>';
  4535.                     } else {
  4536.                         return '<ul>';
  4537.                     }
  4538.                     */
  4539.                     
  4540.                     return '<li>';
  4541.                     
  4542.                     
  4543.                 },
  4544.                 'childClose' => '</li>',
  4545.                 'nodeDecorator' => function($node) {
  4546.                   return '<a href="./categoryedit/'.$node['categoryId'].'" class="treeNodeLink">'.$node['categoryName'].'</a>[<a href="./categoryedit/'.$node['categoryId'].'" class="treeLinkLeft">'.$this->translator->trans('system.edit').'</a>][<a href="./categoryremove/'.$node['categoryId'].'" class="treeLink">'.$this->translator->trans('system.remove').'</a>]';
  4547.                 }
  4548.                 );
  4549.         
  4550.         /*
  4551.         $options = array(
  4552.                 'decorate' => true,
  4553.                 'rootOpen' => '<ul>',
  4554.                 'rootClose' => '</ul>',
  4555.                 'childOpen' => '<li>',
  4556.                 'childClose' => '</li>',
  4557.                 'nodeDecorator' => function($node) {
  4558.                 return '<a href="./categoryedit/'.$node['categoryId'].'" class="treeNodeLink">'.$node['categoryName'].'</a>[<a href="./categoryedit/'.$node['categoryId'].'" class="treeLinkLeft">'.$this->translator->trans('system.edit').'</a>][<a href="./categoryremove/'.$node['categoryId'].'" class="treeLink">'.$this->translator->trans('system.remove').'</a>]';
  4559.                 }
  4560.                 );
  4561.         */
  4562.         
  4563.         /*
  4564.         $arrayTree = $repo->childrenHierarchy();
  4565.         print("<hr>qqw arrayTree: ");
  4566.         print_r($arrayTree);
  4567.         */
  4568.         
  4569.         /*
  4570.         $rootNodes = $repo->getRootNodes();
  4571.         
  4572.         print("<hr>qqw Root Nodes: ");
  4573.         print_r($rootNodes);        
  4574.         */
  4575.         
  4576.         $htmlTree $repo->childrenHierarchy(
  4577.                 null
  4578.                 false
  4579.                 $options
  4580.                 );
  4581.         
  4582.             
  4583.         
  4584.         //$children = $repo->children($vegetables, false, null, 'ASC', false);
  4585.         
  4586.         //echo "<br>qqw childCount: ".$repo->childCount($root);
  4587.         
  4588.         /*
  4589.         $fruits = new Category();
  4590.         $fruits->setCategoryName('Fruits');
  4591.         $fruits->setParent($food);
  4592.         
  4593.         $vegetables = new Category();
  4594.         $vegetables->setCategoryName('Vegetables');
  4595.         $vegetables->setParent($food);
  4596.         
  4597.         $carrots = new Category();
  4598.         $carrots->setCategoryName('Carrots');
  4599.         $carrots->setParent($vegetables);
  4600.         
  4601.         $dem->persist($food);
  4602.         $dem->persist($fruits);
  4603.         $dem->persist($vegetables);
  4604.         $dem->persist($carrots);
  4605.         $dem->flush();
  4606.         */      
  4607.         
  4608.         //echo $request->attributes->get('_route');
  4609.         //echo $request->getPathInfo();
  4610.          
  4611.         /* we render data */
  4612.         return $this->render('categories.html.twig',
  4613.                 array(  'headerData' => $this -> getPageHeader($request),
  4614.                         'categoryList' => $categoryList,
  4615.                         'htmlTree' => $htmlTree,
  4616.                         'user' => $user,
  4617.                         'menu' => $this -> adminMenu($request),'mainMenu' => $this -> adminMainMenu($request),'mainMenu' => $this -> adminMainMenu($request),
  4618.                 )
  4619.                 );
  4620.     
  4621.     }  
  4622.     
  4623.     /**
  4624.      * @Route("/categoryedit/{categoryId}", name="categoryEdit")
  4625.      */
  4626.     public function categoryEditAction(Request $request$categoryId)
  4627.     {
  4628.         /* we load session data */
  4629.         parent::init($request);
  4630.         $session $request->getSession();
  4631.         // we check if any user is logged in
  4632.         if(!$this->isLoggedUser($request)) {
  4633.             return $this->redirectToRoute('login');
  4634.         }            
  4635.     
  4636.         /* we load entity managers */
  4637.         $em $this->doctrine->getManager();
  4638.         $dem $this->doctrine->getManager('dynamic_em');
  4639.          
  4640.         $userId $session->get('user')->getUserId();
  4641.         $user $em->getRepository(User::class)->getUser($userId);
  4642.          
  4643.         /* we get current e-shop */
  4644.         $eshop $em->getRepository(Eshop::class)->getCurrentEshop($userId);
  4645.         
  4646.         $category $dem->getRepository(Eshop::class)->getCategory($categoryId);
  4647.      
  4648.         $categoryCollection $dem->getRepository(Eshop::class)->getCategoryListByEshop($eshop->getEshopId());
  4649.              
  4650.         //$serviceCollection = $em->getRepository(Service::class)->getServiceList();
  4651.          
  4652.         /* 
  4653.         print('<br>QQW cat ID: '.$categoryId);
  4654.         \Doctrine\Common\Util\Debug::dump($category);
  4655.         */
  4656.         /* we build category edit form */
  4657.         $formBuilder $this->createFormBuilder($category);
  4658.         $formBuilder->add('save'SubmitType::class, array('label' => $this->translator->trans('form.button.save'),
  4659.                 'attr' => array('class' => 'butt_big'))); 
  4660.         
  4661.         /* category name - multilangual fields */
  4662.         foreach($eshop->getLanguages() as $lang) {
  4663.         
  4664.             $fieldLabel $this->translator->trans('eshop.category_name').' ['.$lang->getLangKey().']';
  4665.             $category->setLocale($lang->getLangKey());
  4666.             $dem->refresh($category);
  4667.             $fieldValue $category->getCategoryName();
  4668.              
  4669.             $formBuilder->add('categoryName_'.$lang->getLangKey(), TextType::class, array(
  4670.                     'required' => false,
  4671.                     'mapped' => false,
  4672.                     'label' => $fieldLabel,
  4673.                     'attr' => array('class' => 'text_form''size' => 35'value' => $fieldValue),
  4674.                     'label_attr' => array('class' => 'form_field_label')
  4675.             ));
  4676.              
  4677.         }   
  4678.         /* we add category list */
  4679.         $categories = array();
  4680.         $categories['Root'] = 0;
  4681.         foreach($categoryCollection as $cat)
  4682.         {
  4683.             $catId $cat->getCategoryId();
  4684.             $cat->setLocale($session->get('lang')->getLangKey());
  4685.             $dem->refresh($cat);
  4686.             //print('<br>qqw cat: '.$catId);
  4687.             $categories[$cat->getCategoryName()] = $catId;
  4688.         
  4689.         }    
  4690.         
  4691.         if($category->getParent() === null) {
  4692.             $selectedCategory 0;
  4693.         } else {
  4694.             $selectedCategory $category->getParent()->getCategoryId();
  4695.         }
  4696.         
  4697.         $formBuilder->add('parentCategoryId'ChoiceType::class, array(
  4698.                 'choices' => $categories,
  4699.                 'mapped' => false,
  4700.                 'label' => $this->translator->trans('eshop.parent_category'),
  4701.                 'attr' => array('class' => 'selector'),
  4702.                 'label_attr' => array('class' => 'form_field_label'),
  4703.                 'data' => $selectedCategory
  4704.         ));     
  4705.          
  4706.         $formBuilder->add('categoryKey'TextType::class, array(
  4707.                 'required' => false,
  4708.                 'label' => $this->translator->trans('eshop.category_key'),
  4709.                 'attr' => array('class' => 'text_form''size' => 35'value' => $category->getCategoryKey()),
  4710.                 'label_attr' => array('class' => 'form_field_label')
  4711.         ));
  4712.         $formBuilder->add('ERPKey'TextType::class, array(
  4713.                 'required' => false,
  4714.                 'label' => $this->translator->trans('system.erp_key'),
  4715.                 'attr' => array('class' => 'text_form''size' => 35'value' => $category->getERPKey()),
  4716.                 'label_attr' => array('class' => 'form_field_label')
  4717.         ));        
  4718.         $formBuilder->add('isActive'ChoiceType::class, array(
  4719.                 'choices' => array(
  4720.                                 'Yes' => true,
  4721.                                 'No' => false
  4722.                              ),
  4723.                 'required' => false,
  4724.                 'mapped' => false,
  4725.                 'multiple' => false,
  4726.                 'expanded' => false,
  4727.                 'placeholder' => false,
  4728.                 'attr' => array('class' => 'selector'),
  4729.                 'label_attr' => array('class' => 'form_field_label'),
  4730.                 'data' => ($category->getIsActive()=="0"?0:1
  4731.         ));
  4732.         $formBuilder->add('priority'TextType::class, array(
  4733.             'required' => false,
  4734.             'label' => $this->translator->trans('system.priority'),
  4735.             'attr' => array('class' => 'text_form''size' => 10'value' => $category->getPriority()),
  4736.             'label_attr' => array('class' => 'form_field_label')
  4737.         ));
  4738.         $image1Label $this->translator->trans('image.main');
  4739.         if(!empty($category->getImage1())) {
  4740.             $image1Label .= " [ ".$category->getImage1()." ]";
  4741.         }
  4742.         $formBuilder->add('image1'FileType::class, array(
  4743.                 'required' => false,
  4744.                 'data_class' => null,
  4745.                 'label' => $image1Label,
  4746.                 'attr' => array('class' => 'text_form_file''size' => 22'value' => 'vvx2'),
  4747.                 'label_attr' => array('class' => 'form_field_label_block'),
  4748.         ));     
  4749.         /* product description - multilangual fields */
  4750.         foreach($eshop->getLanguages() as $lang) {
  4751.         
  4752.             $fieldLabel $this->translator->trans('eshop.category_description').' ['.$lang->getLangKey().']';
  4753.             $category->setLocale($lang->getLangKey());
  4754.             $dem->refresh($category);
  4755.             $fieldValue $category->getCategoryDescription();
  4756.             
  4757.             $formBuilder->add('categoryDescription_'.$lang->getLangKey(), TextareaType::class, array(
  4758.                     'required' => false,
  4759.                     'mapped' => false,
  4760.                     'label' => $fieldLabel,
  4761.                     'attr' => array('class' => 'textarea_form''cols' => 69'rows' => 7'value' => $fieldValue),
  4762.                     'label_attr' => array('class' => 'form_textarea_label2'),
  4763.                     'data' => $fieldValue,
  4764.             ));             
  4765.              
  4766.         }  
  4767.         /* we set default width of image thumbnail */
  4768.         $formBuilder->add('imageThumbWidth'TextType::class, array(
  4769.                 'required' => false,
  4770.                 'label' => $this->translator->trans('product.products').' - '.$this->translator->trans('image.thumb_width'),
  4771.                 'attr' => array('class' => 'text_form''size' => 10'value' => $category->getImageThumbWidth()),
  4772.                 'label_attr' => array('class' => 'form_field_label')
  4773.         ));     
  4774.         /* we set default height of image thumbnail */
  4775.         $formBuilder->add('imageThumbHeight'TextType::class, array(
  4776.                 'required' => false,
  4777.                 'label' => $this->translator->trans('product.products').' - '.$this->translator->trans('image.thumb_height'),
  4778.                 'attr' => array('class' => 'text_form''size' => 10'value' => $category->getImageThumbHeight()),
  4779.                 'label_attr' => array('class' => 'form_field_label')
  4780.         ));     
  4781.         /* 
  4782.         print('<hr>qqw categories ');
  4783.         \Doctrine\Common\Util\Debug::dump($categories);
  4784.         
  4785.         print('<hr>qqw categories 2');
  4786.         \Doctrine\Common\Util\Debug::dump($categories2);
  4787.         */      
  4788.         $formBuilder->add('save2'SubmitType::class, array('label' => $this->translator->trans('form.button.save'),
  4789.                 'attr' => array('class' => 'butt_big')));
  4790.          
  4791.         $form $formBuilder->getForm();
  4792.          
  4793.         $form->handleRequest($request);
  4794.          
  4795.         if ($request->getMethod() == 'POST') {
  4796.             if ($form->isValid()) {
  4797.                 $formData $form->getData();
  4798.     
  4799.                 //print('<br>We create new user');
  4800.                 //$user = new User;   
  4801.                 /* we load and set parent category */
  4802.                 
  4803.                 $parentCategory $dem->getRepository(Eshop::class)->getCategory($form['parentCategoryId']->getData());
  4804.                 $category->setParent($parentCategory);
  4805.                 /*
  4806.                 print('<br>QQW parentCategoryId: '.$request->request->get('form')['parentCategoryId']);
  4807.                 \Doctrine\Common\Util\Debug::dump($parentCategory);
  4808.                 */
  4809.                 
  4810.                 /* multilangual fields */
  4811.                 foreach($eshop->getLanguages() as $lang) {
  4812.                     $category->setLocale($lang->getLangKey());
  4813.                     $dem->refresh($category);
  4814.                     $category->setCategoryName($form['categoryName_' $lang->getLangKey()]->getData());
  4815.                     $category->setCategoryDescription($form['categoryDescription_' $lang->getLangKey()]->getData());
  4816.                     $dem->persist($category);
  4817.                     $dem->flush();
  4818.                 }    
  4819.                 
  4820.                 /* we handle images */
  4821.                 $image1 $request->files->get('form')['image1'];
  4822.                 /* we check user folder for user files */
  4823.                 if(!$this->isUserFolder($request)) {
  4824.                     $this->createUserFolder($request);
  4825.                 }
  4826.                 
  4827.                 $userDirs $this->getUserFolderPaths($request);
  4828.                 
  4829.                 /* image 1 */
  4830.                 if(!empty($image1)) {
  4831.                     $fileName1 md5(uniqid()).'.'.$image1->guessExtension();
  4832.                     $image1->move($userDirs['images'], $fileName1);
  4833.                     $category->setImage1($fileName1);
  4834.                 }               
  4835.                 
  4836.                 /* we remove old service associations */
  4837.                 /*
  4838.                  foreach($user->getServices() as $service) {
  4839.                  $user->removeService($service);
  4840.                  }
  4841.                  */
  4842.                  
  4843.                 /* we load user services */
  4844.                 /*
  4845.                  if(!empty($request->request->get('form')['services'])) {
  4846.                  foreach($request->request->get('form')['services'] as $serviceId) {
  4847.                  $addService = $em->getRepository(Service::class)->getService($serviceId);
  4848.                  $user->addService($addService);
  4849.                  }
  4850.                  }
  4851.                  */
  4852.                 //print('<br>QQW categoryKey: '.$form['categoryKey']->getData());
  4853.                 /* we load user data from register form into user object */
  4854.                 $category->setCategoryKey($form['categoryKey']->getData());
  4855.                 $category->setERPKey($form['ERPKey']->getData());
  4856.                 //$category->setIsActive($request->request->get('form')['isActive']);
  4857.                 $category->setIsActive($form['isActive']->getData());
  4858.                 $category->setPriority($form['priority']->getData());
  4859.                 $category->setImageThumbWidth($formData->getImageThumbWidth());
  4860.                 $category->setImageThumbHeight($formData->getImageThumbHeight());
  4861.     
  4862.                 //print('<br>QQW priority: '.$form['priority']->getData());
  4863.                 //\Doctrine\Common\Util\Debug::dump($category);        
  4864.                 //die();    
  4865.       
  4866.                 /* we persist and save */
  4867.                 //$em->persist($user);
  4868.                 $dem->persist($category);
  4869.                 $dem->flush();
  4870.                  
  4871.                 $this->addFlash('notice''Category was updated.');
  4872.     
  4873.                 return $this->redirectToRoute('categoryEdit', array('categoryId' => $category->getCategoryId()));
  4874.                  
  4875.             }
  4876.     
  4877.         }
  4878.     
  4879.         /* we render data */
  4880.         return $this->render('categoryEdit.html.twig',
  4881.                 array(  'headerData' => $this -> getPageHeader($request),
  4882.                         'form' => $formBuilder->getForm()->createView(),
  4883.                         'category' => $category,
  4884.                         'user' => $user,
  4885.                         'menu' => $this -> adminMenu($request),'mainMenu' => $this -> adminMainMenu($request),'mainMenu' => $this -> adminMainMenu($request),
  4886.                 )
  4887.                 );
  4888.     
  4889.     }
  4890.     
  4891.     /**
  4892.      * @Route("/categoryremove/{categoryId}", name="categoryRemove")
  4893.      */
  4894.     public function categoryRemoveAction(Request $request$categoryId)
  4895.     {
  4896.     
  4897.         /* we load session data */
  4898.         parent::init($request);
  4899.         $session $request->getSession();
  4900.     
  4901.         /* we load entity managers */
  4902.         $em $this->doctrine->getManager();
  4903.         $dem $this->doctrine->getManager('dynamic_em');
  4904.     
  4905.         $userId $session->get('user')->getUserId();
  4906.     
  4907.         /* we get current e-shop */
  4908.         $eshop $em->getRepository(Eshop::class)->getCurrentEshop($userId);
  4909.          
  4910.         $category $dem->getRepository(Eshop::class)->getCategory($categoryId);
  4911.     
  4912.         /*
  4913.         print('<hr>qqw category: ');
  4914.         \Doctrine\Common\Util\Debug::dump($category);
  4915.         */
  4916.         
  4917.         $repo $dem->getRepository(Category::class);
  4918.         //$repo->removeFromTree($category);
  4919.         
  4920.         $dem->remove($category);
  4921.         
  4922.         //$em->persist($user);
  4923.         $dem->flush();
  4924.         
  4925.         $this->addFlash('notice''Category was removed.');
  4926.         
  4927.         return $this->redirectToRoute('categories');
  4928.         
  4929.         //die();
  4930.         
  4931.     }
  4932.     
  4933.     /**
  4934.      * @Route("/eshopConfig", name="eshopConfig")
  4935.      */
  4936.     public function eshopConfigAction(Request $request)
  4937.     {
  4938.         /* we load session data */
  4939.         parent::init($request);
  4940.         $session $request->getSession();
  4941.         // we check if any user is logged in
  4942.         if(!$this->isLoggedUser($request)) {
  4943.             return $this->redirectToRoute('login');
  4944.         }         
  4945.     
  4946.         /* we load master entity manager */
  4947.         $em $this->doctrine->getManager();
  4948.         $dem $this->doctrine->getManager('dynamic_em');
  4949.         
  4950.         $currentUserId $session->get('user')->getUserId();
  4951.         $user $em->getRepository(User::class)->getUser($currentUserId);
  4952.         /* we get current e-shop */
  4953.         $eshop $em->getRepository(Eshop::class)->getCurrentEshop($currentUserId);
  4954.         $userId $session->get('user')->getUserId();
  4955.         /* we get css designs */
  4956.         $cssDesignCollection $dem->getRepository(CssDesign::class)->getCssDesignList();
  4957.         if(count($cssDesignCollection) == 0) {
  4958.             print('we create new css file');
  4959.             $cssDesign = new CssDesign;
  4960.             $cssDesign->setCssDesignName($user->getUserName());
  4961.             $cssDesign->setCssDesignFile($user->getUserName().".css");
  4962.             /* we persist and save */
  4963.             $dem->persist($cssDesign);
  4964.             $dem->flush();
  4965.             $this->addFlash('notice'$this->translator->trans('module.cssDesigner_created'));
  4966.             return $this->redirectToRoute('webConfig');
  4967.         }
  4968.         
  4969.         /* we get languages */
  4970.         $langCollection $em->getRepository(Language::class)->getLanguageList();
  4971.    
  4972.         /* we get currencies */
  4973.         $currencyCollection $em->getRepository(Currency::class)->getCurrencyList();
  4974.         
  4975.         /* we get css designs */
  4976.         $cssDesignCollection $dem->getRepository(CssDesign::class)->getCssDesignList();
  4977.         
  4978.         /* we get wireframes */
  4979.         $wireFrameCollection $em->getRepository(WireFrame::class)->getWireFrameListByService(1);
  4980.         /* we get galleries */
  4981.         $galleryCollection $dem->getRepository(Gallery::class)->getGalleryListByUser($userId);
  4982.         /* we build register form */
  4983.         $formBuilder $this->createFormBuilder($eshop);
  4984.          
  4985.         $formBuilder->add('eshopName'TextType::class, array(
  4986.                 'required' => false,
  4987.                 'label' => $this->translator->trans('eshop.name'),
  4988.                 'attr' => array('class' => 'text_form''size' => 35'value' => $eshop->getEshopName()),
  4989.                 'label_attr' => array('class' => 'form_field_label')
  4990.         ));
  4991.         
  4992.         /* we add language list */
  4993.         $languages = array();
  4994.         foreach($langCollection as $lang)
  4995.         {
  4996.             $langId $lang->getLangId();
  4997.             $languages[$lang->getLangName()] = $lang->getLangId();
  4998.         }
  4999.         $selectedLanguages = array();
  5000.         if (!empty($eshop->getLanguages())) {
  5001.             foreach($eshop->getLanguages() as $lang) {
  5002.                 $selectedLanguages[] = $lang->getLangId();
  5003.             }
  5004.         }
  5005.         $formBuilder->add('languages'ChoiceType::class, array(
  5006.                 'choices' => $languages,
  5007.                 'required' => false,
  5008.                 'mapped' => false,
  5009.                 'multiple' => true,
  5010.                 'expanded' => true,
  5011.                 'label_attr' => array('class' => 'form_field_label'),
  5012.                 'attr' => array('class' => 'form_field_text'),
  5013.                 'data' => $selectedLanguages
  5014.         ));  
  5015.         
  5016.         $formBuilder->add('preferredLanguageId'ChoiceType::class, array(
  5017.                 'choices' => $languages,
  5018.                 'required' => true,
  5019.                 'mapped' => false,
  5020.                 'multiple' => false,
  5021.                 'placeholder' => false,
  5022.                 'expanded' => true,
  5023.                 'label_attr' => array('class' => 'form_field_label'),
  5024.                 'attr' => array('class' => 'form_field_text'),
  5025.                 'data' => $eshop->getPreferredLanguageId()
  5026.         ));     
  5027.         
  5028.         /* we add currency list */
  5029.         $currencies = array();
  5030.         foreach($currencyCollection as $currency) {
  5031.             $currencyId $currency->getCurrencyId();
  5032.             $currencies[$currency->getCurrencyName()] = $currency->getCurrencyId();
  5033.         }
  5034.         
  5035.         $selectedCurrencies = array();
  5036.         foreach($eshop->getCurrencies() as $currency) {
  5037.             $selectedCurrencies[] = $currency->getCurrencyId();
  5038.         }
  5039.         
  5040.         $formBuilder->add('currencies'ChoiceType::class, array(
  5041.                 'choices' => $currencies,
  5042.                 'required' => false,
  5043.                 'mapped' => false,
  5044.                 'multiple' => true,
  5045.                 'expanded' => true,
  5046.                 'label_attr' => array('class' => 'form_field_label'),
  5047.                 'attr' => array('class' => 'form_field_text'),
  5048.                 'data' => $selectedCurrencies
  5049.         ));  
  5050.         
  5051.         $formBuilder->add('preferredCurrencyId'ChoiceType::class, array(
  5052.                 'choices' => $currencies,
  5053.                 'required' => true,
  5054.                 'mapped' => false,
  5055.                 'multiple' => false,
  5056.                 'placeholder' => false,
  5057.                 'expanded' => true,
  5058.                 'label_attr' => array('class' => 'form_field_label'),
  5059.                 'attr' => array('class' => 'form_field_text'),
  5060.                 'data' => $eshop->getPreferredCurrencyId()
  5061.         ));     
  5062.         
  5063.         /* we add css designs list */
  5064.         $cssDesigns = array();
  5065.         $selectedCss '';
  5066.         foreach($cssDesignCollection as $cssDesign)
  5067.         {
  5068.             $cssDesignId $cssDesign->getCssDesignId();
  5069.             $cssDesigns[$cssDesign->getCssDesignName()] = $cssDesignId;
  5070.             /* we look for selected css design of the e-shop */ 
  5071.             if($cssDesign->getCssDesignFile() == $eshop->getEshopCss()) {
  5072.                 $selectedCss $cssDesign->getCssDesignId();
  5073.             }
  5074.         }
  5075.         $formBuilder->add('cssDesigns'ChoiceType::class, array(
  5076.                 'choices' => $cssDesigns,
  5077.                 'required' => true,
  5078.                 'mapped' => false,
  5079.                 'multiple' => false,
  5080.                 'expanded' => true,
  5081.                 'placeholder' => false,
  5082.                 'label_attr' => array('class' => 'form_field_label'),
  5083.                 'attr' => array('class' => 'form_field_text'),              
  5084.                 'data' => $selectedCss,
  5085.         )); 
  5086.         /* we select product list view */
  5087.         $productViews = array("LIST"=>"LIST""GRID"=>"GRID""B2BLIST"=>"B2BLIST");
  5088.         $selectedProductView $eshop->getProductView();
  5089.         //print("<br>qqw ProductView: ".$eshop->getProductView());
  5090.         
  5091.         $formBuilder->add('productViews'ChoiceType::class, array(
  5092.                 'choices' => $productViews,
  5093.                 'required' => true,
  5094.                 'mapped' => false,
  5095.                 'multiple' => false,
  5096.                 'expanded' => true,
  5097.                 'placeholder' => false,
  5098.                 'label_attr' => array('class' => 'form_field_label'),
  5099.                 'attr' => array('class' => 'form_field_text'),              
  5100.                 'data' => $selectedProductView,
  5101.         )); 
  5102.         /* we set count product per page */
  5103.         $formBuilder->add('countPerPage'TextType::class, array(
  5104.                 'required' => false,
  5105.                 'label' => $this->translator->trans('product.count_per_page'),
  5106.                 'attr' => array('class' => 'text_form''size' => 10'value' => $eshop->getCountPerPage()),
  5107.                 'label_attr' => array('class' => 'form_field_label')
  5108.         ));          
  5109.         /* we display Products From Subfolders */
  5110.         $formBuilder->add('displayProductsFromSubfolders'ChoiceType::class, array(
  5111.                 'choices' => array('Yes' => true'No' => false),
  5112.                 'required' => false,
  5113.                 'mapped' => false,
  5114.                 'multiple' => false,
  5115.                 'expanded' => true,
  5116.                 'placeholder' => false,
  5117.                 'label_attr' => array('class' => 'form_field_label'),
  5118.                 'attr' => array('class' => 'form_field_text'),              
  5119.                 'data' => $eshop->isDisplayProductsFromSubfolders(),
  5120.         )); 
  5121.         
  5122.         /* we display Products From Subfolders - level */
  5123.         $formBuilder->add('displayProductsFromSubfoldersLevel'TextType::class, array(
  5124.                 'required' => false,
  5125.                 'label' => $this->translator->trans('eshop.products_subfolders_level'),
  5126.                 'attr' => array('class' => 'text_form''size' => 10'value' => $eshop->getDisplayProductsFromSubfoldersLevel()),
  5127.                 'label_attr' => array('class' => 'form_field_label')
  5128.         ));         
  5129.         /* we set preferred VAT */
  5130.         $formBuilder->add('preferredVAT'TextType::class, array(
  5131.                 'required' => false,
  5132.                 'label' => $this->translator->trans('eshop.preferred_VAT'),
  5133.                 'attr' => array('class' => 'text_form''size' => 10'value' => $eshop->getPreferredVAT()),
  5134.                 'label_attr' => array('class' => 'form_field_label')
  5135.         ));                  
  5136.         $formBuilder->add('displayNettoPrices'ChoiceType::class, array(
  5137.                 'choices' => array('Yes' => true'No' => false),
  5138.                 'required' => false,
  5139.                 'mapped' => false,
  5140.                 'multiple' => false,
  5141.                 'expanded' => true,
  5142.                 'placeholder' => false,
  5143.                 'label_attr' => array('class' => 'form_field_label'),
  5144.                 'attr' => array('class' => 'form_field_text'),              
  5145.                 'data' => $eshop->isDisplayNettoPrices(),
  5146.         ));  
  5147.         $formBuilder->add('isStock'ChoiceType::class, array(
  5148.                 'choices' => array('Yes' => true'No' => false),
  5149.                 'required' => false,
  5150.                 'mapped' => false,
  5151.                 'multiple' => false,
  5152.                 'expanded' => true,
  5153.                 'placeholder' => false,
  5154.                 'label' => $this->translator->trans('eshop.view_stock'),
  5155.                 'label_attr' => array('class' => 'form_field_label'),
  5156.                 'attr' => array('class' => 'form_field_text'),              
  5157.                 'data' => $eshop->isIsStock(),
  5158.         ));                 
  5159.   
  5160.         /* we set cut of long descriptions in product list */
  5161.         $formBuilder->add('cutLongDescription'TextType::class, array(
  5162.                 'required' => false,
  5163.                 'label' => $this->translator->trans('eshop.cut_long_description'),
  5164.                 'attr' => array('class' => 'text_form''size' => 10'value' => $eshop->getCutLongDescription()),
  5165.                 'label_attr' => array('class' => 'form_field_label')
  5166.         ));     
  5167.         
  5168.         /* we set price rounding */
  5169.         $formBuilder->add('roundPrice'TextType::class, array(
  5170.                 'required' => false,
  5171.                 'label' => $this->translator->trans('eshop.price_round'),
  5172.                 'attr' => array('class' => 'text_form''size' => 10'value' => $eshop->getRoundPrice()),
  5173.                 'label_attr' => array('class' => 'form_field_label')
  5174.         ));     
  5175.         
  5176.         /* we set default width of image thumbnail */
  5177.         $formBuilder->add('imageThumbWidth'TextType::class, array(
  5178.                 'required' => false,
  5179.                 'label' => $this->translator->trans('image.thumb_width'),
  5180.                 'attr' => array('class' => 'text_form''size' => 10'value' => $eshop->getImageThumbWidth()),
  5181.                 'label_attr' => array('class' => 'form_field_label')
  5182.         ));     
  5183.         /* we set default height of image thumbnail */
  5184.         $formBuilder->add('imageThumbHeight'TextType::class, array(
  5185.                 'required' => false,
  5186.                 'label' => $this->translator->trans('image.thumb_height'),
  5187.                 'attr' => array('class' => 'text_form''size' => 10'value' => $eshop->getImageThumbHeight()),
  5188.                 'label_attr' => array('class' => 'form_field_label')
  5189.         ));   
  5190.         /* we set default width of category image thumbnail */
  5191.         $formBuilder->add('categoryImageThumbWidth'TextType::class, array(
  5192.                 'required' => false,
  5193.                 'label' => $this->translator->trans('image.category_thumb_width'),
  5194.                 'attr' => array('class' => 'text_form''size' => 10'value' => $eshop->getCategoryImageThumbWidth()),
  5195.                 'label_attr' => array('class' => 'form_field_label')
  5196.         ));  
  5197.         $formBuilder->add('isAsynchrounousShopping'ChoiceType::class, array(
  5198.                 'choices' => array('Yes' => true'No' => false),
  5199.                 'required' => false,
  5200.                 'mapped' => false,
  5201.                 'multiple' => false,
  5202.                 'expanded' => true,
  5203.                 'placeholder' => false,
  5204.                 'label' => $this->translator->trans('eshop.is_asynchrounous_shopping'),
  5205.                 'label_attr' => array('class' => 'form_field_label'),
  5206.                 'attr' => array('class' => 'form_field_text'),              
  5207.                 'data' => $eshop->isIsAsynchrounousShopping(),
  5208.         ));       
  5209.         $formBuilder->add('isVirtualReality'ChoiceType::class, array(
  5210.                 'choices' => array('Yes' => true'No' => false),
  5211.                 'required' => false,
  5212.                 'mapped' => false,
  5213.                 'multiple' => false,
  5214.                 'expanded' => true,
  5215.                 'placeholder' => false,
  5216.                 'label' => $this->translator->trans('eshop.is_virtual_reality'),
  5217.                 'label_attr' => array('class' => 'form_field_label'),
  5218.                 'attr' => array('class' => 'form_field_text'),              
  5219.                 'data' => $eshop->isIsVirtualReality(),
  5220.         ));                                
  5221.         
  5222.         /* we add home wireframe */
  5223.         $wireFrames = array();
  5224.         $selectedWireFrame '';
  5225.         foreach($wireFrameCollection as $wireFrame)
  5226.         {
  5227.             $wireFrameId $wireFrame->getWireFrameId();
  5228.             $wireFrames[$wireFrame->getWireFrameName()] = $wireFrameId;
  5229.              
  5230.             /* we look for selected wireframe of the eshop */
  5231.             if($wireFrame->getWireFrameId() == $eshop->getWireFrameId()) {
  5232.                 $selectedWireFrame $wireFrame->getWireFrameId();
  5233.             }
  5234.         }
  5235.          
  5236.         $formBuilder->add('wireFrame'ChoiceType::class, array(
  5237.                 'choices' => $wireFrames,
  5238.                 'required' => true,
  5239.                 'mapped' => false,
  5240.                 'multiple' => false,
  5241.                 'expanded' => true,
  5242.                 'placeholder' => false,
  5243.                 'label' => $this->translator->trans('eshop.wireframe_home'),
  5244.                 'label_attr' => array('class' => 'form_field_label'),
  5245.                 'attr' => array('class' => 'form_field_text'),              
  5246.                 'data' => $selectedWireFrame,
  5247.         ));     
  5248.         
  5249.         /* we add product list wireframe */
  5250.         $wireFrames = array();
  5251.         $selectedWireFrame '';
  5252.         foreach($wireFrameCollection as $wireFrame)
  5253.         {
  5254.             $wireFrameId $wireFrame->getWireFrameId();
  5255.             $wireFrames[$wireFrame->getWireFrameName()] = $wireFrameId;
  5256.              
  5257.             /* we look for selected wireframe of the eshop */
  5258.             if($wireFrame->getWireFrameId() == $eshop->getProductListWireFrameId()) {
  5259.                 $selectedWireFrame $wireFrame->getWireFrameId();
  5260.             }
  5261.         }
  5262.         
  5263.         $formBuilder->add('wireFrameProductList'ChoiceType::class, array(
  5264.                 'choices' => $wireFrames,
  5265.                 'required' => true,
  5266.                 'mapped' => false,
  5267.                 'multiple' => false,
  5268.                 'expanded' => true,
  5269.                 'placeholder' => false,
  5270.                 'label' => $this->translator->trans('eshop.wireframe_product_list'),
  5271.                 'label_attr' => array('class' => 'form_field_label'),
  5272.                 'attr' => array('class' => 'form_field_text'),
  5273.                 'data' => $selectedWireFrame,
  5274.         ));     
  5275.         
  5276.         /* we add product detail wireframe */
  5277.         $wireFrames = array();
  5278.         $selectedWireFrame '';
  5279.         foreach($wireFrameCollection as $wireFrame)
  5280.         {
  5281.             $wireFrameId $wireFrame->getWireFrameId();
  5282.             $wireFrames[$wireFrame->getWireFrameName()] = $wireFrameId;
  5283.              
  5284.             /* we look for selected wireframe of the eshop */
  5285.             if($wireFrame->getWireFrameId() == $eshop->getProductDetailWireFrameId()) {
  5286.                 $selectedWireFrame $wireFrame->getWireFrameId();
  5287.             }
  5288.         }
  5289.          
  5290.         $formBuilder->add('wireFrameProductDetail'ChoiceType::class, array(
  5291.                 'choices' => $wireFrames,
  5292.                 'required' => true,
  5293.                 'mapped' => false,
  5294.                 'multiple' => false,
  5295.                 'expanded' => true,
  5296.                 'placeholder' => false,
  5297.                 'label' => $this->translator->trans('eshop.wireframe_product_detail'),
  5298.                 'label_attr' => array('class' => 'form_field_label'),
  5299.                 'attr' => array('class' => 'form_field_text'),
  5300.                 'data' => $selectedWireFrame,
  5301.         ));    
  5302.         
  5303.         $formBuilder->add('save'SubmitType::class, array('label' => $this->translator->trans('form.send'),
  5304.                 'attr' => array('class' => 'butt_big')));
  5305.          
  5306.         $form $formBuilder->getForm();
  5307.          
  5308.         $form->handleRequest($request);
  5309.          
  5310.         if ($request->getMethod() == 'POST') {
  5311.              
  5312.             //$form->bindRequest($request);
  5313.              
  5314.             if ($form->isValid()) {
  5315.                 $formData $form->getData();
  5316.                 /* we load eshop data from form into object */
  5317.                 $eshop->setEshopName($formData->getEshopName());
  5318.                 /* we remove old language associations */
  5319.                 if(!empty($eshop->getLanguages())) {
  5320.                     foreach ($eshop->getLanguages() as $lang) {
  5321.                         $eshop->removeLanguage($lang);
  5322.                     }
  5323.                 }
  5324.                     
  5325.                 /* we load eshop languages */
  5326.                 if(!empty($form['languages']->getData()) and is_array($form['languages']->getData())) {
  5327.                     foreach($form['languages']->getData() as $langId) {
  5328.                         print('<br>lang id: '.$langId);
  5329.                         $addLang $em->getRepository(Language::class)->getLanguage($langId);
  5330.                         print('<br>lang id 2: '.$addLang->getLangId());
  5331.                         $eshop->addLanguage($addLang);
  5332.                         //$->get('user')->addService($addService);
  5333.                     }
  5334.                 }
  5335.                 
  5336.                 /* we set default language */
  5337.                 $eshop->setPreferredLanguageId($form['preferredLanguageId']->getData());
  5338.                 
  5339.                 /* we remove old currency associations */
  5340.                 foreach($eshop->getCurrencies() as $currency) {
  5341.                     $eshop->removeCurrency($currency);
  5342.                 }
  5343.                 
  5344.                 /* we load eshop currencies */
  5345.                 if(!empty($form['currencies']->getData())) {
  5346.                     foreach($form['currencies']->getData() as $currencyId) {
  5347.                         $addCurrency $em->getRepository(Currency::class)->getCurrency($currencyId);
  5348.                         $eshop->addCurrency($addCurrency);
  5349.                     }
  5350.                 }    
  5351.                  
  5352.                 /* we set default currency */
  5353.                 $eshop->setPreferredCurrencyId($form['preferredCurrencyId']->getData());
  5354.                 
  5355.                 /* we set css design */
  5356.                 if(!empty($form['cssDesigns']->getData())) {
  5357.                     $cssDesign $dem->getRepository(CssDesign::class)->getCssDesign($form['cssDesigns']->getData());
  5358.                     $eshop->setEshopCss($cssDesign->getCssDesignFile());  
  5359.                 }
  5360.                 $eshop->setProductView($formData->getProductView());
  5361.                 $eshop->setCountPerPage($formData->getCountPerPage());
  5362.                 $eshop->setPreferredVAT($formData->getPreferredVAT());
  5363.                 
  5364.                 $eshop->setImageThumbWidth($formData->getImageThumbWidth());
  5365.                 $eshop->setImageThumbHeight($formData->getImageThumbHeight());
  5366.                 $eshop->setCategoryImageThumbWidth($formData->getCategoryImageThumbWidth());
  5367.                 $eshop->setRoundPrice($formData->getRoundPrice());
  5368.                 $eshop->setCutLongDescription($formData->getCutLongDescription());
  5369.                 if(!empty($form['displayProductsFromSubfolders']->getData())) {
  5370.                     $eshop->setDisplayProductsFromSubfolders($form['displayProductsFromSubfolders']->getData());
  5371.                 }
  5372.                 
  5373.                 if(!empty($form['displayProductsFromSubfoldersLevel']->getData())) {
  5374.                     $eshop->setDisplayProductsFromSubfoldersLevel($form['displayProductsFromSubfoldersLevel']->getData());
  5375.                 }                
  5376.                 if(!empty($form['displayNettoPrices']->getData())) {
  5377.                     $eshop->setDisplayNettoPrices($form['displayNettoPrices']->getData());
  5378.                 }           
  5379.                 $eshop->setIsStock($form['isStock']->getData());                
  5380.                 $eshop->setIsAsynchrounousShopping($form['isAsynchrounousShopping']->getData());    
  5381.                 $eshop->setIsVirtualReality($form['isVirtualReality']->getData());             
  5382.                 /* home wireframe setting */
  5383.                 $eshop->setWireFrameId($form['wireFrame']->getData());
  5384.                 
  5385.                 /* product list wireframe setting */
  5386.                 $eshop->setProductListWireFrameId($form['wireFrameProductList']->getData());
  5387.                 /* product detail wireframe setting */
  5388.                 $eshop->setProductDetailWireFrameId($form['wireFrameProductDetail']->getData());
  5389.                 
  5390.                 //setEshopName($request->request->get('form')['eshopName']);
  5391.                 
  5392.                 /*
  5393.                 print('<br>qqw user exists: ');
  5394.                 \Doctrine\Common\Util\Debug::dump($user);
  5395.                 */
  5396.                 /* we persist and save user */
  5397.                 $em->persist($eshop);
  5398.                 $em->flush();
  5399.                     
  5400.                 $this->addFlash('notice''Eshop was updated.');
  5401.                     
  5402.                 return $this->redirectToRoute('eshopConfig');
  5403.                  
  5404.             }
  5405.              
  5406.         }       
  5407.     
  5408.         /* we render data */
  5409.         return $this->render('eshopConfig.html.twig',
  5410.                 array(  'headerData' => $this -> getPageHeader($request),
  5411.                         'form' => $formBuilder->getForm()->createView(),
  5412.                         'menu' => $this -> adminMenu($request),
  5413.                         'mainMenu' => $this -> adminMainMenu($request),
  5414.                         'user' => $user,
  5415.                 )
  5416.                 );
  5417.     
  5418.     }    
  5419.     
  5420.     /**
  5421.      * @Route("/eshopnew", name="eshopNew")
  5422.      */
  5423.     public function eshopNewAction(Request $request)
  5424.     {
  5425.     
  5426.         /* we load session data */
  5427.         parent::init($request);
  5428.     
  5429.         $session $request->getSession();
  5430.         /* we load entity managers */
  5431.         $em $this->doctrine->getManager();
  5432.         $dem $this->doctrine->getManager('dynamic_em');
  5433.         $userId $session->get('user')->getUserId();
  5434.         $user $em->getRepository(User::class)->getUser($userId);
  5435.     
  5436.         /* we build login form */
  5437.         $formBuilder $this->createFormBuilder();
  5438.     
  5439.         $formBuilder->add('eshopName'TextType::class, array(
  5440.                 'required' => true,
  5441.                 'label' => $this->translator->trans('eshop.name'),
  5442.                 'attr' => array('class' => 'text_form''size' => 50),
  5443.                 'label_attr' => array('class' => 'form_field_label'),
  5444.         ));
  5445.     
  5446.         $formBuilder->add('save'SubmitType::class, array('label' => $this->translator->trans('form.button.save'),
  5447.                 'attr' => array('class' => 'butt_big')));
  5448.     
  5449.         $form $formBuilder->getForm();
  5450.         $form->handleRequest($request);
  5451.     
  5452.         if ($request->getMethod() == 'POST') {
  5453.     
  5454.             if ($form->isValid()) {
  5455.                 // create and persist e-shop
  5456.                 $this->eshopCreate($request$form['eshopName']->getData());
  5457.                 return $this->redirectToRoute('eshopAdmin'); 
  5458.             }
  5459.              
  5460.         }
  5461.     
  5462.         /* we render data */
  5463.         return $this->render('eshopNew.html.twig',
  5464.                 array(  'form' => $formBuilder->getForm()->createView(),
  5465.                         'user' => $user,
  5466.                         'headerData' => $this -> getPageHeader($request),
  5467.                         'menu' => $this -> adminMenu($request),'mainMenu' => $this -> adminMainMenu($request),'mainMenu' => $this -> adminMainMenu($request),
  5468.                 )
  5469.                 );
  5470.     
  5471.     }
  5472.     public function eshopCreate(Request $request$eshopName "Test shop")
  5473.     {       
  5474.         /* we load session data */
  5475.         parent::init($request);
  5476.     
  5477.         $session $request->getSession();
  5478.     
  5479.         $em $this->doctrine->getManager();
  5480.         $dem $this->doctrine->getManager('dynamic_em');
  5481.         
  5482.         //print('qqw creating eshop...');
  5483.         $eshop = new Eshop;
  5484.         $eshop->setEshopName($eshopName);
  5485.         $eshop->setUserId($session->get('user')->getUserId());
  5486.         // we set default currency
  5487.         $eshop->setPreferredCurrencyId(1);  
  5488.         // we set default language
  5489.         $eshop->setPreferredLanguageId(1);
  5490.         // wireframe setting
  5491.         $eshop->setWireFrameId(5);
  5492.         $eshop->setProductListWireFrameId(5);              
  5493.         $eshop->setProductDetailWireFrameId(5);     
  5494.         // we add currency
  5495.         $addCurrency $em->getRepository(Currency::class)->getCurrency(1);
  5496.         $eshop->addCurrency($addCurrency);    
  5497.         // we add language
  5498.         $addLang $em->getRepository(Language::class)->getLanguage(1);
  5499.         $eshop->addLanguage($addLang);
  5500.         // we add price level
  5501.         $priceLevel = new PriceLevel;
  5502.         $priceLevel->setPriceLevelName('default');        
  5503.         /* we persist and save */
  5504.         $dem->persist($priceLevel);           
  5505.  
  5506.         // we set this eshop as current one 
  5507.         $em->getRepository(Eshop::class)->unsetCurrentEshop($session->get('user')->getUserId());
  5508.         $eshop->setEshopCurrent(true);
  5509.         // we persist and save
  5510.         $em->persist($eshop);
  5511.         $em->flush();
  5512.         
  5513.         
  5514.         // we insert data fixtures
  5515.         //@todo uncomment
  5516.         //$this->eshopDataFixtures($request);
  5517.         //die();
  5518.         $this->addFlash('notice'$this->translator->trans('eshop.created'));
  5519.         //return $this->redirectToRoute('eshopAdmin');      
  5520.     }
  5521.     /**
  5522.      * we insert default data into e-shop from basicdemo account
  5523.     */
  5524.     public function eshopDataFixtures(Request $request)
  5525.     {       
  5526.         /* we load session data */
  5527.         parent::init($request);
  5528.     
  5529.         $session $request->getSession();
  5530.     
  5531.         $em $this->doctrine->getManager();
  5532.         $dem $this->doctrine->getManager('dynamic_em');
  5533.         $demo_em $this->doctrine->getManager('eshop_demo_em');
  5534.         
  5535.         print('qqw eshop data fixtures...');
  5536.         $userId $session->get('user')->getUserId();
  5537.         /* we get current e-shop */
  5538.         $currenteshop $em->getRepository(Eshop::class)->getCurrentEshop($userId);
  5539.          
  5540.         /* we get basicdemo e-shop */
  5541.         $demoUserId 97//demobasic user id
  5542.         $demoshop $em->getRepository(Eshop::class)->getCurrentEshop($demoUserId);
  5543.         print('<br>qqw current eshop id: '.$demoshop->getEshopId());
  5544.         $demoCategoryCollection $demo_em->getRepository(Eshop::class)->getCategoryListByEshop($demoshop->getEshopId());
  5545.         $demoProductCollection $demo_em->getRepository(Product::class)->getProductListByEshop($demoshop->getEshopId(), 3000);
  5546.         //$cat->setLocale($session->get('lang')->getLangKey());
  5547.         
  5548.         foreach($demoCategoryCollection as $cat)
  5549.         {
  5550.             $catId $cat->getCategoryId();
  5551.             // print('<br>qqw cat: '.$catId);
  5552.             // \Doctrine\Common\Util\Debug::dump($cat); 
  5553.                 //we update or create e-shop category
  5554.                 $category $dem->getRepository(Eshop::class)->getCategoryByErpKey($cat->getCategoryKey());
  5555.                 if(empty($category)) {
  5556.                     $category = new Category;
  5557.                 }
  5558.                 //$category = $cat;
  5559.                 $category->setIsActive($cat->getIsActive());
  5560.                 $category->setEshopId($currenteshop->getEshopId());
  5561.                 $category->setCategoryKey($cat->getCategoryKey()); 
  5562.                 $category->setErpKey($cat->getCategoryKey()); 
  5563.                 $parentCategory null;
  5564.                 $category->setParent($parentCategory);
  5565.                 $category->setCategoryName($cat->getCategoryName());
  5566.                 $category->setCategoryDescription($cat->getCategoryDescription());                
  5567.                 
  5568.                 /*
  5569.                 // multilangual fields 
  5570.                 foreach($demoshop->getLanguages() as $lang) {
  5571.                     $cat->setLocale($lang->getLangKey());
  5572.                     $category->setLocale($lang->getLangKey());
  5573.                     $demo_em->refresh($cat);
  5574.                     $dem->refresh($category); 
  5575.                     $session->get('lang')->getLangKey()
  5576.                     print('<br>qqw cat name ('.$lang->getLangKey().'): '.$cat->getCategoryName());
  5577.                     $category->setCategoryName($cat->getCategoryName());
  5578.                     $category->setCategoryDescription($cat->getCategoryDescription());
  5579.                     //print('<br>qqw cat['.$lang->getLangKey().']: '.$category->getCategoryName());
  5580.                     $dem->persist($category);
  5581.                     $dem->flush();
  5582.                 } 
  5583.                 */
  5584.                  
  5585.                 // we persist and save category 
  5586.                 $dem->persist($category);
  5587.                 $dem->flush();
  5588.                 //we load product for this category
  5589.                 $categoryArray = array();
  5590.                 $categoryArray[] = $cat;
  5591.                 $demoProductCollection $demo_em->getRepository(Product::class)->getProductListByCategory($categoryArray0200false);
  5592.                 foreach($demoProductCollection as $prod) {
  5593.                     $prodId $prod->getProductId();
  5594.                     // print('<hr>qqw product: '.$prodId);
  5595.                     // \Doctrine\Common\Util\Debug::dump($prod);    
  5596.                     //we update or create e-shop category
  5597.                     $product $dem->getRepository(Product::class)->getProductByErpKey($prod->getProductKey());
  5598.                     if(empty($product)) {
  5599.                         $product = new Product;
  5600.                         $product->addCategory($category);
  5601.                         // we add product prices
  5602.                         
  5603.                         if(!empty($prod->getPrices())) {
  5604.                             foreach($prod->getPrices() as $priceDemo) {      
  5605.                                 $price = new Price;
  5606.                                 $price->setNettoValue($priceDemo->getNettoValue());
  5607.                                 $price->setBruttoValue($priceDemo->getBruttoValue());
  5608.                                 //$price->setProductId($product->getProductId());
  5609.                                 $price->setPriceLevelId(1);
  5610.                                 
  5611.                                 $dem->persist($price);
  5612.                                 $dem->flush();
  5613.                                 $product->addPrice($price); 
  5614.                             }                   
  5615.                         }
  5616.                         
  5617.                     }
  5618.                     $product->setIsActive($prod->getIsActive());
  5619.                     //$product->setEshopId($currenteshop->getEshopId());
  5620.                     $product->setProductKey($prod->getProductKey()); 
  5621.                     $product->setErpKey($prod->getProductKey()); 
  5622.                     $product->setProductName($prod->getProductName());
  5623.                     $product->setProductDescription($prod->getProductDescription());                    
  5624.                     /*
  5625.                     // multilangual fields 
  5626.                     foreach($demoshop->getLanguages() as $lang) {
  5627.                         $prod->setLocale($lang->getLangKey());
  5628.                         $product->setLocale($lang->getLangKey());
  5629.                         $demo_em->refresh($prod);
  5630.                         //$dem->refresh($category);
  5631.                         print('<br>qqw prod name ('.$lang->getLangKey().'): '.$prod->getProductName());
  5632.                         $product->setProductName($prod->getProductName());
  5633.                         $product->setProductDescription($prod->getProductDescription());
  5634.                         $dem->persist($product);
  5635.                         $dem->flush();
  5636.                         
  5637.                     } 
  5638.                     */
  5639.                     
  5640.                     // we persist and save product 
  5641.                     $dem->persist($product);
  5642.                     $dem->flush();                       
  5643.                 }
  5644.         
  5645.         }  
  5646.         /*
  5647.         foreach($demoProductCollection as $prod)
  5648.         {
  5649.             $prodId = $prod->getProductId();
  5650.             print('<hr>qqw product: '.$prodId);
  5651.             \Doctrine\Common\Util\Debug::dump($prod);    
  5652.                 //we update or create e-shop category
  5653.                 $product = $dem->getRepository(Product::class)->getProductByErpKey($prod->getProductKey());
  5654.                 //getCategoryByErpKey($cat->getCategoryKey());
  5655.                 if(empty($product)) {
  5656.                     $product = new Product;
  5657.                 }
  5658.                 $product->setIsActive($prod->getIsActive());
  5659.                 //$product->setEshopId($currenteshop->getEshopId());
  5660.                 $product->setProductKey($prod->getProductKey()); 
  5661.                 $product->setErpKey($prod->getProductKey()); 
  5662.                 $parentCategory = null;
  5663.                 $product->setParent($parentCategory);
  5664.                 
  5665.                 // multilangual fields 
  5666.                 foreach($demoshop->getLanguages() as $lang) {
  5667.                     $prod->setLocale($lang->getLangKey());
  5668.                     $product->setLocale($lang->getLangKey());
  5669.                     $demo_em->refresh($prod);
  5670.                     //$dem->refresh($category);
  5671.                     print('<br>qqw prod name ('.$lang->getLangKey().'): '.$prod->getProductName());
  5672.                     $product->setProductName($prod->getProductName());
  5673.                     $product->setProductDescription($prod->getProductDescription());
  5674.                     
  5675.                     $dem->persist($product);
  5676.                     $dem->flush();
  5677.                     
  5678.                 } 
  5679.                 
  5680.                 // we persist and save product 
  5681.                 $dem->persist($product);
  5682.                 $dem->flush();   
  5683.                           
  5684.         } 
  5685.         */    
  5686.     }    
  5687.     
  5688.     public function categoryTreeMenu($eshopRequest $request)
  5689.     {    
  5690.         
  5691.         /* we load session data */
  5692.         parent::init($request);
  5693.         $session $request->getSession();
  5694.         
  5695.         /* we load entity managers */
  5696.         $em $this->doctrine->getManager();
  5697.         $dem $this->doctrine->getManager('dynamic_em');
  5698.         
  5699.         $userId $eshop->getUserId();
  5700.         
  5701.         $session->set('eshop'$eshop);
  5702.         
  5703.         /* we get current e-shop */
  5704.         //$eshop = $em->getRepository(Eshop::class)->getCurrentEshop($currentUserId);
  5705.       
  5706.         $repo $dem->getRepository(Category::class);
  5707.          
  5708.         $this->dynamicEntityManager $dem;
  5709.         $this->currentEshop $eshop;
  5710.         $options = array(
  5711.                 'decorate' => true,
  5712.                 'rootOpen' => '<ul class="tree">',
  5713.                 'rootClose' => '</ul>',
  5714.                 'childOpen' => function($node) {
  5715.         
  5716.                     /*
  5717.                      print('<br>QQW node: ');
  5718.                      \Doctrine\Common\Util\Debug::dump($node);
  5719.                      */
  5720.         
  5721.                     if($node['eshopId'] == $this->currentEshop->getEshopId() && !empty($node['isActive']) && $node['isActive']) {
  5722.                         return '<li class="treeItem">';
  5723.                     } else {
  5724.                         return '<li class="treeItemHidden">';
  5725.                     }
  5726.             
  5727.                     return '<li class="treeItem">';
  5728.                 },
  5729.                 'childClose' => '</li>',
  5730.                 'nodeDecorator' => function($node) {
  5731.                     $url $this->generateUrl('eshop',array('eshopId'=>$this->currentEshop->getEshopId()));
  5732.                     return '<a href="'.$url.'/category/'.$node['categoryId'].'" class="treeNodeLink">'.$node['categoryName'].'</a>';
  5733.                 }
  5734.                 );
  5735.          
  5736.         $htmlTree $repo->childrenHierarchy(
  5737.                 null,
  5738.                 false,
  5739.                 $options
  5740.                 );
  5741.          
  5742.         return $htmlTree;           
  5743.         
  5744.     }
  5745.     public function categoryTopMenu($eshopRequest $request)
  5746.     {    
  5747.         /* we load session data */
  5748.         parent::init($request);
  5749.         $session $request->getSession();
  5750.         
  5751.         /* we load entity managers */
  5752.         $em $this->doctrine->getManager();
  5753.         $dem $this->doctrine->getManager('dynamic_em');
  5754. //        print('<br>eshop id:'.$eshop->getEshopId());
  5755. //        $categoryList = $dem->getRepository(Eshop::class)->getRootCategoryListByEshop($eshop->getEshopId());
  5756. //        foreach($categoryList as $cat) {
  5757. //
  5758. //            print('<hr>QQW cat: ');
  5759. //            \Doctrine\Common\Util\Debug::dump($cat);
  5760. //        }
  5761.         $rootNodes $dem->getRepository(Category::class)->getRootNodes();
  5762.         $childNodes = array();
  5763.         foreach($rootNodes as $cat) {
  5764.             if($cat->getEshopId() == $eshop->getEshopId() && $cat->getIsActive()) {
  5765.                 $catName $cat->getCategoryName();
  5766.                 $cat->setLocale($session->get('lang')->getLangKey());
  5767.                 $dem->refresh($cat);
  5768.                 if ($cat->getCategoryName() == '') {
  5769.                     $cat->setCategoryName($catName);
  5770.                 }
  5771.                 if ($cat->getCategoryName() != '') {
  5772.                     $childNodes[] = $cat;
  5773.                 }
  5774. //                print('<hr>QQW category: ');
  5775. //                \Doctrine\Common\Util\Debug::dump($cat);
  5776.             }
  5777.         }
  5778.         
  5779. //         print('<br>QQW categoryTopMenu: ');
  5780. //         \Doctrine\Common\Util\Debug::dump($childNodes);
  5781.       return $childNodes;
  5782.     }  
  5783.     /**
  5784.      * @Route("/eshop/{eshopId}/eshopNewlang", name="eshopNewlang")
  5785.      */
  5786.     public function eshopNewlangAction(Request $request$eshopId) {
  5787.         /* we load session data */
  5788.         parent::init($request);
  5789.         $em $this->doctrine->getManager();
  5790.         $session $request->getSession();
  5791.         /* setting new language for e-shop */
  5792.         if(!empty($request->query->get('newlang'))) {
  5793.           //print("<br>QQW setting new e-shop language: ".$request->query->get('newlang'));
  5794.           $lang $em->getRepository(Language::class)->getLanguageByKey($request->query->get('newlang'));
  5795.           $changeLangMessage $this->translator->trans('system.language_changed_to', [], 'messages'$lang->getLangKey());
  5796.         
  5797.           if(!empty($lang)) {
  5798.             $session->set('lang'$lang);  
  5799.             $this->addFlash('notice'$changeLangMessage.' '.$lang->getLangName().'.');   
  5800.           }
  5801.       }
  5802.       
  5803.       /*
  5804.       $referer = $request->headers->get('referer');
  5805.       $lastPath = substr($referer, strpos($referer, $request->getBaseUrl()));
  5806.       $lastPath = str_replace($request->getBaseUrl(), '', $lastPath);
  5807.   
  5808.       $matcher = $this->get('router')->getMatcher();
  5809.       $parameters = $matcher->match($lastPath);
  5810.       $route = $parameters['_route'];      
  5811.       
  5812.       print("<br>QQW newlangAction: ");
  5813.       \Doctrine\Common\Util\Debug::dump($session->get('lang')); 
  5814.       die();
  5815.       */
  5816.       //print('<br>qqw eshopId: '.$eshopId);
  5817.       //return $this->redirectToRoute($route);     
  5818.       return $this->redirectToRoute('eshop', array('eshopId' => $eshopId)); 
  5819.     }  
  5820.     /**
  5821.      * @Route("/eshop/{eshopId}/eshopNewcurr", name="eshopNewcurr")
  5822.      */
  5823.     public function eshopNewcurrAction(Request $request$eshopId) {
  5824.                          
  5825.         /* we load session data */
  5826.         parent::init($request);                       
  5827.         $em $this->doctrine->getManager();
  5828.                             
  5829.         $session $request->getSession();
  5830.         /* setting new currency for e-shop */
  5831.         if(!empty($request->query->get('newEshopCurrency'))) {
  5832.           //print("<br>QQW setting new e-shop currency: ".$request->query->get('newEshopCurrency'));
  5833.           $curr $em->getRepository(Currency::class)->getCurrencyByKey($request->query->get('newEshopCurrency'));
  5834.         
  5835.           if(!empty($curr)) {
  5836.             $session->set('eshopCurrency'$curr);  
  5837.             $this->addFlash('notice'$this->translator->trans('system.currency_changed_to').' '.$curr->getCurrencyName().'.');   
  5838.           }
  5839.       }
  5840.       /*
  5841.       $referer = $request->headers->get('referer');
  5842.       $lastPath = substr($referer, strpos($referer, $request->getBaseUrl()));
  5843.       $lastPath = str_replace($request->getBaseUrl(), '', $lastPath);
  5844.   
  5845.       $matcher = $this->get('router')->getMatcher();
  5846.       $parameters = $matcher->match($lastPath);
  5847.       $route = $parameters['_route'];      
  5848.       
  5849.       print("<br>QQW newlangAction: ");
  5850.       \Doctrine\Common\Util\Debug::dump($session->get('lang')); 
  5851.       die();
  5852.       */
  5853.       //return $this->redirectToRoute($route);     
  5854.       return $this->redirectToRoute('eshop', array('eshopId' => $eshopId)); 
  5855.     }      
  5856.     /**
  5857.      * @Route("/orderlist", name="orderList")
  5858.      */
  5859.     public function orderListAction(Request $request)
  5860.     {
  5861.         /* we load session data */
  5862.         parent::init($request);     
  5863.         $session $request->getSession(); 
  5864.         
  5865.         // we check if any user is logged in
  5866.         if(!$this->isLoggedUser($request)) {
  5867.             return $this->redirectToRoute('login');
  5868.         }  
  5869.         
  5870.         /* we load users entity manager */
  5871.         $em $this->doctrine->getManager();
  5872.         $dem $this->doctrine->getManager('dynamic_em');
  5873.         /* we get current user */
  5874.         $userId $session->get('user')->getUserId();
  5875.         $user $em->getRepository(User::class)->getUser($userId);
  5876.         
  5877.         /* we get current e-shop */
  5878.         $eshop $em->getRepository(Eshop::class)->getCurrentEshop($userId);
  5879.         $defaultCurrency $em->getRepository(Currency::class)->getCurrency($eshop->getPreferredCurrencyId());
  5880.          
  5881.         $orderList $dem->getRepository(Order::class)->getOrderList("orderId""DESC");
  5882.         /* we load order prices */
  5883.         $orderPrices = array();
  5884.         foreach($orderList as $order) {
  5885.             if(!empty($order->getCurrencyKey())) {
  5886.                 $targetCurrency $em->getRepository(Currency::class)->getCurrencyByKey($order->getCurrencyKey());
  5887.             } else {
  5888.                 $targetCurrency $defaultCurrency;
  5889.             }
  5890.             
  5891.             $orderPrices[$order->getOrderId()] = $dem->getRepository(Order::class)->getOrderPrice($order->getOrderId(), $targetCurrencyfalse$eshop$defaultCurrency);
  5892.         }
  5893.         /* we render data */
  5894.         return $this->render('orderList.html.twig',
  5895.                 array('headerData' => $this -> getPageHeader($request),
  5896.                       'orderList' => $orderList,
  5897.                       'orderPrices' => $orderPrices,
  5898.                       'menu' => $this -> adminMenu($request),'mainMenu' => $this -> adminMainMenu($request),
  5899.                       'mainMenu' => $this -> adminMainMenu($request),
  5900.                       'user' => $user,
  5901.                 )
  5902.                 );
  5903.     
  5904.     }   
  5905.     /**
  5906.      * @Route("/orderedit/{orderId}", name="orderEdit")
  5907.      */
  5908.     public function orderEditAction(Request $request$orderId)
  5909.     {
  5910.         /* we load session data */
  5911.         parent::init($request);
  5912.         $session $request->getSession();
  5913.         
  5914.         /* we load entity managers */
  5915.         $em $this->doctrine->getManager();
  5916.         $dem $this->doctrine->getManager('dynamic_em');
  5917.          
  5918.         $userId $session->get('user')->getUserId();
  5919.         $user $em->getRepository(User::class)->getUser($userId);
  5920.         
  5921.         /* we get current e-shop */
  5922.         $eshop $em->getRepository(Eshop::class)->getCurrentEshop($userId);
  5923.         $eshopCurrency $em->getRepository(Currency::class)->getCurrency($eshop->getPreferredCurrencyId());
  5924.  
  5925.         $order $dem->getRepository(Order::class)->getOrder($orderId);
  5926.         if(!empty($order->getCurrencyKey())) {
  5927.             $targetCurrency $em->getRepository(Currency::class)->getCurrencyByKey($order->getCurrencyKey());
  5928.         } else {
  5929.             $targetCurrency $eshopCurrency;
  5930.         }
  5931.         $orderPrice $dem->getRepository(Order::class)->getOrderPrice($order->getOrderId(), $targetCurrencyfalse$eshop$eshopCurrency);
  5932.         $orderPriceVAT $dem->getRepository(Order::class)->getOrderPrice($order->getOrderId(), $targetCurrencytrue$eshop$eshopCurrency);
  5933.         $deliveryCost $dem->getRepository(Price::class)->getCurrencyRatedPrice($order->getEshopDelivery()->getCost(), $eshopCurrency$targetCurrency);
  5934.         $order->getEshopDelivery()->setCost(round($deliveryCost2));
  5935.         $paymentCost $dem->getRepository(Price::class)->getCurrencyRatedPrice($order->getEshopPayment()->getCost(), $eshopCurrency$targetCurrency);
  5936.         $order->getEshopPayment()->setCost(round($paymentCost2));       
  5937.         //print('<br>QQW orderPrice: '.$orderPrice);
  5938.         //print('<br>QQW orderPrice VAT: '.$orderPriceVAT);
  5939.         //\Doctrine\Common\Util\Debug::dump($orderPrice);
  5940.         /* we render data */
  5941.         return $this->render('orderEdit.html.twig',
  5942.             array('headerData' => $this -> getPageHeader($request),
  5943.                   'order' => $order,
  5944.                   'orderPrice' => $orderPrice,  
  5945.                   'orderPriceVAT' => $orderPriceVAT,                                    
  5946.                   'menu' => $this -> adminMenu($request),'mainMenu' => $this -> adminMainMenu($request),'mainMenu' => $this -> adminMainMenu($request),
  5947.                   'eshopCurrency' => $eshopCurrency,   
  5948.                   'eshop' => $eshop,
  5949.                   'user' => $user,
  5950.                 )
  5951.         );        
  5952.     }
  5953.     /**
  5954.      * @Route("/eshop/{eshopId}/page/{pageId}", name="eshopPage")
  5955.      */
  5956.     public function pageAction(Request $request$eshopId$pageId)
  5957.     {
  5958.     
  5959.         /* we load session data */
  5960.         parent::init($request);
  5961.         $session $request->getSession();
  5962.         //print('<br>QQW page ID: '.$pageId);
  5963.     
  5964.         /* we load entity managers */
  5965.         $em $this->doctrine->getManager();
  5966.         $dem $this->doctrine->getManager('dynamic_em');
  5967.         /* we get current e-shop */
  5968.         $eshop $em->getRepository(Eshop::class)->getEshop($eshopId);
  5969.         $eshopHeader $dem->getRepository(Eshop::class)->getEshopHeader($eshopId);
  5970.         if(!empty($eshopHeader)) {
  5971.           $eshopHeader->setLocale($session->get('lang')->getLangKey());
  5972.           $dem->refresh($eshopHeader);            
  5973.         }
  5974.         /* we load footer for the current website */
  5975.         $eshopFooter $dem->getRepository(Eshop::class)->getEshopFooter($eshopId);
  5976.         if(!empty($eshopFooter)) {         
  5977.           $eshopFooter->setLocale($session->get('lang')->getLangKey());
  5978.           $dem->refresh($eshopFooter);  
  5979.         }  
  5980.         /* we get wireframe */
  5981.         $wireFrame $em->getRepository(WireFrame::class)->getWireFrame($eshop->getWireFrameId());
  5982.         /* we load page for the current webpage */
  5983.         $page $dem->getRepository(WebPage::class)->getWebPage($pageId);
  5984.         $page->setLocale($session->get('lang')->getLangKey());
  5985.         $dem->refresh($page);
  5986.         
  5987.         /*
  5988.         print('<br>qqw page id: '.$pageId);
  5989.         \Doctrine\Common\Util\Debug::dump($page);
  5990.         */           
  5991.         
  5992.         /* we parse the page content for placeholders */
  5993.         $pageContent $this->parseContent($request$page->getWebPageContent());
  5994.         $page->setWebPageContent($pageContent);
  5995.         /* 
  5996.         print('<br>qqw webMenuVertical: ');
  5997.         \Doctrine\Common\Util\Debug::dump($webMenuVertical);
  5998.         */
  5999.         /* we render data */
  6000.         return $this->render('eshopPage.html.twig',
  6001.                 array(  'headerData' => $this -> getPageHeader($request),
  6002.                         'eshop' => $eshop,  
  6003.                         'wireFrame' => $wireFrame,  
  6004.                         'categoryTreeMenu' => $this->categoryTreeMenu($eshop$request),
  6005.                         'categoryTopMenu' => $this->categoryTopMenu($eshop$request), 
  6006.                         'eshopHeader' => $eshopHeader,
  6007.                         'eshopFooter' => $eshopFooter,                             
  6008.                         'page' => $page,
  6009.                 )
  6010.                 );
  6011.     
  6012.     }     
  6013.     /**
  6014.      * @Route("/eshop/{eshopId}/request", name="eshopRequest")
  6015.      */
  6016.     public function eshopRequestAction(Request $request$eshopId)
  6017.     {
  6018.     
  6019.         /* we load session data */
  6020.         parent::init($request);
  6021.         $session $request->getSession();
  6022.         /* we load entity managers */
  6023.         $em $this->doctrine->getManager();
  6024.         $dem $this->doctrine->getManager('dynamic_em');
  6025.         /* we get current e-shop */
  6026.         $eshop $em->getRepository(Eshop::class)->getEshop($eshopId);
  6027.         /* we get current user */
  6028.         $user $em->getRepository(User::class)->getUser($eshop->getUserId());
  6029.         $eshopHeader $dem->getRepository(Eshop::class)->getEshopHeader($eshopId);
  6030.         if(!empty($eshopHeader)) {
  6031.           $eshopHeader->setLocale($session->get('lang')->getLangKey());
  6032.           $dem->refresh($eshopHeader);            
  6033.         }
  6034.         /* we load footer for the current website */
  6035.         $eshopFooter $dem->getRepository(Eshop::class)->getEshopFooter($eshopId);
  6036.         if(!empty($eshopFooter)) {         
  6037.           $eshopFooter->setLocale($session->get('lang')->getLangKey());
  6038.           $dem->refresh($eshopFooter);  
  6039.         }  
  6040.         /* we get wireframe */
  6041.         $wireFrame $em->getRepository(WireFrame::class)->getWireFrame($eshop->getWireFrameId());
  6042.         $subject $request->query->get('subject');
  6043.         $email '';
  6044.         $telephone '';   
  6045.         $message '';  
  6046.         /* we get product info */
  6047.         if(!empty($request->query->get('productId'))) {
  6048.             //print('<br>qqw loading productId: '.$request->query->get('productId'));
  6049.             $productId $request->query->get('productId');
  6050.             $product $dem->getRepository(Product::class)->getProduct($productId);
  6051.             $message .= $product->getProductName().' (ID: '.$product->getProductKey().' | ERP: '.$product->getERPKey().' | EAN: '.$product->getEAN().')'
  6052.             //\Doctrine\Common\Util\Debug::dump($product);
  6053.         }
  6054.         /* we check if customer exists */
  6055.         if(!empty($session->get('contact'))) {
  6056.             $contact $dem->getRepository(Contact::class)->getContact($session->get('contact')->getContactId());
  6057.             $email $contact->getEmail();
  6058.             $telephone $contact->getPhone();
  6059.         }  
  6060.         //isModule ReCaptcha
  6061.         $module $em->getRepository(Module::class)->getModule(41);
  6062.         $isReCaptchaModule $em->getRepository(User::class)->userHasModule($user$module);
  6063.         $reCaptcha null;
  6064.         if($isReCaptchaModule) {
  6065.             //we load re-captcha
  6066.             $reCaptcha $dem->getRepository(ReCaptcha::class)->findOneBy(['reCaptchaId'=> 1]);
  6067.         }       
  6068.         //print('<br>qqw subject: '.$subject);
  6069.         /* 
  6070.         print('<br>qqw webMenuVertical: ');
  6071.         \Doctrine\Common\Util\Debug::dump($webMenuVertical);
  6072.         */
  6073.     
  6074.         /* we build login form */
  6075.         $formBuilder $this->createFormBuilder();
  6076.         
  6077.         $formBuilder->add('request_subject'TextType::class, array(
  6078.                 'required' => true,
  6079.                 'label' => $this->translator->trans('eshop.request_subject'),
  6080.                 'attr' => array('class' => 'text_form''size' => 60'value' => $subject),
  6081.                 'label_attr' => array('class' => 'form_field_label'),
  6082.         ));
  6083.         $formBuilder->add('request_email'EmailType::class, array(
  6084.                 'required' => true,
  6085.                 'label' => $this->translator->trans('eshop.request_email'),
  6086.                 'attr' => array('class' => 'text_form''size' => 60'value' => $email),
  6087.                 'label_attr' => array('class' => 'form_field_label'),
  6088.         ));     
  6089.         $formBuilder->add('request_telephone'TextType::class, array(
  6090.                 'required' => true,
  6091.                 'label' => $this->translator->trans('eshop.request_telephone'),
  6092.                 'attr' => array('class' => 'text_form''size' => 60'value' => $telephone),
  6093.                 'label_attr' => array('class' => 'form_field_label'),
  6094.         ));             
  6095.         
  6096.         $formBuilder->add('request_message'TextareaType::class, array(
  6097.                 'required' => false,
  6098.                 'label' => $this->translator->trans('eshop.request_message'),
  6099.                 'attr' => array('class' => 'inputTextArea''cols' => 70'rows' => 15'value' => $message),
  6100.                 'label_attr' => array('class' => 'form_textarea_label'),
  6101.                 'data' => $message,
  6102.         ));
  6103.         
  6104.         $formBuilder->add('save'SubmitType::class, array('label' => $this->translator->trans('eshop.request_send'),
  6105.                 'attr' => array('class' => 'requestFormButton')));
  6106.         
  6107.         $form $formBuilder->getForm();        
  6108.         
  6109.         $form->handleRequest($request);
  6110.         $mailToAdminStatus '';
  6111.         
  6112.         if ($request->getMethod() == 'POST') {
  6113.         
  6114.             //we prepare captcha
  6115.             if(!$isReCaptchaModule) {
  6116.                 $captchaResponse "noCaptcha";
  6117.             } else {
  6118.                 $captchaResponse $request->get('g-recaptcha-response');
  6119.             }            
  6120.         
  6121.             if ($form->isValid() && $captchaResponse != "") {
  6122.                 // perform some action, such as save the object to the database
  6123.                 //print('<br>sending email request from: '.$request->request->get('form')['request_email']);
  6124.                 
  6125.                 /* we load html template */
  6126.                 //$emailText = $this->getRegisterEmail($request, $eshop, $contact);
  6127.                 $emailText $this->getEshopRequestEmail($request$eshop$request->request->get('form')['request_email'], $request->request->get('form')['request_subject'], $request->request->get('form')['request_message'], $request->request->get('form')['request_telephone'] );                
  6128.                  /* we prepare request emailing */
  6129.                 $name $eshop->getEshopName();
  6130.                 $toSuperadmin      'easycommerc@gmail.com'
  6131.                 $to      $user->getEmail(); 
  6132.                 $subject $name.' - '.$subject;
  6133.                 $message $emailText;                         
  6134.                 $from 'noreply@easycommerc.com';
  6135.                 $headers  "MIME-Version: 1.0\r\n";
  6136.                 $headers .= "Content-type: text/html; charset=UTF-8\r\n";
  6137.                 $headers .= "From: {$name} <{$from}>\r\n";
  6138.                 $headers .= "Reply-To: <{$from}>\r\n";
  6139.                 $headers .= "Subject: {$subject}\r\n";
  6140.                 $headers .= "X-Mailer: PHP/".phpversion()."\r\n";
  6141.                 
  6142.                 /* we send email to e-shop admin */
  6143.                 if(@mail($to$subject$message$headers)) {
  6144.                     //print('<br>Email was sent.');
  6145.                         //we send email to users contact person
  6146.                         if(!empty($user->getContactPersonEmail())) {
  6147.                             mail($user->getContactPersonEmail(), $subject$message$headers);
  6148.                         }
  6149.                     $mailToAdminStatus $this->translator->trans('eshop.email_request_sent').': '.$to;
  6150.                     $this->addFlash('notice'$mailToAdminStatus);
  6151.                 } else {
  6152.                     //print('<br>Email was not sent.');
  6153.                     $mailToAdminStatus $this->translator->trans('eshop.email_admin_order_error'.': '.$to);
  6154.                 }                   
  6155.                 // we send email to super admin 
  6156.                 /*
  6157.                 if(@mail($toSuperadmin, $subject, $message, $headers)) {
  6158.                     //print('<br>Email was sent.');
  6159.                     //$mailToAdminStatus = $this->translator->trans('eshop.email_request_sent').': '.$to;
  6160.                     //$this->addFlash('notice', $mailToAdminStatus);
  6161.                 } else {
  6162.                     //print('<br>Email was not sent.');
  6163.                     //$mailToAdminStatus = $this->translator->trans('eshop.email_admin_order_error'.': '.$to);
  6164.                 } 
  6165.                 */
  6166.                  /*        
  6167.                  print('<br>qqw contact exists: ');
  6168.                  \Doctrine\Common\Util\Debug::dump($contactExist);
  6169.                  */
  6170.                 
  6171.                 //die();
  6172.             }
  6173.             else {
  6174.                 $this->addFlash('error'$this->translator->trans('system.form_not_valid'));
  6175.             }
  6176.         
  6177.         }       
  6178.         
  6179.         /* we render data */
  6180.         return $this->render('eshopRequest.html.twig',
  6181.                 array(  'headerData' => $this -> getPageHeader($request),
  6182.                         'eshop' => $eshop,  
  6183.                         'form' => $formBuilder->getForm()->createView(),
  6184.                         'wireFrame' => $wireFrame,  
  6185.                         'categoryTreeMenu' => $this->categoryTreeMenu($eshop$request),
  6186.                         'categoryTopMenu' => $this->categoryTopMenu($eshop$request), 
  6187.                         'eshopHeader' => $eshopHeader,
  6188.                         'eshopFooter' => $eshopFooter,   
  6189.                         'subject' => $subject
  6190.                         'mailToAdminStatus' => $mailToAdminStatus,   
  6191.                         'reCaptcha' => $reCaptcha,                                                     
  6192.                 )
  6193.                 );
  6194.     
  6195.     }  
  6196.     /**
  6197.      * @Route("/eshop/{eshopId}/page/{pageId}", name="eshopPage")
  6198.      */
  6199.     /*
  6200.     public function pageAction(Request $request, $eshopId, $pageId)
  6201.     {
  6202.     
  6203.         // we load session data 
  6204.         parent::init($request);
  6205.         $session = $request->getSession();
  6206.         //print('<br>QQW page ID: '.$pageId);
  6207.     
  6208.         // we load entity managers 
  6209.         $em = $this->doctrine->getManager();
  6210.         $dem = $this->doctrine->getManager('dynamic_em');
  6211.         // we get current e-shop 
  6212.         $eshop = $em->getRepository(Eshop::class)->getEshop($eshopId);
  6213.    */
  6214.     /**
  6215.      * @Route("/eshop/{eshopId}/api/products", name="APIProducts")
  6216.      */
  6217.     public function APIProductsAction(Request $request$eshopId)
  6218.     {
  6219.         /* we load session data */
  6220.         parent::init($request);     
  6221.         $session $request->getSession(); 
  6222.         /* we load users entity manager */
  6223.         $em $this->doctrine->getManager();
  6224.         $dem $this->doctrine->getManager('dynamic_em');
  6225.         // we get current e-shop 
  6226.         $eshop $em->getRepository(Eshop::class)->getEshop($eshopId);
  6227.         //print('<br>qqw eshop: '.$eshop->getEshopId());
  6228.         //\Doctrine\Common\Util\Debug::dump($eshop);
  6229.         $limit 300;
  6230.         $offset 0;
  6231.         $defaultCurrency $em->getRepository(Currency::class)->getCurrency($eshop->getPreferredCurrencyId());
  6232.         $productList $dem->getRepository(Product::class)->getProductListByEshop($eshop->getEshopId(), $limit$offset);   
  6233.         $productListAPI = array();
  6234.         foreach ($productList as $product) {
  6235.             //print('<br>qqw product: ');
  6236.             //\Doctrine\Common\Util\Debug::dump($product);
  6237.             $productAPI = array();
  6238.             $productAPI['productId'] = $product->getProductId();
  6239.             $productAPI['productKey'] = $product->getProductKey();  
  6240.             $productAPI['EAN'] = $product->getEAN();           
  6241.             $productAPI['productName'] = $product->getProductName();
  6242.             $productAPI['productDescription'] = $product->getProductDescription();            
  6243.             $productListAPI[] = $productAPI;  
  6244.         }
  6245.         //die('qqw API close');
  6246.         //products
  6247.         
  6248.         
  6249.         $count count($productListAPI);      
  6250.         $pages 10;
  6251.         $page 1;
  6252.         $system = array('code' => 200'message' => 'OK');
  6253.         $metadata = array('count' => $count'limit' => 100'pages' => $pages'page' => $page);
  6254.         //die(); 
  6255.          
  6256.         /* we prepare data for view */
  6257.         $viewData = array('system' => $system,
  6258.                           'data' => $productListAPI
  6259.                           'metadata' => $metadata,
  6260.                 );           
  6261.         // we output json
  6262.         return new JsonResponse($viewData);
  6263.     
  6264.     }   
  6265.     public function getTopProducts(Request $request$eshop$topProductLimit 7)
  6266.     {
  6267.         /* we load users entity manager */
  6268.         $em $this->doctrine->getManager();
  6269.         $dem $this->doctrine->getManager('dynamic_em');
  6270.         $session $request->getSession(); 
  6271.         $topProductList $dem->getRepository(OrderItem::class)->getTopProductList($topProductLimit);
  6272.         
  6273.         $productIds = [];
  6274.         $topProducts = [];
  6275.         foreach($topProductList as $orderItem) {
  6276.             $pId $orderItem['productId'];
  6277.             $topProduct $orderItem;      
  6278.             $product $dem->getRepository(Product::class)->getProduct($pId);
  6279.             if($product) {
  6280.                 $topProducts[$pId] = $topProduct;
  6281.                 $productIds[] = $pId;
  6282.             }
  6283.         }
  6284.         // we load prices
  6285.         $productPriceList $dem->getRepository(Product::class)->getProductPriceList($productIds);
  6286.         $defaultCurrency $em->getRepository(Currency::class)->getCurrency($eshop->getPreferredCurrencyId());
  6287.         $targetCurrency $session->get('eshopCurrency');
  6288.         $currencyKey $targetCurrency->getCurrencyKey();
  6289.             
  6290.         // we load currency rated prices
  6291.         $productPriceList $dem->getRepository(Product::class)->getCurrencyRatedProductPriceList($productPriceList$defaultCurrency$targetCurrency);
  6292.         foreach($topProductList as $orderItem) {
  6293.             $pId $orderItem['productId'];
  6294.             /* we get price(s) to display */
  6295.             $displayPrice null;
  6296.             foreach($productPriceList as $price) {
  6297.                 if($price->getProductId() == $pId) {
  6298.                     /* we get default price level */
  6299.                     if($price->getPriceLevelId() == 1) {
  6300.                         //$displayPrice = round($price->getBruttoValue(),$eshop->getRoundPrice());
  6301.                         $displayPrice round($price->getNettoValue(),$eshop->getRoundPrice());
  6302.                         $topProducts[$pId]['displayPrice'] = $displayPrice;
  6303.                         $topProducts[$pId]['currencyKey'] = $currencyKey;                        
  6304.                     }
  6305.                     
  6306.                 }
  6307.             }  
  6308.         }       
  6309.         //print('<br>QQW topProductList: ');
  6310.         //\Doctrine\Common\Util\Debug::dump($topProductList);
  6311.         // print('<br>QQW topProducts: ');
  6312.         // \Doctrine\Common\Util\Debug::dump($topProducts);
  6313.         // print('<hr>QQW topProducts PriceList: ');
  6314.         // \Doctrine\Common\Util\Debug::dump($productPriceList);        
  6315.         return $topProducts;
  6316.     }               
  6317.    
  6318.     public function adminMenu(Request $request)
  6319.     {
  6320.         $menuItems = array(
  6321.                 => array('link' => 'eshopAdmin''langKey' => 'eshop.admin''routeName' => 'eshopAdmin'),
  6322.                 => array('link' => 'orderlist''langKey' => 'eshop.orders''routeName' => 'orderList'),
  6323.                 => array('link' => 'productedit''langKey' => 'eshop.products''routeName' => 'productListEdit'),
  6324.                 => array('link' => 'productnew''langKey' => 'eshop.new_product''routeName' => 'productNew'),
  6325.                 => array('link' => 'categories''langKey' => 'eshop.categories''routeName' => 'categories'),
  6326.                 => array('link' => 'categorynew''langKey' => 'eshop.new_category''routeName' => 'categoryNew'),
  6327.                 => array('link' => 'contacts''langKey' => 'knowledgebase.contacts''routeName' => 'contacts'),
  6328.                 => array('link' => 'eshopnew''langKey' => 'eshop.new_eshop''routeName' => 'eshopNew'),
  6329.                 => array('link' => 'eshopConfig''langKey' => 'eshop.config''routeName' => 'eshopConfig'),
  6330.         );   
  6331.         
  6332.         return $menuItems;
  6333.     
  6334.     }    
  6335.      
  6336. }