src/Controller/EshopController.php line 618

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.php',
  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.             /* we render data */
  2698.             return $this->render('eshopHomeContact.html.twig',
  2699.                     array('headerData' => $this -> getPageHeader($request),
  2700.                             'contact' => $contact,
  2701.                             'eshop' => $eshop,
  2702.                             'wireFrame' => $wireFrame,
  2703.                             'categoryTreeMenu' => $this->categoryTreeMenu($eshop$request),
  2704.                             'categoryTopMenu' => $this->categoryTopMenu($eshop$request),   
  2705.                             'eshopHeader' => $eshopHeader,
  2706.                             'eshopFooter' => $eshopFooter,  
  2707.                             'orderList' => $orderList
  2708.                             'orderPrices' => $orderPrices
  2709.                     )
  2710.                     );
  2711.         
  2712.         }       
  2713.         /**
  2714.          * @Route("/eshop/{eshopId}/eshopOrderContact/{orderId}", name="eshopOrderContact")
  2715.          */
  2716.         public function eshopOrderContactAction(Request $request$eshopId$orderId) {
  2717.         
  2718.             /* we load session data */
  2719.             parent::init($request);
  2720.         
  2721.             $session $request->getSession();
  2722.         
  2723.             /* we load entity managers */
  2724.             $em $this->doctrine->getManager();
  2725.             $dem $this->doctrine->getManager('dynamic_em');
  2726.         
  2727.             /* we get current e-shop */
  2728.             $eshop $em->getRepository(Eshop::class)->getEshop($eshopId);
  2729.             $eshopCurrency $em->getRepository(Currency::class)->getCurrency($eshop->getPreferredCurrencyId());
  2730.             $eshopHeader $dem->getRepository(Eshop::class)->getEshopHeader($eshopId);
  2731.             if(!empty($eshopHeader)) {
  2732.               $eshopHeader->setLocale($session->get('lang')->getLangKey());
  2733.               $dem->refresh($eshopHeader);            
  2734.             }
  2735.             /* we load footer for the current website */
  2736.             $eshopFooter $dem->getRepository(Eshop::class)->getEshopFooter($eshopId);
  2737.             if(!empty($eshopFooter)) {         
  2738.               $eshopFooter->setLocale($session->get('lang')->getLangKey());
  2739.               $dem->refresh($eshopFooter);  
  2740.             }  
  2741.             $wireFrame $em->getRepository(WireFrame::class)->getWireFrame($eshop->getProductDetailWireFrameId());
  2742.             $contactId $session->get('contact')->getContactId();
  2743.             $contact $dem->getRepository(Contact::class)->getContact($contactId);
  2744.             /* we load order */
  2745.             $order $dem->getRepository(Order::class)->getOrder($orderId);
  2746.             if(!empty($order->getCurrencyKey())) {
  2747.                 $targetCurrency $em->getRepository(Currency::class)->getCurrencyByKey($order->getCurrencyKey());
  2748.             } else {
  2749.                 $targetCurrency $eshopCurrency;
  2750.             }    
  2751.             $orderPrice $dem->getRepository(Order::class)->getOrderPrice($order->getOrderId(), $targetCurrencyfalse$eshop$eshopCurrency);
  2752.             $orderPriceVAT $dem->getRepository(Order::class)->getOrderPrice($order->getOrderId(), $targetCurrencytrue$eshop$eshopCurrency);
  2753.             if(!empty($order->getEshopDelivery())) {
  2754.                 //we set delivery cost in selected currency
  2755.                 $deliveryCost $dem->getRepository(Price::class)->getCurrencyRatedPrice($order->getEshopDelivery()->getCost(), $eshopCurrency$targetCurrency);
  2756.                 $order->getEshopDelivery()->setCost(round($deliveryCost2));
  2757.             }    
  2758.             if(!empty($order->getEshopDelivery())) {
  2759.                 //we set payment cost in selected currency
  2760.                 $paymentCost $dem->getRepository(Price::class)->getCurrencyRatedPrice($order->getEshopPayment()->getCost(), $eshopCurrency$targetCurrency);
  2761.                 $order->getEshopPayment()->setCost(round($paymentCost2));  
  2762.             }  
  2763.             
  2764.             //print('<hr>QQW order '.$orderId.': ');
  2765.             //\Doctrine\Common\Util\Debug::dump($order);                        
  2766.             /* we render data */
  2767.             return $this->render('eshopOrderContact.html.twig',
  2768.                     array('headerData' => $this -> getPageHeader($request),
  2769.                             'contact' => $contact,
  2770.                             'eshop' => $eshop,
  2771.                             'wireFrame' => $wireFrame,
  2772.                             'categoryTreeMenu' => $this->categoryTreeMenu($eshop$request),
  2773.                             'categoryTopMenu' => $this->categoryTopMenu($eshop$request),   
  2774.                             'eshopHeader' => $eshopHeader,
  2775.                             'eshopFooter' => $eshopFooter,  
  2776.                             'order' => $order
  2777.                             'orderPrice' => $orderPrice,    
  2778.                             'orderPriceVAT' => $orderPriceVAT,                                                      
  2779.                     )
  2780.                     );
  2781.         
  2782.         }               
  2783.    
  2784.         /**
  2785.          * @Route("/eshop/{eshopId}/basket", name="eshopBasket")
  2786.          */
  2787.         public function eshopBasketAction(Request $request$eshopId) {
  2788.              
  2789.             /* we load session data */
  2790.             parent::init($request);
  2791.              
  2792.             $session $request->getSession();
  2793.              
  2794.             /* we load entity managers */
  2795.             $em $this->doctrine->getManager();
  2796.             $dem $this->doctrine->getManager('dynamic_em');
  2797.              
  2798.             /* we get current e-shop */
  2799.             $eshop $em->getRepository(Eshop::class)->getEshop($eshopId);
  2800.         
  2801.             $user $em->getRepository(User::class)->getUser($eshop->getUserId());
  2802.         
  2803.             $userDirs $this->getUserFolderPathsFromUserId($eshop->getUserId());
  2804.         
  2805.             $eshopHeader $dem->getRepository(Eshop::class)->getEshopHeader($eshopId);
  2806.             if(!empty($eshopHeader)) {
  2807.               $eshopHeader->setLocale($session->get('lang')->getLangKey());
  2808.               $dem->refresh($eshopHeader);            
  2809.             }
  2810.             /* we load footer for the current website */
  2811.             $eshopFooter $dem->getRepository(Eshop::class)->getEshopFooter($eshopId);
  2812.             if(!empty($eshopFooter)) {         
  2813.               $eshopFooter->setLocale($session->get('lang')->getLangKey());
  2814.               $dem->refresh($eshopFooter);  
  2815.             }  
  2816.       
  2817.             /* we load home page for the current website */
  2818.             $homePage $dem->getRepository(Eshop::class)->getHomePage($eshopId);
  2819.             //$wireFrame = $em->getRepository(WireFrame::class)->getWireFrame($eshop->getProductDetailWireFrameId());
  2820.         
  2821.             /* removing basket item */
  2822.             if(!empty($request->query->get('removeBasketItem'))) {
  2823.                 //print('<br>qqw removing item: '.$request->query->get('removeBasketItem'));
  2824.                 
  2825.                 $processResult false;
  2826.                 foreach($session->get('order')->getOrderItems() as $orderItem) {
  2827.                   if($orderItem->getProductId() == $request->query->get('removeBasketItem')) {
  2828.                     //print('<br>qqw item exists in basket');
  2829.                     $session->get('order')->removeOrderItem($orderItem);
  2830.                     $processResult true;
  2831.                   } 
  2832.                 }
  2833.                 
  2834.                 if($processResult) {
  2835.                     $this->addFlash('notice'$this->translator->trans('eshop.basket_item_removed'));
  2836.                 }
  2837.                 
  2838.             }    
  2839.             /* we update product(s) in basket - POST form action */
  2840.             if(!empty($request->request->get('updateBasket'))) {
  2841. //                print('<br>qqw updating basket:');
  2842.                 $newUnits $request->request->all('basketItemUnit');
  2843.                 $processResult true;
  2844.                 foreach($session->get('order')->getOrderItems() as $orderItem) {
  2845.                     $productId $orderItem->getProductId();
  2846.                     $productUnits $orderItem->getOrderItemUnits();
  2847.                     //print('<br>qqw product id: '.$productId.' :: units: '.$productUnits);
  2848.                     if(!empty($newUnits[$productId])) {
  2849.                         //print(' :: qqw new units: '.$newUnits[$productId]);
  2850.                         $orderItem->setOrderItemUnits($newUnits[$productId]);
  2851.                     }
  2852.     
  2853.                 }
  2854.                 
  2855.                 if($processResult) {
  2856.                     $this->addFlash('notice'$this->translator->trans('eshop.basket_item_updated'));
  2857.                 }                
  2858.             }  
  2859.             //print('<br>qqw session order: ');
  2860.             //\Doctrine\Common\Util\Debug::dump($session->get('order'));  
  2861.             /* we remove session order if it exists and if basket is empty */
  2862.             if(!empty($session->get('order')) && count($session->get('order')->getOrderItems()) == 0) {
  2863.                 $session->remove('order');
  2864.             }                      
  2865.         
  2866.             $productThumbs = array();
  2867.             $products = array();
  2868.             if(!empty($session->get('order')) && $session->get('order')->getEshopId() == $eshopId) {
  2869.                 foreach($session->get('order')->getOrderItems() as $orderItem) {
  2870.                     $pId $orderItem->getProductId();
  2871.                     $product $dem->getRepository(Product::class)->getProduct($pId);
  2872.                     if(!empty($product)) {  
  2873.                         $products[$pId] = $product;
  2874.                     }   
  2875.                     if(!empty($product) && $product->getImage1() != "") {     
  2876.                         //$imagePath = 'users/'.$user->getUserName().'/images/'.$product->getImage1();    
  2877.                         if (strpos($product->getImage1(), 'http') === false) {
  2878.                             $imagePath 'users/'.$user->getUserName().'/images/'.$product->getImage1();
  2879.                             $imageThumbPath 'users/'.$user->getUserName().'/images/thumb_'.$product->getImage1();
  2880.                         } else {
  2881.                             $imagePath $product->getImage1();
  2882.                             $path parse_url($imagePathPHP_URL_PATH);
  2883.                             $imageThumbPath 'users/'.$user->getUserName().'/images/thumb_'.basename($path);
  2884.                         } 
  2885.                         //$imageThumbPath = 'users/'.$user->getUserName().'/images/thumb_'.$product->getImage1();
  2886.                         $imageThumb $this->getEshopImageThumb($eshop$imagePath$imageThumbPath);
  2887.                         $productThumbs[$pId] = $imageThumb;
  2888.                     }
  2889.                 }   
  2890.             }
  2891.             
  2892.             /* we render data */
  2893.             return $this->render('eshopBasket.html.twig',
  2894.                     array('headerData' => $this -> getPageHeader($request),
  2895.                             'eshop' => $eshop,
  2896.                             'wireFrame' => null,
  2897.                             'categoryTreeMenu' => $this->categoryTreeMenu($eshop$request),
  2898.                             'categoryTopMenu' => $this->categoryTopMenu($eshop$request), 
  2899.                             'eshopHeader' => $eshopHeader,
  2900.                             'eshopFooter' => $eshopFooter,  
  2901.                             'homePage' => $homePage,  
  2902.                             'products' => $products,                             
  2903.                             'productThumbs' => $productThumbs,   
  2904.                             'userDirs' => $userDirs,   
  2905.                     )
  2906.                     );
  2907.              
  2908.         }       
  2909.  
  2910.         /**
  2911.          * @Route("/eshop/{eshopId}/payment", name="payment")
  2912.          */        
  2913.         public function eshopPaymentAction(Request $request$eshopId) {
  2914.              
  2915.             /* we load session data */
  2916.             parent::init($request);
  2917.              
  2918.             $session $request->getSession();
  2919.              
  2920.             /* we load entity managers */
  2921.             $em $this->doctrine->getManager();
  2922.             $dem $this->doctrine->getManager('dynamic_em');
  2923.             /* we get current e-shop */
  2924.             $eshop $em->getRepository(Eshop::class)->getEshop($eshopId);
  2925.             $userId $eshop->getUserId();
  2926.             $user $em->getRepository(User::class)->getUser($userId);
  2927.             $defaultCurrency $em->getRepository(Currency::class)->getCurrency($eshop->getPreferredCurrencyId());
  2928.             $targetCurrency $session->get('eshopCurrency');
  2929.             $eshopHeader $dem->getRepository(Eshop::class)->getEshopHeader($eshopId);
  2930.             if(!empty($eshopHeader)) {
  2931.               $eshopHeader->setLocale($session->get('lang')->getLangKey());
  2932.               $dem->refresh($eshopHeader);            
  2933.             }
  2934.             /* we load footer for the current website */
  2935.             $eshopFooter $dem->getRepository(Eshop::class)->getEshopFooter($eshopId);
  2936.             if(!empty($eshopFooter)) {         
  2937.               $eshopFooter->setLocale($session->get('lang')->getLangKey());
  2938.               $dem->refresh($eshopFooter);  
  2939.             }  
  2940.  
  2941.             /* we add delivery to order - POST form action */;
  2942.             if(!empty($request->request->get('delivery'))) {
  2943.                 //print("<br>qqw setting order delivery 2: ".$request->request->get('delivery'));
  2944.                 $eshopDelivery $dem->getRepository(EshopDelivery::class)->getEshopDelivery($request->request->get('delivery'));
  2945.                 $session->get('order')->setEshopDelivery($eshopDelivery);
  2946.                 /*
  2947.                 print('<br>qqw orderEshopDelivery 0: ');
  2948.                 \Doctrine\Common\Util\Debug::dump($eshopDelivery);
  2949.                 */
  2950.             }     
  2951.             /* we add payment to order - POST form action */;
  2952.             if(!empty($request->request->get('paymentSubmit'))) {
  2953.                 //print('<br>qqw payment submit: '.$request->request->get('payment'));
  2954.                 
  2955.                 //$eshopPayment = $dem->getRepository(EshopPayment::class)->getEshopPayment($request->request->get('payment'));
  2956.                 $eshopPayment $dem->getRepository(EshopPayment::class)->getEshopPaymentFromPayment($request->request->get('payment'));
  2957.                 //$eshopPayment = $dem->getRepository(EshopPayment::class)->getEshopPayment(1);
  2958.                 //\Doctrine\Common\Util\Debug::dump($eshopPayment);
  2959.                 $session->get('order')->setEshopPayment($eshopPayment);
  2960.                 if(!empty($eshopPayment)) {
  2961.                     return $this->redirectToRoute('customer', array('eshopId' => $eshopId));
  2962.                 } else {
  2963.                     $this->addFlash('error'$this->translator->trans('eshop.select_payment'));  
  2964.                 }
  2965.             }                       
  2966.             //$wireFrame = $em->getRepository(WireFrame::class)->getWireFrame($eshop->getProductDetailWireFrameId());
  2967.             //$orderPrice = $dem->getRepository(Order::class)->getOrderPrice($session->get('order')->getOrderId());
  2968.              $totalPrice 0;
  2969.                 foreach($session->get('order')->getOrderItems() as $orderItem) {
  2970.                     
  2971.                     //print('<br>qqw basket order item: ');
  2972.                     //\Doctrine\Common\Util\Debug::dump($orderItem);
  2973.                     
  2974.                     if(empty($orderItem->getOrderItemPrice())) {
  2975.                         $orderItem->setOrderItemPrice(0);
  2976.                     }       
  2977.                 
  2978.                     $productPrice $orderItem->getOrderItemPrice() * $orderItem->getOrderItemUnits();
  2979.                     if(empty($productPrice)) {
  2980.                         $productPrice 0;
  2981.                     }
  2982.                     $totalPrice $totalPrice $productPrice;
  2983.                 }     
  2984.             //print('<br>qqw totalPrice 0: '.$totalPrice);       
  2985.             /* we get delivery list from master db */
  2986.             $deliveryList $em->getRepository(Delivery::class)->getDeliveryList();
  2987.             /* we get delivery list of this e-shop */
  2988.             $eshopDeliveryList = array();
  2989.             foreach($deliveryList as $delivery) {
  2990.                 $eshopDelivery $dem->getRepository(EshopDelivery::class)->getEshopDeliveryFromDelivery($delivery->getDeliveryId());  
  2991.                 if(!empty($eshopDelivery)) {
  2992.                     $eshopDelivery->setLocale($session->get('lang')->getLangKey());
  2993.                     $dem->refresh($eshopDelivery); 
  2994.                     //print('<br>QQW delivery 2: ');
  2995.                     //\Doctrine\Common\Util\Debug::dump($deshopDelivery); 
  2996.                     //we check limits from and to order price
  2997.                     if(!empty($eshopDelivery->getEnableFromOrderPrice())) {
  2998.                        $fromLimit $eshopDelivery->getEnableFromOrderPrice();
  2999.                     } else {
  3000.                         $fromLimit 0;
  3001.                     }
  3002.                     if(!empty($eshopDelivery->getEnableToOrderPrice())) {
  3003.                        $toLimit $eshopDelivery->getEnableToOrderPrice();
  3004.                     } else {
  3005.                         $toLimit 999999999;
  3006.                     }   
  3007.                     //print('<br>QQW totalPrice: '.$totalPrice);                  
  3008.                     
  3009.                     if(($totalPrice $fromLimit && $totalPrice $toLimit) || $totalPrice == 0) {
  3010.                         //we set cost in selected currency
  3011.                         $deliveryCost $dem->getRepository(Price::class)->getCurrencyRatedPrice($eshopDelivery->getCost(), $defaultCurrency$targetCurrency);
  3012.                         $eshopDelivery->setCost(round($deliveryCost2));
  3013.                         $eshopDeliveryList[$delivery->getDeliveryId()] = $eshopDelivery;
  3014.                     }
  3015.                     //print('<br>qqw '.$eshopDelivery->getEshopDeliveryName().' limit from: '.$eshopDelivery->getEnableFromOrderPrice());
  3016.                     
  3017.                     //print('<br>qqw deliveryCost: '.$deliveryCost);
  3018.                 }
  3019.             }
  3020.             /* we get payment list from master db */
  3021.             $paymentList $em->getRepository(Payment::class)->getPaymentList();
  3022.             /* we get payment list of this e-shop */
  3023.             $eshopPaymentList = array();
  3024.             foreach($paymentList as $payment) {
  3025.                 $eshopPayment $dem->getRepository(EshopPayment::class)->getEshopPaymentFromPayment($payment->getPaymentId());
  3026.                 if(!empty($eshopPayment)) {
  3027.                     $eshopPayment->setLocale($session->get('lang')->getLangKey());
  3028.                     $dem->refresh($eshopPayment); 
  3029.                     //we set cost in selected currency
  3030.                     $paymentCost $dem->getRepository(Price::class)->getCurrencyRatedPrice($eshopPayment->getCost(), $defaultCurrency$targetCurrency);
  3031.                     $eshopPayment->setCost(round($paymentCost2));                    
  3032.                     if(!empty($session->get('order')->getEshopDelivery())) {
  3033.                         /* we add to payment list only if it is payment associated with selected delivery */
  3034.                         foreach($session->get('order')->getEshopDelivery()->getEshopPayments() as $orderEshopPayment) {
  3035.                             if($orderEshopPayment->getEshopPaymentId() == $eshopPayment->getEshopPaymentId()) {
  3036.                                 $eshopPaymentList[$payment->getPaymentId()] = $eshopPayment;
  3037.                             }
  3038.                         }
  3039.                     } else {
  3040.                         $eshopPaymentList[$payment->getPaymentId()] = $eshopPayment
  3041.                     }
  3042.                 }
  3043.             }   
  3044.             /* we render data */
  3045.             return $this->render('eshopPayment.html.twig',
  3046.                     array('headerData' => $this -> getPageHeader($request),
  3047.                             'eshop' => $eshop,
  3048.                             'user' => $user,
  3049.                             'wireFrame' => null,
  3050.                             'deliveryList' => $deliveryList,
  3051.                             'eshopDeliveryList' => $eshopDeliveryList,    
  3052.                             'paymentList' => $paymentList,
  3053.                             'eshopPaymentList' => $eshopPaymentList,   
  3054.                             'orderEshopDelivery' => $session->get('order')->getEshopDelivery(),  
  3055.                             'orderEshopPayment' => $session->get('order')->getEshopPayment(), 
  3056.                             'categoryTreeMenu' => $this->categoryTreeMenu($eshop$request),
  3057.                             'categoryTopMenu' => $this->categoryTopMenu($eshop$request), 
  3058.                             'eshopHeader' => $eshopHeader,
  3059.                             'eshopFooter' => $eshopFooter,    
  3060.                     )
  3061.                     );
  3062.              
  3063.         }    
  3064.         /**
  3065.          * @Route("/eshop/{eshopId}/search", name="search")
  3066.          */        
  3067.         public function eshopSearchAction(Request $request$eshopId) {
  3068.              
  3069.             /* we load session data */
  3070.             parent::init($request);
  3071.              
  3072.             $session $request->getSession();
  3073.              
  3074.             /* we load entity managers */
  3075.             $em $this->doctrine->getManager();
  3076.             $dem $this->doctrine->getManager('dynamic_em');
  3077.             /* we get current e-shop */
  3078.             $eshop $em->getRepository(Eshop::class)->getEshop($eshopId);
  3079.             $eshopHeader $dem->getRepository(Eshop::class)->getEshopHeader($eshopId);
  3080.             if(!empty($eshopHeader)) {
  3081.               $eshopHeader->setLocale($session->get('lang')->getLangKey());
  3082.               $dem->refresh($eshopHeader);            
  3083.             }
  3084.             /* we load footer for the current website */
  3085.             $eshopFooter $dem->getRepository(Eshop::class)->getEshopFooter($eshopId);
  3086.             if(!empty($eshopFooter)) {         
  3087.               $eshopFooter->setLocale($session->get('lang')->getLangKey());
  3088.               $dem->refresh($eshopFooter);  
  3089.             }  
  3090.             $user $em->getRepository(User::class)->getUser($eshop->getUserId());
  3091.             $productList = [];   
  3092.             $displayPrice null;    
  3093.             $productPriceList = [];     
  3094.             $productThumbs null;    
  3095.             $productCount 0;
  3096.             $categoryList = [];                                            
  3097.  
  3098.             /* we search according to searchString */;
  3099.             $searchString '';
  3100.             if(!empty($request->get('searchstring'))) {
  3101.                 $searchString $request->get('searchstring');
  3102.             } 
  3103.             
  3104.             if ($searchString != '') {
  3105.             
  3106.             /* we get category list */    
  3107.             $categoryList $dem->getRepository(Eshop::class)->getCategoryListBySearch($eshopIdtrim($searchString));
  3108.             /* we get product list */
  3109.             $productPerPage $eshop->getCountPerPage();
  3110.             $page $request->query->get('page');
  3111.             $firstRecord = ($page $productPerPage) - $productPerPage;
  3112.             if($firstRecord 1) {
  3113.                 $firstRecord 0;
  3114.             }
  3115.             $productList $dem->getRepository(Product::class)->getProductListBySearch($eshopIdtrim($searchString));
  3116.             /*
  3117.             foreach($productList as $product) {
  3118.                 print('<br>QQW product: ');
  3119.                 \Doctrine\Common\Util\Debug::dump($product->getProductName()); 
  3120.             }    
  3121.             */       
  3122.             $productCount count($productList);            
  3123.                 /* we load product ids into array */
  3124.                 /* we setup and validate images */
  3125.               $productIds = array();
  3126.               $productImages = array();
  3127.               $productThumbs = array();
  3128.                 foreach($productList as $product) {
  3129.                 $pId $product->getProductId();
  3130.                     $productIds[] = $pId;
  3131.                     if($product->getImage1() != "") {     
  3132.                         //$imagePath = 'users/'.$user->getUserName().'/images/'.$product->getImage1();   
  3133.                           if (strpos($product->getImage1(), 'http') === false) {
  3134.                             $imagePath 'users/'.$user->getUserName().'/images/'.$product->getImage1();
  3135.                             $imageThumbPath 'users/'.$user->getUserName().'/images/thumb_'.$product->getImage1();
  3136.                           } else {
  3137.                             $imagePath $product->getImage1();
  3138.                             $path parse_url($imagePathPHP_URL_PATH);
  3139.                             $imageThumbPath 'users/'.$user->getUserName().'/images/thumb_'.basename($path);
  3140.                           } 
  3141.                         /*
  3142.                         print('<br>qqw imagePath: '.$imagePath);
  3143.                         print('<br>qqw imageThumbPath: '.$imageThumbPath);   
  3144.                         */
  3145.                         $imageThumb $this->getEshopImageThumb($eshop$imagePath$imageThumbPath);
  3146.                         $productThumbs[$pId] = $imageThumb;
  3147.                       }
  3148.                     //print('<br>qqw productName: '.$product->getProductName());
  3149.                     
  3150.                     /* we setup product names - if empty then we load multilingual values */
  3151.                     $productName '';
  3152.                     if(!empty($product->getProductName()) && $product->getProductName() != '') {
  3153.                         $productName $product->getProductName();
  3154.                     } else {
  3155.                         //we try to get the product name from multilangual fields 
  3156.                         foreach($eshop->getLanguages() as $lang) {
  3157.                             $product->setLocale($lang->getLangKey());
  3158.                             $dem->refresh($product);
  3159.                             if(!empty($product->getProductName()) && $product->getProductName() != '') {
  3160.                                 $productName $product->getProductName();
  3161.                             }
  3162.                         }
  3163.                     }
  3164.                     //print('<br>qqw pname 1: '.$productName);
  3165.                     $product->setProductName($productName);
  3166.                     $dem->flush();
  3167.                     
  3168.                     //print('<br>qqw pname 2: '.$product->getProductName());
  3169.                     /* we setup product descriptions - if empty then we load multilingual values */
  3170.                     $productDescription '';
  3171.                     if(!empty($product->getProductDescription()) && $product->getProductDescription() != '') {
  3172.                         $productDescription $product->getProductDescription();
  3173.                     } else {
  3174.                         //we try to get the product description from multilangual fields 
  3175.                         foreach($eshop->getLanguages() as $lang) {
  3176.                             $product->setLocale($lang->getLangKey());
  3177.                             $dem->refresh($product);
  3178.                             if(!empty($product->getProductDescription()) && $product->getProductDescription() != '') {
  3179.                                 $productDescription $product->getProductDescription();
  3180.                             }
  3181.                         }
  3182.                     }
  3183.                     //print('<br>qqw pDescription: '.$productDescription);
  3184.                     $product->setProductDescription($productDescription);      
  3185.                     $dem->flush();      
  3186.               
  3187.               
  3188.             }
  3189.             /* we load prices */
  3190.             $productPriceList $dem->getRepository(Product::class)->getProductPriceList($productIds);
  3191.             $defaultCurrency $em->getRepository(Currency::class)->getCurrency($eshop->getPreferredCurrencyId());
  3192.             $targetCurrency $session->get('eshopCurrency');
  3193.             
  3194.             /* we load currency rated prices */
  3195.             $productPriceList $dem->getRepository(Product::class)->getCurrencyRatedProductPriceList($productPriceList$defaultCurrency$targetCurrency);
  3196.             /* we get price(s) to display */
  3197.             $displayPrice null;
  3198.             foreach($productPriceList as $price) {
  3199.                 if($price->getProductId() == $product->getProductId()) {
  3200.                     /* we get default price level */
  3201.                     if($price->getPriceLevelId() == 1) {
  3202.                         //$displayPrice = round($price->getBruttoValue(),$eshop->getRoundPrice());
  3203.                         $displayPrice round($price->getNettoValue(),$eshop->getRoundPrice());
  3204.                     }
  3205.                     
  3206.                 }
  3207.             }         
  3208.             /* we add product(s) to basket - POST form action */
  3209.             if(!empty($request->request->get('basket'))) {
  3210.                 // we call method to add to basket 
  3211.                 $this->addToBasket($request$eshopId$request->request->get('productId'));
  3212.             }
  3213.          }
  3214.             $productView $eshop->getProductView();
  3215.             /* we render data */
  3216.             return $this->render('eshopSearch.html.twig',
  3217.                     array('headerData' => $this -> getPageHeader($request),
  3218.                             'eshop' => $eshop,
  3219.                             'user' => $user,
  3220.                             'productView' => $productView,
  3221.                             'productList' => $productList,
  3222.                             'displayPrice' => $displayPrice,
  3223.                             'productPriceList' => $productPriceList,
  3224.                             'productThumbs' => $productThumbs,  
  3225.                             'productCount' => $productCount,                          
  3226.                             'wireFrame' => null,
  3227.                             'categoryTreeMenu' => $this->categoryTreeMenu($eshop$request),
  3228.                             'categoryTopMenu' => $this->categoryTopMenu($eshop$request), 
  3229.                             'eshopHeader' => $eshopHeader,
  3230.                             'eshopFooter' => $eshopFooter,    
  3231.                             'searchString' => $searchString,  
  3232.                             'categoryList' => $categoryList,                                                 
  3233.                     )
  3234.                     );
  3235.              
  3236.         }    
  3237.         /**
  3238.          * @Route("/eshop/{eshopId}/customer", name="customer")
  3239.          */        
  3240.         public function eshopCustomerAction(Request $request$eshopId) {
  3241.              
  3242.             /* we load session data */
  3243.             parent::init($request);
  3244.              
  3245.             $session $request->getSession();
  3246.              
  3247.             /* we load entity managers */
  3248.             $em $this->doctrine->getManager();
  3249.             $dem $this->doctrine->getManager('dynamic_em');
  3250.             
  3251.             /* we get current e-shop */
  3252.             $eshop $em->getRepository(Eshop::class)->getEshop($eshopId);
  3253.             $eshopHeader $dem->getRepository(Eshop::class)->getEshopHeader($eshopId);
  3254.             if(!empty($eshopHeader)) {
  3255.               $eshopHeader->setLocale($session->get('lang')->getLangKey());
  3256.               $dem->refresh($eshopHeader);            
  3257.             }
  3258.             /* we load footer for the current website */
  3259.             $eshopFooter $dem->getRepository(Eshop::class)->getEshopFooter($eshopId);
  3260.             if(!empty($eshopFooter)) {         
  3261.               $eshopFooter->setLocale($session->get('lang')->getLangKey());
  3262.               $dem->refresh($eshopFooter);  
  3263.             }  
  3264.             $user $em->getRepository(User::class)->getUser($eshop->getUserId());
  3265.             //we set contact from db to session
  3266.             if(!empty($session->get('contact'))) {
  3267.                 $contact $dem->getRepository(Contact::class)->getContactFromUsername($session->get('contact')->getContactUserName());
  3268.                 $session->set('contact'$contact);
  3269.             }
  3270.             //isModule PayPal
  3271.             $module $em->getRepository(Module::class)->getModule(9);
  3272.             $isPayPalModule $em->getRepository(User::class)->userHasModule($user$module);
  3273.             /* we prepare data for the form */
  3274.             if(!empty($request->request->get('firstName'))) {
  3275.                 $firstName $request->request->get('firstName');
  3276.             } elseif(!empty($session->get('contact'))) {
  3277.                 $firstName $session->get('contact')->getFirstName();
  3278.             } else {
  3279.                 $firstName '';
  3280.             }
  3281.             if(!empty($request->request->get('lastName'))) {
  3282.                 $lastName $request->request->get('lastName');
  3283.             } elseif(!empty($session->get('contact'))) {
  3284.                 $lastName $session->get('contact')->getLastName();
  3285.             } else {
  3286.                 $lastName '';
  3287.             }            
  3288.             if(!empty($request->request->get('companyName'))) {
  3289.                 $company $request->request->get('companyName');
  3290.             } elseif(!empty($session->get('contact'))) {
  3291.                 $company $session->get('contact')->getCompanyName();
  3292.             } else {
  3293.                 $company '';
  3294.             }
  3295.             if(!empty($request->request->get('email'))) {
  3296.                 $email $request->request->get('email');
  3297.             } elseif(!empty($session->get('contact'))) {
  3298.                 $email $session->get('contact')->getEmail();
  3299.             } else {
  3300.                 $email '';
  3301.             }
  3302.             if(!empty($request->request->get('phone'))) {
  3303.                 $telefon $request->request->get('phone');
  3304.             } elseif(!empty($session->get('contact'))) {
  3305.                 $telefon $session->get('contact')->getPhone();
  3306.             } else {
  3307.                 $telefon '';
  3308.             }
  3309.             if(!empty($request->request->get('addressStreet'))) {
  3310.                 $addressStreet $request->request->get('addressStreet');
  3311.             } elseif(!empty($session->get('contact')) && !empty($session->get('contact')->getAddress())) {
  3312.                 $addressStreet $session->get('contact')->getAddress()->getStreet();
  3313.             } else {
  3314.                 $addressStreet '';
  3315.             }
  3316.             if(!empty($request->request->get('addressStreetNumber'))) {
  3317.                 $addressStreetNumber $request->request->get('addressStreetNumber');
  3318.             } elseif(!empty($session->get('contact')) && !empty($session->get('contact')->getAddress())) {
  3319.                 $addressStreetNumber $session->get('contact')->getAddress()->getStreetNumber();
  3320.             } else {
  3321.                 $addressStreetNumber '';
  3322.             }     
  3323.             if(!empty($request->request->get('addressCity'))) {
  3324.                 $addressCity $request->request->get('addressCity');
  3325.             } elseif(!empty($session->get('contact')) && !empty($session->get('contact')->getAddress())) {
  3326.                 $addressCity $session->get('contact')->getAddress()->getCity();
  3327.             } else {
  3328.                 $addressCity '';
  3329.             }   
  3330.             
  3331.             if(!empty($request->request->get('addressZipCode'))) {
  3332.                 $addressZipCode $request->request->get('addressZipCode');
  3333.             } elseif(!empty($session->get('contact')) && !empty($session->get('contact')->getAddress())) {
  3334.                 $addressZipCode $session->get('contact')->getAddress()->getZipCode();
  3335.             } else {
  3336.                 $addressZipCode '';
  3337.             }   
  3338.             
  3339.             if(!empty($request->request->get('addressCountry'))) {
  3340.                 $addressCountry $request->request->get('addressCountry');
  3341.             } elseif(!empty($session->get('contact')) && !empty($session->get('contact')->getAddress())) {
  3342.                 $addressCountry $session->get('contact')->getAddress()->getCountry();
  3343.             } else {
  3344.                 $addressCountry '';
  3345.             }                                        
  3346.             if(!empty($request->request->get('address'))) {
  3347.                 $address $request->request->get('address');
  3348.             } elseif(!empty($session->get('contact'))) {
  3349.                 $address $session->get('contact')->getAddress1();
  3350.             } else {
  3351.                 $address '';
  3352.             }
  3353.             if(!empty($request->request->get('contactUserName'))) {
  3354.                 $username $request->request->get('contactUserName');
  3355.             } elseif(!empty($session->get('contact'))) {
  3356.                 $username $session->get('contact')->getContactUserName();
  3357.             } else {
  3358.                 $username '';
  3359.             }
  3360.             if(!empty($request->request->get('contactUserPassword'))) {
  3361.                 $password $request->request->get('contactUserPassword');
  3362.             } elseif(!empty($session->get('contact'))) {
  3363.                 $password $session->get('contact')->getContactUserPassword();
  3364.             } else {
  3365.                 $password '';
  3366.             }
  3367.             if(!empty($request->request->get('password_retype'))) {
  3368.                 $password_retype $request->request->get('password_retype');
  3369.             } elseif(!empty($session->get('contact'))) {
  3370.                 $password_retype $session->get('contact')->getContactUserPassword();
  3371.             } else {
  3372.                 $password_retype '';
  3373.             }   
  3374.             if(!empty($request->request->get('businessId'))) {
  3375.                 $businessId $request->request->get('businessId');
  3376.             } elseif(!empty($session->get('contact'))) {
  3377.                 $businessId $session->get('contact')->getBusinessId();
  3378.             } else {
  3379.                 $businessId '';
  3380.             }
  3381.              if(!empty($request->request->get('DICId'))) {
  3382.                 $DICId $request->request->get('DICId');
  3383.             } elseif(!empty($session->get('contact'))) {
  3384.                 $DICId $session->get('contact')->getDICId();
  3385.             } else {
  3386.                 $DICId '';
  3387.             }                           
  3388.             /* we build register form */
  3389.             $contact = new Contact;
  3390.             $formBuilder $this->createFormBuilder($contact);
  3391.             $formBuilder->add('lastName'TextType::class, array(
  3392.                     'required' => true,
  3393.                     'label' => $this->translator->trans('knowledgebase.last_name'),
  3394.                     'attr' => array('class' => 'text_form''size' => 35'value' => $lastName),
  3395.                     'label_attr' => array('class' => 'form_field_label_required')
  3396.             ));  
  3397.             $formBuilder->add('firstName'TextType::class, array(
  3398.                     'required' => true,
  3399.                     'label' => $this->translator->trans('knowledgebase.first_name'),
  3400.                     'attr' => array('class' => 'text_form''size' => 35'value' => $firstName),
  3401.                     'label_attr' => array('class' => 'form_field_label_required')
  3402.             ));
  3403.             $formBuilder->add('email'EmailType::class, array(
  3404.                     'required' => true,
  3405.                     'attr' => array('class' => 'text_form''size' => 35'value' => $email),
  3406.                     'label_attr' => array('class' => 'form_field_label_required'),
  3407.             ));
  3408.             $formBuilder->add('contactUserName'TextType::class, array(
  3409.                     'required' => true,
  3410.                     'label' => $this->translator->trans('user.username'),
  3411.                     'empty_data'  => '',
  3412.                     'attr' => array('class' => 'text_form''size' => 35'value' => $username),
  3413.                     'label_attr' => array('class' => 'form_field_label_required'),
  3414.             ));
  3415.             $formBuilder->add('contactUserPassword'PasswordType::class, array(
  3416.                     'required' => true,
  3417.                     'label' => $this->translator->trans('user.password'),
  3418.                     'attr' => array('class' => 'text_form''size' => 35'value' => $password),
  3419.                     'label_attr' => array('class' => 'form_field_label_required'),
  3420.             ));
  3421.             $formBuilder->add('phone'TextType::class, array(
  3422.                     'required' => false,
  3423.                     'label' => $this->translator->trans('user.telephone'),
  3424.                     'attr' => array('class' => 'text_form''size' => 35'value' => $telefon),
  3425.                     'label_attr' => array('class' => 'form_field_label'),
  3426.             ));
  3427.             /* we add address */
  3428.             $formBuilder->add('addressStreet'TextType::class, array(
  3429.                     'required' => true,
  3430.                     'mapped' => false,
  3431.                     'label' => $this->translator->trans('address.street'),
  3432.                     'attr' => array('class' => 'text_form''size' => 35'value' => $addressStreet),
  3433.                     'label_attr' => array('class' => 'form_field_label_required'),
  3434.             ));
  3435.             $formBuilder->add('addressStreetNumber'TextType::class, array(
  3436.                     'required' => true,
  3437.                     'mapped' => false,
  3438.                     'label' => $this->translator->trans('address.street_number'),
  3439.                     'attr' => array('class' => 'text_form''size' => 10'value' => $addressStreetNumber),
  3440.                     'label_attr' => array('class' => 'form_field_label_required'),
  3441.             ));
  3442.             $formBuilder->add('addressZipCode'TextType::class, array(
  3443.                     'required' => true,
  3444.                     'mapped' => false,
  3445.                     'label' => $this->translator->trans('address.zip_code'),
  3446.                     'attr' => array('class' => 'text_form''size' => 10'value' => $addressZipCode),
  3447.                     'label_attr' => array('class' => 'form_field_label_required'),
  3448.             ));
  3449.             $formBuilder->add('addressCity'TextType::class, array(
  3450.                     'required' => true,
  3451.                     'mapped' => false,
  3452.                     'label' => $this->translator->trans('address.city'),
  3453.                     'attr' => array('class' => 'text_form''size' => 35'value' => $addressCity),
  3454.                     'label_attr' => array('class' => 'form_field_label_required'),
  3455.             ));
  3456.             $formBuilder->add('addressCountry'TextType::class, array(
  3457.                     'required' => true,
  3458.                     'mapped' => false,
  3459.                     'label' => $this->translator->trans('address.country'),
  3460.                     'attr' => array('class' => 'text_form''size' => 35'value' => $addressCountry),
  3461.                     'label_attr' => array('class' => 'form_field_label_required'),
  3462.             ));
  3463.             $formBuilder->add('companyName'TextType::class, array(
  3464.                     'required' => false,
  3465.                     'label' => $this->translator->trans('user.company'),
  3466.                     'attr' => array('class' => 'text_form''size' => 35'value' => $company),
  3467.                     'label_attr' => array('class' => 'form_field_label')
  3468.             ));
  3469.             $formBuilder->add('businessId'TextType::class, array(
  3470.                     'required' => false,
  3471.                     'label' => $this->translator->trans('user.business_number'),
  3472.                     'attr' => array('class' => 'text_form''size' => 35'value' => $businessId),
  3473.                     'label_attr' => array('class' => 'form_field_label')
  3474.             ));
  3475.             $formBuilder->add('DICId'TextType::class, array(
  3476.                     'required' => false,
  3477.                     'label' => $this->translator->trans('user.DIC_number'),
  3478.                     'attr' => array('class' => 'text_form''size' => 35'value' => $DICId),
  3479.                     'label_attr' => array('class' => 'form_field_label')
  3480.             ));
  3481.             
  3482.             /*
  3483.             $formBuilder->add('address', TextareaType::class, array(
  3484.                     'required' => false,
  3485.                     'label' => $this->translator->trans('user.address'),
  3486.                     'attr' => array('class' => 'textarea_form', 'cols' => 33, 'rows' => 2, 'value' => $address),
  3487.                     'label_attr' => array('class' => 'form_textarea_label'),
  3488.                     'data' => $address,
  3489.             ));
  3490.             */
  3491.             /*
  3492.             $formBuilder->add('password_retype', PasswordType::class, array(
  3493.                     'required' => true,
  3494.                     'label' => $this->translator->trans('user.password_retype'),
  3495.                     'attr' => array('class' => 'text_form', 'size' => 35, 'value' => $password_retype),
  3496.                     'label_attr' => array('class' => 'form_field_label_required'),
  3497.             ));    
  3498.             */  
  3499.         
  3500.         //isModule e-Privacy Consent
  3501.         $module $em->getRepository(Module::class)->getModule(30);
  3502.         $isConsentModule $em->getRepository(User::class)->userHasModule($user$module);
  3503.         $consentList null;
  3504.         $consentDescriptions = array();
  3505.         if($isConsentModule) {
  3506.             //print('<br>qqw is module e-Privacy Consent');
  3507.  
  3508.             $consentList $dem->getRepository(Consent::class)->getConsentList();
  3509.             $consents = array();
  3510.             $consentRequired false;
  3511.             foreach($consentList as $consent) {
  3512.                 //print('<br>Consent: '.$consent->getConsentName());
  3513.                 $consent->setLocale($session->get('lang')->getLangKey());
  3514.                 $dem->refresh($consent); 
  3515.                 if($consent->isBlockOrder()) {
  3516.                     $consentRequired true;
  3517.                 }
  3518.                 $consents[$consent->getConsentName()] = $consent->getConsentId();
  3519.                 $consentDescriptions[$consent->getConsentId()] = $consent->getConsentDescription();
  3520.             }
  3521.             $selectedConsents = array();
  3522.             $formBuilder->add('consents'ChoiceType::class, array(
  3523.                     'choices' => $consents,
  3524.                     'required' => $consentRequired,
  3525.                     'mapped' => false,
  3526.                     'multiple' => true,
  3527.                     'expanded' => true,
  3528.                     'label_attr' => array('class' => 'consent_label'),
  3529.                     'attr' => array('class' => 'form_field_text'),
  3530.                     'choice_attr' => function($val$key$index) {
  3531.                         // adds a class like attending_yes, attending_no, etc
  3532.                         return ['class' => 'choiceBlock5''required' => 'required'];
  3533.                     },
  3534.                     'data' => $selectedConsents
  3535.             ));
  3536.         }    
  3537.         $formBuilder->add('save'SubmitType::class, array('label' => $this->translator->trans('eshop.complete_order'),
  3538.                 'attr' => array('class' => 'completeOrderButton')));
  3539.         $form $formBuilder->getForm();
  3540.         
  3541.             $form->handleRequest($request);
  3542.             
  3543.             if ($request->getMethod() == 'POST') {
  3544.             
  3545.                 //$form->bindRequest($request);
  3546.             
  3547.                 if ($form->isValid()) {
  3548.                     $formData $form->getData();
  3549.             
  3550.                     /* we check if this contact already exists */
  3551.                     $contactExist $dem->getRepository(Contact::class)->getContactFromUsername($formData->getContactUsername());
  3552.             
  3553.                     /*
  3554.                     print('<br>qqw contact exists: ');
  3555.                     \Doctrine\Common\Util\Debug::dump($contactExist);
  3556.                     */
  3557.                     /* we create new contact
  3558.                     if($contactExist === null) {
  3559.             
  3560.                         /* we check if the password fields are the same */
  3561.                         $password $formData->getContactUserPassword();
  3562.                         //$retypePassword = $request->request->get('form')['password_retype'];
  3563.                             if(!empty($session->get('contact'))) {
  3564.                                 /* */
  3565.                                 $contact $dem->getRepository(Contact::class)->getContactFromUsername($formData->getContactUsername());
  3566.                                 $password $formData->getContactUserPassword();
  3567.                             } else {
  3568.                                 print('<br>We create new contact');
  3569.                                 //$contact = new Contact;
  3570.                                 $password md5($formData->getContactUserPassword());
  3571.                             }
  3572.                             /* we load contact data from register form into contact object */
  3573.                             $contact->setFirstName($formData->getFirstName());
  3574.                             $contact->setLastName($formData->getLastName());
  3575.                             $contact->setCompanyName($formData->getCompanyName());
  3576.                             $contact->setContactUserName($formData->getContactUserName());
  3577.                             $contact->setEmail($formData->getEmail());
  3578.                             $contact->setPhone($formData->getPhone());
  3579.                             $contact->setContactUserPassword($password);
  3580.                             //$address = $contact->getAddress();
  3581.                             if(empty($contact->getAddress())) {
  3582.                                $address = new Address;
  3583.                             } else {
  3584.                                $address $contact->getAddress();
  3585.                             }
  3586.                             $address->setStreet($form['addressStreet']->getData());
  3587.                             $address->setStreetNumber($form['addressStreetNumber']->getData());
  3588.                             $address->setCity($form['addressCity']->getData());
  3589.                             $address->setZipCode($form['addressZipCode']->getData());
  3590.                             $address->setCountry($form['addressCountry']->getData());
  3591.                             $contact->setAddress($address);
  3592.                             $contact->setBusinessId($formData->getBusinessId());
  3593.                             $contact->setDICId($formData->getDICId());
  3594.                             /* we remove old consents */
  3595.                             if(!empty($contact->getConsents())) {
  3596.                                 foreach($contact->getConsents() as $consent) {
  3597.                                     $contact->removeConsent($consent);
  3598.                                     //$dem->refresh($product);
  3599.                                     //$dem->persist($cat);
  3600.                                 }
  3601.                             }
  3602.                             /* we save consents */
  3603.                             if(!empty($form['consents']->getData())) {
  3604.                                 foreach($form['consents']->getData() as $consentId) {
  3605.                                     $consent $dem->getRepository(Consent::class)->getConsent($consentId);
  3606.                                     $contact->addConsent($consent);
  3607.                                 }
  3608.                             }
  3609.                             /* we persist and save contact */
  3610.                             $dem->persist($contact);
  3611.                             $dem->flush();
  3612.             
  3613.                             //$this->addFlash('notice', $this->translator->trans('eshop.contact_new_created'));
  3614.                             
  3615.                             /* we load logged contact into session */
  3616.                             $session $request->getSession();
  3617.                             $session->set('contact'$contact);    
  3618.                             
  3619.                             /* we load logged user into order 
  3620.                             //$session->get('order')->setEshopContact($contact); 
  3621.                             /*
  3622.                             print('<br>qqw contact: ');
  3623.                             \Doctrine\Common\Util\Debug::dump($session->get('contact'));        
  3624.                             */
  3625.                             return $this->redirectToRoute('thankyou', array('eshopId' => $eshopId));
  3626.             
  3627.                     }
  3628.                     else {
  3629.                         $this->addFlash('error''E-shop account with this username already exists.');
  3630.                     }
  3631.             
  3632.                 }
  3633.             /* we setup wireframe and layout extensoin */
  3634.             if(!empty($wireFrame)) {
  3635.                 $wireFrameFile $wireFrame->getWireFrameFile();
  3636.             } else {
  3637.                 $wireFrameFile 'eshopLayoutFlat.html.twig';
  3638.             }
  3639.             $currentUserId $eshop->getUserId();
  3640.             $paypalList $dem->getRepository(Paypal::class)->getPaypalListByUser($currentUserId);
  3641.             $userPaypal null;
  3642.             foreach($paypalList as $paypal) {
  3643.                 $userPaypal $dem->getRepository(Paypal::class)->getPaypal($paypal->getPaypalId());
  3644.             }
  3645.             
  3646.             /*
  3647.             print('<br>qqw paypalList: ');
  3648.             \Doctrine\Common\Util\Debug::dump($paypalList);            
  3649.             print('<br>qqw paypal: ');
  3650.             \Doctrine\Common\Util\Debug::dump($userPaypal);
  3651.             */
  3652.             
  3653.             /* we render data */
  3654.             return $this->render('eshopCustomer.html.twig',
  3655.                     array('headerData' => $this -> getPageHeader($request),
  3656.                             'form' => $formBuilder->getForm()->createView(),
  3657.                             'formRaw' => $formBuilder->getForm(),
  3658.                             'eshop' => $eshop,
  3659.                             'wireFrame' => null,
  3660.                             'wireFrameFile' => $wireFrameFile,                            
  3661.                             'categoryTreeMenu' => $this->categoryTreeMenu($eshop$request),
  3662.                             'categoryTopMenu' => $this->categoryTopMenu($eshop$request), 
  3663.                             'eshopHeader' => $eshopHeader,
  3664.                             'eshopFooter' => $eshopFooter,    
  3665.                             'isConsentModule' => $isConsentModule,    
  3666.                             'consentList' => $consentList
  3667.                             'consentDescriptions' => $consentDescriptions
  3668.                             'isPayPalModule' => $isPayPalModule,
  3669.                             'paypal' => $userPaypal                                                       
  3670.                     )
  3671.                     );
  3672.              
  3673.         }   
  3674.         /**
  3675.          * @Route("/eshop/{eshopId}/thankyou", name="thankyou")
  3676.          */        
  3677.         public function thankyouAction(Request $request$eshopId) {
  3678.               
  3679.             /* we load session data */
  3680.             parent::init($request);
  3681.              
  3682.             $session $request->getSession();
  3683.              
  3684.             /* we load entity managers */
  3685.             $em $this->doctrine->getManager();
  3686.             $dem $this->doctrine->getManager('dynamic_em');
  3687.             
  3688.             /* we get current e-shop */
  3689.             $eshop $em->getRepository(Eshop::class)->getEshop($eshopId);
  3690.             $eshopHeader $dem->getRepository(Eshop::class)->getEshopHeader($eshopId);
  3691.             if(!empty($eshopHeader)) {
  3692.               $eshopHeader->setLocale($session->get('lang')->getLangKey());
  3693.               $dem->refresh($eshopHeader);            
  3694.             }
  3695.             /* we load footer for the current website */
  3696.             $eshopFooter $dem->getRepository(Eshop::class)->getEshopFooter($eshopId);
  3697.             if(!empty($eshopFooter)) {         
  3698.               $eshopFooter->setLocale($session->get('lang')->getLangKey());
  3699.               $dem->refresh($eshopFooter);  
  3700.             }  
  3701.             /* we get user */
  3702.             $user $em->getRepository(User::class)->getUser($eshop->getUserId());
  3703.             if(empty($session->get('order'))) {
  3704.                     $this->addFlash('error''Order session timed out.');
  3705.                     return $this->redirectToRoute('eshopHome'); 
  3706.             }
  3707.             
  3708.             /* we setup order fields */
  3709.             $dateTimeNow = new \DateTime("now");            
  3710.             $session->get('order')->setDateCreated($dateTimeNow);
  3711.             $order $session->get('order');
  3712.             /* we get new order id */
  3713.             $getMaxOrderId $dem->getRepository(Order::class)->getMaxOrderId() + 1;
  3714.             /* we persist order items into db */
  3715.             $orderItems $session->get('order')->getOrderItems();
  3716.             foreach($orderItems as $orderItem) {
  3717.                 $orderItem->setOrderId($getMaxOrderId);
  3718.                 $dem->persist($orderItem);
  3719.             }
  3720.             //print('<br>qqw del id: '.$session->get('order')->getEshopDelivery()->getDeliveryId());
  3721.             /* we persist delivery */
  3722.             //$orderDelivery = $em->getRepository(Delivery::class)->getDelivery($session->get('order')->getEshopDelivery()->getDeliveryId());
  3723.             $orderDelivery $dem->getRepository(EshopDelivery::class)->getEshopDelivery($session->get('order')->getEshopDelivery()->getEshopDeliveryId());
  3724.             $order->setEshopDelivery($orderDelivery);
  3725.             $orderPayment $dem->getRepository(EshopPayment::class)->getEshopPayment($session->get('order')->getEshopPayment()->getEshopPaymentId());
  3726.             $order->setEshopPayment($orderPayment);
  3727.             //$dem->persist($orderDelivery);
  3728.             /*
  3729.              print('<br>qqw orderDelivery: ');
  3730.             \Doctrine\Common\Util\Debug::dump($orderDelivery);
  3731.             */
  3732.             //die('<br>qqw Delivery x');  
  3733.             //$orderDelivery = $session->get('order')->getEshopDelivery();
  3734.             //$dem->persist($orderDelivery);
  3735.             //$orderPayment = $session->get('order')->getEshopPayment();
  3736.             //$dem->persist($orderPayment);
  3737.             
  3738.             /* we persist customer */
  3739.             if(!empty($session->get('contact'))) {
  3740.                 //print('<br>qqw existing customer');
  3741.                 $orderContact $dem->getRepository(Contact::class)->getContact($session->get('contact')->getContactId());
  3742.                 if(empty($orderContact)) {
  3743.                     $orderContact $session->get('contact');
  3744.                 }
  3745.                 $order->setEshopContact($orderContact);
  3746.             } else {
  3747.                 $orderContact $session->get('order')->getEshopContact();
  3748.             }
  3749.              
  3750.             /*          
  3751.             print('<br>qqw orderContact: ');
  3752.             \Doctrine\Common\Util\Debug::dump($orderContact);
  3753.             
  3754.             
  3755.              print('<br>qqw contact: ');
  3756.              \Doctrine\Common\Util\Debug::dump($session->get('contact'));    
  3757.              */  
  3758.             $order->setIp($request->getClientIp());        
  3759.             $dem->persist($orderContact);          
  3760.             /* we persist order into db */
  3761.             $dem->persist($order);
  3762.             $dem->flush();
  3763.             /* we remove the order from session */
  3764.             $session->remove('order');
  3765.             /* we prepare emailing */
  3766.             $name $eshop->getEshopName();
  3767.             $to      $user->getEmail();
  3768.             $subject $name.' - '.$this->translator->trans('eshop.email_order_subject').': #'.$order->getOrderId();
  3769.             $message $this->translator->trans('eshop.email_order_text');
  3770.             /* we load order email cms text for the current eshop */
  3771.             $orderEmail $dem->getRepository(WebPage::class)->getEmailOrder($eshopId);
  3772.             if(!empty($orderEmail)) {
  3773.                 $message .= $orderEmail->getWebPageContent();
  3774.             } 
  3775.             /* we load order email cms text for the current eshop */
  3776.             /* we get order prices */
  3777.             $eshopCurrency $em->getRepository(Currency::class)->getCurrency($eshop->getPreferredCurrencyId());
  3778.             if(!empty($order->getCurrencyKey())) {
  3779.                 $targetCurrency $em->getRepository(Currency::class)->getCurrencyByKey($order->getCurrencyKey());
  3780.             } else {
  3781.                 $targetCurrency $eshopCurrency;
  3782.             }
  3783.             $orderPrice $dem->getRepository(Order::class)->getOrderPrice($order->getOrderId(), $targetCurrencyfalse$eshop$eshopCurrency);
  3784.             $orderPriceVAT $dem->getRepository(Order::class)->getOrderPrice($order->getOrderId(), $targetCurrencytrue$eshop$eshopCurrency);
  3785.             $orderEmailText $this->getOrderEmail($request$eshop$order$orderPrice$orderPriceVAT);
  3786.             $message .= $orderEmailText;
  3787.             $from 'noreply@virtualrealitycommerce.cz';
  3788.             /*
  3789.             $headers  = "MIME-Version: 1.0\r\n";
  3790.             $headers .= "Content-type: text/html; charset=UTF-8\r\n";
  3791.             $headers .= "From: {$name} <{$from}>\r\n";
  3792.             $headers .= "Reply-To: <{$from}>\r\n";
  3793.             $headers .= "Subject: {$subject}\r\n";
  3794.             $headers .= "X-Mailer: PHP/".phpversion()."\r\n";
  3795.             */
  3796.             // we send email to eshop owner
  3797.             if($this->sendEmail($to$subject$from$message)) {
  3798.                 if(!empty($user->getContactPersonEmail())) {
  3799.                     $this->sendEmail($user->getContactPersonEmail(), $subject$from$message);
  3800.                 }
  3801.                 $mailToAdminStatus $this->translator->trans('eshop.email_admin_order_ok').': '.$to;
  3802.             } else {
  3803.                 $mailToAdminStatus $this->translator->trans('eshop.email_admin_order_error'.': '.$to);
  3804.             }
  3805.             // we send email to customer 
  3806.             $to      $orderContact->getEmail();    
  3807.             if($this->sendEmail($to$subject$from$message)) {
  3808.                 $mailToCustomerStatus $this->translator->trans('eshop.email_customer_order_ok').': '.$to;
  3809.             } else {   
  3810.                 $mailToCustomerStatus $this->translator->trans('eshop.email_customer_order_error'.': '.$to);
  3811.             }
  3812.             
  3813.             /*
  3814.             // we send email to e-shop admin - sendmail, sendemail 
  3815.             if(@mail($to, $subject, $message, $headers)) {
  3816.                 //print('<br>Email was sent.');
  3817.                 //we send email to users contact person
  3818.                 if(!empty($user->getContactPersonEmail())) {
  3819.                     mail($user->getContactPersonEmail(), $subject, $message, $headers);
  3820.                 }
  3821.                 
  3822.             } else {
  3823.                 //print('<br>Email was not sent.');
  3824.                 $mailToAdminStatus = $this->translator->trans('eshop.email_admin_order_error'.': '.$to);
  3825.             }   
  3826.             // we send email to customer 
  3827.             $to      = $orderContact->getEmail();    
  3828.             if(@mail($to, $subject, $message, $headers)) {
  3829.                 //print('<br>Email was sent.');
  3830.                 $mailToCustomerStatus = $this->translator->trans('eshop.email_customer_order_ok').': '.$to;
  3831.             } else {
  3832.                 //print('<br>Email was not sent.');
  3833.                 $mailToCustomerStatus = $this->translator->trans('eshop.email_customer_order_error'.': '.$to);
  3834.             }     
  3835.             */             
  3836.             /* we render data */
  3837.             return $this->render('eshopThankYou.html.twig',
  3838.                     array('headerData' => $this -> getPageHeader($request),
  3839.                             'eshop' => $eshop,
  3840.                             'order' => $order,
  3841.                             'user' => $user,
  3842.                             'wireFrame' => null,
  3843.                             'categoryTreeMenu' => $this->categoryTreeMenu($eshop$request),
  3844.                             'categoryTopMenu' => $this->categoryTopMenu($eshop$request), 
  3845.                             'eshopHeader' => $eshopHeader,
  3846.                             'eshopFooter' => $eshopFooter,   
  3847.                             'mailToAdminStatus' => $mailToAdminStatus,  
  3848.                             'mailToCustomerStatus' => $mailToCustomerStatus,    
  3849.                     )
  3850.                     );
  3851.     }
  3852.       
  3853.     public function getOrderEmail(Request $request$eshop$order$orderPrice=null$orderPriceVAT=null)
  3854.     {
  3855.         /* we load session data */
  3856.         parent::init($request);
  3857.          
  3858.         $session $request->getSession();
  3859.          
  3860.         /* we load entity managers */
  3861.         $em $this->doctrine->getManager();
  3862.         $dem $this->doctrine->getManager('dynamic_em');
  3863.         /* we get user */
  3864.         $user $em->getRepository(User::class)->getUser($eshop->getUserId());
  3865.         $defaultCurrency $em->getRepository(Currency::class)->getCurrency($eshop->getPreferredCurrencyId());
  3866.         if(!empty($order->getCurrencyKey())) {
  3867.             $targetCurrency $em->getRepository(Currency::class)->getCurrencyByKey($order->getCurrencyKey());
  3868.         } else {
  3869.             $targetCurrency $session->get('eshopCurrency');        
  3870.         }
  3871.  
  3872.         if(!empty($order->getDateCreated())) {
  3873.           $dateCreated $order->getDateCreated()->format('Y\-m\-d\ H:i:s');
  3874.         } else {
  3875.           $dateCreated '';
  3876.         }
  3877.         $emailText '<h3>'.$this->translator->trans('eshop.order_detail').'</h3>';
  3878.         $emailText .= '<table width="100%" style="background-color: #EFEFEF; color: Black;font-family: Arial;font-size: 14px;border:Gray solid 1px;" cellspacing="0" cellpadding="3">
  3879.             <tr>
  3880.               <td><strong>'.$this->translator->trans('eshop.order').':</strong></td> 
  3881.               <td>'.$order->getOrderId().'</td> 
  3882.             </tr>
  3883.             <tr>
  3884.               <td><strong>'.$this->translator->trans('system.date_created').':</strong></td> 
  3885.               <td>'.$dateCreated.'</td>                 
  3886.             </tr></table> '
  3887.         $emailText .= '<h3>'.$this->translator->trans('eshop.order_items').'</h3>
  3888.         <table width="100%" style="background-color: #EFEFEF; color: Black;font-family: Arial;font-size: 14px;border:Gray solid 1px;" cellspacing="0" cellpadding="3">
  3889.             <tr>
  3890.                 <th style="text-align:left;background-color: LightGray;">id#</th> 
  3891.                 <th style="text-align:left;background-color: LightGray;">'.$this->translator->trans('product.name').'</th> 
  3892.                 <th style="text-align:left;background-color: LightGray;">'.$this->translator->trans('product.key').'</th>
  3893.                 <th style="text-align:left;background-color: LightGray;">'.$this->translator->trans('system.units').'</th> 
  3894.                 <th style="text-align:left;background-color: LightGray;">'.$this->translator->trans('eshop.price_piece').'</th>   
  3895.                 <th style="text-align:left;background-color: LightGray;">'.$this->translator->trans('eshop.price').'</th>         
  3896.             </tr>  '
  3897.             $totalPrice 0;
  3898.             $totalPriceVAT 0;
  3899.             foreach($order->getOrderItems() as $orderItem) {
  3900.                 if(empty($orderItem->getOrderItemPrice())) {
  3901.                     $orderItem->setOrderItemPrice(0);
  3902.                 }      
  3903.                 $productKey "";
  3904.                 if(!empty($orderItem->getProductId())) {
  3905.                     $product $dem->getRepository(Product::class)->getProduct($orderItem->getProductId());
  3906.                     $productKey $product->getERPKey();
  3907.                 }
  3908.             
  3909.                 $productPrice $orderItem->getOrderItemPrice() * $orderItem->getOrderItemUnits();
  3910.                 if(!empty($orderItem->getOrderItemPriceBrutto())) {
  3911.                     $productPriceVAT $orderItem->getOrderItemPriceBrutto() * $orderItem->getOrderItemUnits();
  3912.                 } else {
  3913.                     $productPriceVAT $orderItem->getOrderItemPrice() * $orderItem->getOrderItemUnits();
  3914.                 }
  3915.                 if(empty($productPrice)) { 
  3916.                     $productPrice 0;
  3917.                 }
  3918.                 $totalPrice $totalPrice $productPrice;
  3919.                 $totalPriceVAT $totalPriceVAT $productPriceVAT;                
  3920.                 $emailText .= '<tr>
  3921.                   <td>'.$orderItem->getOrderItemId().'</td>
  3922.                   <td>
  3923.                     <strong>'.$orderItem->getOrderItemTitle().'</strong>
  3924.                   </td>
  3925.                   <td>'.$productKey.'</td>
  3926.                   <td>'.$orderItem->getOrderItemUnits().'</td>
  3927.                   <td>'.$orderItem->getOrderItemPrice().' '.$orderItem->getCurrencyKey().'</td>
  3928.                   <td>'.($orderItem->getOrderItemUnits()*$orderItem->getOrderItemPrice()).' '.$orderItem->getCurrencyKey().'</td>
  3929.                 </tr>';
  3930.             }
  3931.         $emailText .= '</table>';
  3932.         $emailText .= '<h3>'.$this->translator->trans('eshop.customer').'</h3>
  3933.         <table width="100%" style="background-color: #EFEFEF; color: Black;font-family: Arial;font-size: 14px;border:Gray solid 1px;" cellspacing="0" cellpadding="3">
  3934.             <tr>
  3935.                 <th style="text-align:left;background-color: LightGray;">id#</th> 
  3936.                 <th style="text-align:left;background-color: LightGray;">'.$this->translator->trans('knowledgebase.first_name').'</th>  
  3937.                 <th style="text-align:left;background-color: LightGray;">'.$this->translator->trans('knowledgebase.last_name').'</th>
  3938.                 <th style="text-align:left;background-color: LightGray;">'.$this->translator->trans('knowledgebase.company_name').'</th>
  3939.                 <th style="text-align:left;background-color: LightGray;">'.$this->translator->trans('knowledgebase.email').'</th>  
  3940.                 <th style="text-align:left;background-color: LightGray;">'.$this->translator->trans('knowledgebase.phone').'</th>         
  3941.                 <th style="text-align:left;background-color: LightGray;">'.$this->translator->trans('address.street').'</th> 
  3942.                 <th style="text-align:left;background-color: LightGray;">'.$this->translator->trans('address.street_number').'</th>
  3943.                 <th style="text-align:left;background-color: LightGray;">'.$this->translator->trans('address.city').'</th> 
  3944.                 <th style="text-align:left;background-color: LightGray;">'.$this->translator->trans('address.zip_code').'</th>
  3945.                 <th style="text-align:left;background-color: LightGray;">'.$this->translator->trans('address.country').'</th>
  3946.             </tr> 
  3947.             <tr>
  3948.                 <td>'.$order->getEshopContact()->getContactId().'</td>
  3949.                 <td>'.$order->getEshopContact()->getFirstName().'</td>
  3950.                 <td>'.$order->getEshopContact()->getLastName().'</td>
  3951.                 <td>'.$order->getEshopContact()->getCompanyName().'</td>
  3952.                 <td>'.$order->getEshopContact()->getEmail().'</td>
  3953.                 <td>'.$order->getEshopContact()->getPhone().'</td>
  3954.                 <td>'.(!empty($order->getEshopContact()->getAddress())?$order->getEshopContact()->getAddress()->getStreet():"").'</td>
  3955.                 <td>'.(!empty($order->getEshopContact()->getAddress())?$order->getEshopContact()->getAddress()->getStreetNumber():"").'</td>                
  3956.                 <td>'.(!empty($order->getEshopContact()->getAddress())?$order->getEshopContact()->getAddress()->getCity():"").'</td>
  3957.                 <td>'.(!empty($order->getEshopContact()->getAddress())?$order->getEshopContact()->getAddress()->getZipCode():"").'</td>
  3958.                 <td>'.(!empty($order->getEshopContact()->getAddress())?$order->getEshopContact()->getAddress()->getCountry():"").'</td>
  3959.     
  3960.             </tr>     
  3961.         </table>';
  3962.         if($order->getEshopContact()->getBusinessId()) {
  3963.             $emailText .= '<div style="padding: 2px;"><strong>'.$this->translator->trans('user.business_number').': </strong>'.$order->getEshopContact()->getBusinessId().'</div>';
  3964.         }
  3965.         if($order->getEshopContact()->getDICId()) {
  3966.             $emailText .= '<div style="padding: 2px;"><strong>'.$this->translator->trans('user.DIC_number').': </strong>'.$order->getEshopContact()->getDICId().'</div>';
  3967.         }        
  3968.         /* we display delivery and price */
  3969.         $emailText .= '<h3>'.$this->translator->trans('eshop.delivery_payment').'</h3>';
  3970.         $emailText .= '<table width="100%" style="background-color: #EFEFEF; color: Black;font-family: Arial;font-size: 14px;border:Gray solid 1px;" cellspacing="0" cellpadding="3">';
  3971.         $emailText .= '<tr><td><strong>'.$this->translator->trans('eshop.delivery').':</strong>';
  3972.         $emailText .= '</td><td>';
  3973.             
  3974.             if(!empty($order->getEshopDelivery())) {
  3975.                 //we set cost in selected currency
  3976.                 $deliveryCost $dem->getRepository(Price::class)->getCurrencyRatedPrice($order->getEshopDelivery()->getCost(), $defaultCurrency$targetCurrency);
  3977.                 $order->getEshopDelivery()->setCost(round($deliveryCost2));
  3978.                 $emailText .= $order->getEshopDelivery()->getEshopDeliveryName();
  3979.                 $emailText .= '<span> [ '.$order->getEshopDelivery()->getCost().' '.$targetCurrency->getCurrencyKey().' ]</span>';
  3980.             }
  3981.         $emailText .= '</td></tr>
  3982.         <tr><td><strong>'.$this->translator->trans('eshop.payment').':</strong>';
  3983.         $emailText .= '</td><td>';
  3984.             if(!empty($order->getEshopPayment())) {
  3985.                 //we set cost in selected currency
  3986.                 $paymentCost $dem->getRepository(Price::class)->getCurrencyRatedPrice($order->getEshopPayment()->getCost(), $defaultCurrency$targetCurrency);
  3987.                 $order->getEshopPayment()->setCost(round($paymentCost2));
  3988.                 $emailText .= $order->getEshopPayment()->getEshopPaymentName();
  3989.                 $emailText .= '<span> [ '.$order->getEshopPayment()->getCost().' '.$targetCurrency->getCurrencyKey().' ]</span>';
  3990.                 if ($order->getEshopPayment()->getPaymentId() == 2) {
  3991.                     // we add sellers bank account info into email
  3992.                     $bankAccountInfo $user->getBankAccount();
  3993.                     $emailText .= '<br>'.$this->translator->trans('eshop.email_bank_account').': '.$bankAccountInfo;
  3994.                 }
  3995.             }
  3996.         $emailText .= '</td></tr>
  3997.         </table>';      
  3998.         /* we display total price */
  3999.         $emailText .= '<br>
  4000.         <table width="100%" style="background-color: #EFEFEF; color: Black;font-family: Arial;font-size: 14px;border:Gray solid 1px;" cellspacing="0" cellpadding="3">
  4001.         <tr><td>'.$this->translator->trans('eshop.price_product_total').':</td><td>'.$totalPrice.' '.$targetCurrency->getCurrencyKey().'</td></tr>
  4002.         <tr><td>'.$this->translator->trans('product.price_with_VAT').':</td><td>'.$totalPriceVAT.' '.$targetCurrency->getCurrencyKey().'</td></tr>';
  4003.         if(!empty($orderPrice)) {
  4004.             $emailText .= '<tr><td><strong>'.$this->translator->trans('eshop.price_total').':</strong></td>';
  4005.             $emailText .= '<td><strong>'.$orderPrice.' '.$targetCurrency->getCurrencyKey().'</strong></td>';
  4006.             $emailText .= '</tr>';  
  4007.         } 
  4008.         if(!empty($orderPriceVAT)) {
  4009.             $emailText .= '<tr><td><strong>'.$this->translator->trans('eshop.price_total_VAT').':</strong></td>';
  4010.             $emailText .= '<td><strong>'.$orderPriceVAT.' '.$targetCurrency->getCurrencyKey().'</strong></td>';
  4011.             $emailText .= '</tr>';  
  4012.         } 
  4013.         $emailText .= '</table>';            
  4014.         return $emailText;
  4015.     }
  4016.     public function getRegisterEmail(Request $request$eshop$contact)
  4017.     {
  4018.         $emailText '<h1>'.$this->translator->trans('eshop.register').' #'.$contact->getContactId().'</h1>';
  4019.         $emailText .= '<h3>'.$this->translator->trans('eshop.customer').'</h3>
  4020.         <table style="color: Black;font-family: Arial;font-size: 14px;border-top:DarkGray solid 2px;border-bottom: DarkGray solid 2px;" cellspacing="0" cellpadding="0">
  4021.             <tr>
  4022.                 <th style="padding: 3px;text-align:left;background-color: LightGray;">id</th> 
  4023.                 <th style="padding: 3px;text-align:left;background-color: LightGray;">'.$this->translator->trans('knowledgebase.first_name').'</th>  
  4024.                 <th style="padding: 3px;text-align:left;background-color: LightGray;">'.$this->translator->trans('knowledgebase.last_name').'</th>
  4025.                 <th style="padding: 3px;text-align:left;background-color: LightGray;">'.$this->translator->trans('knowledgebase.company_name').'</th>
  4026.                 <th style="padding: 3px;text-align:left;background-color: LightGray;">'.$this->translator->trans('knowledgebase.email').'</th>  
  4027.                 <th style="padding: 3px;text-align:left;background-color: LightGray;">'.$this->translator->trans('knowledgebase.phone').'</th>         
  4028.                 <th style="padding: 3px;text-align:left;background-color: LightGray;">'.$this->translator->trans('knowledgebase.user_name').'</th>         
  4029.             </tr> 
  4030.             <tr>
  4031.                 <td style="padding: 3px;">'.$contact->getContactId().'</td>
  4032.                 <td style="padding: 3px;">'.$contact->getFirstName().'</td>
  4033.                 <td style="padding: 3px;">'.$contact->getLastName().'</td>
  4034.                 <td style="padding: 3px;">'.$contact->getCompanyName().'</td>
  4035.                 <td style="padding: 3px;">'.$contact->getEmail().'</td>
  4036.                 <td style="padding: 3px;">'.$contact->getPhone().'</td>
  4037.                 <td style="padding: 3px;">'.$contact->getContactUserName().'</td>          
  4038.             </tr>     
  4039.         </table>';            
  4040.         return $emailText;
  4041.     }
  4042.     public function getEshopRequestEmail(Request $request$eshop$eshopRequestEmail$eshopRequestSubject$eshopRequestMessage$eshopRequestTelephone)
  4043.     {
  4044.         $emailText '<h1>'.$this->translator->trans('eshop.request').'</h1>';
  4045.         $dateTimeNow = new \DateTime("now");
  4046.         $dateCreated $dateTimeNow->format('Y\-m\-d\ H:i:s');
  4047.  
  4048.         $emailText '<h3>'.$this->translator->trans('eshop.request_detail').'</h3>';
  4049.         $emailText .= '<table width="100%" style="background-color: #EFEFEF; color: Black;font-family: Arial;font-size: 14px;border:Gray solid 1px;" cellspacing="0" cellpadding="3">
  4050.             <tr>
  4051.               <td><strong>'.$this->translator->trans('system.date_created').':</strong></td> 
  4052.               <td>'.$dateCreated.'</td>                 
  4053.             </tr>        
  4054.             <tr>
  4055.               <td><strong>Email:</strong></td> 
  4056.               <td>'.$eshopRequestEmail.'</td> 
  4057.             </tr>
  4058.             <tr>
  4059.               <td><strong>'.$this->translator->trans('user.telephone').':</strong></td> 
  4060.               <td>'.$eshopRequestTelephone.'</td> 
  4061.             </tr>            
  4062.             <tr>
  4063.               <td><strong>'.$this->translator->trans('eshop.request_subject').':</strong></td> 
  4064.               <td>'.$eshopRequestSubject.'</td> 
  4065.             </tr>
  4066.             <tr>
  4067.               <td><strong>'.$this->translator->trans('eshop.request_message').':</strong></td> 
  4068.               <td>'.$eshopRequestMessage.'</td> 
  4069.             </tr>            
  4070.             </table> ';    
  4071.         return $emailText;
  4072.     }
  4073.     public function getForgottenPasswordEmail(Request $request$eshop$email)
  4074.     {
  4075.         $link 'https://'.$_SERVER['HTTP_HOST'].'/eshop/'.$eshop->getEshopId().'/forgottenpasswordupdate/'.$email;
  4076.         $emailText '<h1>'.$this->translator->trans('user.forgotten_password').'</h1>';
  4077.         $emailText .= $this->translator->trans('user.forgotten_password_link').'
  4078.        
  4079.                 <a href="'.$link.'" target="_blank" style="padding: 3px;">'.$link.'</a>
  4080.      
  4081.                         ';            
  4082.         return $emailText;
  4083.     }    
  4084.     /**
  4085.      * @Route("/eshopAdmin", name="eshopAdmin")
  4086.      */
  4087.     public function eshopAdminAction(Request $request)
  4088.     {
  4089.         /* we load session data */
  4090.         parent::init($request);
  4091.         
  4092.         $session $request->getSession();
  4093.         // we check if any user is logged in
  4094.         if(!$this->isLoggedUser($request)) {
  4095.             return $this->redirectToRoute('login');
  4096.         }    
  4097.         /* we load entity managers */
  4098.         $em $this->doctrine->getManager();
  4099.         $dem $this->doctrine->getManager('dynamic_em');
  4100.         
  4101.         /* we get current user */
  4102.         $currentUserId $session->get('user')->getUserId();
  4103.         $user $em->getRepository(User::class)->getUser($currentUserId);
  4104.         /* setting current eshop */
  4105.         if(!empty($request->query->get('setCurrent'))) {
  4106.             $eshop $em->getRepository(Eshop::class)->getEshop($request->query->get('setCurrent'));
  4107.             $em->getRepository(Eshop::class)->setCurrentEshop($currentUserId$request->query->get('setCurrent'));
  4108.             $session->set('eshop'$eshop);
  4109.             
  4110.             $this->addFlash('notice''The eshop '.$eshop->getEshopName().' was set as current one.');
  4111.             return $this->redirectToRoute('eshopAdmin');
  4112.             
  4113.         }
  4114.         
  4115.         /* we get current e-shop */
  4116. //        print('<br>qqw currentUserId: '.$currentUserId);
  4117.         $currentEshop $em->getRepository(Eshop::class)->getCurrentEshop($currentUserId);
  4118.         if(!empty($currentEshop)) {
  4119.             $defaultCurrency $em->getRepository(Currency::class)->getCurrency($currentEshop->getPreferredCurrencyId());
  4120.         } else {
  4121.             $defaultCurrency null;
  4122.         }
  4123.       
  4124.       /*
  4125.         print('<br>qqw currentEshop: ');
  4126.         \Doctrine\Common\Util\Debug::dump($currentEshop->getEshopId());
  4127.       */      
  4128.       
  4129.         /* we load list of eshops for logged user */
  4130.         $eshopList $em->getRepository(Eshop::class)->getEshopListByUser($currentUserId);
  4131.         //we create new e-shop if there is none
  4132.         if(count($eshopList) == 0) {
  4133.             $this->eshopCreate($request);
  4134.             return $this->redirectToRoute('eshopAdmin'); 
  4135.         }
  4136.         
  4137.         if(!empty($currentEshop)) {
  4138.             /* we load list of web pages for the current eshop */
  4139.             $webPageList $dem->getRepository(WebPage::class)->getWebPageListByEshop($currentEshop->getEshopId());
  4140.      
  4141.             $eshopHeader $dem->getRepository(Eshop::class)->getEshopHeader($currentEshop->getEshopId());
  4142.             if(!empty($eshopHeader)) {
  4143.               $eshopHeader->setLocale($session->get('lang')->getLangKey());
  4144.               $dem->refresh($eshopHeader);            
  4145.             }
  4146.             /* we load footer for the current website */
  4147.             $eshopFooter $dem->getRepository(Eshop::class)->getEshopFooter($currentEshop->getEshopId());
  4148.             if(!empty($eshopFooter)) {         
  4149.               $eshopFooter->setLocale($session->get('lang')->getLangKey());
  4150.               $dem->refresh($eshopFooter);  
  4151.             }  
  4152.         } else {
  4153.             $webPageList = array();
  4154.             //$webMenuList = array();
  4155.             $eshopHeader null;
  4156.             $eshopFooter null;
  4157.         }      
  4158.         
  4159.       
  4160.         /* we load list of wireframes */
  4161.         $wireFrameList $em->getRepository(WireFrame::class)->getWireFrameList();
  4162.         
  4163.         /* we prepare array of wireframes */
  4164.         $wireFrameArray = array();
  4165.         foreach($wireFrameList as $wireFrame) {
  4166.             $wireFrameArray[$wireFrame->getWireFrameId()] = $wireFrame;
  4167.         }
  4168.          
  4169.         /* we prepare array of count(products) */
  4170.         $productCountArray = array();
  4171.         /*
  4172.         foreach($websiteList as $website) {
  4173.             $productCountArray[$website->getWebsiteId()] = $dem->getRepository(WebPage::class)->getWebPageCountByWebsite($website->getWebsiteId());
  4174.         } 
  4175.         */      
  4176.         
  4177.         /* we load list of modules for e-shop service */
  4178.         $service $em->getRepository(Service::class)->getService(1);
  4179.         /* we load recent orders */
  4180.         $orderList $dem->getRepository(Order::class)->getOrderList("orderId""DESC"10);
  4181.         /* we load order prices */
  4182.         $orderPrices = array();
  4183.         if(!empty($defaultCurrency)) {
  4184.             foreach($orderList as $order) {
  4185.                 if(!empty($order->getCurrencyKey())) {
  4186.                     $targetCurrency $em->getRepository(Currency::class)->getCurrencyByKey($order->getCurrencyKey());
  4187.                 } else {
  4188.                     $targetCurrency $defaultCurrency;
  4189.                 }
  4190.                 
  4191.                 
  4192.                 $orderPrices[$order->getOrderId()] = $dem->getRepository(Order::class)->getOrderPrice($order->getOrderId(), $targetCurrencyfalse$currentEshop$defaultCurrency);
  4193.                 
  4194.             }
  4195.         }
  4196.         //$moduleCollection = $em->getRepository(Module::class)->getModuleList();
  4197.         
  4198.         /*
  4199.         print('<br>qqw moduleCollection: ');
  4200.         \Doctrine\Common\Util\Debug::dump($moduleCollection);
  4201.         
  4202.         print('<hr>qqw userModuleCollection: ');
  4203.         \Doctrine\Common\Util\Debug::dump($user->getModules());   ());      
  4204.         */
  4205.         /* we render data */
  4206.         return $this->render('eshopAdmin.html.twig',
  4207.                 array('headerData' => $this -> getPageHeader($request),
  4208.                       'eshopList' => $eshopList,
  4209.                       'eshopHeader' => $eshopHeader,
  4210.                       'eshopFooter' => $eshopFooter,
  4211.                       'webPageList' => $webPageList,
  4212.                       'moduleList' => $service->getModules(),
  4213.                       'userModuleList' => $user->getModules(),
  4214.                       'wireFrameArray' => $wireFrameArray,
  4215.                       'productCountArray' => $productCountArray,
  4216.                       'orderList' => $orderList,
  4217.                       'orderPrices' => $orderPrices,
  4218.                       'user' => $user,
  4219.                       'menu' => $this -> adminMenu($request),'mainMenu' => $this -> adminMainMenu($request),'mainMenu' => $this -> adminMainMenu($request),
  4220.                 )
  4221.                 );
  4222.     
  4223.     }
  4224.     
  4225.     /**
  4226.      * @Route("/categorynew", name="categoryNew")
  4227.      */
  4228.     public function categoryNewAction(Request $request)
  4229.     {
  4230.         /* we load session data */
  4231.         parent::init($request);
  4232.     
  4233.         $session $request->getSession();
  4234.     
  4235.         $em $this->doctrine->getManager();
  4236.         $dem $this->doctrine->getManager('dynamic_em');
  4237.         
  4238.         $currentUserId $session->get('user')->getUserId();
  4239.         $user $em->getRepository(User::class)->getUser($currentUserId);
  4240.         
  4241.         /* we get current e-shop */
  4242.         $eshop $em->getRepository(Eshop::class)->getCurrentEshop($currentUserId);
  4243.          
  4244.         $categoryCollection $dem->getRepository(Eshop::class)->getCategoryListByEshop($eshop->getEshopId());
  4245.          
  4246.          
  4247.         /* we build login form */
  4248.         $category = new Category;
  4249.         $formBuilder $this->createFormBuilder($category);
  4250.          
  4251.         $formBuilder->add('categoryName'TextType::class, array(
  4252.                 'required' => true,
  4253.                 'label' => $this->translator->trans('eshop.category_name'),
  4254.                 'attr' => array('class' => 'text_form''size' => 22),
  4255.                 'label_attr' => array('class' => 'form_field_label'),
  4256.         ));
  4257.         /* we add category list */
  4258.         $categories = array();
  4259.         $categories['RootX'] = 0;
  4260.         foreach($categoryCollection as $cat)
  4261.         {
  4262.             $catId $cat->getCategoryId();
  4263.             //print('<br>qqw cat: '.$catId);
  4264.             $categories[$cat->getCategoryName()] = $catId;
  4265.         }  
  4266.         
  4267.         /*
  4268.         print('<hr>qqw categories ');
  4269.         \Doctrine\Common\Util\Debug::dump($categories);
  4270.         
  4271.         print('<hr>qqw categories 2');
  4272.         \Doctrine\Common\Util\Debug::dump($categories2);
  4273.         */      
  4274.         
  4275.         $formBuilder->add('categories'ChoiceType::class, array(
  4276.                 'choices' => $categories,
  4277.                 'mapped' => false,
  4278.                 'attr' => array('class' => 'selector'),
  4279.                 'label' => $this->translator->trans('eshop.parent_category'),
  4280.                 'label_attr' => array('class' => 'form_field_label')
  4281.         ));     
  4282.         
  4283.         $formBuilder->add('save'SubmitType::class, array('label' => $this->translator->trans('form.button.save'),
  4284.                 'attr' => array('class' => 'butt_big')));
  4285.          
  4286.         $form $formBuilder->getForm();
  4287.         $form->handleRequest($request);
  4288.          
  4289.         if ($request->getMethod() == 'POST') {
  4290.     
  4291.             if ($form->isValid()) {
  4292.                 $formData $form->getData();
  4293.                  
  4294.                 /* we load users entity manager */
  4295.                 $dem $this->doctrine->getManager('dynamic_em');
  4296.                  
  4297.                 //$userName = $request->request->get('form')['username'];
  4298.                 //$userExist = $em->getRepository(User::class)->getUserFromLogin($userName, $request->request->get('form')['password']);
  4299.                 
  4300.                 $root $dem->getRepository(Eshop::class)->getCategory(1);
  4301.                 $dem->persist($eshop);
  4302.                 $category->setCategoryName($formData->getCategoryName());
  4303.                 $category->setIsActive(1);
  4304.                 $category->setEshopId($eshop->getEshopId());
  4305.                 if(intval($form['categories']->getData()) == 0) {
  4306.                     $parentCategory null;
  4307.                 } else {
  4308.                     $parentCategory $dem->getRepository(Eshop::class)->getCategory(intval($form['categories']->getData()));
  4309.                 }
  4310.                 $category->setParent($parentCategory);
  4311.                  
  4312.                 /* we persist and save category */
  4313.                 $dem->persist($category);
  4314.                 $dem->flush();
  4315.                  
  4316.                 $this->addFlash('notice''New category was created.');
  4317.                 
  4318.                 return $this->redirectToRoute('categoryEdit', array('categoryId' => $category->getCategoryId()));
  4319.                  
  4320.             }
  4321.              
  4322.         }
  4323.     
  4324.         /* we render data */
  4325.         return $this->render('categoryNew.html.twig',
  4326.                 array('form' => $formBuilder->getForm()->createView(),
  4327.                         'headerData' => $this -> getPageHeader($request),
  4328.                         'user' => $user,
  4329.                         'menu' => $this -> adminMenu($request),'mainMenu' => $this -> adminMainMenu($request),'mainMenu' => $this -> adminMainMenu($request),
  4330.                 )
  4331.                 );
  4332.     
  4333.     }
  4334.         
  4335.     /**
  4336.      * @Route("/categories", name="categories")
  4337.      */
  4338.     public function categoriesAction(Request $request)
  4339.     {
  4340.         /* we load session data */
  4341.         parent::init($request);
  4342.         $session $request->getSession();
  4343.         // we check if any user is logged in
  4344.         if(!$this->isLoggedUser($request)) {
  4345.             return $this->redirectToRoute('login');
  4346.         }            
  4347.          
  4348.         /* we load entity managers */
  4349.         $em $this->doctrine->getManager();
  4350.         $dem $this->doctrine->getManager('dynamic_em');
  4351.     
  4352.         $currentUserId $session->get('user')->getUserId();
  4353.         $user $em->getRepository(User::class)->getUser($currentUserId);
  4354.          
  4355.         /* we get current e-shop */
  4356.         $eshop $em->getRepository(Eshop::class)->getCurrentEshop($currentUserId);
  4357.         /* we do a action with selected products */
  4358.         if (!empty($request->request->get('selectCategoriesSubmit'))) {
  4359. //            print('<br>qqw selectedCategories:');
  4360.             set_time_limit(60);
  4361.             $productIds = [];
  4362.             foreach ($request->request->all('selectedCategories') as $cId) {
  4363. //                print('<br>qqw cID: '.$cId);
  4364.                 $categoryIds[] = $cId;
  4365.                 /* we get product and remove it */
  4366. //                $category = $dem->getRepository(Eshop::class)->getCategory($cId);
  4367.                 $category $dem->getRepository(Category::class)->findOneBy(['categoryId'=> $cId]);
  4368.                 if (!empty($category)) {
  4369.                     $dem->remove($category);
  4370.                     $em->persist($category);
  4371.                     $dem->flush();
  4372.                 }
  4373.             }
  4374.             /* we remove product prices */
  4375.             $productPriceList $dem->getRepository(Product::class)->getProductPriceList($productIds);
  4376.             foreach($productPriceList as $price) {
  4377.                 //print('<br>qqw removing price: ');
  4378.                 $dem->remove($price);
  4379.                 $dem->flush();
  4380.             }
  4381.             $this->addFlash('notice'$this->translator->trans('category.removed'));
  4382.         }
  4383.         $categoryList $dem->getRepository(Eshop::class)->getCategoryListByEshop($eshop->getEshopId());
  4384.          
  4385.         $root $dem->getRepository(Eshop::class)->getCategory(1);
  4386.         if(isset($GLOBALS['request']) && $GLOBALS['request']) {
  4387.             $locale $GLOBALS['request']->getLocale();    
  4388.             //print('<br>qqw locale: '.$locale);
  4389.         }
  4390.         foreach($categoryList as $cat) {
  4391.             $cat->setLocale('en');
  4392.             //$cat->setLocale($locale);
  4393.             $dem->refresh($cat);
  4394.             //print('<br>qqw cat (id '.$cat->getCategoryId().'): '.$cat->getCategoryName());
  4395.         }
  4396.         /* category name - multilangual fields */
  4397.         /*
  4398.         foreach($eshop->getLanguages() as $lang) {
  4399.         
  4400.             //$fieldLabel = $this->translator->trans('eshop.category_name').' ['.$lang->getLangKey().']';
  4401.             $category->setLocale($lang->getLangKey());
  4402.             $dem->refresh($category);
  4403.             $fieldValue = $category->getCategoryName();
  4404.  
  4405.         } 
  4406.         */  
  4407.         
  4408.         //$vegetables = $dem->getRepository(Eshop::class)->getCategory(9);
  4409.         
  4410.         /*
  4411.         $food = new Category();
  4412.         $food->setCategoryName('Food');
  4413.         $food->setParent($root);
  4414.         
  4415.         $fruits = new Category();
  4416.         $fruits->setCategoryName('Fruits');
  4417.         $fruits->setParent($food);      
  4418.         
  4419.         $vegetables = new Category();
  4420.         $vegetables->setCategoryName('Vegetables');
  4421.         $vegetables->setParent($food);
  4422.          
  4423.         $carrots = new Category();
  4424.         $carrots->setCategoryName('Carrots');
  4425.         $carrots->setParent($vegetables);       
  4426.         
  4427.         $dem->persist($fruits);
  4428.         $dem->persist($vegetables);
  4429.         $dem->persist($carrots);        
  4430.         $dem->persist($food);
  4431.         $dem->flush();
  4432.         */
  4433.         
  4434.         
  4435.         //$repo = $em->getRepository('Entity\Category');
  4436.         
  4437.         $repo $dem->getRepository(Category::class);
  4438.         
  4439.         $this->dynamicEntityManager $dem;
  4440.         $this->currentEshop $eshop;
  4441.         
  4442.         $options = array(
  4443.                 'decorate' => true,             
  4444.                 'rootOpen' => '<ul>',
  4445.                 'rootClose' => '</ul>',
  4446.                 'childOpen' => function($node) {
  4447.                     
  4448.                     
  4449.                     //print('<br>QQW node: ');
  4450.                     //\Doctrine\Common\Util\Debug::dump($node);
  4451.                         
  4452.                     
  4453.                     if($node['eshopId'] == $this->currentEshop->getEshopId()) {
  4454.                         return '<li>';
  4455.                     } else {
  4456.                         return '<li class="treeItemHidden">';
  4457.                     }                   
  4458.                     
  4459.                     /*
  4460.                     print('<br>QQW getEshop: '.$cat->getEshop()->getEshopId());
  4461.                     print('<br>QQW currentEshop: '.$this->currentEshop->getEshopId());
  4462.                     
  4463.                     if($cat->getEshop()->getEshopId() == $this->currentEshop->getEshopId()) {
  4464.                         return '<li>currShop'; 
  4465.                     } else {
  4466.                         return '<li>';
  4467.                     }
  4468.                     
  4469.                     print('<hr>QQW cat: ');
  4470.                     
  4471.                     
  4472.                     print('<hr>QQW cat: ');
  4473.                     \Doctrine\Common\Util\Debug::dump($cat);    
  4474.                     */              
  4475.                     /*
  4476.                     if($node['categoryName'] == "Nokia") {
  4477.                         return '<h1>QQW NOKIA</h1><ul>';
  4478.                     } else {
  4479.                         return '<ul>';
  4480.                     }
  4481.                     */
  4482.                     
  4483.                     return '<li>';
  4484.                     
  4485.                     
  4486.                 },
  4487.                 'childClose' => '</li>',
  4488.                 'nodeDecorator' => function($node) {
  4489.                   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>]';
  4490.                 }
  4491.                 );
  4492.         
  4493.         /*
  4494.         $options = array(
  4495.                 'decorate' => true,
  4496.                 'rootOpen' => '<ul>',
  4497.                 'rootClose' => '</ul>',
  4498.                 'childOpen' => '<li>',
  4499.                 'childClose' => '</li>',
  4500.                 'nodeDecorator' => function($node) {
  4501.                 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>]';
  4502.                 }
  4503.                 );
  4504.         */
  4505.         
  4506.         /*
  4507.         $arrayTree = $repo->childrenHierarchy();
  4508.         print("<hr>qqw arrayTree: ");
  4509.         print_r($arrayTree);
  4510.         */
  4511.         
  4512.         /*
  4513.         $rootNodes = $repo->getRootNodes();
  4514.         
  4515.         print("<hr>qqw Root Nodes: ");
  4516.         print_r($rootNodes);        
  4517.         */
  4518.         
  4519.         $htmlTree $repo->childrenHierarchy(
  4520.                 null
  4521.                 false
  4522.                 $options
  4523.                 );
  4524.         
  4525.             
  4526.         
  4527.         //$children = $repo->children($vegetables, false, null, 'ASC', false);
  4528.         
  4529.         //echo "<br>qqw childCount: ".$repo->childCount($root);
  4530.         
  4531.         /*
  4532.         $fruits = new Category();
  4533.         $fruits->setCategoryName('Fruits');
  4534.         $fruits->setParent($food);
  4535.         
  4536.         $vegetables = new Category();
  4537.         $vegetables->setCategoryName('Vegetables');
  4538.         $vegetables->setParent($food);
  4539.         
  4540.         $carrots = new Category();
  4541.         $carrots->setCategoryName('Carrots');
  4542.         $carrots->setParent($vegetables);
  4543.         
  4544.         $dem->persist($food);
  4545.         $dem->persist($fruits);
  4546.         $dem->persist($vegetables);
  4547.         $dem->persist($carrots);
  4548.         $dem->flush();
  4549.         */      
  4550.         
  4551.         //echo $request->attributes->get('_route');
  4552.         //echo $request->getPathInfo();
  4553.          
  4554.         /* we render data */
  4555.         return $this->render('categories.html.twig',
  4556.                 array(  'headerData' => $this -> getPageHeader($request),
  4557.                         'categoryList' => $categoryList,
  4558.                         'htmlTree' => $htmlTree,
  4559.                         'user' => $user,
  4560.                         'menu' => $this -> adminMenu($request),'mainMenu' => $this -> adminMainMenu($request),'mainMenu' => $this -> adminMainMenu($request),
  4561.                 )
  4562.                 );
  4563.     
  4564.     }  
  4565.     
  4566.     /**
  4567.      * @Route("/categoryedit/{categoryId}", name="categoryEdit")
  4568.      */
  4569.     public function categoryEditAction(Request $request$categoryId)
  4570.     {
  4571.         /* we load session data */
  4572.         parent::init($request);
  4573.         $session $request->getSession();
  4574.         // we check if any user is logged in
  4575.         if(!$this->isLoggedUser($request)) {
  4576.             return $this->redirectToRoute('login');
  4577.         }            
  4578.     
  4579.         /* we load entity managers */
  4580.         $em $this->doctrine->getManager();
  4581.         $dem $this->doctrine->getManager('dynamic_em');
  4582.          
  4583.         $userId $session->get('user')->getUserId();
  4584.         $user $em->getRepository(User::class)->getUser($userId);
  4585.          
  4586.         /* we get current e-shop */
  4587.         $eshop $em->getRepository(Eshop::class)->getCurrentEshop($userId);
  4588.         
  4589.         $category $dem->getRepository(Eshop::class)->getCategory($categoryId);
  4590.      
  4591.         $categoryCollection $dem->getRepository(Eshop::class)->getCategoryListByEshop($eshop->getEshopId());
  4592.              
  4593.         //$serviceCollection = $em->getRepository(Service::class)->getServiceList();
  4594.          
  4595.         /* 
  4596.         print('<br>QQW cat ID: '.$categoryId);
  4597.         \Doctrine\Common\Util\Debug::dump($category);
  4598.         */
  4599.         /* we build category edit form */
  4600.         $formBuilder $this->createFormBuilder($category);
  4601.         $formBuilder->add('save'SubmitType::class, array('label' => $this->translator->trans('form.button.save'),
  4602.                 'attr' => array('class' => 'butt_big'))); 
  4603.         
  4604.         /* category name - multilangual fields */
  4605.         foreach($eshop->getLanguages() as $lang) {
  4606.         
  4607.             $fieldLabel $this->translator->trans('eshop.category_name').' ['.$lang->getLangKey().']';
  4608.             $category->setLocale($lang->getLangKey());
  4609.             $dem->refresh($category);
  4610.             $fieldValue $category->getCategoryName();
  4611.              
  4612.             $formBuilder->add('categoryName_'.$lang->getLangKey(), TextType::class, array(
  4613.                     'required' => false,
  4614.                     'mapped' => false,
  4615.                     'label' => $fieldLabel,
  4616.                     'attr' => array('class' => 'text_form''size' => 35'value' => $fieldValue),
  4617.                     'label_attr' => array('class' => 'form_field_label')
  4618.             ));
  4619.              
  4620.         }   
  4621.         /* we add category list */
  4622.         $categories = array();
  4623.         $categories['Root'] = 0;
  4624.         foreach($categoryCollection as $cat)
  4625.         {
  4626.             $catId $cat->getCategoryId();
  4627.             $cat->setLocale($session->get('lang')->getLangKey());
  4628.             $dem->refresh($cat);
  4629.             //print('<br>qqw cat: '.$catId);
  4630.             $categories[$cat->getCategoryName()] = $catId;
  4631.         
  4632.         }    
  4633.         
  4634.         if($category->getParent() === null) {
  4635.             $selectedCategory 0;
  4636.         } else {
  4637.             $selectedCategory $category->getParent()->getCategoryId();
  4638.         }
  4639.         
  4640.         $formBuilder->add('parentCategoryId'ChoiceType::class, array(
  4641.                 'choices' => $categories,
  4642.                 'mapped' => false,
  4643.                 'label' => $this->translator->trans('eshop.parent_category'),
  4644.                 'attr' => array('class' => 'selector'),
  4645.                 'label_attr' => array('class' => 'form_field_label'),
  4646.                 'data' => $selectedCategory
  4647.         ));     
  4648.          
  4649.         $formBuilder->add('categoryKey'TextType::class, array(
  4650.                 'required' => false,
  4651.                 'label' => $this->translator->trans('eshop.category_key'),
  4652.                 'attr' => array('class' => 'text_form''size' => 35'value' => $category->getCategoryKey()),
  4653.                 'label_attr' => array('class' => 'form_field_label')
  4654.         ));
  4655.         $formBuilder->add('ERPKey'TextType::class, array(
  4656.                 'required' => false,
  4657.                 'label' => $this->translator->trans('system.erp_key'),
  4658.                 'attr' => array('class' => 'text_form''size' => 35'value' => $category->getERPKey()),
  4659.                 'label_attr' => array('class' => 'form_field_label')
  4660.         ));        
  4661.         $formBuilder->add('isActive'ChoiceType::class, array(
  4662.                 'choices' => array(
  4663.                                 'Yes' => true,
  4664.                                 'No' => false
  4665.                              ),
  4666.                 'required' => false,
  4667.                 'mapped' => false,
  4668.                 'multiple' => false,
  4669.                 'expanded' => false,
  4670.                 'placeholder' => false,
  4671.                 'attr' => array('class' => 'selector'),
  4672.                 'label_attr' => array('class' => 'form_field_label'),
  4673.                 'data' => ($category->getIsActive()=="0"?0:1
  4674.         ));             
  4675.         
  4676.         $image1Label $this->translator->trans('image.main');
  4677.         if(!empty($category->getImage1())) {
  4678.             $image1Label .= " [ ".$category->getImage1()." ]";
  4679.         }
  4680.         $formBuilder->add('image1'FileType::class, array(
  4681.                 'required' => false,
  4682.                 'data_class' => null,
  4683.                 'label' => $image1Label,
  4684.                 'attr' => array('class' => 'text_form_file''size' => 22'value' => 'vvx2'),
  4685.                 'label_attr' => array('class' => 'form_field_label_block'),
  4686.         ));     
  4687.         /* product description - multilangual fields */
  4688.         foreach($eshop->getLanguages() as $lang) {
  4689.         
  4690.             $fieldLabel $this->translator->trans('eshop.category_description').' ['.$lang->getLangKey().']';
  4691.             $category->setLocale($lang->getLangKey());
  4692.             $dem->refresh($category);
  4693.             $fieldValue $category->getCategoryDescription();
  4694.             
  4695.             $formBuilder->add('categoryDescription_'.$lang->getLangKey(), TextareaType::class, array(
  4696.                     'required' => false,
  4697.                     'mapped' => false,
  4698.                     'label' => $fieldLabel,
  4699.                     'attr' => array('class' => 'textarea_form''cols' => 69'rows' => 7'value' => $fieldValue),
  4700.                     'label_attr' => array('class' => 'form_textarea_label2'),
  4701.                     'data' => $fieldValue,
  4702.             ));             
  4703.              
  4704.         }  
  4705.         /* we set default width of image thumbnail */
  4706.         $formBuilder->add('imageThumbWidth'TextType::class, array(
  4707.                 'required' => false,
  4708.                 'label' => $this->translator->trans('product.products').' - '.$this->translator->trans('image.thumb_width'),
  4709.                 'attr' => array('class' => 'text_form''size' => 10'value' => $category->getImageThumbWidth()),
  4710.                 'label_attr' => array('class' => 'form_field_label')
  4711.         ));     
  4712.         /* we set default height of image thumbnail */
  4713.         $formBuilder->add('imageThumbHeight'TextType::class, array(
  4714.                 'required' => false,
  4715.                 'label' => $this->translator->trans('product.products').' - '.$this->translator->trans('image.thumb_height'),
  4716.                 'attr' => array('class' => 'text_form''size' => 10'value' => $category->getImageThumbHeight()),
  4717.                 'label_attr' => array('class' => 'form_field_label')
  4718.         ));     
  4719.         /* 
  4720.         print('<hr>qqw categories ');
  4721.         \Doctrine\Common\Util\Debug::dump($categories);
  4722.         
  4723.         print('<hr>qqw categories 2');
  4724.         \Doctrine\Common\Util\Debug::dump($categories2);
  4725.         */      
  4726.         $formBuilder->add('save2'SubmitType::class, array('label' => $this->translator->trans('form.button.save'),
  4727.                 'attr' => array('class' => 'butt_big')));
  4728.          
  4729.         $form $formBuilder->getForm();
  4730.          
  4731.         $form->handleRequest($request);
  4732.          
  4733.         if ($request->getMethod() == 'POST') {
  4734.             if ($form->isValid()) {
  4735.                 $formData $form->getData();
  4736.     
  4737.                 //print('<br>We create new user');
  4738.                 //$user = new User;   
  4739.                 /* we load and set parent category */
  4740.                 
  4741.                 $parentCategory $dem->getRepository(Eshop::class)->getCategory($form['parentCategoryId']->getData());
  4742.                 $category->setParent($parentCategory);
  4743.                 /*
  4744.                 print('<br>QQW parentCategoryId: '.$request->request->get('form')['parentCategoryId']);
  4745.                 \Doctrine\Common\Util\Debug::dump($parentCategory);
  4746.                 */
  4747.                 
  4748.                 /* multilangual fields */
  4749.                 foreach($eshop->getLanguages() as $lang) {
  4750.                     $category->setLocale($lang->getLangKey());
  4751.                     $dem->refresh($category);
  4752.                     $category->setCategoryName($form['categoryName_' $lang->getLangKey()]->getData());
  4753.                     $category->setCategoryDescription($form['categoryDescription_' $lang->getLangKey()]->getData());
  4754.                     $dem->persist($category);
  4755.                     $dem->flush();
  4756.                 }    
  4757.                 
  4758.                 /* we handle images */
  4759.                 $image1 $request->files->get('form')['image1'];
  4760.                 /* we check user folder for user files */
  4761.                 if(!$this->isUserFolder($request)) {
  4762.                     $this->createUserFolder($request);
  4763.                 }
  4764.                 
  4765.                 $userDirs $this->getUserFolderPaths($request);
  4766.                 
  4767.                 /* image 1 */
  4768.                 if(!empty($image1)) {
  4769.                     $fileName1 md5(uniqid()).'.'.$image1->guessExtension();
  4770.                     $image1->move($userDirs['images'], $fileName1);
  4771.                     $category->setImage1($fileName1);
  4772.                 }               
  4773.                 
  4774.                 /* we remove old service associations */
  4775.                 /*
  4776.                  foreach($user->getServices() as $service) {
  4777.                  $user->removeService($service);
  4778.                  }
  4779.                  */
  4780.                  
  4781.                 /* we load user services */
  4782.                 /*
  4783.                  if(!empty($request->request->get('form')['services'])) {
  4784.                  foreach($request->request->get('form')['services'] as $serviceId) {
  4785.                  $addService = $em->getRepository(Service::class)->getService($serviceId);
  4786.                  $user->addService($addService);
  4787.                  }
  4788.                  }
  4789.                  */
  4790.                 //print('<br>QQW categoryKey: '.$form['categoryKey']->getData());
  4791.                 /* we load user data from register form into user object */
  4792.                 $category->setCategoryKey($form['categoryKey']->getData());
  4793.                 $category->setERPKey($form['ERPKey']->getData());
  4794.                 //$category->setIsActive($request->request->get('form')['isActive']);
  4795.                 $category->setIsActive($formData->getIsActive());
  4796.                 $category->setImageThumbWidth($formData->getImageThumbWidth());
  4797.                 $category->setImageThumbHeight($formData->getImageThumbHeight());
  4798.     
  4799.                 //print('<br>QQW cat ID 2: '.$request->request->get('form')['isActive']);
  4800.                 //\Doctrine\Common\Util\Debug::dump($category);        
  4801.                 //die();    
  4802.       
  4803.                 /* we persist and save */
  4804.                 //$em->persist($user);
  4805.                 $dem->persist($category);
  4806.                 $dem->flush();
  4807.                  
  4808.                 $this->addFlash('notice''Category was updated.');
  4809.     
  4810.                 return $this->redirectToRoute('categoryEdit', array('categoryId' => $category->getCategoryId()));
  4811.                  
  4812.             }
  4813.     
  4814.         }
  4815.     
  4816.         /* we render data */
  4817.         return $this->render('categoryEdit.html.twig',
  4818.                 array(  'headerData' => $this -> getPageHeader($request),
  4819.                         'form' => $formBuilder->getForm()->createView(),
  4820.                         'category' => $category,
  4821.                         'user' => $user,
  4822.                         'menu' => $this -> adminMenu($request),'mainMenu' => $this -> adminMainMenu($request),'mainMenu' => $this -> adminMainMenu($request),
  4823.                 )
  4824.                 );
  4825.     
  4826.     }
  4827.     
  4828.     /**
  4829.      * @Route("/categoryremove/{categoryId}", name="categoryRemove")
  4830.      */
  4831.     public function categoryRemoveAction(Request $request$categoryId)
  4832.     {
  4833.     
  4834.         /* we load session data */
  4835.         parent::init($request);
  4836.         $session $request->getSession();
  4837.     
  4838.         /* we load entity managers */
  4839.         $em $this->doctrine->getManager();
  4840.         $dem $this->doctrine->getManager('dynamic_em');
  4841.     
  4842.         $userId $session->get('user')->getUserId();
  4843.     
  4844.         /* we get current e-shop */
  4845.         $eshop $em->getRepository(Eshop::class)->getCurrentEshop($userId);
  4846.          
  4847.         $category $dem->getRepository(Eshop::class)->getCategory($categoryId);
  4848.     
  4849.         /*
  4850.         print('<hr>qqw category: ');
  4851.         \Doctrine\Common\Util\Debug::dump($category);
  4852.         */
  4853.         
  4854.         $repo $dem->getRepository(Category::class);
  4855.         //$repo->removeFromTree($category);
  4856.         
  4857.         $dem->remove($category);
  4858.         
  4859.         //$em->persist($user);
  4860.         $dem->flush();
  4861.         
  4862.         $this->addFlash('notice''Category was removed.');
  4863.         
  4864.         return $this->redirectToRoute('categories');
  4865.         
  4866.         //die();
  4867.         
  4868.     }
  4869.     
  4870.     /**
  4871.      * @Route("/eshopConfig", name="eshopConfig")
  4872.      */
  4873.     public function eshopConfigAction(Request $request)
  4874.     {
  4875.         /* we load session data */
  4876.         parent::init($request);
  4877.         $session $request->getSession();
  4878.         // we check if any user is logged in
  4879.         if(!$this->isLoggedUser($request)) {
  4880.             return $this->redirectToRoute('login');
  4881.         }         
  4882.     
  4883.         /* we load master entity manager */
  4884.         $em $this->doctrine->getManager();
  4885.         $dem $this->doctrine->getManager('dynamic_em');
  4886.         
  4887.         $currentUserId $session->get('user')->getUserId();
  4888.         $user $em->getRepository(User::class)->getUser($currentUserId);
  4889.         /* we get current e-shop */
  4890.         $eshop $em->getRepository(Eshop::class)->getCurrentEshop($currentUserId);
  4891.         $userId $session->get('user')->getUserId();
  4892.         /* we get css designs */
  4893.         $cssDesignCollection $dem->getRepository(CssDesign::class)->getCssDesignList();
  4894.         if(count($cssDesignCollection) == 0) {
  4895.             print('we create new css file');
  4896.             $cssDesign = new CssDesign;
  4897.             $cssDesign->setCssDesignName($user->getUserName());
  4898.             $cssDesign->setCssDesignFile($user->getUserName().".css");
  4899.             /* we persist and save */
  4900.             $dem->persist($cssDesign);
  4901.             $dem->flush();
  4902.             $this->addFlash('notice'$this->translator->trans('module.cssDesigner_created'));
  4903.             return $this->redirectToRoute('webConfig');
  4904.         }
  4905.         
  4906.         /* we get languages */
  4907.         $langCollection $em->getRepository(Language::class)->getLanguageList();
  4908.    
  4909.         /* we get currencies */
  4910.         $currencyCollection $em->getRepository(Currency::class)->getCurrencyList();
  4911.         
  4912.         /* we get css designs */
  4913.         $cssDesignCollection $dem->getRepository(CssDesign::class)->getCssDesignList();
  4914.         
  4915.         /* we get wireframes */
  4916.         $wireFrameCollection $em->getRepository(WireFrame::class)->getWireFrameListByService(1);
  4917.         /* we get galleries */
  4918.         $galleryCollection $dem->getRepository(Gallery::class)->getGalleryListByUser($userId);
  4919.         /* we build register form */
  4920.         $formBuilder $this->createFormBuilder($eshop);
  4921.          
  4922.         $formBuilder->add('eshopName'TextType::class, array(
  4923.                 'required' => false,
  4924.                 'label' => $this->translator->trans('eshop.name'),
  4925.                 'attr' => array('class' => 'text_form''size' => 35'value' => $eshop->getEshopName()),
  4926.                 'label_attr' => array('class' => 'form_field_label')
  4927.         ));
  4928.         
  4929.         /* we add language list */
  4930.         $languages = array();
  4931.         foreach($langCollection as $lang)
  4932.         {
  4933.             $langId $lang->getLangId();
  4934.             $languages[$lang->getLangName()] = $lang->getLangId();
  4935.         }
  4936.         $selectedLanguages = array();
  4937.         if (!empty($eshop->getLanguages())) {
  4938.             foreach($eshop->getLanguages() as $lang) {
  4939.                 $selectedLanguages[] = $lang->getLangId();
  4940.             }
  4941.         }
  4942.         $formBuilder->add('languages'ChoiceType::class, array(
  4943.                 'choices' => $languages,
  4944.                 'required' => false,
  4945.                 'mapped' => false,
  4946.                 'multiple' => true,
  4947.                 'expanded' => true,
  4948.                 'label_attr' => array('class' => 'form_field_label'),
  4949.                 'attr' => array('class' => 'form_field_text'),
  4950.                 'data' => $selectedLanguages
  4951.         ));  
  4952.         
  4953.         $formBuilder->add('preferredLanguageId'ChoiceType::class, array(
  4954.                 'choices' => $languages,
  4955.                 'required' => true,
  4956.                 'mapped' => false,
  4957.                 'multiple' => false,
  4958.                 'placeholder' => false,
  4959.                 'expanded' => true,
  4960.                 'label_attr' => array('class' => 'form_field_label'),
  4961.                 'attr' => array('class' => 'form_field_text'),
  4962.                 'data' => $eshop->getPreferredLanguageId()
  4963.         ));     
  4964.         
  4965.         /* we add currency list */
  4966.         $currencies = array();
  4967.         foreach($currencyCollection as $currency) {
  4968.             $currencyId $currency->getCurrencyId();
  4969.             $currencies[$currency->getCurrencyName()] = $currency->getCurrencyId();
  4970.         }
  4971.         
  4972.         $selectedCurrencies = array();
  4973.         foreach($eshop->getCurrencies() as $currency) {
  4974.             $selectedCurrencies[] = $currency->getCurrencyId();
  4975.         }
  4976.         
  4977.         $formBuilder->add('currencies'ChoiceType::class, array(
  4978.                 'choices' => $currencies,
  4979.                 'required' => false,
  4980.                 'mapped' => false,
  4981.                 'multiple' => true,
  4982.                 'expanded' => true,
  4983.                 'label_attr' => array('class' => 'form_field_label'),
  4984.                 'attr' => array('class' => 'form_field_text'),
  4985.                 'data' => $selectedCurrencies
  4986.         ));  
  4987.         
  4988.         $formBuilder->add('preferredCurrencyId'ChoiceType::class, array(
  4989.                 'choices' => $currencies,
  4990.                 'required' => true,
  4991.                 'mapped' => false,
  4992.                 'multiple' => false,
  4993.                 'placeholder' => false,
  4994.                 'expanded' => true,
  4995.                 'label_attr' => array('class' => 'form_field_label'),
  4996.                 'attr' => array('class' => 'form_field_text'),
  4997.                 'data' => $eshop->getPreferredCurrencyId()
  4998.         ));     
  4999.         
  5000.         /* we add css designs list */
  5001.         $cssDesigns = array();
  5002.         $selectedCss '';
  5003.         foreach($cssDesignCollection as $cssDesign)
  5004.         {
  5005.             $cssDesignId $cssDesign->getCssDesignId();
  5006.             $cssDesigns[$cssDesign->getCssDesignName()] = $cssDesignId;
  5007.             /* we look for selected css design of the e-shop */ 
  5008.             if($cssDesign->getCssDesignFile() == $eshop->getEshopCss()) {
  5009.                 $selectedCss $cssDesign->getCssDesignId();
  5010.             }
  5011.         }
  5012.         $formBuilder->add('cssDesigns'ChoiceType::class, array(
  5013.                 'choices' => $cssDesigns,
  5014.                 'required' => true,
  5015.                 'mapped' => false,
  5016.                 'multiple' => false,
  5017.                 'expanded' => true,
  5018.                 'placeholder' => false,
  5019.                 'label_attr' => array('class' => 'form_field_label'),
  5020.                 'attr' => array('class' => 'form_field_text'),              
  5021.                 'data' => $selectedCss,
  5022.         )); 
  5023.         /* we select product list view */
  5024.         $productViews = array("LIST"=>"LIST""GRID"=>"GRID""B2BLIST"=>"B2BLIST");
  5025.         $selectedProductView $eshop->getProductView();
  5026.         //print("<br>qqw ProductView: ".$eshop->getProductView());
  5027.         
  5028.         $formBuilder->add('productViews'ChoiceType::class, array(
  5029.                 'choices' => $productViews,
  5030.                 'required' => true,
  5031.                 'mapped' => false,
  5032.                 'multiple' => false,
  5033.                 'expanded' => true,
  5034.                 'placeholder' => false,
  5035.                 'label_attr' => array('class' => 'form_field_label'),
  5036.                 'attr' => array('class' => 'form_field_text'),              
  5037.                 'data' => $selectedProductView,
  5038.         )); 
  5039.         /* we set count product per page */
  5040.         $formBuilder->add('countPerPage'TextType::class, array(
  5041.                 'required' => false,
  5042.                 'label' => $this->translator->trans('product.count_per_page'),
  5043.                 'attr' => array('class' => 'text_form''size' => 10'value' => $eshop->getCountPerPage()),
  5044.                 'label_attr' => array('class' => 'form_field_label')
  5045.         ));          
  5046.         /* we display Products From Subfolders */
  5047.         $formBuilder->add('displayProductsFromSubfolders'ChoiceType::class, array(
  5048.                 'choices' => array('Yes' => true'No' => false),
  5049.                 'required' => false,
  5050.                 'mapped' => false,
  5051.                 'multiple' => false,
  5052.                 'expanded' => true,
  5053.                 'placeholder' => false,
  5054.                 'label_attr' => array('class' => 'form_field_label'),
  5055.                 'attr' => array('class' => 'form_field_text'),              
  5056.                 'data' => $eshop->isDisplayProductsFromSubfolders(),
  5057.         )); 
  5058.         
  5059.         /* we display Products From Subfolders - level */
  5060.         $formBuilder->add('displayProductsFromSubfoldersLevel'TextType::class, array(
  5061.                 'required' => false,
  5062.                 'label' => $this->translator->trans('eshop.products_subfolders_level'),
  5063.                 'attr' => array('class' => 'text_form''size' => 10'value' => $eshop->getDisplayProductsFromSubfoldersLevel()),
  5064.                 'label_attr' => array('class' => 'form_field_label')
  5065.         ));         
  5066.         /* we set preferred VAT */
  5067.         $formBuilder->add('preferredVAT'TextType::class, array(
  5068.                 'required' => false,
  5069.                 'label' => $this->translator->trans('eshop.preferred_VAT'),
  5070.                 'attr' => array('class' => 'text_form''size' => 10'value' => $eshop->getPreferredVAT()),
  5071.                 'label_attr' => array('class' => 'form_field_label')
  5072.         ));                  
  5073.         $formBuilder->add('displayNettoPrices'ChoiceType::class, array(
  5074.                 'choices' => array('Yes' => true'No' => false),
  5075.                 'required' => false,
  5076.                 'mapped' => false,
  5077.                 'multiple' => false,
  5078.                 'expanded' => true,
  5079.                 'placeholder' => false,
  5080.                 'label_attr' => array('class' => 'form_field_label'),
  5081.                 'attr' => array('class' => 'form_field_text'),              
  5082.                 'data' => $eshop->isDisplayNettoPrices(),
  5083.         ));  
  5084.         $formBuilder->add('isStock'ChoiceType::class, array(
  5085.                 'choices' => array('Yes' => true'No' => false),
  5086.                 'required' => false,
  5087.                 'mapped' => false,
  5088.                 'multiple' => false,
  5089.                 'expanded' => true,
  5090.                 'placeholder' => false,
  5091.                 'label' => $this->translator->trans('eshop.view_stock'),
  5092.                 'label_attr' => array('class' => 'form_field_label'),
  5093.                 'attr' => array('class' => 'form_field_text'),              
  5094.                 'data' => $eshop->isIsStock(),
  5095.         ));                 
  5096.   
  5097.         /* we set cut of long descriptions in product list */
  5098.         $formBuilder->add('cutLongDescription'TextType::class, array(
  5099.                 'required' => false,
  5100.                 'label' => $this->translator->trans('eshop.cut_long_description'),
  5101.                 'attr' => array('class' => 'text_form''size' => 10'value' => $eshop->getCutLongDescription()),
  5102.                 'label_attr' => array('class' => 'form_field_label')
  5103.         ));     
  5104.         
  5105.         /* we set price rounding */
  5106.         $formBuilder->add('roundPrice'TextType::class, array(
  5107.                 'required' => false,
  5108.                 'label' => $this->translator->trans('eshop.price_round'),
  5109.                 'attr' => array('class' => 'text_form''size' => 10'value' => $eshop->getRoundPrice()),
  5110.                 'label_attr' => array('class' => 'form_field_label')
  5111.         ));     
  5112.         
  5113.         /* we set default width of image thumbnail */
  5114.         $formBuilder->add('imageThumbWidth'TextType::class, array(
  5115.                 'required' => false,
  5116.                 'label' => $this->translator->trans('image.thumb_width'),
  5117.                 'attr' => array('class' => 'text_form''size' => 10'value' => $eshop->getImageThumbWidth()),
  5118.                 'label_attr' => array('class' => 'form_field_label')
  5119.         ));     
  5120.         /* we set default height of image thumbnail */
  5121.         $formBuilder->add('imageThumbHeight'TextType::class, array(
  5122.                 'required' => false,
  5123.                 'label' => $this->translator->trans('image.thumb_height'),
  5124.                 'attr' => array('class' => 'text_form''size' => 10'value' => $eshop->getImageThumbHeight()),
  5125.                 'label_attr' => array('class' => 'form_field_label')
  5126.         ));   
  5127.         /* we set default width of category image thumbnail */
  5128.         $formBuilder->add('categoryImageThumbWidth'TextType::class, array(
  5129.                 'required' => false,
  5130.                 'label' => $this->translator->trans('image.category_thumb_width'),
  5131.                 'attr' => array('class' => 'text_form''size' => 10'value' => $eshop->getCategoryImageThumbWidth()),
  5132.                 'label_attr' => array('class' => 'form_field_label')
  5133.         ));  
  5134.         $formBuilder->add('isAsynchrounousShopping'ChoiceType::class, array(
  5135.                 'choices' => array('Yes' => true'No' => false),
  5136.                 'required' => false,
  5137.                 'mapped' => false,
  5138.                 'multiple' => false,
  5139.                 'expanded' => true,
  5140.                 'placeholder' => false,
  5141.                 'label' => $this->translator->trans('eshop.is_asynchrounous_shopping'),
  5142.                 'label_attr' => array('class' => 'form_field_label'),
  5143.                 'attr' => array('class' => 'form_field_text'),              
  5144.                 'data' => $eshop->isIsAsynchrounousShopping(),
  5145.         ));       
  5146.         $formBuilder->add('isVirtualReality'ChoiceType::class, array(
  5147.                 'choices' => array('Yes' => true'No' => false),
  5148.                 'required' => false,
  5149.                 'mapped' => false,
  5150.                 'multiple' => false,
  5151.                 'expanded' => true,
  5152.                 'placeholder' => false,
  5153.                 'label' => $this->translator->trans('eshop.is_virtual_reality'),
  5154.                 'label_attr' => array('class' => 'form_field_label'),
  5155.                 'attr' => array('class' => 'form_field_text'),              
  5156.                 'data' => $eshop->isIsVirtualReality(),
  5157.         ));                                
  5158.         
  5159.         /* we add home wireframe */
  5160.         $wireFrames = array();
  5161.         $selectedWireFrame '';
  5162.         foreach($wireFrameCollection as $wireFrame)
  5163.         {
  5164.             $wireFrameId $wireFrame->getWireFrameId();
  5165.             $wireFrames[$wireFrame->getWireFrameName()] = $wireFrameId;
  5166.              
  5167.             /* we look for selected wireframe of the eshop */
  5168.             if($wireFrame->getWireFrameId() == $eshop->getWireFrameId()) {
  5169.                 $selectedWireFrame $wireFrame->getWireFrameId();
  5170.             }
  5171.         }
  5172.          
  5173.         $formBuilder->add('wireFrame'ChoiceType::class, array(
  5174.                 'choices' => $wireFrames,
  5175.                 'required' => true,
  5176.                 'mapped' => false,
  5177.                 'multiple' => false,
  5178.                 'expanded' => true,
  5179.                 'placeholder' => false,
  5180.                 'label' => $this->translator->trans('eshop.wireframe_home'),
  5181.                 'label_attr' => array('class' => 'form_field_label'),
  5182.                 'attr' => array('class' => 'form_field_text'),              
  5183.                 'data' => $selectedWireFrame,
  5184.         ));     
  5185.         
  5186.         /* we add product list wireframe */
  5187.         $wireFrames = array();
  5188.         $selectedWireFrame '';
  5189.         foreach($wireFrameCollection as $wireFrame)
  5190.         {
  5191.             $wireFrameId $wireFrame->getWireFrameId();
  5192.             $wireFrames[$wireFrame->getWireFrameName()] = $wireFrameId;
  5193.              
  5194.             /* we look for selected wireframe of the eshop */
  5195.             if($wireFrame->getWireFrameId() == $eshop->getProductListWireFrameId()) {
  5196.                 $selectedWireFrame $wireFrame->getWireFrameId();
  5197.             }
  5198.         }
  5199.         
  5200.         $formBuilder->add('wireFrameProductList'ChoiceType::class, array(
  5201.                 'choices' => $wireFrames,
  5202.                 'required' => true,
  5203.                 'mapped' => false,
  5204.                 'multiple' => false,
  5205.                 'expanded' => true,
  5206.                 'placeholder' => false,
  5207.                 'label' => $this->translator->trans('eshop.wireframe_product_list'),
  5208.                 'label_attr' => array('class' => 'form_field_label'),
  5209.                 'attr' => array('class' => 'form_field_text'),
  5210.                 'data' => $selectedWireFrame,
  5211.         ));     
  5212.         
  5213.         /* we add product detail wireframe */
  5214.         $wireFrames = array();
  5215.         $selectedWireFrame '';
  5216.         foreach($wireFrameCollection as $wireFrame)
  5217.         {
  5218.             $wireFrameId $wireFrame->getWireFrameId();
  5219.             $wireFrames[$wireFrame->getWireFrameName()] = $wireFrameId;
  5220.              
  5221.             /* we look for selected wireframe of the eshop */
  5222.             if($wireFrame->getWireFrameId() == $eshop->getProductDetailWireFrameId()) {
  5223.                 $selectedWireFrame $wireFrame->getWireFrameId();
  5224.             }
  5225.         }
  5226.          
  5227.         $formBuilder->add('wireFrameProductDetail'ChoiceType::class, array(
  5228.                 'choices' => $wireFrames,
  5229.                 'required' => true,
  5230.                 'mapped' => false,
  5231.                 'multiple' => false,
  5232.                 'expanded' => true,
  5233.                 'placeholder' => false,
  5234.                 'label' => $this->translator->trans('eshop.wireframe_product_detail'),
  5235.                 'label_attr' => array('class' => 'form_field_label'),
  5236.                 'attr' => array('class' => 'form_field_text'),
  5237.                 'data' => $selectedWireFrame,
  5238.         ));    
  5239.         
  5240.         $formBuilder->add('save'SubmitType::class, array('label' => $this->translator->trans('form.send'),
  5241.                 'attr' => array('class' => 'butt_big')));
  5242.          
  5243.         $form $formBuilder->getForm();
  5244.          
  5245.         $form->handleRequest($request);
  5246.          
  5247.         if ($request->getMethod() == 'POST') {
  5248.              
  5249.             //$form->bindRequest($request);
  5250.              
  5251.             if ($form->isValid()) {
  5252.                 $formData $form->getData();
  5253.                 /* we load eshop data from form into object */
  5254.                 $eshop->setEshopName($formData->getEshopName());
  5255.                 /* we remove old language associations */
  5256.                 if(!empty($eshop->getLanguages())) {
  5257.                     foreach ($eshop->getLanguages() as $lang) {
  5258.                         $eshop->removeLanguage($lang);
  5259.                     }
  5260.                 }
  5261.                     
  5262.                 /* we load eshop languages */
  5263.                 if(!empty($form['languages']->getData()) and is_array($form['languages']->getData())) {
  5264.                     foreach($form['languages']->getData() as $langId) {
  5265.                         print('<br>lang id: '.$langId);
  5266.                         $addLang $em->getRepository(Language::class)->getLanguage($langId);
  5267.                         print('<br>lang id 2: '.$addLang->getLangId());
  5268.                         $eshop->addLanguage($addLang);
  5269.                         //$->get('user')->addService($addService);
  5270.                     }
  5271.                 }
  5272.                 
  5273.                 /* we set default language */
  5274.                 $eshop->setPreferredLanguageId($form['preferredLanguageId']->getData());
  5275.                 
  5276.                 /* we remove old currency associations */
  5277.                 foreach($eshop->getCurrencies() as $currency) {
  5278.                     $eshop->removeCurrency($currency);
  5279.                 }
  5280.                 
  5281.                 /* we load eshop currencies */
  5282.                 if(!empty($form['currencies']->getData())) {
  5283.                     foreach($form['currencies']->getData() as $currencyId) {
  5284.                         $addCurrency $em->getRepository(Currency::class)->getCurrency($currencyId);
  5285.                         $eshop->addCurrency($addCurrency);
  5286.                     }
  5287.                 }    
  5288.                  
  5289.                 /* we set default currency */
  5290.                 $eshop->setPreferredCurrencyId($form['preferredCurrencyId']->getData());
  5291.                 
  5292.                 /* we set css design */
  5293.                 if(!empty($form['cssDesigns']->getData())) {
  5294.                     $cssDesign $dem->getRepository(CssDesign::class)->getCssDesign($form['cssDesigns']->getData());
  5295.                     $eshop->setEshopCss($cssDesign->getCssDesignFile());  
  5296.                 }
  5297.                 $eshop->setProductView($formData->getProductView());
  5298.                 $eshop->setCountPerPage($formData->getCountPerPage());
  5299.                 $eshop->setPreferredVAT($formData->getPreferredVAT());
  5300.                 
  5301.                 $eshop->setImageThumbWidth($formData->getImageThumbWidth());
  5302.                 $eshop->setImageThumbHeight($formData->getImageThumbHeight());
  5303.                 $eshop->setCategoryImageThumbWidth($formData->getCategoryImageThumbWidth());
  5304.                 $eshop->setRoundPrice($formData->getRoundPrice());
  5305.                 $eshop->setCutLongDescription($formData->getCutLongDescription());
  5306.                 if(!empty($form['displayProductsFromSubfolders']->getData())) {
  5307.                     $eshop->setDisplayProductsFromSubfolders($form['displayProductsFromSubfolders']->getData());
  5308.                 }
  5309.                 
  5310.                 if(!empty($form['displayProductsFromSubfoldersLevel']->getData())) {
  5311.                     $eshop->setDisplayProductsFromSubfoldersLevel($form['displayProductsFromSubfoldersLevel']->getData());
  5312.                 }                
  5313.                 if(!empty($form['displayNettoPrices']->getData())) {
  5314.                     $eshop->setDisplayNettoPrices($form['displayNettoPrices']->getData());
  5315.                 }         
  5316.                 if(!empty($form['isStock']->getData())) {
  5317.                     $eshop->setIsStock($form['isStock']->getData());
  5318.                 }                  
  5319.                 
  5320.                 if(!empty($form['isAsynchrounousShopping']->getData())) {
  5321.                     $eshop->setIsAsynchrounousShopping($form['isAsynchrounousShopping']->getData());
  5322.                 }                   
  5323.                 if(!empty($form['isVirtualReality']->getData())) {
  5324.                     $eshop->setIsVirtualReality($form['isVirtualReality']->getData());
  5325.                 }  
  5326.                 /* home wireframe setting */
  5327.                 $eshop->setWireFrameId($form['wireFrame']->getData());
  5328.                 
  5329.                 /* product list wireframe setting */
  5330.                 $eshop->setProductListWireFrameId($form['wireFrameProductList']->getData());
  5331.                 /* product detail wireframe setting */
  5332.                 $eshop->setProductDetailWireFrameId($form['wireFrameProductDetail']->getData());
  5333.                 
  5334.                 //setEshopName($request->request->get('form')['eshopName']);
  5335.                 
  5336.                 /*
  5337.                 print('<br>qqw user exists: ');
  5338.                 \Doctrine\Common\Util\Debug::dump($user);
  5339.                 */
  5340.                 /* we persist and save user */
  5341.                 $em->persist($eshop);
  5342.                 $em->flush();
  5343.                     
  5344.                 $this->addFlash('notice''Eshop was updated.');
  5345.                     
  5346.                 return $this->redirectToRoute('eshopConfig');
  5347.                  
  5348.             }
  5349.              
  5350.         }       
  5351.     
  5352.         /* we render data */
  5353.         return $this->render('eshopConfig.html.twig',
  5354.                 array(  'headerData' => $this -> getPageHeader($request),
  5355.                         'form' => $formBuilder->getForm()->createView(),
  5356.                         'menu' => $this -> adminMenu($request),
  5357.                         'mainMenu' => $this -> adminMainMenu($request),
  5358.                         'user' => $user,
  5359.                 )
  5360.                 );
  5361.     
  5362.     }    
  5363.     
  5364.     /**
  5365.      * @Route("/eshopnew", name="eshopNew")
  5366.      */
  5367.     public function eshopNewAction(Request $request)
  5368.     {
  5369.     
  5370.         /* we load session data */
  5371.         parent::init($request);
  5372.     
  5373.         $session $request->getSession();
  5374.         /* we load entity managers */
  5375.         $em $this->doctrine->getManager();
  5376.         $dem $this->doctrine->getManager('dynamic_em');
  5377.         $userId $session->get('user')->getUserId();
  5378.         $user $em->getRepository(User::class)->getUser($userId);
  5379.     
  5380.         /* we build login form */
  5381.         $formBuilder $this->createFormBuilder();
  5382.     
  5383.         $formBuilder->add('eshopName'TextType::class, array(
  5384.                 'required' => true,
  5385.                 'label' => $this->translator->trans('eshop.name'),
  5386.                 'attr' => array('class' => 'text_form''size' => 50),
  5387.                 'label_attr' => array('class' => 'form_field_label'),
  5388.         ));
  5389.     
  5390.         $formBuilder->add('save'SubmitType::class, array('label' => $this->translator->trans('form.button.save'),
  5391.                 'attr' => array('class' => 'butt_big')));
  5392.     
  5393.         $form $formBuilder->getForm();
  5394.         $form->handleRequest($request);
  5395.     
  5396.         if ($request->getMethod() == 'POST') {
  5397.     
  5398.             if ($form->isValid()) {
  5399.                 // create and persist e-shop
  5400.                 $this->eshopCreate($request$form['eshopName']->getData());
  5401.                 return $this->redirectToRoute('eshopAdmin'); 
  5402.             }
  5403.              
  5404.         }
  5405.     
  5406.         /* we render data */
  5407.         return $this->render('eshopNew.html.twig',
  5408.                 array(  'form' => $formBuilder->getForm()->createView(),
  5409.                         'user' => $user,
  5410.                         'headerData' => $this -> getPageHeader($request),
  5411.                         'menu' => $this -> adminMenu($request),'mainMenu' => $this -> adminMainMenu($request),'mainMenu' => $this -> adminMainMenu($request),
  5412.                 )
  5413.                 );
  5414.     
  5415.     }
  5416.     public function eshopCreate(Request $request$eshopName "Test shop")
  5417.     {       
  5418.         /* we load session data */
  5419.         parent::init($request);
  5420.     
  5421.         $session $request->getSession();
  5422.     
  5423.         $em $this->doctrine->getManager();
  5424.         $dem $this->doctrine->getManager('dynamic_em');
  5425.         
  5426.         //print('qqw creating eshop...');
  5427.         $eshop = new Eshop;
  5428.         $eshop->setEshopName($eshopName);
  5429.         $eshop->setUserId($session->get('user')->getUserId());
  5430.         // we set default currency
  5431.         $eshop->setPreferredCurrencyId(1);  
  5432.         // we set default language
  5433.         $eshop->setPreferredLanguageId(1);
  5434.         // wireframe setting
  5435.         $eshop->setWireFrameId(5);
  5436.         $eshop->setProductListWireFrameId(5);              
  5437.         $eshop->setProductDetailWireFrameId(5);     
  5438.         // we add currency
  5439.         $addCurrency $em->getRepository(Currency::class)->getCurrency(1);
  5440.         $eshop->addCurrency($addCurrency);    
  5441.         // we add language
  5442.         $addLang $em->getRepository(Language::class)->getLanguage(1);
  5443.         $eshop->addLanguage($addLang);
  5444.         // we add price level
  5445.         $priceLevel = new PriceLevel;
  5446.         $priceLevel->setPriceLevelName('default');        
  5447.         /* we persist and save */
  5448.         $dem->persist($priceLevel);           
  5449.  
  5450.         // we set this eshop as current one 
  5451.         $em->getRepository(Eshop::class)->unsetCurrentEshop($session->get('user')->getUserId());
  5452.         $eshop->setEshopCurrent(true);
  5453.         // we persist and save
  5454.         $em->persist($eshop);
  5455.         $em->flush();
  5456.         
  5457.         
  5458.         // we insert data fixtures
  5459.         //@todo uncomment
  5460.         //$this->eshopDataFixtures($request);
  5461.         //die();
  5462.         $this->addFlash('notice'$this->translator->trans('eshop.created'));
  5463.         //return $this->redirectToRoute('eshopAdmin');      
  5464.     }
  5465.     /**
  5466.      * we insert default data into e-shop from basicdemo account
  5467.     */
  5468.     public function eshopDataFixtures(Request $request)
  5469.     {       
  5470.         /* we load session data */
  5471.         parent::init($request);
  5472.     
  5473.         $session $request->getSession();
  5474.     
  5475.         $em $this->doctrine->getManager();
  5476.         $dem $this->doctrine->getManager('dynamic_em');
  5477.         $demo_em $this->doctrine->getManager('eshop_demo_em');
  5478.         
  5479.         print('qqw eshop data fixtures...');
  5480.         $userId $session->get('user')->getUserId();
  5481.         /* we get current e-shop */
  5482.         $currenteshop $em->getRepository(Eshop::class)->getCurrentEshop($userId);
  5483.          
  5484.         /* we get basicdemo e-shop */
  5485.         $demoUserId 97//demobasic user id
  5486.         $demoshop $em->getRepository(Eshop::class)->getCurrentEshop($demoUserId);
  5487.         print('<br>qqw current eshop id: '.$demoshop->getEshopId());
  5488.         $demoCategoryCollection $demo_em->getRepository(Eshop::class)->getCategoryListByEshop($demoshop->getEshopId());
  5489.         $demoProductCollection $demo_em->getRepository(Product::class)->getProductListByEshop($demoshop->getEshopId(), 3000);
  5490.         //$cat->setLocale($session->get('lang')->getLangKey());
  5491.         
  5492.         foreach($demoCategoryCollection as $cat)
  5493.         {
  5494.             $catId $cat->getCategoryId();
  5495.             // print('<br>qqw cat: '.$catId);
  5496.             // \Doctrine\Common\Util\Debug::dump($cat); 
  5497.                 //we update or create e-shop category
  5498.                 $category $dem->getRepository(Eshop::class)->getCategoryByErpKey($cat->getCategoryKey());
  5499.                 if(empty($category)) {
  5500.                     $category = new Category;
  5501.                 }
  5502.                 //$category = $cat;
  5503.                 $category->setIsActive($cat->getIsActive());
  5504.                 $category->setEshopId($currenteshop->getEshopId());
  5505.                 $category->setCategoryKey($cat->getCategoryKey()); 
  5506.                 $category->setErpKey($cat->getCategoryKey()); 
  5507.                 $parentCategory null;
  5508.                 $category->setParent($parentCategory);
  5509.                 $category->setCategoryName($cat->getCategoryName());
  5510.                 $category->setCategoryDescription($cat->getCategoryDescription());                
  5511.                 
  5512.                 /*
  5513.                 // multilangual fields 
  5514.                 foreach($demoshop->getLanguages() as $lang) {
  5515.                     $cat->setLocale($lang->getLangKey());
  5516.                     $category->setLocale($lang->getLangKey());
  5517.                     $demo_em->refresh($cat);
  5518.                     $dem->refresh($category); 
  5519.                     $session->get('lang')->getLangKey()
  5520.                     print('<br>qqw cat name ('.$lang->getLangKey().'): '.$cat->getCategoryName());
  5521.                     $category->setCategoryName($cat->getCategoryName());
  5522.                     $category->setCategoryDescription($cat->getCategoryDescription());
  5523.                     //print('<br>qqw cat['.$lang->getLangKey().']: '.$category->getCategoryName());
  5524.                     $dem->persist($category);
  5525.                     $dem->flush();
  5526.                 } 
  5527.                 */
  5528.                  
  5529.                 // we persist and save category 
  5530.                 $dem->persist($category);
  5531.                 $dem->flush();
  5532.                 //we load product for this category
  5533.                 $categoryArray = array();
  5534.                 $categoryArray[] = $cat;
  5535.                 $demoProductCollection $demo_em->getRepository(Product::class)->getProductListByCategory($categoryArray0200false);
  5536.                 foreach($demoProductCollection as $prod) {
  5537.                     $prodId $prod->getProductId();
  5538.                     // print('<hr>qqw product: '.$prodId);
  5539.                     // \Doctrine\Common\Util\Debug::dump($prod);    
  5540.                     //we update or create e-shop category
  5541.                     $product $dem->getRepository(Product::class)->getProductByErpKey($prod->getProductKey());
  5542.                     if(empty($product)) {
  5543.                         $product = new Product;
  5544.                         $product->addCategory($category);
  5545.                         // we add product prices
  5546.                         
  5547.                         if(!empty($prod->getPrices())) {
  5548.                             foreach($prod->getPrices() as $priceDemo) {      
  5549.                                 $price = new Price;
  5550.                                 $price->setNettoValue($priceDemo->getNettoValue());
  5551.                                 $price->setBruttoValue($priceDemo->getBruttoValue());
  5552.                                 //$price->setProductId($product->getProductId());
  5553.                                 $price->setPriceLevelId(1);
  5554.                                 
  5555.                                 $dem->persist($price);
  5556.                                 $dem->flush();
  5557.                                 $product->addPrice($price); 
  5558.                             }                   
  5559.                         }
  5560.                         
  5561.                     }
  5562.                     $product->setIsActive($prod->getIsActive());
  5563.                     //$product->setEshopId($currenteshop->getEshopId());
  5564.                     $product->setProductKey($prod->getProductKey()); 
  5565.                     $product->setErpKey($prod->getProductKey()); 
  5566.                     $product->setProductName($prod->getProductName());
  5567.                     $product->setProductDescription($prod->getProductDescription());                    
  5568.                     /*
  5569.                     // multilangual fields 
  5570.                     foreach($demoshop->getLanguages() as $lang) {
  5571.                         $prod->setLocale($lang->getLangKey());
  5572.                         $product->setLocale($lang->getLangKey());
  5573.                         $demo_em->refresh($prod);
  5574.                         //$dem->refresh($category);
  5575.                         print('<br>qqw prod name ('.$lang->getLangKey().'): '.$prod->getProductName());
  5576.                         $product->setProductName($prod->getProductName());
  5577.                         $product->setProductDescription($prod->getProductDescription());
  5578.                         $dem->persist($product);
  5579.                         $dem->flush();
  5580.                         
  5581.                     } 
  5582.                     */
  5583.                     
  5584.                     // we persist and save product 
  5585.                     $dem->persist($product);
  5586.                     $dem->flush();                       
  5587.                 }
  5588.         
  5589.         }  
  5590.         /*
  5591.         foreach($demoProductCollection as $prod)
  5592.         {
  5593.             $prodId = $prod->getProductId();
  5594.             print('<hr>qqw product: '.$prodId);
  5595.             \Doctrine\Common\Util\Debug::dump($prod);    
  5596.                 //we update or create e-shop category
  5597.                 $product = $dem->getRepository(Product::class)->getProductByErpKey($prod->getProductKey());
  5598.                 //getCategoryByErpKey($cat->getCategoryKey());
  5599.                 if(empty($product)) {
  5600.                     $product = new Product;
  5601.                 }
  5602.                 $product->setIsActive($prod->getIsActive());
  5603.                 //$product->setEshopId($currenteshop->getEshopId());
  5604.                 $product->setProductKey($prod->getProductKey()); 
  5605.                 $product->setErpKey($prod->getProductKey()); 
  5606.                 $parentCategory = null;
  5607.                 $product->setParent($parentCategory);
  5608.                 
  5609.                 // multilangual fields 
  5610.                 foreach($demoshop->getLanguages() as $lang) {
  5611.                     $prod->setLocale($lang->getLangKey());
  5612.                     $product->setLocale($lang->getLangKey());
  5613.                     $demo_em->refresh($prod);
  5614.                     //$dem->refresh($category);
  5615.                     print('<br>qqw prod name ('.$lang->getLangKey().'): '.$prod->getProductName());
  5616.                     $product->setProductName($prod->getProductName());
  5617.                     $product->setProductDescription($prod->getProductDescription());
  5618.                     
  5619.                     $dem->persist($product);
  5620.                     $dem->flush();
  5621.                     
  5622.                 } 
  5623.                 
  5624.                 // we persist and save product 
  5625.                 $dem->persist($product);
  5626.                 $dem->flush();   
  5627.                           
  5628.         } 
  5629.         */    
  5630.     }    
  5631.     
  5632.     public function categoryTreeMenu($eshopRequest $request)
  5633.     {    
  5634.         
  5635.         /* we load session data */
  5636.         parent::init($request);
  5637.         $session $request->getSession();
  5638.         
  5639.         /* we load entity managers */
  5640.         $em $this->doctrine->getManager();
  5641.         $dem $this->doctrine->getManager('dynamic_em');
  5642.         
  5643.         $userId $eshop->getUserId();
  5644.         
  5645.         $session->set('eshop'$eshop);
  5646.         
  5647.         /* we get current e-shop */
  5648.         //$eshop = $em->getRepository(Eshop::class)->getCurrentEshop($currentUserId);
  5649.       
  5650.         $repo $dem->getRepository(Category::class);
  5651.          
  5652.         $this->dynamicEntityManager $dem;
  5653.         $this->currentEshop $eshop;
  5654.         $options = array(
  5655.                 'decorate' => true,
  5656.                 'rootOpen' => '<ul class="tree">',
  5657.                 'rootClose' => '</ul>',
  5658.                 'childOpen' => function($node) {
  5659.         
  5660.                     /*
  5661.                      print('<br>QQW node: ');
  5662.                      \Doctrine\Common\Util\Debug::dump($node);
  5663.                      */
  5664.         
  5665.                     if($node['eshopId'] == $this->currentEshop->getEshopId() && !empty($node['isActive']) && $node['isActive']) {
  5666.                         return '<li class="treeItem">';
  5667.                     } else {
  5668.                         return '<li class="treeItemHidden">';
  5669.                     }
  5670.             
  5671.                     return '<li class="treeItem">';
  5672.                 },
  5673.                 'childClose' => '</li>',
  5674.                 'nodeDecorator' => function($node) {
  5675.                     $url $this->generateUrl('eshop',array('eshopId'=>$this->currentEshop->getEshopId()));
  5676.                     return '<a href="'.$url.'/category/'.$node['categoryId'].'" class="treeNodeLink">'.$node['categoryName'].'</a>';
  5677.                 }
  5678.                 );
  5679.          
  5680.         $htmlTree $repo->childrenHierarchy(
  5681.                 null,
  5682.                 false,
  5683.                 $options
  5684.                 );
  5685.          
  5686.         return $htmlTree;           
  5687.         
  5688.     }
  5689.     public function categoryTopMenu($eshopRequest $request)
  5690.     {    
  5691.         /* we load session data */
  5692.         parent::init($request);
  5693.         $session $request->getSession();
  5694.         
  5695.         /* we load entity managers */
  5696.         $em $this->doctrine->getManager();
  5697.         $dem $this->doctrine->getManager('dynamic_em');
  5698. //        print('<br>eshop id:'.$eshop->getEshopId());
  5699. //        $categoryList = $dem->getRepository(Eshop::class)->getRootCategoryListByEshop($eshop->getEshopId());
  5700. //        foreach($categoryList as $cat) {
  5701. //
  5702. //            print('<hr>QQW cat: ');
  5703. //            \Doctrine\Common\Util\Debug::dump($cat);
  5704. //        }
  5705.         $rootNodes $dem->getRepository(Category::class)->getRootNodes();
  5706.         $childNodes = array();
  5707.         foreach($rootNodes as $cat) {
  5708.             if($cat->getEshopId() == $eshop->getEshopId() && $cat->getIsActive()) {
  5709.                 $catName $cat->getCategoryName();
  5710.                 $cat->setLocale($session->get('lang')->getLangKey());
  5711.                 $dem->refresh($cat);
  5712.                 if ($cat->getCategoryName() == '') {
  5713.                     $cat->setCategoryName($catName);
  5714.                 }
  5715.                 if ($cat->getCategoryName() != '') {
  5716.                     $childNodes[] = $cat;
  5717.                 }
  5718. //                print('<hr>QQW category: ');
  5719. //                \Doctrine\Common\Util\Debug::dump($cat);
  5720.             }
  5721.         }
  5722.         
  5723. //         print('<br>QQW categoryTopMenu: ');
  5724. //         \Doctrine\Common\Util\Debug::dump($childNodes);
  5725.       return $childNodes;
  5726.     }  
  5727.     /**
  5728.      * @Route("/eshop/{eshopId}/eshopNewlang", name="eshopNewlang")
  5729.      */
  5730.     public function eshopNewlangAction(Request $request$eshopId) {
  5731.         /* we load session data */
  5732.         parent::init($request);
  5733.         $em $this->doctrine->getManager();
  5734.         $session $request->getSession();
  5735.         /* setting new language for e-shop */
  5736.         if(!empty($request->query->get('newlang'))) {
  5737.           //print("<br>QQW setting new e-shop language: ".$request->query->get('newlang'));
  5738.           $lang $em->getRepository(Language::class)->getLanguageByKey($request->query->get('newlang'));
  5739.           $changeLangMessage $this->translator->trans('system.language_changed_to', [], 'messages'$lang->getLangKey());
  5740.         
  5741.           if(!empty($lang)) {
  5742.             $session->set('lang'$lang);  
  5743.             $this->addFlash('notice'$changeLangMessage.' '.$lang->getLangName().'.');   
  5744.           }
  5745.       }
  5746.       
  5747.       /*
  5748.       $referer = $request->headers->get('referer');
  5749.       $lastPath = substr($referer, strpos($referer, $request->getBaseUrl()));
  5750.       $lastPath = str_replace($request->getBaseUrl(), '', $lastPath);
  5751.   
  5752.       $matcher = $this->get('router')->getMatcher();
  5753.       $parameters = $matcher->match($lastPath);
  5754.       $route = $parameters['_route'];      
  5755.       
  5756.       print("<br>QQW newlangAction: ");
  5757.       \Doctrine\Common\Util\Debug::dump($session->get('lang')); 
  5758.       die();
  5759.       */
  5760.       //print('<br>qqw eshopId: '.$eshopId);
  5761.       //return $this->redirectToRoute($route);     
  5762.       return $this->redirectToRoute('eshop', array('eshopId' => $eshopId)); 
  5763.     }  
  5764.     /**
  5765.      * @Route("/eshop/{eshopId}/eshopNewcurr", name="eshopNewcurr")
  5766.      */
  5767.     public function eshopNewcurrAction(Request $request$eshopId) {
  5768.                          
  5769.         /* we load session data */
  5770.         parent::init($request);                       
  5771.         $em $this->doctrine->getManager();
  5772.                             
  5773.         $session $request->getSession();
  5774.         /* setting new currency for e-shop */
  5775.         if(!empty($request->query->get('newEshopCurrency'))) {
  5776.           //print("<br>QQW setting new e-shop currency: ".$request->query->get('newEshopCurrency'));
  5777.           $curr $em->getRepository(Currency::class)->getCurrencyByKey($request->query->get('newEshopCurrency'));
  5778.         
  5779.           if(!empty($curr)) {
  5780.             $session->set('eshopCurrency'$curr);  
  5781.             $this->addFlash('notice'$this->translator->trans('system.currency_changed_to').' '.$curr->getCurrencyName().'.');   
  5782.           }
  5783.       }
  5784.       /*
  5785.       $referer = $request->headers->get('referer');
  5786.       $lastPath = substr($referer, strpos($referer, $request->getBaseUrl()));
  5787.       $lastPath = str_replace($request->getBaseUrl(), '', $lastPath);
  5788.   
  5789.       $matcher = $this->get('router')->getMatcher();
  5790.       $parameters = $matcher->match($lastPath);
  5791.       $route = $parameters['_route'];      
  5792.       
  5793.       print("<br>QQW newlangAction: ");
  5794.       \Doctrine\Common\Util\Debug::dump($session->get('lang')); 
  5795.       die();
  5796.       */
  5797.       //return $this->redirectToRoute($route);     
  5798.       return $this->redirectToRoute('eshop', array('eshopId' => $eshopId)); 
  5799.     }      
  5800.     /**
  5801.      * @Route("/orderlist", name="orderList")
  5802.      */
  5803.     public function orderListAction(Request $request)
  5804.     {
  5805.         /* we load session data */
  5806.         parent::init($request);     
  5807.         $session $request->getSession(); 
  5808.         
  5809.         // we check if any user is logged in
  5810.         if(!$this->isLoggedUser($request)) {
  5811.             return $this->redirectToRoute('login');
  5812.         }  
  5813.         
  5814.         /* we load users entity manager */
  5815.         $em $this->doctrine->getManager();
  5816.         $dem $this->doctrine->getManager('dynamic_em');
  5817.         /* we get current user */
  5818.         $userId $session->get('user')->getUserId();
  5819.         $user $em->getRepository(User::class)->getUser($userId);
  5820.         
  5821.         /* we get current e-shop */
  5822.         $eshop $em->getRepository(Eshop::class)->getCurrentEshop($userId);
  5823.         $defaultCurrency $em->getRepository(Currency::class)->getCurrency($eshop->getPreferredCurrencyId());
  5824.          
  5825.         $orderList $dem->getRepository(Order::class)->getOrderList("orderId""DESC");
  5826.         /* we load order prices */
  5827.         $orderPrices = array();
  5828.         foreach($orderList as $order) {
  5829.             if(!empty($order->getCurrencyKey())) {
  5830.                 $targetCurrency $em->getRepository(Currency::class)->getCurrencyByKey($order->getCurrencyKey());
  5831.             } else {
  5832.                 $targetCurrency $defaultCurrency;
  5833.             }
  5834.             
  5835.             $orderPrices[$order->getOrderId()] = $dem->getRepository(Order::class)->getOrderPrice($order->getOrderId(), $targetCurrencyfalse$eshop$defaultCurrency);
  5836.         }
  5837.         /* we render data */
  5838.         return $this->render('orderList.html.twig',
  5839.                 array('headerData' => $this -> getPageHeader($request),
  5840.                       'orderList' => $orderList,
  5841.                       'orderPrices' => $orderPrices,
  5842.                       'menu' => $this -> adminMenu($request),'mainMenu' => $this -> adminMainMenu($request),
  5843.                       'mainMenu' => $this -> adminMainMenu($request),
  5844.                       'user' => $user,
  5845.                 )
  5846.                 );
  5847.     
  5848.     }   
  5849.     /**
  5850.      * @Route("/orderedit/{orderId}", name="orderEdit")
  5851.      */
  5852.     public function orderEditAction(Request $request$orderId)
  5853.     {
  5854.         /* we load session data */
  5855.         parent::init($request);
  5856.         $session $request->getSession();
  5857.         
  5858.         /* we load entity managers */
  5859.         $em $this->doctrine->getManager();
  5860.         $dem $this->doctrine->getManager('dynamic_em');
  5861.          
  5862.         $userId $session->get('user')->getUserId();
  5863.         $user $em->getRepository(User::class)->getUser($userId);
  5864.         
  5865.         /* we get current e-shop */
  5866.         $eshop $em->getRepository(Eshop::class)->getCurrentEshop($userId);
  5867.         $eshopCurrency $em->getRepository(Currency::class)->getCurrency($eshop->getPreferredCurrencyId());
  5868.  
  5869.         $order $dem->getRepository(Order::class)->getOrder($orderId);
  5870.         if(!empty($order->getCurrencyKey())) {
  5871.             $targetCurrency $em->getRepository(Currency::class)->getCurrencyByKey($order->getCurrencyKey());
  5872.         } else {
  5873.             $targetCurrency $eshopCurrency;
  5874.         }
  5875.         $orderPrice $dem->getRepository(Order::class)->getOrderPrice($order->getOrderId(), $targetCurrencyfalse$eshop$eshopCurrency);
  5876.         $orderPriceVAT $dem->getRepository(Order::class)->getOrderPrice($order->getOrderId(), $targetCurrencytrue$eshop$eshopCurrency);
  5877.         $deliveryCost $dem->getRepository(Price::class)->getCurrencyRatedPrice($order->getEshopDelivery()->getCost(), $eshopCurrency$targetCurrency);
  5878.         $order->getEshopDelivery()->setCost(round($deliveryCost2));
  5879.         $paymentCost $dem->getRepository(Price::class)->getCurrencyRatedPrice($order->getEshopPayment()->getCost(), $eshopCurrency$targetCurrency);
  5880.         $order->getEshopPayment()->setCost(round($paymentCost2));       
  5881.         //print('<br>QQW orderPrice: '.$orderPrice);
  5882.         //print('<br>QQW orderPrice VAT: '.$orderPriceVAT);
  5883.         //\Doctrine\Common\Util\Debug::dump($orderPrice);
  5884.         /* we render data */
  5885.         return $this->render('orderEdit.html.twig',
  5886.             array('headerData' => $this -> getPageHeader($request),
  5887.                   'order' => $order,
  5888.                   'orderPrice' => $orderPrice,  
  5889.                   'orderPriceVAT' => $orderPriceVAT,                                    
  5890.                   'menu' => $this -> adminMenu($request),'mainMenu' => $this -> adminMainMenu($request),'mainMenu' => $this -> adminMainMenu($request),
  5891.                   'eshopCurrency' => $eshopCurrency,   
  5892.                   'eshop' => $eshop,
  5893.                   'user' => $user,
  5894.                 )
  5895.         );        
  5896.     }
  5897.     /**
  5898.      * @Route("/eshop/{eshopId}/page/{pageId}", name="eshopPage")
  5899.      */
  5900.     public function pageAction(Request $request$eshopId$pageId)
  5901.     {
  5902.     
  5903.         /* we load session data */
  5904.         parent::init($request);
  5905.         $session $request->getSession();
  5906.         //print('<br>QQW page ID: '.$pageId);
  5907.     
  5908.         /* we load entity managers */
  5909.         $em $this->doctrine->getManager();
  5910.         $dem $this->doctrine->getManager('dynamic_em');
  5911.         /* we get current e-shop */
  5912.         $eshop $em->getRepository(Eshop::class)->getEshop($eshopId);
  5913.         $eshopHeader $dem->getRepository(Eshop::class)->getEshopHeader($eshopId);
  5914.         if(!empty($eshopHeader)) {
  5915.           $eshopHeader->setLocale($session->get('lang')->getLangKey());
  5916.           $dem->refresh($eshopHeader);            
  5917.         }
  5918.         /* we load footer for the current website */
  5919.         $eshopFooter $dem->getRepository(Eshop::class)->getEshopFooter($eshopId);
  5920.         if(!empty($eshopFooter)) {         
  5921.           $eshopFooter->setLocale($session->get('lang')->getLangKey());
  5922.           $dem->refresh($eshopFooter);  
  5923.         }  
  5924.         /* we get wireframe */
  5925.         $wireFrame $em->getRepository(WireFrame::class)->getWireFrame($eshop->getWireFrameId());
  5926.         /* we load page for the current webpage */
  5927.         $page $dem->getRepository(WebPage::class)->getWebPage($pageId);
  5928.         
  5929.         /*
  5930.         print('<br>qqw page id: '.$pageId);
  5931.         \Doctrine\Common\Util\Debug::dump($page);
  5932.         */           
  5933.         
  5934.         /* we parse the page content for placeholders */
  5935.         $pageContent $this->parseContent($request$page->getWebPageContent());
  5936.         $page->setWebPageContent($pageContent);
  5937.         /* 
  5938.         print('<br>qqw webMenuVertical: ');
  5939.         \Doctrine\Common\Util\Debug::dump($webMenuVertical);
  5940.         */
  5941.         /* we render data */
  5942.         return $this->render('eshopPage.html.php',
  5943.                 array(  'headerData' => $this -> getPageHeader($request),
  5944.                         'eshop' => $eshop,  
  5945.                         'wireFrame' => $wireFrame,  
  5946.                         'categoryTreeMenu' => $this->categoryTreeMenu($eshop$request),
  5947.                         'categoryTopMenu' => $this->categoryTopMenu($eshop$request), 
  5948.                         'eshopHeader' => $eshopHeader,
  5949.                         'eshopFooter' => $eshopFooter,                             
  5950.                         'page' => $page,
  5951.                 )
  5952.                 );
  5953.     
  5954.     }     
  5955.     /**
  5956.      * @Route("/eshop/{eshopId}/request", name="eshopRequest")
  5957.      */
  5958.     public function eshopRequestAction(Request $request$eshopId)
  5959.     {
  5960.     
  5961.         /* we load session data */
  5962.         parent::init($request);
  5963.         $session $request->getSession();
  5964.         /* we load entity managers */
  5965.         $em $this->doctrine->getManager();
  5966.         $dem $this->doctrine->getManager('dynamic_em');
  5967.         /* we get current e-shop */
  5968.         $eshop $em->getRepository(Eshop::class)->getEshop($eshopId);
  5969.         /* we get current user */
  5970.         $user $em->getRepository(User::class)->getUser($eshop->getUserId());
  5971.         $eshopHeader $dem->getRepository(Eshop::class)->getEshopHeader($eshopId);
  5972.         if(!empty($eshopHeader)) {
  5973.           $eshopHeader->setLocale($session->get('lang')->getLangKey());
  5974.           $dem->refresh($eshopHeader);            
  5975.         }
  5976.         /* we load footer for the current website */
  5977.         $eshopFooter $dem->getRepository(Eshop::class)->getEshopFooter($eshopId);
  5978.         if(!empty($eshopFooter)) {         
  5979.           $eshopFooter->setLocale($session->get('lang')->getLangKey());
  5980.           $dem->refresh($eshopFooter);  
  5981.         }  
  5982.         /* we get wireframe */
  5983.         $wireFrame $em->getRepository(WireFrame::class)->getWireFrame($eshop->getWireFrameId());
  5984.         $subject $request->query->get('subject');
  5985.         $email '';
  5986.         $telephone '';   
  5987.         $message '';  
  5988.         /* we get product info */
  5989.         if(!empty($request->query->get('productId'))) {
  5990.             //print('<br>qqw loading productId: '.$request->query->get('productId'));
  5991.             $productId $request->query->get('productId');
  5992.             $product $dem->getRepository(Product::class)->getProduct($productId);
  5993.             $message .= $product->getProductName().' (ID: '.$product->getProductKey().' | ERP: '.$product->getERPKey().' | EAN: '.$product->getEAN().')'
  5994.             //\Doctrine\Common\Util\Debug::dump($product);
  5995.         }
  5996.         /* we check if customer exists */
  5997.         if(!empty($session->get('contact'))) {
  5998.             $contact $dem->getRepository(Contact::class)->getContact($session->get('contact')->getContactId());
  5999.             $email $contact->getEmail();
  6000.             $telephone $contact->getPhone();
  6001.         }  
  6002.         //isModule ReCaptcha
  6003.         $module $em->getRepository(Module::class)->getModule(41);
  6004.         $isReCaptchaModule $em->getRepository(User::class)->userHasModule($user$module);
  6005.         $reCaptcha null;
  6006.         if($isReCaptchaModule) {
  6007.             //we load re-captcha
  6008.             $reCaptcha $dem->getRepository(ReCaptcha::class)->findOneBy(['reCaptchaId'=> 1]);
  6009.         }       
  6010.         //print('<br>qqw subject: '.$subject);
  6011.         /* 
  6012.         print('<br>qqw webMenuVertical: ');
  6013.         \Doctrine\Common\Util\Debug::dump($webMenuVertical);
  6014.         */
  6015.     
  6016.         /* we build login form */
  6017.         $formBuilder $this->createFormBuilder();
  6018.         
  6019.         $formBuilder->add('request_subject'TextType::class, array(
  6020.                 'required' => true,
  6021.                 'label' => $this->translator->trans('eshop.request_subject'),
  6022.                 'attr' => array('class' => 'text_form''size' => 60'value' => $subject),
  6023.                 'label_attr' => array('class' => 'form_field_label'),
  6024.         ));
  6025.         $formBuilder->add('request_email'EmailType::class, array(
  6026.                 'required' => true,
  6027.                 'label' => $this->translator->trans('eshop.request_email'),
  6028.                 'attr' => array('class' => 'text_form''size' => 60'value' => $email),
  6029.                 'label_attr' => array('class' => 'form_field_label'),
  6030.         ));     
  6031.         $formBuilder->add('request_telephone'TextType::class, array(
  6032.                 'required' => true,
  6033.                 'label' => $this->translator->trans('eshop.request_telephone'),
  6034.                 'attr' => array('class' => 'text_form''size' => 60'value' => $telephone),
  6035.                 'label_attr' => array('class' => 'form_field_label'),
  6036.         ));             
  6037.         
  6038.         $formBuilder->add('request_message'TextareaType::class, array(
  6039.                 'required' => false,
  6040.                 'label' => $this->translator->trans('eshop.request_message'),
  6041.                 'attr' => array('class' => 'inputTextArea''cols' => 70'rows' => 15'value' => $message),
  6042.                 'label_attr' => array('class' => 'form_textarea_label'),
  6043.                 'data' => $message,
  6044.         ));
  6045.         
  6046.         $formBuilder->add('save'SubmitType::class, array('label' => $this->translator->trans('eshop.request_send'),
  6047.                 'attr' => array('class' => 'requestFormButton')));
  6048.         
  6049.         $form $formBuilder->getForm();        
  6050.         
  6051.         $form->handleRequest($request);
  6052.         $mailToAdminStatus '';
  6053.         
  6054.         if ($request->getMethod() == 'POST') {
  6055.         
  6056.             //we prepare captcha
  6057.             if(!$isReCaptchaModule) {
  6058.                 $captchaResponse "noCaptcha";
  6059.             } else {
  6060.                 $captchaResponse $request->get('g-recaptcha-response');
  6061.             }            
  6062.         
  6063.             if ($form->isValid() && $captchaResponse != "") {
  6064.                 // perform some action, such as save the object to the database
  6065.                 //print('<br>sending email request from: '.$request->request->get('form')['request_email']);
  6066.                 
  6067.                 /* we load html template */
  6068.                 //$emailText = $this->getRegisterEmail($request, $eshop, $contact);
  6069.                 $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'] );                
  6070.                  /* we prepare request emailing */
  6071.                 $name $eshop->getEshopName();
  6072.                 $toSuperadmin      'easycommerc@gmail.com'
  6073.                 $to      $user->getEmail(); 
  6074.                 $subject $name.' - '.$subject;
  6075.                 $message $emailText;                         
  6076.                 $from 'noreply@easycommerc.com';
  6077.                 $headers  "MIME-Version: 1.0\r\n";
  6078.                 $headers .= "Content-type: text/html; charset=UTF-8\r\n";
  6079.                 $headers .= "From: {$name} <{$from}>\r\n";
  6080.                 $headers .= "Reply-To: <{$from}>\r\n";
  6081.                 $headers .= "Subject: {$subject}\r\n";
  6082.                 $headers .= "X-Mailer: PHP/".phpversion()."\r\n";
  6083.                 
  6084.                 /* we send email to e-shop admin */
  6085.                 if(@mail($to$subject$message$headers)) {
  6086.                     //print('<br>Email was sent.');
  6087.                         //we send email to users contact person
  6088.                         if(!empty($user->getContactPersonEmail())) {
  6089.                             mail($user->getContactPersonEmail(), $subject$message$headers);
  6090.                         }
  6091.                     $mailToAdminStatus $this->translator->trans('eshop.email_request_sent').': '.$to;
  6092.                     $this->addFlash('notice'$mailToAdminStatus);
  6093.                 } else {
  6094.                     //print('<br>Email was not sent.');
  6095.                     $mailToAdminStatus $this->translator->trans('eshop.email_admin_order_error'.': '.$to);
  6096.                 }                   
  6097.                 // we send email to super admin 
  6098.                 /*
  6099.                 if(@mail($toSuperadmin, $subject, $message, $headers)) {
  6100.                     //print('<br>Email was sent.');
  6101.                     //$mailToAdminStatus = $this->translator->trans('eshop.email_request_sent').': '.$to;
  6102.                     //$this->addFlash('notice', $mailToAdminStatus);
  6103.                 } else {
  6104.                     //print('<br>Email was not sent.');
  6105.                     //$mailToAdminStatus = $this->translator->trans('eshop.email_admin_order_error'.': '.$to);
  6106.                 } 
  6107.                 */
  6108.                  /*        
  6109.                  print('<br>qqw contact exists: ');
  6110.                  \Doctrine\Common\Util\Debug::dump($contactExist);
  6111.                  */
  6112.                 
  6113.                 //die();
  6114.             }
  6115.             else {
  6116.                 $this->addFlash('error'$this->translator->trans('system.form_not_valid'));
  6117.             }
  6118.         
  6119.         }       
  6120.         
  6121.         /* we render data */
  6122.         return $this->render('eshopRequest.html.twig',
  6123.                 array(  'headerData' => $this -> getPageHeader($request),
  6124.                         'eshop' => $eshop,  
  6125.                         'form' => $formBuilder->getForm()->createView(),
  6126.                         'wireFrame' => $wireFrame,  
  6127.                         'categoryTreeMenu' => $this->categoryTreeMenu($eshop$request),
  6128.                         'categoryTopMenu' => $this->categoryTopMenu($eshop$request), 
  6129.                         'eshopHeader' => $eshopHeader,
  6130.                         'eshopFooter' => $eshopFooter,   
  6131.                         'subject' => $subject
  6132.                         'mailToAdminStatus' => $mailToAdminStatus,   
  6133.                         'reCaptcha' => $reCaptcha,                                                     
  6134.                 )
  6135.                 );
  6136.     
  6137.     }  
  6138.     /**
  6139.      * @Route("/eshop/{eshopId}/page/{pageId}", name="eshopPage")
  6140.      */
  6141.     /*
  6142.     public function pageAction(Request $request, $eshopId, $pageId)
  6143.     {
  6144.     
  6145.         // we load session data 
  6146.         parent::init($request);
  6147.         $session = $request->getSession();
  6148.         //print('<br>QQW page ID: '.$pageId);
  6149.     
  6150.         // we load entity managers 
  6151.         $em = $this->doctrine->getManager();
  6152.         $dem = $this->doctrine->getManager('dynamic_em');
  6153.         // we get current e-shop 
  6154.         $eshop = $em->getRepository(Eshop::class)->getEshop($eshopId);
  6155.    */
  6156.     /**
  6157.      * @Route("/eshop/{eshopId}/api/products", name="APIProducts")
  6158.      */
  6159.     public function APIProductsAction(Request $request$eshopId)
  6160.     {
  6161.         /* we load session data */
  6162.         parent::init($request);     
  6163.         $session $request->getSession(); 
  6164.         /* we load users entity manager */
  6165.         $em $this->doctrine->getManager();
  6166.         $dem $this->doctrine->getManager('dynamic_em');
  6167.         // we get current e-shop 
  6168.         $eshop $em->getRepository(Eshop::class)->getEshop($eshopId);
  6169.         //print('<br>qqw eshop: '.$eshop->getEshopId());
  6170.         //\Doctrine\Common\Util\Debug::dump($eshop);
  6171.         $limit 300;
  6172.         $offset 0;
  6173.         $defaultCurrency $em->getRepository(Currency::class)->getCurrency($eshop->getPreferredCurrencyId());
  6174.         $productList $dem->getRepository(Product::class)->getProductListByEshop($eshop->getEshopId(), $limit$offset);   
  6175.         $productListAPI = array();
  6176.         foreach ($productList as $product) {
  6177.             //print('<br>qqw product: ');
  6178.             //\Doctrine\Common\Util\Debug::dump($product);
  6179.             $productAPI = array();
  6180.             $productAPI['productId'] = $product->getProductId();
  6181.             $productAPI['productKey'] = $product->getProductKey();  
  6182.             $productAPI['EAN'] = $product->getEAN();           
  6183.             $productAPI['productName'] = $product->getProductName();
  6184.             $productAPI['productDescription'] = $product->getProductDescription();            
  6185.             $productListAPI[] = $productAPI;  
  6186.         }
  6187.         //die('qqw API close');
  6188.         //products
  6189.         
  6190.         
  6191.         $count count($productListAPI);      
  6192.         $pages 10;
  6193.         $page 1;
  6194.         $system = array('code' => 200'message' => 'OK');
  6195.         $metadata = array('count' => $count'limit' => 100'pages' => $pages'page' => $page);
  6196.         //die(); 
  6197.          
  6198.         /* we prepare data for view */
  6199.         $viewData = array('system' => $system,
  6200.                           'data' => $productListAPI
  6201.                           'metadata' => $metadata,
  6202.                 );           
  6203.         // we output json
  6204.         return new JsonResponse($viewData);
  6205.     
  6206.     }   
  6207.     public function getTopProducts(Request $request$eshop$topProductLimit 7)
  6208.     {
  6209.         /* we load users entity manager */
  6210.         $em $this->doctrine->getManager();
  6211.         $dem $this->doctrine->getManager('dynamic_em');
  6212.         $session $request->getSession(); 
  6213.         $topProductList $dem->getRepository(OrderItem::class)->getTopProductList($topProductLimit);
  6214.         
  6215.         $productIds = [];
  6216.         $topProducts = [];
  6217.         foreach($topProductList as $orderItem) {
  6218.             $pId $orderItem['productId'];
  6219.             $topProduct $orderItem;      
  6220.             $product $dem->getRepository(Product::class)->getProduct($pId);
  6221.             if($product) {
  6222.                 $topProducts[$pId] = $topProduct;
  6223.                 $productIds[] = $pId;
  6224.             }
  6225.         }
  6226.         // we load prices
  6227.         $productPriceList $dem->getRepository(Product::class)->getProductPriceList($productIds);
  6228.         $defaultCurrency $em->getRepository(Currency::class)->getCurrency($eshop->getPreferredCurrencyId());
  6229.         $targetCurrency $session->get('eshopCurrency');
  6230.         $currencyKey $targetCurrency->getCurrencyKey();
  6231.             
  6232.         // we load currency rated prices
  6233.         $productPriceList $dem->getRepository(Product::class)->getCurrencyRatedProductPriceList($productPriceList$defaultCurrency$targetCurrency);
  6234.         foreach($topProductList as $orderItem) {
  6235.             $pId $orderItem['productId'];
  6236.             /* we get price(s) to display */
  6237.             $displayPrice null;
  6238.             foreach($productPriceList as $price) {
  6239.                 if($price->getProductId() == $pId) {
  6240.                     /* we get default price level */
  6241.                     if($price->getPriceLevelId() == 1) {
  6242.                         //$displayPrice = round($price->getBruttoValue(),$eshop->getRoundPrice());
  6243.                         $displayPrice round($price->getNettoValue(),$eshop->getRoundPrice());
  6244.                         $topProducts[$pId]['displayPrice'] = $displayPrice;
  6245.                         $topProducts[$pId]['currencyKey'] = $currencyKey;                        
  6246.                     }
  6247.                     
  6248.                 }
  6249.             }  
  6250.         }       
  6251.         //print('<br>QQW topProductList: ');
  6252.         //\Doctrine\Common\Util\Debug::dump($topProductList);
  6253.         // print('<br>QQW topProducts: ');
  6254.         // \Doctrine\Common\Util\Debug::dump($topProducts);
  6255.         // print('<hr>QQW topProducts PriceList: ');
  6256.         // \Doctrine\Common\Util\Debug::dump($productPriceList);        
  6257.         return $topProducts;
  6258.     }               
  6259.    
  6260.     public function adminMenu(Request $request)
  6261.     {
  6262.         $menuItems = array(
  6263.                 => array('link' => 'eshopAdmin''langKey' => 'eshop.admin''routeName' => 'eshopAdmin'),
  6264.                 => array('link' => 'orderlist''langKey' => 'eshop.orders''routeName' => 'orderList'),
  6265.                 => array('link' => 'productedit''langKey' => 'eshop.products''routeName' => 'productListEdit'),
  6266.                 => array('link' => 'productnew''langKey' => 'eshop.new_product''routeName' => 'productNew'),
  6267.                 => array('link' => 'categories''langKey' => 'eshop.categories''routeName' => 'categories'),
  6268.                 => array('link' => 'categorynew''langKey' => 'eshop.new_category''routeName' => 'categoryNew'),
  6269.                 => array('link' => 'contacts''langKey' => 'knowledgebase.contacts''routeName' => 'contacts'),
  6270.                 => array('link' => 'eshopnew''langKey' => 'eshop.new_eshop''routeName' => 'eshopNew'),
  6271.                 => array('link' => 'eshopConfig''langKey' => 'eshop.config''routeName' => 'eshopConfig'),
  6272.         );   
  6273.         
  6274.         return $menuItems;
  6275.     
  6276.     }    
  6277.      
  6278. }