src/Trinity/WebshopBundle/Controller/WebshopController.php line 1766

Open in your IDE?
  1. <?php
  2. namespace App\Trinity\WebshopBundle\Controller;
  3. use App\CmsBundle\Controller\StorageController;
  4. use App\Trinity\WebshopBundle\Entity\Cart;
  5. use App\Trinity\WebshopBundle\Entity\CartProduct;
  6. use App\Trinity\WebshopBundle\Entity\Product;
  7. use App\Trinity\WebshopBundle\Entity\ProductList;
  8. use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
  9. use Symfony\Component\Routing\Annotation\Route;
  10. use Sensio\Bundle\FrameworkExtraBundle\Configuration\Security;
  11. use Symfony\Component\HttpFoundation\Request;
  12. use Symfony\Component\HttpFoundation\Response;
  13. use Symfony\Component\HttpFoundation\JsonResponse;
  14. use App\Trinity\WebshopBundle\Entity\Settings;
  15. // Custom form elements
  16. use Symfony\Bridge\Doctrine\Form\Type\EntityType;
  17. use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
  18. use Symfony\Component\HttpKernel\EventListener\AbstractSessionListener;
  19. use App\Trinity\WebshopBundle\Entity\GiftCard;
  20. use App\Trinity\WebshopBundle\Entity\Category;
  21. use Symfony\Component\Intl\Countries;
  22. class WebshopController extends StorageController
  23. {
  24.     private $WebshopUser null;
  25.     private $passwordEncoder null;
  26.     private function getWebshopUser(){
  27.         if($this->getUser()){
  28.             $WebshopUser $this->getDoctrine()->getRepository('TrinityWebshopBundle:User')->findOneByUser($this->getUser());
  29.             if(!empty($WebshopUser)){
  30.                 $this->WebshopUser $WebshopUser;
  31.             }else{
  32.                 $loginUser $this->getUser();
  33.                 $this->WebshopUser = new \App\Trinity\WebshopBundle\Entity\User();
  34.                 $this->WebshopUser->setUser($loginUser);
  35.                 if(!empty($this->Webshop)){
  36.                     $this->WebshopUser->setWebshop($this->Webshop);
  37.                 }
  38.                 $em $this->getDoctrine()->getManager();
  39.                 $em->persist($this->WebshopUser);
  40.                 $em->flush();
  41.             }
  42.         }
  43.         return $this->WebshopUser;
  44.     }
  45.     /**
  46.      * @Route("/admin/webshop/webshop", name="admin_mod_webshop_mod_webshop")
  47.      * @Template()
  48.      */
  49.     public function indexActionRequest $request$id null)
  50.     {
  51.         // Initialize StorageController
  52.         parent::init($request);
  53.         $this->breadcrumbs->addRouteItem('Nieuwe bundel''admin_mod_webshop_mod_webshop');
  54.         return $this->attributes([
  55.             // Variables
  56.         ]);
  57.     }
  58.     /**
  59.      * @Route("/betaling/", name="mod_webshop_betaling_redirect")
  60.      * @Template()
  61.      */
  62.     public function betalingCountRequest $request$id null)
  63.     {
  64.         parent::init($request);
  65.         $url '/';
  66.         if(!empty($_GET['refnr'])){
  67.             $Product $this->getDoctrine()->getRepository('TrinityWebshopBundle:Product')->findOneBySku($_GET['refnr']);
  68.             if(!empty($Product)){
  69.                 $url $this->host . ($this->WebshopSettings->getUri() ? '/' $this->WebshopSettings->getUri() : $this->generateUrl('homepage')) . $Product->getCategory()->first()->getCategory()->getUri() . '/' $Product->getSlug() . '?utm_source=visreactie&utm_medium=email&utm_campaign=';
  70.             }
  71.         }
  72.         return $this->redirect($url);
  73.     }
  74.     /**
  75.      * @Route("/choice-flow/results", name="mod_webshop_choice_flow_results")
  76.      * @Template()
  77.      */
  78.     public function choiceFlowResults(Request $request): Response
  79.     {
  80.         parent::init($request);
  81.         $specs = ['spec' => []];
  82.         $price_range = [010000];
  83.         if(!empty($_GET['specs'])){
  84.             foreach($_GET['specs'] as $k => $spec_id){
  85.                 $value_id $_GET['values'][$k];
  86.                 if($spec_id == 'price'){
  87.                     $price_range explode('-'$value_id);
  88.                     continue;
  89.                 }
  90.                 $Spec $this->getDoctrine()->getRepository('TrinityWebshopBundle:Spec')->find($spec_id);
  91.                 $SpecValue $this->getDoctrine()->getRepository('TrinityWebshopBundle:SpecValue')->find($value_id);
  92.                 if(!empty($Spec) && !empty($SpecValue)){
  93.                     if($SpecValue->getSpec() == $Spec){
  94.                         $specs['spec'][$Spec->getId()] = $SpecValue->getValue();
  95.                     }
  96.                 }
  97.             }
  98.         }else{
  99.             foreach($_POST['specs'] as $k => $spec_id){
  100.                 $value_id $_POST['values'][$k];
  101.                 if($spec_id == 'price'){
  102.                     $price_range explode('-'$value_id);
  103.                     continue;
  104.                 }
  105.                 $Spec $this->getDoctrine()->getRepository('TrinityWebshopBundle:Spec')->find($spec_id);
  106.                 $SpecValue $this->getDoctrine()->getRepository('TrinityWebshopBundle:SpecValue')->find($value_id);
  107.                 if(!empty($Spec) && !empty($SpecValue)){
  108.                     if($SpecValue->getSpec() == $Spec){
  109.                         $specs['spec'][$Spec->getId()] = $SpecValue->getValue();
  110.                     }
  111.                 }
  112.             }
  113.         }
  114.         // Fetch products with specs
  115.         $products_raw $this->getDoctrine()->getRepository('TrinityWebshopBundle:Product')->findAnyBySpecs($specs$price_range);
  116.         $products = [];
  117.         foreach($products_raw as $ProductEntity){
  118.             $products[] = $ProductEntity->getJson($this->WebshopSettings$this->get('router'));
  119.         }
  120.         
  121.         return new JsonResponse([
  122.             'success' => true,
  123.             'products' => $products,
  124.         ], 200);
  125.     }
  126.     /**
  127.      * @Route("/psku/{slug}", name="webshop_shortlink")
  128.      * @Template()
  129.      */
  130.     public function shortlinkRequest $request$slug)
  131.     {
  132.         parent::init($request);
  133.         $url '/';
  134.         $Product $this->getDoctrine()->getRepository('TrinityWebshopBundle:Product')->findOneBySlug($slug);
  135.         if(!empty($Product)){
  136.             $url $this->host . ($this->WebshopSettings->getUri() ? '/' $this->WebshopSettings->getUri() : $this->generateUrl('homepage')) . $Product->getCategory()->first()->getCategory()->getUri() . '/' $Product->getSlug() . '';
  137.         }
  138.         return $this->redirect($url);
  139.     }
  140.     /**
  141.      * @Route("/webshop_data/productcount", name="mod_webshop_count")
  142.      * @Template()
  143.      */
  144.     public function productCountRequest $request$id null)
  145.     {
  146.         // Initialize StorageController
  147.         parent::init($request);
  148.         return $this->attributes([
  149.             // Variables
  150.         ]);
  151.     }
  152.     /**
  153.      * @Route("/webshop_data/primary-address/{id}", name="mod_webshop_primary_address")
  154.      * @Template()
  155.      */
  156.     public function primaryAddressActionRequest $request$id null)
  157.     {
  158.         parent::init($request);
  159.         $em $this->getDoctrine()->getManager();
  160.         $WebshopUser $this->getDoctrine()->getRepository('TrinityWebshopBundle:User')->findOneByUser($this->getUser());
  161.         foreach ($WebshopUser->getAddresses() as $Address) {
  162.             if($Address->getId() == $id){
  163.                 $Address->setPriority(true);
  164.             }else{
  165.                 $Address->setPriority(false);
  166.             }
  167.             $em->persist($Address);
  168.         }
  169.         $em->flush();
  170.         return new JsonResponse([
  171.             'success' => true
  172.         ]);
  173.     }
  174.     public function esi_latestAction(Request $request$config null$params null$Settings null){
  175.         $Settings $this->getDoctrine()->getRepository('TrinityWebshopBundle:Settings')->find($Settings);
  176.         $this->init($request);
  177.         $this->Timer->mark('WEBSHOP: widget_latest | start');
  178.         $locale $Settings->getWebshop()->getLanguage()->getLocale();
  179.         $hash md5(serialize($config) . $locale);
  180.         $cache_file $this->getWidgetCacheFile($hash);
  181.         $widgetCache false
  182.         if($this->WebshopSettings->getWidgetCache()) {
  183.             $widgetCache true;
  184.         }
  185.         if($widgetCache && file_exists($cache_file) && (((time() - filemtime($cache_file)) / 60) / 60) < 3){
  186.             $cache json_decode(file_get_contents($cache_file), true);
  187.         }else{
  188.         $Webshop $this->getDoctrine()->getRepository('TrinityWebshopBundle:Webshop')->getByLanguageAndSettings($this->language$this->Settings);
  189.         $cats null;
  190.         if(!empty($config['category_id']) && is_array($config['category_id'])){
  191.             $cats $config['category_id'];
  192.         }
  193.         if(!empty($config['all_categories'])){
  194.             $cats = [];
  195.         }
  196.         $filters = [];
  197.         if(!empty($config['specs'])){
  198.             foreach($config['specs'] as $k => $id){
  199.                 $filters[$id] = $config['spec_values'][$k];
  200.             }
  201.         }
  202.         // $products = $this->getDoctrine()->getRepository('TrinityWebshopBundle:Product')->findBy(['webshop' => $Webshop, 'enabled' => true, 'visible' => true], ['id' => 'desc'], (!empty($config['limit']) ? (int)$config['limit'] : null), (!empty($config['offset']) ? (int)$config['offset'] : null));
  203.         $products $this->getDoctrine()->getRepository('TrinityWebshopBundle:Product')->search(
  204.             $Webshop// Webshop
  205.             [
  206.                 'category' => $cats,
  207.                 'filters' => $filters,
  208.                     'price' => 1,
  209.                 'visible' => true,
  210.             ], // filters
  211.             'date_modified'// order
  212.             'desc'// orderDir
  213.             false// noLimit
  214.             false// ignoreStock
  215.             1// page
  216.             (!empty($config['limit']) ? (int)$config['limit'] : null// limit
  217.                 0true
  218.         );
  219.         if(isset($products['results'])){
  220.             $products $products['results'];
  221.         }
  222.             $cache = [
  223.                 'config' => $config,
  224.                 'products' => [],
  225.             ];
  226.             foreach($products as $Product){
  227.                 $ProductCategory $Product->getCategory()->first();
  228.                 if(empty($ProductCategory)){
  229.                     continue;
  230.                 }
  231.                 $Category $ProductCategory->getCategory();
  232.                 $uri '';
  233.                 if(!empty($this->WebshopSettings) && !empty($this->WebshopSettings->getUri())){
  234.                     $uri $this->generateUrl('homepage') . $this->WebshopSettings->getUri();
  235.                 }else{
  236.                     if(!empty($this->Settings->getBaseuri())){
  237.                         $uri str_replace('/'''$this->Settings->getBaseuri()) . '/';
  238.                     }
  239.                 }
  240.                 if(!empty($Category)){
  241.                     $uri .= $Category->getUri() . '/';
  242.                 }
  243.                 $uri .= $Product->getSlug();
  244.                 $media '/bundles/trinitywebshop/img/no-product-image.png';
  245.                 $media2 null;
  246.                 $mediaWebp null;
  247.                 $mediaWebp2 null;
  248.                 $mediaMime null;
  249.                 $mediaMime2 null;
  250.                 $mediaBlur null;
  251.                 $mediaBlur2 null;
  252.                 $mediaBlurWebp null;
  253.                 $mediaBlurWebp2 null;
  254.                 if(!empty($Product->getMedia()) && !empty($Product->getMedia()->first())){
  255.                     $pMedia $Product->getMedia()->first();
  256.                     $mediaMime $pMedia->getMime();
  257.                     $media '/' $pMedia->getWebPath('small');
  258.                     if ($pMedia->hasWebp()) {
  259.                         $mediaWebp '/' $pMedia->getWebpPath('small');
  260.                         
  261.                         if ($pMedia->hasBlurred()) {
  262.                             $mediaBlurWebp $pMedia->getBlurredWebpPath();
  263.                         }
  264.                     }
  265.                     
  266.                     if ($pMedia->hasBlurred()) {
  267.                         $mediaBlur $pMedia->getBlurredWebPath();                        
  268.                     }
  269.                     if ($Product->getMedia()->count() > 1) {
  270.                         $pMedia2 $Product->getMedia()->next();
  271.                         $mediaMime2 $pMedia2->getMime();
  272.                         $media2 '/' $pMedia2->getWebPath('small');
  273.                     
  274.                        if ($pMedia2->hasWebp()) {
  275.                             $mediaWebp2 '/' $pMedia2->getWebpPath('small');
  276.                             if ($pMedia->hasBlurred()) {
  277.                                 $mediaBlurWebp2 $pMedia->getBlurredWebpPath();
  278.                             }
  279.                         }
  280.                         if ($pMedia->hasBlurred()) {
  281.                             $mediaBlur2 $pMedia->getBlurredWebPath();
  282.                         }
  283.                     }
  284.                 }else{
  285.                     if($this->WebshopSettings->getDefaultProductImage()){
  286.                         $media $this->WebshopSettings->getDefaultProductImage();
  287.                     }
  288.                 }
  289.   
  290.                 
  291.                 
  292.                 if($Category->getLabel() != 'Ongesorteerd'){
  293.                     $cache['products'][] = [
  294.                         'id'           => $Product->getId(),
  295.                         'number'       => $Product->getNumber(),
  296.                         'uri'          => $uri,
  297.                         'new'          => $Product->getNew(),
  298.                         'hasPromotion' => $Product->hasPromotion(),
  299.                         'hasCombi'     => $Product->hasCombi(),
  300.                         'exclusive'     => $Product->getExclusive(),
  301.                         'newFrom'      => $Product->getNewFrom(),
  302.                         'canOrder'     => $Product->canOrder(),
  303.                         'newTill'      => $Product->getNewTill(),
  304.                         'priceSale'    => $Product->getPriceSale(),
  305.                         'priceSalePercent'  => $Product->getPriceSalePercent(),
  306.                         'label'        => $Product->getLabel(),
  307.                         'labelSub'     => $Product->getLabelSub(),
  308.                         'brand'        => $Product->getBrand(),
  309.                         'type'         => $Product->getType(),
  310.                         'intro'        => $Product->getIntro() ?? '',
  311.                         'price'        => $Product->getDisplayPrice($this->WebshopSettings),
  312.                         'visible'      => $Product->getVisible(),
  313.                         'enabled'      => $Product->getEnabled(),
  314.                         'mediaMime'    => $mediaMime,
  315.                         'mediaMime2'   => $mediaMime2,
  316.                         'media'        => $media,
  317.                         'media2'       => $media2,
  318.                         'mediaWebp'    => $mediaWebp,
  319.                         'mediaWebp2'   => $mediaWebp2,
  320.                         'mediaBlur'    => $mediaBlur,
  321.                         'mediaBlur2'   => $mediaBlur2,
  322.                         'mediaBlurWebp' => $mediaBlurWebp,
  323.                         'mediaBlurWebp2' => $mediaBlurWebp2,
  324.                         'category'     => [
  325.                             'id'    => $Category->getId(),
  326.                             'label' => $Category->getLabel(),
  327.                         ],
  328.                     ];
  329.                 }
  330.                 file_put_contents($cache_filejson_encode($cache));
  331.             }
  332.         }
  333.         $this->Timer->mark('WEBSHOP: widget_latest | end');
  334.         $response $this->render('@TrinityWebshop/default/esi_widget_latest.html.twig'$this->attributes([
  335.             'config'   => $cache['config'],
  336.             'params' => $params,
  337.             'products' => $cache['products'],
  338.         ]));
  339.         if(!empty($this->cache_widget)){
  340.             $response->headers->set(AbstractSessionListener::NO_AUTO_CACHE_CONTROL_HEADER'true');
  341.             $response->setPublic();
  342.             $response->setMaxAge($this->cache_widget);
  343.             $response->headers->addCacheControlDirective('must-revalidate');  
  344.             $response->setVary(array('Accept-Encoding''User-Agent'));
  345.             $response->headers->addCacheControlDirective('max-age'$this->cache_widget);
  346.             $response->setSharedMaxAge($this->cache_widget);
  347.         }
  348.         return $response;
  349.     }
  350.     public function widget_latest($config$params$SettingsRequest $request){
  351.         return $this->renderView('@TrinityWebshop/default/widget_latest.html.twig'$this->attributes([
  352.             'esi_config'   => $config,
  353.             'esi_params'   => $params,
  354.             'esi_Settings' => $Settings->getId(), // For caching an ID is needed
  355.         ]));
  356.     }
  357.     public function esi_productsAction(Request $request$config null$params null$Settings null){
  358.         $Settings $this->getDoctrine()->getRepository('TrinityWebshopBundle:Settings')->find($Settings);
  359.         $this->init($request);
  360.         $this->Timer->mark('WEBSHOP: widget_products | start');
  361.         $locale $Settings->getWebshop()->getLanguage()->getLocale();
  362.         $hash md5(serialize($config) . $locale);
  363.         $cache_file str_replace('src/Trinity/WebshopBundle/Controller''var/cache/webshop/'__DIR__) . $hash;
  364.         $widgetCache false;
  365.         if($this->WebshopSettings->getWidgetCache()) {
  366.             $widgetCache true;
  367.         }
  368.         if($widgetCache && file_exists($cache_file) && (((time() - filemtime($cache_file)) / 60) / 60) < 3){
  369.             $cache json_decode(file_get_contents($cache_file), true);
  370.         }else{
  371.         $Webshop $this->getDoctrine()->getRepository('TrinityWebshopBundle:Webshop')->getByLanguageAndSettings($this->language$this->Settings);
  372.             
  373.         $filters = [];
  374.         if(!empty($config['specs'])){
  375.             foreach($config['specs'] as $k => $id){
  376.                 $filters[$id] = $config['spec_values'][$k];
  377.             }
  378.         }
  379.         $products = [];
  380.         $description '';
  381.         if(!empty($config['category_id'])){
  382.             $products $this->getDoctrine()->getRepository('TrinityWebshopBundle:Product')->search($Webshop, [
  383.                 'filters' => $filters,
  384.                     'price' => 1,
  385.                     'visible' => true,
  386.                     'category' => $config['category_id'],
  387.                     ], 'pos''desc'falsefalse1$config['limit'], 0true);
  388.             if(count($config['category_id']) === 1){
  389.                 $Category $this->getDoctrine()->getRepository('TrinityWebshopBundle:Category')->find($config['category_id'][0]);
  390.                 if(!empty($Category)){
  391.                     $description $Category->getDescription();
  392.                 }
  393.             }
  394.         }else{
  395.             $products $this->getDoctrine()->getRepository('TrinityWebshopBundle:Product')->search($Webshop, [
  396.                 'filters' => $filters,
  397.                 'price' => 1,
  398.                 'visible' => true,
  399.                 ], 'pos''desc'falsefalse1$config['limit'], 0true);
  400.         }
  401.             if(isset($products['results'])){
  402.                 $products $products['results'];
  403.             }
  404.             $cache = [
  405.             'config' => $config,
  406.                 'products' => [],
  407.             ];
  408.             foreach($products as $Product){
  409.                 $ProductCategory $Product->getCategory()->first();
  410.                 $Category $ProductCategory->getCategory();
  411.                 $uri '/';
  412.                 if(!empty($this->WebshopSettings) && !empty($this->WebshopSettings->getUri())){
  413.                     $uri $this->generateUrl('homepage') . $this->WebshopSettings->getUri();
  414.                 }else{
  415.                     if(!empty($this->Settings->getBaseuri())){
  416.                         $uri str_replace('/'''$this->Settings->getBaseuri()) . '/';
  417.                     }
  418.                 }
  419.                 if(!empty($Category)){
  420.                     $uri .= $Category->getUri() . '/';
  421.                 }
  422.                 $uri .= $Product->getSlug();
  423.                 $media '/bundles/trinitywebshop/img/no-product-image.png';
  424.                 $media2 null;
  425.                 $mediaWebp null;
  426.                 $mediaWebp2 null;
  427.                 $mediaMime null;
  428.                 $mediaMime2 null;
  429.                 $mediaBlur null;
  430.                 $mediaBlur2 null;
  431.                 $mediaBlurWebp null;
  432.                 $mediaBlurWebp2 null;
  433.                 if(!empty($Product->getMedia()) && !empty($Product->getMedia()->first())){
  434.                     $pMedia $Product->getMedia()->first();
  435.                     $mediaMime $pMedia->getMime();
  436.                     $media '/' $pMedia->getWebPath('small');
  437.                     if ($pMedia->hasWebp()) {
  438.                         $mediaWebp '/' $pMedia->getWebpPath('small');
  439.                         
  440.                         if ($pMedia->hasBlurred()) {
  441.                             $mediaBlurWebp '/' $pMedia->getBlurredWebpPath();
  442.                         }
  443.                     }
  444.                     
  445.                     if ($pMedia->hasBlurred()) {
  446.                         $mediaBlur '/' $pMedia->getBlurredWebPath();                        
  447.                     }
  448.                     if ($Product->getMedia()->count() > 1) {
  449.                         $pMedia2 $Product->getMedia()->next();
  450.                         $mediaMime2 $pMedia2->getMime();
  451.                         $media2 '/' $pMedia2->getWebPath('small');
  452.                     
  453.                        if ($pMedia2->hasWebp()) {
  454.                             $mediaWebp2 '/' $pMedia2->getWebpPath('small');
  455.                             if ($pMedia->hasBlurred()) {
  456.                                 $mediaBlurWebp2 '/' $pMedia->getBlurredWebpPath();
  457.                             }
  458.                         }
  459.                         if ($pMedia->hasBlurred()) {
  460.                             $mediaBlur2 '/' $pMedia->getBlurredWebPath();
  461.                         }
  462.                     }
  463.                 }else{
  464.                     if($this->WebshopSettings->getDefaultProductImage()){
  465.                         $media $this->WebshopSettings->getDefaultProductImage();
  466.                     }
  467.                 }
  468.                 if($Category->getLabel() != 'Ongesorteerd'){
  469.                     $cache['products'][] = [
  470.                         'id'           => $Product->getId(),
  471.                         'uri'          => $uri,
  472.                         'new'          => $Product->getNew(),
  473.                         'hasPromotion' => $Product->hasPromotion(),
  474.                         'hasCombi'     => $Product->hasCombi(),
  475.                         'exclusive'     => $Product->getExclusive(),
  476.                         'newFrom'      => $Product->getNewFrom(),
  477.                         'canOrder'     => $Product->canOrder(),
  478.                         'newTill'      => $Product->getNewTill(),
  479.                         'priceSale'    => $Product->getPriceSale(),
  480.                         'priceSalePercent'  => $Product->getPriceSalePercent(),
  481.                         'label'        => $Product->getLabel(),
  482.                         'labelSub'     => $Product->getLabelSub(),
  483.                         'brand'        => $Product->getBrand(),
  484.                         'type'         => $Product->getType(),
  485.                         'intro'        => $Product->getIntro() ?? '',
  486.                         'price'        => $Product->getDisplayPrice($this->WebshopSettings),
  487.                         'visible'      => $Product->getVisible(),
  488.                         'enabled'      => $Product->getEnabled(),
  489.                         'mediaMime'    => $mediaMime,
  490.                         'mediaMime2'   => $mediaMime2,
  491.                         'media'        => $media,
  492.                         'media2'       => $media2,
  493.                         'mediaWebp'    => $mediaWebp,
  494.                         'mediaWebp2'   => $mediaWebp2,
  495.                         'mediaBlur'    => $mediaBlur,
  496.                         'mediaBlur2'   => $mediaBlur2,
  497.                         'mediaBlurWebp' => $mediaBlurWebp,
  498.                         'mediaBlurWebp2' => $mediaBlurWebp2,
  499.                         'category'     => [
  500.                             'id'    => $Category->getId(),
  501.                             'label' => $Category->getLabel(),
  502.                         ],
  503.                     ];
  504.                 }
  505.                 file_put_contents($cache_filejson_encode($cache));
  506.             }
  507.         }
  508.         $this->Timer->mark('WEBSHOP: widget_products | end');
  509.         $response $this->render('@TrinityWebshop/default/esi_widget_products.html.twig'$this->attributes([
  510.             'config'      => $cache['config'],
  511.             'params'      => $params,
  512.             'description' => '',//$description,
  513.             'products'    => $cache['products'],
  514.         ]));
  515.         if(!empty($this->cache_widget)){
  516.             $response->headers->set(AbstractSessionListener::NO_AUTO_CACHE_CONTROL_HEADER'true');
  517.             $response->setPublic();
  518.             $response->setMaxAge($this->cache_widget);
  519.             $response->headers->addCacheControlDirective('must-revalidate');  
  520.             $response->setVary(array('Accept-Encoding''User-Agent'));
  521.             $response->headers->addCacheControlDirective('max-age'$this->cache_widget);
  522.             $response->setSharedMaxAge($this->cache_widget);
  523.         }
  524.         return $response;
  525.     }
  526.     public function widget_products($config$params$SettingsRequest $request){
  527.         return $this->renderView('@TrinityWebshop/default/widget_products.html.twig'$this->attributes([
  528.             'esi_config'   => $config,
  529.             'esi_params'   => $params,
  530.             'esi_Settings' => $Settings->getId(), // For caching an ID is needed
  531.         ]));
  532.     }
  533.     public function esi_subcategoryAction(Request $request$config null$params null$Settings null){
  534.         $Settings $this->getDoctrine()->getRepository('TrinityWebshopBundle:Settings')->find($Settings);
  535.         $this->init($request);
  536.         $this->Timer->mark('WEBSHOP: widget_subcategory | start');
  537.         $locale $Settings->getWebshop()->getLanguage()->getLocale();
  538.         $hash md5(serialize($config) . $locale);
  539.         $cache_file $this->getWidgetCacheFile($hash);
  540.         $widgetCache false;
  541.         if($this->WebshopSettings->getWidgetCache()) {
  542.             $widgetCache true;
  543.         }
  544.         if($widgetCache && file_exists($cache_file) && (((time() - filemtime($cache_file)) / 60) / 60) < && (((time() - filemtime($cache_file)) / 60) / 60) < 3){
  545.             $cache json_decode(file_get_contents($cache_file), true);
  546.         }else{
  547.             $cache = [
  548.                 'config'     => $config,
  549.                 'categories' => [],
  550.             ];
  551.         $C null;
  552.         $counts = [];
  553.         if(!empty($config['category_id'])){
  554.             if(!is_array($config['category_id'])) $config['category_id'] = [$config['category_id']];
  555.             foreach($config['category_id'] as $id){
  556.                     $cache['categories'] = $this->getDoctrine()->getRepository('TrinityWebshopBundle:Category')->findSubsWithCounts($id0);
  557.                 /*$C = $this->getDoctrine()->getRepository('TrinityWebshopBundle:Category')->findBy();
  558.                 $n = 1;
  559.                 foreach($C->getChildren() as $SC){
  560.                     $categories[$SC->getId()] = $SC;
  561.                     if(!empty($config['limit']) && $n >= $config['limit']){
  562.                         break;
  563.                     }
  564.                     $n++;
  565.                 }*/
  566.             }
  567.         }
  568.             file_put_contents($cache_filejson_encode($cache));
  569.         }
  570.         $this->Timer->mark('WEBSHOP: widget_subcategory | end');
  571.         $response $this->render('@TrinityWebshop/default/esi_widget_subcategory.html.twig'$this->attributes([
  572.             'config'     => $config,
  573.             'params'     => $params,
  574.             // 'counts'     => $counts,
  575.             // 'C'          => $C,
  576.             'categories' => $cache['categories'],
  577.         ]));
  578.         if(!empty($this->cache_widget)){
  579.             $response->headers->set(AbstractSessionListener::NO_AUTO_CACHE_CONTROL_HEADER'true');
  580.             $response->setPublic();
  581.             $response->setMaxAge($this->cache_widget);
  582.             $response->headers->addCacheControlDirective('must-revalidate');  
  583.             $response->setVary(array('Accept-Encoding''User-Agent'));
  584.             $response->headers->addCacheControlDirective('max-age'$this->cache_widget);
  585.             $response->setSharedMaxAge($this->cache_widget);
  586.         }
  587.         return $response;
  588.     }
  589.     public function widget_subcategory($config$params$SettingsRequest $request){
  590.         return $this->renderView('@TrinityWebshop/default/widget_subcategory.html.twig'$this->attributes([
  591.             'esi_config'   => $config,
  592.             'esi_params'   => $params,
  593.             'esi_Settings' => $Settings->getId(), // For caching an ID is needed
  594.         ]));
  595.     }
  596.     public function widget_searchwithcat($config$params$SettingsRequest $request){
  597.         $this->init($request);
  598.         $this->Timer->mark('WEBSHOP: widget_searchwithcat | start');
  599.         $categories = [];
  600.         $Webshop $this->getDoctrine()->getRepository('TrinityWebshopBundle:Webshop')->getByLanguageAndSettings($this->language$this->Settings);
  601.         $Categories $this->getDoctrine()->getRepository('TrinityWebshopBundle:Category')->findBy(['webshop' => $Webshop]);
  602.         foreach ($Categories as $cat) {
  603.             if(empty($cat->getParent())){
  604.                 array_push($categories$cat);
  605.             }
  606.         }
  607.         $specs = [];
  608.         if(!empty($config['specs'])){
  609.             foreach($config['specs'] as $specid){
  610.                 $specs[$specid] = $this->getDoctrine()->getRepository('TrinityWebshopBundle:Spec')->find($specid);
  611.             }
  612.         }
  613.         // $categories = [];
  614.         // if(!empty($config['category_id'])){
  615.         //     if(!is_array($config['category_id'])) $config['category_id'] = [$config['category_id']];
  616.         //     foreach($config['category_id'] as $id){
  617.         //         $C = $this->getDoctrine()->getRepository('TrinityWebshopBundle:Category')->find($id);
  618.         //         foreach($C->getChildren() as $SC){
  619.         //             $categories[$SC->getId()] = $SC;
  620.         //         }
  621.         //     }
  622.         // }
  623.         $this->Timer->mark('WEBSHOP: widget_searchwithcat | end');
  624.         
  625.         return $this->renderView('@TrinityWebshop/default/widget_searchwithcat.html.twig'$this->attributes([
  626.             'config' => $config,
  627.             'params' => $params,
  628.             'categories' => $categories,
  629.             'specs' => $specs,
  630.         ]));
  631.     }
  632.     public function widget_categories($config$params$SettingsRequest $request){
  633.         $this->init($request);
  634.         $this->Timer->mark('WEBSHOP: widget_categories | start');
  635.         $categories = [];
  636.         if(!empty($config['category_id'])){
  637.             if(!is_array($config['category_id'])) $config['category_id'] = [$config['category_id']];
  638.             foreach($config['category_id'] as $id){
  639.                 $C $this->getDoctrine()->getRepository('TrinityWebshopBundle:Category')->find($id);
  640.                 foreach($C->getChildren() as $SC){
  641.                     $categories[$SC->getId()] = $SC;
  642.                 }
  643.             }
  644.         }
  645.         $this->Timer->mark('WEBSHOP: widget_categories | end');
  646.         return $this->renderView('@TrinityWebshop/default/widget_categories.html.twig'$this->attributes([
  647.             'config' => $config,
  648.             'params' => $params,
  649.             'categories' => $categories,
  650.         ]));
  651.     }
  652.     public function esi_featuredAction(Request $request$config null$params null$Settings null){
  653.         $Settings $this->getDoctrine()->getRepository('TrinityWebshopBundle:Settings')->find($Settings);
  654.         $this->init($request);
  655.         $this->Timer->mark('WEBSHOP: widget_featured | start');
  656.         $Webshop $this->getDoctrine()->getRepository('TrinityWebshopBundle:Webshop')->getByLanguageAndSettings($this->language$this->Settings);
  657.         $cats null;
  658.         if(!empty($config['category_id']) && is_array($config['category_id'])){
  659.             $cats $config['category_id'];
  660.         }
  661.         if(!empty($config['all_categories'])){
  662.             $cats = [];
  663.         }
  664.         $filters = [];
  665.         if(!empty($config['specs'])){
  666.             foreach($config['specs'] as $k => $id){
  667.                 $filters[$id] = $config['spec_values'][$k];
  668.             }
  669.         }
  670.         // $products = $this->getDoctrine()->getRepository('TrinityWebshopBundle:Product')->findBy(['webshop' => $Webshop, 'enabled' => true, 'visible' => true], ['id' => 'desc'], (!empty($config['limit']) ? (int)$config['limit'] : null), (!empty($config['offset']) ? (int)$config['offset'] : null));
  671.         $products $this->getDoctrine()->getRepository('TrinityWebshopBundle:Product')->search(
  672.             $Webshop// Webshop
  673.             [
  674.                 'category' => $cats,
  675.                 'filters' => $filters,
  676.                 'featured' => true,
  677.                 'visible' => true,
  678.                 // 'debug' => true,
  679.             ], // filters
  680.             'id'// order
  681.             'desc'// orderDir
  682.             false// noLimit
  683.             false// ignoreStock
  684.             1// page
  685.             (!empty($config['limit']) ? (int)$config['limit'] : null// limit
  686.         );
  687.         if(isset($products['results'])){
  688.             $products $products['results'];
  689.         }
  690.         $this->Timer->mark('WEBSHOP: widget_featured | end');
  691.         $response $this->render('@TrinityWebshop/default/esi_widget_featured.html.twig'$this->attributes([
  692.             'config' => $config,
  693.             'params' => $params,
  694.             'products' => $products,
  695.         ]));
  696.         if(!empty($this->cache_widget)){
  697.             $response->headers->set(AbstractSessionListener::NO_AUTO_CACHE_CONTROL_HEADER'true');
  698.             $response->setPublic();
  699.             $response->setMaxAge($this->cache_widget);
  700.             $response->headers->addCacheControlDirective('must-revalidate');  
  701.             $response->setVary(array('Accept-Encoding''User-Agent'));
  702.             $response->headers->addCacheControlDirective('max-age'$this->cache_widget);
  703.             $response->setSharedMaxAge($this->cache_widget);
  704.         }
  705.         return $response;
  706.     }
  707.     public function widget_featured($config$params$SettingsRequest $request){
  708.         return $this->renderView('@TrinityWebshop/default/widget_featured.html.twig'$this->attributes([
  709.             'esi_config'   => $config,
  710.             'esi_params'   => $params,
  711.             'esi_Settings' => $Settings->getId(), // For caching an ID is needed
  712.         ]));
  713.     }
  714.     public function esi_discountedAction(Request $request$config null$params null$Settings null){
  715.         $Settings $this->getDoctrine()->getRepository('TrinityWebshopBundle:Settings')->find($Settings);
  716.         $this->init($request);
  717.         $this->Timer->mark('WEBSHOP: widget_discounted | start');
  718.         $cats null;
  719.         if(!empty($config['category_id']) && is_array($config['category_id'])){
  720.             $cats $config['category_id'];
  721.         }
  722.         if(!empty($config['all_categories'])){
  723.             $cats = [];
  724.         }
  725.         $filters = [];
  726.         $Webshop $this->getDoctrine()->getRepository('TrinityWebshopBundle:Webshop')->getByLanguageAndSettings($this->language$this->Settings);
  727.         $products $this->getDoctrine()->getRepository('TrinityWebshopBundle:Product')->search(
  728.             $Webshop// Webshop
  729.             [
  730.                 'category' => $cats,
  731.                 'filters' => $filters,
  732.                 'discount' => true,
  733.                 'visible' => true,
  734.             ], // filters
  735.             'id'// order
  736.             'desc'// orderDir
  737.             false// noLimit
  738.             false// ignoreStock
  739.             1// page
  740.             (!empty($config['limit']) ? (int)$config['limit'] : null// limit
  741.         );
  742.             if(isset($products['results'])){
  743.                 $products $products['results'];
  744.             }
  745.             $cache = [
  746.             'config' => $config,
  747.                 'products' => [],
  748.             ];
  749.             foreach($products as $Product){
  750.                 $ProductCategory $Product->getCategory()->first();
  751.                 $Category $ProductCategory->getCategory();
  752.                 $uri '';
  753.                 if(!empty($this->WebshopSettings) && !empty($this->WebshopSettings->getUri())){
  754.                     $uri $this->generateUrl('homepage') . $this->WebshopSettings->getUri();
  755.                 }else{
  756.                     if(!empty($this->Settings->getBaseuri())){
  757.                         $uri str_replace('/'''$this->Settings->getBaseuri()) . '/';
  758.                     }
  759.                 }
  760.                 if(!empty($Category)){
  761.                     $uri .= $Category->getUri() . '/';
  762.                 }
  763.                 $uri .= $Product->getSlug();
  764.                 $media '/bundles/trinitywebshop/img/no-product-image.png';
  765.                 $media2 null;
  766.                 $mediaWebp null;
  767.                 $mediaWebp2 null;
  768.                 $mediaMime null;
  769.                 $mediaMime2 null;
  770.                 $mediaBlur null;
  771.                 $mediaBlur2 null;
  772.                 $mediaBlurWebp null;
  773.                 $mediaBlurWebp2 null;
  774.                 if(!empty($Product->getMedia()) && !empty($Product->getMedia()->first())){
  775.                     $pMedia $Product->getMedia()->first();
  776.                     $mediaMime $pMedia->getMime();
  777.                     $media '/' $pMedia->getWebPath('small');
  778.                     if ($pMedia->hasWebp()) {
  779.                         $mediaWebp '/' $pMedia->getWebpPath('small');
  780.                         
  781.                         if ($pMedia->hasBlurred()) {
  782.                             $mediaBlurWebp '/' $pMedia->getBlurredWebpPath();
  783.                         }
  784.                     }
  785.                     
  786.                     if ($pMedia->hasBlurred()) {
  787.                         $mediaBlur '/' $pMedia->getBlurredWebPath();                        
  788.                     }
  789.                     if ($Product->getMedia()->count() > 1) {
  790.                         $pMedia2 $Product->getMedia()->next();
  791.                         $mediaMime2 $pMedia2->getMime();
  792.                         $media2 '/' $pMedia2->getWebPath('small');
  793.                     
  794.                        if ($pMedia2->hasWebp()) {
  795.                             $mediaWebp2 '/' $pMedia2->getWebpPath('small');
  796.                             if ($pMedia->hasBlurred()) {
  797.                                 $mediaBlurWebp2 '/' $pMedia->getBlurredWebpPath();
  798.                             }
  799.                         }
  800.                         if ($pMedia->hasBlurred()) {
  801.                             $mediaBlur2 '/' $pMedia->getBlurredWebPath();
  802.                         }
  803.                     }
  804.                 }else{
  805.                     if($this->WebshopSettings->getDefaultProductImage()){
  806.                         $media $this->WebshopSettings->getDefaultProductImage();
  807.                     }
  808.                 }
  809.                 if($Category->getLabel() != 'Ongesorteerd'){
  810.                     $cache['products'][] = [
  811.                         'id'           => $Product->getId(),
  812.                         'uri'          => $uri,
  813.                         'new'          => $Product->getNew(),
  814.                         'hasPromotion' => $Product->hasPromotion(),
  815.                         'hasCombi'     => $Product->hasCombi(),
  816.                         'exclusive'     => $Product->getExclusive(),
  817.                         'newFrom'      => $Product->getNewFrom(),
  818.                         'canOrder'     => $Product->canOrder(),
  819.                         'newTill'      => $Product->getNewTill(),
  820.                         'priceSale'    => $Product->getPriceSale(),
  821.                         'priceSalePercent'  => $Product->getPriceSalePercent(),
  822.                         'label'        => $Product->getLabel(),
  823.                         'labelSub'     => $Product->getLabelSub(),
  824.                         'brand'        => $Product->getBrand(),
  825.                         'type'         => $Product->getType(),
  826.                         'intro'        => $Product->getIntro() ?? '',
  827.                         'price'        => $Product->getDisplayPrice($this->WebshopSettings),
  828.                         'visible'      => $Product->getVisible(),
  829.                         'enabled'      => $Product->getEnabled(),
  830.                         'mediaMime'    => $mediaMime,
  831.                         'mediaMime2'   => $mediaMime2,
  832.                         'media'        => $media,
  833.                         'media2'       => $media2,
  834.                         'mediaWebp'    => $mediaWebp,
  835.                         'mediaWebp2'   => $mediaWebp2,
  836.                         'mediaBlur'    => $mediaBlur,
  837.                         'mediaBlur2'   => $mediaBlur2,
  838.                         'mediaBlurWebp' => $mediaBlurWebp,
  839.                         'mediaBlurWebp2' => $mediaBlurWebp2,
  840.                         'category'     => [
  841.                             'id'    => $Category->getId(),
  842.                             'label' => $Category->getLabel(),
  843.                         ],
  844.                     ];
  845.                 }
  846.                 // file_put_contents($cache_file, json_encode($cache));
  847.             }
  848.         //$products = $this->getDoctrine()->getRepository('TrinityWebshopBundle:Product')->getByDiscounted($Webshop, (!empty($config['limit']) ? (int)$config['limit'] : null), $config);
  849.         //$products = $this->getDoctrine()->getRepository('TrinityWebshopBundle:Product')->findBy(['webshop' => $Webshop, 'discount' => true, 'enabled' => true, 'visible' => true], ['label' => 'asc'], (!empty($config['limit']) ? (int)$config['limit'] : null));
  850.         
  851.         // dump($products);die();
  852.         $this->Timer->mark('WEBSHOP: widget_discounted | end');
  853.         $response $this->render('@TrinityWebshop/default/esi_widget_discounted.html.twig'$this->attributes([
  854.             'config' => $config,
  855.             'params' => $params,
  856.             'products' => $cache['products'],
  857.         ]));
  858.         if(!empty($this->cache_widget)){
  859.             $response->headers->set(AbstractSessionListener::NO_AUTO_CACHE_CONTROL_HEADER'true');
  860.             $response->setPublic();
  861.             $response->setMaxAge($this->cache_widget);
  862.             $response->headers->addCacheControlDirective('must-revalidate');  
  863.             $response->setVary(array('Accept-Encoding''User-Agent'));
  864.             $response->headers->addCacheControlDirective('max-age'$this->cache_widget);
  865.             $response->setSharedMaxAge($this->cache_widget);
  866.         }
  867.         return $response;
  868.     }
  869.     public function widget_discounted($config$params$SettingsRequest $request){
  870.         return $this->renderView('@TrinityWebshop/default/widget_discounted.html.twig'$this->attributes([
  871.             'esi_config'   => $config,
  872.             'esi_params'   => $params,
  873.             'esi_Settings' => $Settings->getId(), // For caching an ID is needed
  874.         ]));
  875.     }
  876.     public function widget_popular($config$params$SettingsRequest $request){
  877.         parent::init($request);
  878.         $this->Timer->mark('WEBSHOP: widget_popular | start');
  879.         $Webshop $this->getDoctrine()->getRepository('TrinityWebshopBundle:Webshop')->getByLanguageAndSettings($this->language$this->Settings);
  880.         $products $this->getDoctrine()->getRepository('TrinityWebshopBundle:Product')->getBestSoldAllowed($Webshop, (!empty($config['limit']) ? (int)$config['limit'] : null));
  881.         $this->Timer->mark('WEBSHOP: widget_popular | end');
  882.         return $this->renderView('@TrinityWebshop/default/widget_popular.html.twig'$this->attributes([
  883.             'config' => $config,
  884.             'params' => $params,
  885.             'products' => $products,
  886.         ]));
  887.     }
  888.     public function widget_homecats($config$params$SettingsRequest $request){
  889.         parent::init($request);
  890.         $this->Timer->mark('WEBSHOP: widget_homecats | start');
  891.         $Webshop $this->getDoctrine()->getRepository('TrinityWebshopBundle:Webshop')->getByLanguageAndSettings($this->language$this->Settings);
  892.         $categories $this->getDoctrine()->getRepository('TrinityWebshopBundle:Category')->findBy(['webshop' => $Webshop'homepage' => true], ['position' => 'asc']);
  893.         $this->Timer->mark('WEBSHOP: widget_homecats | end');
  894.         return $this->renderView('@TrinityWebshop/default/widget_homecats.html.twig'$this->attributes([
  895.             'config' => $config,
  896.             'params' => $params,
  897.             'categories' => $categories,
  898.         ]));
  899.     }
  900.     public function widget_choice_flow($config$params$SettingsRequest $request){
  901.         parent::init($request);
  902.         $this->Timer->mark('WEBSHOP: widget_choice_flow | start');
  903.         $Webshop $this->getDoctrine()->getRepository('TrinityWebshopBundle:Webshop')->getByLanguageAndSettings($this->language$this->Settings);
  904.         $this->Timer->mark('WEBSHOP: widget_choice_flow | end');
  905.         $specs $config['specs'];
  906.         // Loop through specs and get spec entities
  907.         foreach($specs as $k => $specId){
  908.             $Spec $this->getDoctrine()->getRepository('TrinityWebshopBundle:Spec')->findOneBy(['id' => $specId'type' => 'dropdown']);
  909.             if(!empty($Spec)){
  910.                 $specs[$k] = $Spec;
  911.             }
  912.         }
  913.         return $this->renderView('@TrinityWebshop/default/widget_choice_flow.html.twig'$this->attributes([
  914.             'config' => $config,
  915.             'params' => $params,
  916.             'specs' => $specs,
  917.         ]));
  918.     }
  919.     public function widget_category_masonry($config$params$SettingsRequest $request){
  920.         $this->init($request);
  921.         return $this->renderView('@TrinityWebshop/default/widget_category_masonry.html.twig'$this->attributes([
  922.             'config' => $config,
  923.             'params' => $params,
  924.             //
  925.         ]));
  926.     }
  927.     /**
  928.      * @Route("/webshop_data/order/dl/{id}", name="webshop_order_dl")
  929.      */
  930.     public function orderDlActionRequest $request$id null)
  931.     {
  932.         // Initialize StorageController
  933.         parent::init($request);
  934.         $Order $this->getDoctrine()->getRepository('TrinityWebshopBundle:Order')->find((int)$id);
  935.         if($this->getUser() && $Order->getUser()->getId() == $this->getUser()->getId()){
  936.             // $tpl = str_replace('/Controller', '/Resources/public/invoice_template.html', __DIR__);
  937.             $tplPath '@TrinityWebshop/invoice_template.html.twig';
  938.             $customTplPath preg_replace('/src\/.*?$/''templates/invoice_template.html.twig'__DIR__);
  939.             if(file_exists($customTplPath)){
  940.                 $tplPath '/invoice_template.html.twig';
  941.             }
  942.             $tpl $this->renderView($tplPath$this->attributes([
  943.                 'Order'           => $Order,
  944.             ]));
  945.             $html $tpl;
  946.             $pdf $this->container->get("qipsius.tcpdf")->create();
  947.             $pdf->AddPage();
  948.             $pdf->writeHTML($htmltruefalsetruefalse'');
  949.             $pdf->Output('invoice_' $id '.pdf''D');
  950.             exit;
  951.         }
  952.         throw $this->createNotFoundException($this->trans('Het product bestaat niet', [], "webshop"));
  953.     }
  954.     public function widget_profile_orders($config$params$SettingsRequest $request$finish false){
  955.         parent::init($request);
  956.         if($params[0] == 'dl'){
  957.             // Download file
  958.             $OrderProduct $this->getDoctrine()->getRepository('TrinityWebshopBundle:OrderProduct')->find((int)$params[1]);
  959.             if(!empty($OrderProduct)){
  960.                 $em $this->getDoctrine()->getManager();
  961.                 $Order $OrderProduct->getOrder();
  962.                 $Product $OrderProduct->getProduct();
  963.                 if(!empty($Order) && !empty($Order) && $Order->getUser()->getUser() == $this->getUser()){
  964.                     $File $this->getDoctrine()->getRepository('TrinityWebshopBundle:ProductFile')->findOneBy(['product' => $Product'id' => $params[2]]);
  965.                     if(!empty($File)){
  966.                         $previousDownloads $this->getDoctrine()->getRepository('TrinityWebshopBundle:ProductFileDownload')->findBy(['file' => $File'order_product' => $OrderProduct]);
  967.                         $n count($previousDownloads);
  968.                         /*if($Product->getDownloadLimit() > 0 && $n >= $Product->getDownloadLimit()){
  969.                             throw $this->createNotFoundException($this->trans('Het gekozen bestand is niet meer beschikbaar.', [], "webshop"));
  970.                         }
  971.                         if($Product->getDownloadDays() > 0){
  972.                             $days_offset = date('YmdHis', strtotime('-' . $Product->getDownloadDays() . ' day'));
  973.                             if($Order->getDate()->format('YmdHis') <= $days_offset){
  974.                                 throw $this->createNotFoundException($this->trans('Het gekozen bestand is niet meer beschikbaar.', [], "webshop"));
  975.                             }
  976.                         }*/
  977.                         $h = new \App\Trinity\WebshopBundle\Entity\ProductFileDownload();
  978.                         $h->setDate(new \DateTime());
  979.                         $h->setUser($this->getUser());
  980.                         $h->setOrder($Order);
  981.                         $h->setOrderProduct($OrderProduct);
  982.                         $h->setFile($File);
  983.                         $em->persist($h);
  984.                         $em->flush();
  985.                         $file     $File->getMedia()->getAbsolutePath();
  986.                         $basename basename($file);
  987.                         $length   sprintf("%u"filesize($file));
  988.                         header('Content-Description: File Transfer');
  989.                         header('Content-Type: application/octet-stream');
  990.                         header('Content-Disposition: attachment; filename="' $basename '"');
  991.                         header('Content-Transfer-Encoding: binary');
  992.                         header('Connection: Keep-Alive');
  993.                         header('Expires: 0');
  994.                         header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
  995.                         header('Pragma: public');
  996.                         // header('Content-Length: ' . $length);
  997.                         ob_end_flush();   // <--- instead of ob_clean()
  998.                         set_time_limit(0);
  999.                         readfile($file);
  1000.                         return;
  1001.                     }else{
  1002.                         throw $this->createNotFoundException($this->trans('Het gekozen bestand bestaat niet.', [], "webshop"));
  1003.                     }
  1004.                 }else{
  1005.                     throw $this->createNotFoundException($this->trans('Het gekozen bestand bestaat niet.', [], "webshop"));
  1006.                 }
  1007.             }else{
  1008.                 throw $this->createNotFoundException($this->trans('Het gekozen bestand bestaat niet.', [], "webshop"));
  1009.             }
  1010.         }
  1011.         $Webshop $request->getSession()->get('webshop');
  1012.         $Pay $this->Settings->getPay();
  1013.         $route $request->get('_route');
  1014.         $order_page null;
  1015.         $blocks $this->getDoctrine()->getRepository('CmsBundle:PageBlock')->findByData('TrinityWebshopBundle''profile_orders');
  1016.         foreach($blocks as $Block){
  1017.             $p $Block->getWrapper()->getPage();
  1018.             if($p->getLanguage() == $this->language){
  1019.                 $order_page $p;
  1020.                 break;
  1021.             }
  1022.         }
  1023.         
  1024.         if(is_numeric($params[0])){
  1025.             $order $this->getDoctrine()->getRepository('TrinityWebshopBundle:Order')->find((int)$params[0]);
  1026.             if(!empty($params[1] == 'payment')){
  1027.                 
  1028.                 $Pay->createPayment([
  1029.                     'id'          => $order->getOrderId(),
  1030.                     'order_id'    => $order->getOrderId(),
  1031.                     'amount'      => $order->getTotalPrice(),
  1032.                     'description' => 'Order ' $order->getHash(),
  1033.                     'redirectUrl' => $this->generateUrl($order->getWebshop()->getSettings()->getCheckoutFinishUri(), array('hash' => $order->getHash()), UrlGeneratorInterface::ABSOLUTE_URL),
  1034.                     'method'      => (!empty($params[2]) ? $params[2] : null),
  1035.                     'issuer'      => (!empty($params[2]) && !empty($params[3]) ? $params[3] : null),
  1036.                 ]);
  1037.                 $em $this->getDoctrine()->getManager();
  1038.                 $order->setPaymentId($Pay->id);
  1039.                 $order->setPaymentStatus($Pay->status);
  1040.                 $em->persist($order);
  1041.                 // Payment history
  1042.                 $OrderPayment = new \App\Trinity\WebshopBundle\Entity\OrderPayment();
  1043.                 $OrderPayment->setOrder($order);
  1044.                 $OrderPayment->setDate(new \Datetime());
  1045.                 $OrderPayment->setPaymentId($Pay->id);
  1046.                 $OrderPayment->setPaymentStatus($Pay->status);
  1047.                 $OrderPayment->setIp($_SERVER['REMOTE_ADDR']);
  1048.                 // Save order
  1049.                 // Add to payment history
  1050.                 $em->persist($OrderPayment);
  1051.                 // Remove cart
  1052.                 // $em->remove($Cart);
  1053.                 $em->flush();
  1054.                 header('Location:' $Pay->url);
  1055.                 exit;
  1056.             }else if(!empty($params[1] == 'dl')){
  1057.                 $pdf $this->container->get("qipsius.tcpdf")->create();
  1058.                 // dump($pdf);
  1059.                 exit;
  1060.             }
  1061.             if($finish){
  1062.                 header('Location: /');
  1063.                 exit;
  1064.             }
  1065.             $tax = [];
  1066.             $tax_total 0;
  1067.             /*if($order->getTotalDelivery() > 0){
  1068.                 $tax[21] = (($order->getTotalDelivery() / 100) * 21);
  1069.             }*/
  1070.             if(!empty($order->getProducts())){
  1071.                 foreach($order->getProducts() as $Product){
  1072.                     if(!empty($Product->getProduct())){
  1073.                         $Tax $Product->getProduct()->getTax();
  1074.                     } else {
  1075.                         $Tax null;
  1076.                     }
  1077.                     if(empty($Tax)){
  1078.                         $Tax $this->getDoctrine()->getRepository('TrinityWebshopBundle:Tax')->findOneByPercent(21);
  1079.                     }
  1080.                     $percent $Tax->getPercent();
  1081.                     $price $Product->getTotalPrice();
  1082.                     // dump($price);
  1083.                     $_tax = (($price 100) * $percent);
  1084.                     if(!isset($tax[$percent])) $tax[$percent] = 0;
  1085.                     $tax[$percent] += $_tax;
  1086.                     $tax_total += $_tax;
  1087.                 }
  1088.             }
  1089.             $delivery $order->getTotalDelivery();
  1090.             if(!empty($delivery)){
  1091.                 $t = (($delivery 100) * 21);
  1092.                 if(!isset($tax[21])) {
  1093.                     $tax[21] = 0;
  1094.                 }
  1095.                 $tax[21] += $t;
  1096.                 // $tax_total += $t;
  1097.             }
  1098.             return $this->renderView('@TrinityWebshop/default/widget_profile_orders_view.html.twig'$this->attributes([
  1099.                 'config'          => $config,
  1100.                 'params'          => $params,
  1101.                 'order'           => $order,
  1102.                 'tax'             => $tax,
  1103.                 'order_page'             => $order_page,
  1104.                 'tax_total'       => $tax_total,
  1105.             ]));
  1106.         }else{
  1107.             if($finish){
  1108.                 header('Location: /');
  1109.                 exit;
  1110.             }
  1111.             $page 1;
  1112.             if(!empty($_GET['page'])){ $page $_GET['page']; }
  1113.             $per_page 10;
  1114.             $count $this->getDoctrine()->getRepository('TrinityWebshopBundle:Order')->count(array(
  1115.                 'user' => $this->getWebshopUser(),
  1116.                 // 'webshop' => $Webshop
  1117.             ));
  1118.             $pages ceil($count $per_page);
  1119.             $orders $this->getDoctrine()->getRepository('TrinityWebshopBundle:Order')->findBy(array(
  1120.                 'user' => $this->getWebshopUser(),
  1121.                 // 'webshop' => $Webshop
  1122.             ), array(
  1123.                 'date' => 'desc'
  1124.             ), $per_page, (($page 1) * $per_page));
  1125.             return $this->renderView('@TrinityWebshop/default/widget_profile_orders.html.twig'$this->attributes([
  1126.                 'config'          => $config,
  1127.                 'params'          => $params,
  1128.                 'order_page'      => $order_page,
  1129.                 'orders'          => $orders,
  1130.                 'Pay'             => $Pay,
  1131.                 'pages' => $pages,
  1132.                 'page' => $page,
  1133.             ]));
  1134.         }
  1135.     }
  1136.     public function widget_profile_giftcards($config$params$SettingsRequest $request$finish false){
  1137.         parent::init($request);
  1138.         $Webshop $request->getSession()->get('webshop');
  1139.         $route $request->get('_route');
  1140.         $WebshopUser $this->getWebshopUser();
  1141.         $giftcard_error null;
  1142.         $giftcard_warning null;
  1143.         $giftcard_success null;
  1144.         if(!empty($_POST['giftcard_code'])){
  1145.             $code $_POST['giftcard_code'];
  1146.             $Giftcard $this->getDoctrine()->getRepository(Giftcard::class)->findOneBy(['code' => $code]);
  1147.             if($Giftcard){
  1148.                 if($Giftcard->getUser() != $this->WebshopUser){
  1149.                     $Giftcard->setUser($this->WebshopUser);
  1150.                     $em $this->getDoctrine()->getManager();
  1151.                     $em->persist($Giftcard);
  1152.                     $em->flush();
  1153.                     
  1154.                     $giftcard_success 'De cadeaukaart is succesvol verzilverd.';
  1155.                 }else{
  1156.                     $giftcard_warning 'Deze cadeaukaart is al in gebruik.';
  1157.                 }
  1158.             }else{
  1159.                 $giftcard_error 'Geen cadeaukaart gevonden met deze code.';
  1160.             }
  1161.         }
  1162.         return $this->renderView('@TrinityWebshop/default/widget_profile_giftcards.html.twig'$this->attributes([
  1163.             'config'          => $config,
  1164.             'params'          => $params,
  1165.             'WebshopUser'          => $WebshopUser,
  1166.             'giftcard_success' => $giftcard_success,
  1167.             'giftcard_warning' => $giftcard_warning,
  1168.             'giftcard_error' => $giftcard_error,
  1169.         ]));
  1170.     }
  1171.     public function widget_profile_lists($config$params$SettingsRequest $request){
  1172.         $this->init($request);
  1173.         $order_page null;
  1174.         $blocks $this->getDoctrine()->getRepository('CmsBundle:PageBlock')->findByData('TrinityWebshopBundle''profile_orders');
  1175.         foreach($blocks as $Block){
  1176.             $p $Block->getWrapper()->getPage();
  1177.             if($p->getLanguage() == $this->language){
  1178.                 $order_page $p;
  1179.                 break;
  1180.             }
  1181.         }
  1182.         $Webshop $request->getSession()->get('webshop');
  1183.         $WebshopUser $this->getDoctrine()->getRepository('TrinityWebshopBundle:User')->findOneByUser($this->getUser());
  1184.         if(!empty($_GET['l']) && !empty($_GET['d'])){
  1185.             $p $this->getDoctrine()->getRepository(Product::class)->find($_GET['d']);
  1186.             $l $this->getDoctrine()->getRepository(ProductList::class)->find($_GET['l']);
  1187.             if($l && $p){
  1188.                 $l->removeProduct($p);
  1189.                 $em $this->getDoctrine()->getManager();
  1190.                 $em->persist($l);
  1191.                 $em->flush();
  1192.             }
  1193.         }else if(!empty($_GET['d'])){
  1194.             $l $this->getDoctrine()->getRepository(ProductList::class)->find($_GET['d']);
  1195.             if($l){
  1196.                 $em $this->getDoctrine()->getManager();
  1197.                 $em->remove($l);
  1198.                 $em->flush();
  1199.             }
  1200.         }else if(!empty($_GET['c'])){
  1201.             $List $this->getDoctrine()->getRepository(ProductList::class)->find($_GET['c']);
  1202.             if($List){
  1203.                 $em $this->getDoctrine()->getManager();
  1204.                 $User $WebshopUser->getUser();
  1205.                 // Find previous cart(s)
  1206.                 $carts $em->getRepository(Cart::class)->findBy(['user' => $WebshopUser]);
  1207.                 foreach($carts as $Cart){
  1208.                     // Remove old cart
  1209.                     $em->remove($Cart);
  1210.                 }
  1211.                 // Find previous cart(s)
  1212.                 $carts $em->getRepository(Cart::class)->findBy(['ip' => $_SERVER['REMOTE_ADDR']]);
  1213.                 foreach($carts as $Cart){
  1214.                     // Remove old cart
  1215.                     $em->remove($Cart);
  1216.                 }
  1217.                 $Cart = new Cart();
  1218.                 $Cart->setWebshop($this->Webshop);
  1219.                 $Cart->setLanguage($this->language);
  1220.                 $Cart->setUser($this->getWebshopUser());
  1221.                 $Cart->setDateStart(new \Datetime());
  1222.                 $Cart->setIp($_SERVER['REMOTE_ADDR']);
  1223.                 $Cart->setFirstname($User->getFirstname());
  1224.                 $Cart->setLastname($User->getLastname());
  1225.                 $Cart->setEmail($User->getEmail());
  1226.                 $em->persist($Cart);
  1227.                 foreach($List->getProducts() as $Product){
  1228.                     if(!empty($Product) && $Product instanceof Product){
  1229.                         $CartProduct = new CartProduct();
  1230.                         $CartProduct->setAmount(1);
  1231.                         $CartProduct->setProduct($Product$this->WebshopSettings);
  1232.                         $CartProduct->setCart($Cart);
  1233.                         $em->persist($CartProduct);
  1234.                         $Cart->addProduct($CartProduct);
  1235.                     }
  1236.                 }
  1237.                 $Cart->calculate($this->getDoctrine(), $this->Settings);
  1238.                 $em->persist($Cart);
  1239.                 $em->flush();
  1240.                 $request->getSession()->set('cart'$Cart->getId());
  1241.                 header('Location: ' $this->generateUrl('checkout'));
  1242.                 exit;
  1243.             }
  1244.         }
  1245.         $route $request->get('_route');
  1246.         $lists $this->getDoctrine()->getRepository('TrinityWebshopBundle:ProductList')->findByUser($WebshopUser);
  1247.         return $this->renderView('@TrinityWebshop/default/widget_profile_lists.html.twig'$this->attributes([
  1248.             'config'          => $config,
  1249.             'params'          => $params,
  1250.             'order_page'      => $order_page,
  1251.             'lists'           => $lists,
  1252.         ]));
  1253.     }
  1254.     private function postalcodeToAddress($postalcode$number){
  1255.         $postalcode = (preg_replace('/[^0-9a-zA-Z]/'''$postalcode));
  1256.         if (strlen($postalcode $number) > 5) {
  1257.             $ch curl_init();
  1258.             curl_setopt($chCURLOPT_URL"https://api.postcode.nl/rest/addresses/" $postalcode "/" $number);
  1259.             curl_setopt($chCURLOPT_RETURNTRANSFER1);
  1260.             curl_setopt($chCURLOPT_CUSTOMREQUEST"GET");
  1261.             curl_setopt($chCURLOPT_USERPWD"VPoIVrLzyr2nCtBGg3tSuH7JBZ8qHCx458256zgsjgh:e3NH3amIpGTKJEgJQSqXo8Tnn6TbyLQ6b9PntAsqMXeCuzB29M");
  1262.             // curl_setopt($ch, CURLOPT_HEADER, 1);
  1263.             $result json_decode(curl_exec($ch));
  1264.             curl_close($ch);
  1265.             if(!isset($result->exception)){
  1266.                 if ($result->street && !empty($result->street)) {
  1267.                     return [
  1268.                         'street'     => $result->street,
  1269.                         'number'     => $number,
  1270.                         'postalcode' => $postalcode,
  1271.                         'city'       => $result->city
  1272.                     ];
  1273.                 }
  1274.             }
  1275.         }
  1276.         return null;
  1277.     }
  1278.     public function widget_profile($config$params$SettingsRequest $request){
  1279.         $this->init($request);
  1280.         $Webshop $request->getSession()->get('webshop');
  1281.         $WebshopUser $this->getWebshopUser();
  1282.         $savedProfile false;
  1283.         $route $request->get('_route');
  1284.         $giftcard_error null;
  1285.         $giftcard_warning null;
  1286.         $giftcard_success null;
  1287.         if(!empty($_POST['giftcard_code'])){
  1288.             $code $_POST['giftcard_code'];
  1289.             $Giftcard $this->getDoctrine()->getRepository(Giftcard::class)->findOneBy(['code' => $code]);
  1290.             if($Giftcard){
  1291.                 if($Giftcard->getUser() != $this->WebshopUser){
  1292.                     $Giftcard->setUser($this->WebshopUser);
  1293.                     $em $this->getDoctrine()->getManager();
  1294.                     $em->persist($Giftcard);
  1295.                     $em->flush();
  1296.                     
  1297.                     $giftcard_success 'De cadeaukaart is succesvol verzilverd.';
  1298.                 }else{
  1299.                     $giftcard_warning 'Deze cadeaukaart is al in gebruik.';
  1300.                 }
  1301.             }else{
  1302.                 $giftcard_error 'Geen cadeaukaart gevonden met deze code.';
  1303.             }
  1304.         }
  1305.         $pwd_error '';
  1306.         $pwd_msg '';
  1307.         if(!empty($_POST['pwd'])){
  1308.             if(!empty($_POST['pwd']['first'])){
  1309.                 if($_POST['pwd']['first'] == $_POST['pwd']['second']){
  1310.                     $User $this->getUser();
  1311.                     $passwordEncoder $this->containerInterface->get('security.password_encoder');
  1312.                     $User->setPassword($passwordEncoder->encodePassword($User$_POST['pwd']['first']));
  1313.                     $em $this->getDoctrine()->getManager();
  1314.                     $em->persist($User);
  1315.                     $em->flush();
  1316.                     $pwd_msg $this->trans('Het wachtwoord is gewijzigd.', [], "webshop");
  1317.                 }else{
  1318.                     $pwd_error $this->trans('Het wachtwoord en controle wachtwoord komen niet overeen.', [], "webshop");
  1319.                 }
  1320.             }else{
  1321.                 $pwd_error $this->trans('Wachtwoord is niet ingevuld.', [], "webshop");
  1322.             }
  1323.         }else{
  1324.             if($request->request->get('naw')){
  1325.                 // User profile
  1326.                 $naw $request->request->get('naw');
  1327.                 $User $this->getUser();
  1328.                 if(isset($naw['company'])){
  1329.                     $User->setCompany($naw['company']);
  1330.                 }
  1331.                 if (isset($naw['companytax'])) {
  1332.                     $User->setCompanyTaxNo($naw['companytax']);
  1333.                 }
  1334.                 if (isset($naw['companycoc'])) {
  1335.                     $User->setCompanyKvk($naw['companycoc']);
  1336.                 }
  1337.                 if (isset($naw['companytaxnr'])) {
  1338.                     $User->setCompanyTaxNo($naw['companytaxnr']);
  1339.                 }
  1340.                 if(!empty($naw['dateofbirth'])){
  1341.                     // $db = preg_replace('/^(\d+)-(\d+)-(\d+)$/', '$3-$2-$1', $naw['dateofbirth']) . ' 00:00:00';
  1342.                     $db = new \DateTime($naw['dateofbirth'] . ' 00:00:00');
  1343.                     $User->setDateOfBirth($db);
  1344.                 }
  1345.                 if(isset($naw['gender'])){
  1346.                     $User->setGender($naw['gender']);
  1347.                 }
  1348.                 if(isset($naw['firstname'])){
  1349.                     $User->setFirstname($naw['firstname']);
  1350.                 }
  1351.                 if(isset($naw['lastname'])){
  1352.                     $User->setLastname($naw['lastname']);
  1353.                 }
  1354.                 if(isset($naw['street'])){
  1355.                     $User->setStreet($naw['street']);
  1356.                 }
  1357.                 if(isset($naw['number'])){
  1358.                     $User->setNumber($naw['number']);
  1359.                 }
  1360.                 if(isset($naw['number_add'])){
  1361.                     $User->setNumberAdd($naw['number_add']);
  1362.                 }
  1363.                 if(isset($naw['postalcode'])){
  1364.                     $User->setPostalcode($naw['postalcode']);
  1365.                 }
  1366.                 if(isset($naw['city'])){
  1367.                     $User->setCity($naw['city']);
  1368.                 }
  1369.                 if(isset($naw['country'])){
  1370.                     $User->setCountry($naw['country']);
  1371.                 }
  1372.                 if(isset($naw['phone'])){
  1373.                     $User->setPhone($naw['phone']);
  1374.                 }
  1375.                 // $User->setEmail($naw['email']);
  1376.                 $em $this->getDoctrine()->getManager();
  1377.                 $em->persist($User);
  1378.                 $em->flush();
  1379.                 $savedProfile true;
  1380.             }
  1381.             if(!empty($_GET['delete'])){
  1382.                 $Address $this->getDoctrine()->getRepository('TrinityWebshopBundle:Address')->find($_GET['delete']);
  1383.                 $em $this->getDoctrine()->getManager();
  1384.                 $em->remove($Address);
  1385.                 $em->flush();
  1386.                 header('Location:' $this->generateUrl($route));
  1387.                 exit;
  1388.             }
  1389.             if($request->request->get('postalcode') && $request->request->get('number')){
  1390.                 // $parsed_address = $this->postalcodeToAddress($request->request->get('postalcode'), $request->request->get('number'));
  1391.                 // if($parsed_address){
  1392.                     $Address = new \App\Trinity\WebshopBundle\Entity\Address();
  1393.                     $Address->setUser($WebshopUser);
  1394.                     $Address->setStreet($_POST['street']);
  1395.                     $Address->setNumber($_POST['number']);
  1396.                     $Address->setNumberAdd($_POST['number_add']);
  1397.                     $Address->setPostalcode($_POST['postalcode']);
  1398.                     $Address->setPlace($_POST['city']);
  1399.                     $Address->setCountry($_POST['country']);
  1400.                     $em $this->getDoctrine()->getManager();
  1401.                     if($request->request->get('primary')){
  1402.                         $Address->setPriority(true);
  1403.                         $addresses $this->getDoctrine()->getRepository('TrinityWebshopBundle:Address')->findBy(['user' => $WebshopUser'priority' => true]);
  1404.                         foreach($addresses as $a){
  1405.                             $a->setPriority(false);
  1406.                             $em->persist($a);
  1407.                         }
  1408.                     }
  1409.                     $em->persist($Address);
  1410.                     $em->flush();
  1411.                     header('Location:' $this->generateUrl($route));
  1412.                     exit;
  1413.                 // }
  1414.             }
  1415.         }
  1416.         $countries_available $this->getDoctrine()->getRepository('TrinityWebshopBundle:DeliveryMethod')->findAvailableCountries($Settings);
  1417.         $locale_filter strtoupper($this->language->getLocale());
  1418.         if (in_array($locale_filter$countries_available)) {
  1419.             $country_list = [Countries::getName(strtoupper($locale_filter)) => $locale_filter];
  1420.         } else {
  1421.             $country_list = [];
  1422.         }
  1423.         foreach($countries_available as $cc){
  1424.             if(!in_array($cc$country_list)){
  1425.                 $country_list[Countries::getName(strtoupper($cc))] = $cc;
  1426.             }
  1427.         }
  1428.         return $this->renderView('@TrinityWebshop/default/widget_profile.html.twig'$this->attributes([
  1429.             'config' => $config,
  1430.             'params' => $params,
  1431.             'route' => $route,
  1432.             'country_list' => $country_list,
  1433.             'pwd_error' => $pwd_error,
  1434.             'pwd_msg' => $pwd_msg,
  1435.             'savedProfile' => $savedProfile,
  1436.             'WebshopUser' => $WebshopUser,
  1437.             'giftcard_success' => $giftcard_success,
  1438.             'giftcard_warning' => $giftcard_warning,
  1439.             'giftcard_error' => $giftcard_error,
  1440.         ]));
  1441.     }
  1442.     private function getWidgetCacheFile(string $hash) : string
  1443.     {
  1444.         $dir $this->containerInterface->get('kernel')->getProjectDir() . '/var/cache/webshop/';
  1445.         if(!file_exists($dir)){
  1446.             mkdir($dir);
  1447.         }
  1448.         $subdir substr($hash02);
  1449.         $dir $dir $subdir '/';
  1450.         if(!file_exists($dir)){
  1451.             mkdir($dir);
  1452.         }
  1453.         return ($dir $hash '.widget.html');
  1454.     }
  1455.     /**
  1456.      * Show bundle content to front
  1457.      *
  1458.      * @param  array  $config Array with configuration options
  1459.      * @param  array  $params Additional parameters
  1460.      *
  1461.      * @return string         HTML
  1462.      */
  1463.     public function showAction($config$paramsRequest $request)
  1464.     {
  1465.         // Initialize StorageController
  1466.         parent::init($request);
  1467.         $Webshop $this->getDoctrine()->getRepository('TrinityWebshopBundle:Webshop')->getByLanguageAndSettings($this->language$this->Settings);
  1468.         $Settings $Webshop->getSettings();
  1469.         switch ($config['view']) {
  1470.             case 'category_masonry': return $this->widget_category_masonry($config$params$Settings$request); break;
  1471.             case 'products': return $this->widget_products($config$params$Settings$request); break;
  1472.             case 'newproducts': return $this->widget_newproducts($config$params$Settings$request); break;
  1473.             case 'subcategory': return $this->widget_subcategory($config$params$Settings$request); break;
  1474.             case 'categories': return $this->widget_categories($config$params$Settings$request); break;
  1475.             case 'latest': return $this->widget_latest($config$params$Settings$request); break;
  1476.             case 'featured': return $this->widget_featured($config$params$Settings$request); break;
  1477.             case 'discounted': return $this->widget_discounted($config$params$Settings$request); break;
  1478.             case 'popular': return $this->widget_popular($config$params$Settings$request); break;
  1479.             case 'searchwithcat': return $this->widget_searchwithcat($config$params$Settings$request); break;
  1480.             case 'homecats': return $this->widget_homecats($config$params$Settings$request); break;
  1481.             case 'choice_flow': return $this->widget_choice_flow($config$params$Settings$request); break;
  1482.             case 'profile': return $this->widget_profile($config$params$Settings$request); break;
  1483.             case 'profile_giftcards': return $this->widget_profile_giftcards($config$params$Settings$request); break;
  1484.             case 'profile_orders': return $this->widget_profile_orders($config$params$Settings$request); break;
  1485.             case 'profile_orders_finish': return $this->widget_profile_orders($config$params$Settings$requesttrue); break;
  1486.             case 'profile_lists': return $this->widget_profile_lists($config$params$Settings$request); break;
  1487.         }
  1488.         return $this->renderView('@TrinityWebshop/default/front.html.twig'$this->attributes([]));
  1489.     }
  1490.     /**
  1491.      * Return link data when required within the link form
  1492.      *
  1493.      * @param  object  Doctrine object
  1494.      *
  1495.      * @return array   Array with config options
  1496.      */
  1497.     public function getLinkData($em$Language$Container$Settings){
  1498.         $Webshop $em->getRepository('TrinityWebshopBundle:Webshop')->getByLanguageAndSettings($Language$Settings);
  1499.         $categories $em->getRepository('TrinityWebshopBundle:Category')->findByWebshop($Webshop);
  1500.         $specs $em->getRepository('TrinityWebshopBundle:Spec')->findBy([], ['label' => 'asc']);
  1501.         return [
  1502.             'categories' => $categories,
  1503.             'Language' => $Language,
  1504.             'specs'      => $specs,
  1505.         ];
  1506.     }
  1507.     /**
  1508.      * Show dashboard blocks
  1509.      *
  1510.      * @return array List of blocks
  1511.      */
  1512.     public function dashboardBlocks(){
  1513.         // Return block data to show on Trinity dashboard in the following format.
  1514.         // You can do whatever you want in this function, just return data as below.
  1515.         return [
  1516.             [
  1517.                 'title' => 'Mijn lege module',
  1518.                 'class' => '',
  1519.                 'content' => '<div style="text-align:center;padding:20px;">Lege module</div>'
  1520.             ]
  1521.         ];
  1522.     }
  1523.     public static function resourcesHandler($Settings, array $bundledatastring $projectDir) : ?string
  1524.     {
  1525.         $resources null;
  1526.         $layoutKey = !empty($Settings->getOverrideKey()) ? trim($Settings->getOverrideKey()) . '/' '';
  1527.         $view '';
  1528.         if (isset($bundledata['view'])) {
  1529.             $view $bundledata['view'];
  1530.         }
  1531.         switch($view)
  1532.         {
  1533.             case 'categories':
  1534.             case 'products':
  1535.             case 'latest':
  1536.             case 'homecat'// not used
  1537.             case 'featured':
  1538.             case 'discounted':
  1539.             case 'popular':
  1540.             case 'profile_lists':
  1541.                 $resource_file 'resources_style_bootstrap.json';
  1542.                 break;
  1543.             case 'profile':
  1544.             case 'profile_orders':
  1545.             case 'profile_orders'// && profile_orders_view && profile_orders_finish
  1546.                 $resource_file 'resources_style.json';
  1547.                 break;
  1548.             case 'category_masonry'// not used
  1549.             case 'searchwithcat':
  1550.             case 'subcategory':
  1551.             default:
  1552.                 $resource_file 'resources_empty.json';
  1553.                 break;
  1554.         }
  1555.         // check if file exists or build array in code and return that.
  1556.         $file __DIR__ "/../Resources/views/default/" $resource_file;
  1557.         $override $projectDir '/public/custom/' $layoutKey 'webshop/' $resource_file;
  1558.         if (file_exists($override)) {
  1559.             $resources $override;
  1560.         } else if (file_exists($file)) {
  1561.             $resources $file;
  1562.         }
  1563.         return $resources;
  1564.     }
  1565. }