src/Controller/EshopController.php line 2743

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