src/Controller/EshopController.php line 2835

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