src/Controller/ContentController.php line 46

  1. <?php
  2. namespace App\Controller;
  3. use Pimcore\Controller\FrontendController;
  4. use Pimcore\Bundle\EcommerceFrameworkBundle\Factory;
  5. use Pimcore\Model\DataObject\AbstractObject;
  6. use Pimcore\Model\DataObject\HomeBanner;
  7. use Pimcore\Model\DataObject\Product;
  8. use Pimcore\Model\DataObject\ProductCategory;
  9. // use Pimcore\Model\DataObject\ProductAttribute;
  10. use Pimcore\Model\DataObject\Review;
  11. use Pimcore\Model\DataObject\Recipe;
  12. use Pimcore\Model\DataObject\RecipeDay;
  13. use Pimcore\Model\DataObject\FooterVideo;
  14. use Symfony\Component\HttpFoundation\Request;
  15. use Symfony\Component\Routing\Annotation\Route;
  16. use Symfony\Component\HttpFoundation\Response;
  17. use Pimcore\Bundle\PersonalizationBundle\Targeting\VisitorInfoStorageInterface;
  18. use Pimcore\Model\Tool\Targeting;
  19. use Symfony\Bridge\Twig\Attribute\Template;
  20. use Pimcore\Model\Tool\Targeting\TargetGroup;
  21. use GeoIp2\Database\Reader;
  22. // use Symfony\Component\HttpFoundation\JsonResponse;
  23. /**
  24.  * 
  25.  *@IgnoreAnnotation("Template") 
  26.  * @author PcCom
  27.  */
  28. class ContentController extends FrontendController {
  29.     /**
  30.      * @Template
  31.      *
  32.      * @param Request $request
  33.      *
  34.      * @return array
  35.      */
  36.     /**
  37.      * @var LocaleService
  38.      */
  39.     private $visitorInfoStorage;
  40.     public function __construct(VisitorInfoStorageInterface $visitorInfoStorage) {
  41.         $this->visitorInfoStorage $visitorInfoStorage;
  42.     }
  43.     public function portalAction() {
  44.         
  45.         ini_set('memory_limit','4048M');
  46.        
  47.         $groups = [];
  48.         $code 'AE';
  49.         if (!$this->visitorInfoStorage->hasVisitorInfo()) {
  50.             $groups = [];
  51.             $code 'AE';
  52.         }else{
  53.             $visitorInfo $this->visitorInfoStorage->getVisitorInfo();
  54.             if($visitorInfo instanceof \Pimcore\Targeting\Model\VisitorInfo){
  55.             
  56.                     $groups $visitorInfo->getAssignedTargetGroups();
  57.                     $city $visitorInfo->get('geoip');
  58.                     if($city){
  59.                         $code $city['country']['iso_code'];
  60.                     }
  61.                     
  62.                     if (!$code) {
  63.                         $code 'AE';
  64.                     }   
  65.                 
  66.             }
  67.         }
  68.    
  69.         $groupids = [];
  70.         foreach ($groups as $key => $val) {
  71.             $groupids[] = $val->getId();
  72.         }
  73.         if(!$groupids){
  74.             $groupids[] = '22';
  75.         }
  76.    
  77.         
  78.         /*try {
  79.             $ipaddress = '';
  80.             if (isset($_SERVER['HTTP_CLIENT_IP'])) {
  81.                 $ipaddress = $_SERVER['HTTP_CLIENT_IP'];
  82.             } else if (isset($_SERVER['HTTP_X_FORWARDED_FOR'])) {
  83.                 $ipaddress = $_SERVER['HTTP_X_FORWARDED_FOR'];
  84.             } else if (isset($_SERVER['HTTP_X_FORWARDED'])) {
  85.                 $ipaddress = $_SERVER['HTTP_X_FORWARDED'];
  86.             } else if (isset($_SERVER['HTTP_FORWARDED_FOR'])) {
  87.                 $ipaddress = $_SERVER['HTTP_FORWARDED_FOR'];
  88.             } else if (isset($_SERVER['HTTP_FORWARDED'])) {
  89.                 $ipaddress = $_SERVER['HTTP_FORWARDED'];
  90.             } else if (isset($_SERVER['REMOTE_ADDR'])) {
  91.                 $ipaddress = $_SERVER['REMOTE_ADDR'];
  92.             } else {
  93.                 $ipaddress = 'UNKNOWN';
  94.             }
  95.             if ($ipaddress != 'UNKNOWN') {
  96.                 $ip_info = new  Reader(__DIR__ . '/GeoLite2-Country.mmdb');
  97.                 $record = $ip_info->country($ipaddress);
  98.                 if ($record) {
  99.                     $ip = $record->country->isoCode;
  100.                 }
  101.             }
  102.         } catch (\Exception $e) {
  103.             $ip = '';
  104.            
  105.         }
  106.         $code = $ip; // issign country-iso code to code varible
  107.      
  108.         if ($code == 'AE') {
  109.             $groupids[] = '29';
  110.         } elseif ($code == 'SA') {
  111.             $groupids[] = '27';
  112.         } elseif ($code == 'OM' || $code == 'QA' || $code == 'KW' || $code == 'BH') {
  113.             $groupids[] = '28';
  114.         } else {
  115.             //$code = 'AE';
  116.             $groupids[] = '27';
  117.         }*/
  118.         // Region wise ip Handler end     
  119.       
  120.         $FooterVideo = new FooterVideo\Listing();
  121.         $HomeBanner = new HomeBanner\Listing();
  122.         $Products = new Product\Listing();
  123.         $Products->setLimit('3');
  124.         $Products->load();
  125.         foreach ($Products as $key => $Product) {
  126.            $product[] = $Product;
  127.        
  128.         }  
  129.         $Recipe = new Recipe\Listing();
  130.         $Recipe->setCondition("featured IN (?)"'1');
  131.         $Recipe->setLimit('4');
  132.         $Recipe->load();
  133.     
  134.         $recipe_reviews = new Review\Listing();
  135.         $recipe_reviews->setLimit('10');
  136.         $recipe_reviews->load();
  137.         
  138.         $Categories = new ProductCategory\Listing();
  139.         $Categories->load();
  140.         foreach ($Categories as $key => $Category) {
  141.             $category[] = $Category;
  142.         }
  143.       
  144.         $catwithpro = [];
  145.         foreach ($Categories as $key => $Category) {
  146.             for ($i 0$i count($Category->getProducts()); $i++) {
  147.                 for ($j 0$j count($Category->getProducts()[$i]->getAttributes()); $j++) {
  148.                     $size[$i][] = $Category->getProducts()[$i]->getAttributes()[$j]->getSize();
  149.                 }
  150.                 for ($j 0$j count($Category->getProducts()[$i]->getAttributes()); $j++) {
  151.                     if ($j == 0) {
  152.                         $regions $Category->getProducts()[$i]->getRegions();
  153.                         $show false;
  154.                         if ($regions) {
  155.                             foreach ($regions as $key => $region) {
  156.                                 if (array_search($region$groupids) !== false) {
  157.                                     $show true;
  158.                                 }
  159.                             }
  160.                         }
  161.                         if ($show) :
  162.                             $regionslinks $Category->getProducts()[$i]->getAttributes()[0]->getButtonlinks();
  163.                             $rlink = [];
  164.                             foreach ($regionslinks as $key => $link) {
  165.                                 if ($link['country']->getData() == $code) {
  166.                                     // if ($link['country']->getData() == 'AE') { //temporary
  167.                                     $rlink $link;
  168.                                 }
  169.                             }
  170.                             if (!$rlink) {
  171.                                 foreach ($regionslinks as $key => $link) {
  172.                                     if ($link['country']->getData() == 'AE') {
  173.                                         $rlink $link;
  174.                                     }
  175.                                 }
  176.                             }
  177.                             $sizesUrl = [];
  178.                             foreach ($Category->getProducts()[$i]->getAttributes() as $key => $value) {
  179.                                 $sizesUrl[] = $value->getUrl();
  180.                             }
  181.                             $catwithpro[$Category->getName()][] = [
  182.                                 $Category->getProducts()[$i]->getName(),
  183.                                 $Category->getProducts()[$i]->getAttributes()[0]->getImages()[0]->getPath() . $Category->getProducts()[$i]->getAttributes()[0]->getImages()[0]->getFilename(),
  184.                                 $size[$i],
  185.                                 $Category->getProducts()[$i]->getId(),
  186.                                 (!empty($rlink['lulu'])) ? $rlink['lulu']->getData() : '',
  187.                                 (!empty($rlink['unioncool'])) ? $rlink['unioncool']->getData() : '',
  188.                                 (!empty($rlink['amazon'])) ? $rlink['amazon']->getData() : '',
  189.                                 (!empty($rlink['carrefour'])) ? $rlink['carrefour']->getData() : '',
  190.                                 (!empty($rlink['c4'])) ? $rlink['c4']->getData() : '',
  191.                                 (!empty($rlink['noon'])) ? $rlink['noon']->getData() : '',
  192.                                 (!empty($rlink['danube'])) ? $rlink['danube']->getData() : '',
  193.                                 (!empty($rlink['tawseel'])) ? $rlink['tawseel']->getData() : '',
  194.                                 (!empty($rlink['sultancenter'])) ? $rlink['sultancenter']->getData() : '',
  195.                                 $Category->getProducts()[$i]->getAttributes()[0]->getUrl(),
  196.                                 $sizesUrl,
  197.                                 // $Category->getProducts()[$i]->getAttributes()[$j]->getLulu(),
  198.                                 // $Category->getProducts()[$i]->getAttributes()[$j]->getUnioncool(),
  199.                                 // $Category->getProducts()[$i]->getAttributes()[$j]->getAmazon(),
  200.                                 // $Category->getProducts()[$i]->getAttributes()[$j]->getCarrefour()
  201.                             ];
  202.                         endif;
  203.                     }
  204.                 }
  205.                 if ($Category->getProducts()[$i]->getAttributes()) {
  206.                 }
  207.             }
  208.             $size = [];
  209.         }
  210.      
  211.         $response = new Response();
  212.         $response->setContent(json_encode($catwithpro));
  213.     
  214.         return $this->render('content/Portal.html.twig', [
  215.             'products' => $product,
  216.             'categorydata' => $response->getContent(),
  217.             'categories' => $category,
  218.             'recipe' => $Recipe,
  219.             'homebanners' => $HomeBanner,
  220.             'isPortal' => true,
  221.             'footervideo' => $FooterVideo,
  222.             'country' => $code,
  223.             //'country'=>'AE', // temporary basses
  224.             'groupids' => $groupids,
  225.             'recipe_reviews' => $recipe_reviews,
  226.         ]);
  227.     }
  228.     public function redirectAction() {
  229.         return $this->redirect('/en'301);
  230.     }
  231.     public function sitemapAction() {
  232.         $Recipes = new Recipe\Listing();
  233.         $Recipes->load();
  234.         $Categories = new ProductCategory\Listing();
  235.         $Categories->setOrderKey('sort');
  236.         $Categories->setOrder('asc');
  237.         $Categories->load();
  238.         return $this->render('information/sitemap.html.twig', [
  239.             'recipes' => $Recipes,
  240.             'categories' => $Categories,
  241.         ]);
  242.     }
  243.     /**
  244.      *
  245.      * @Template()
  246.      *
  247.      * @param Request $request
  248.      *
  249.      * @return array
  250.      *
  251.      * @throws \Exception
  252.     */
  253.     public function defaultAction()
  254.     {
  255.         return [];
  256.     }
  257.     /**
  258.      *
  259.      * @Template()
  260.      *
  261.      * @param Request $request
  262.      *
  263.      * @return array
  264.      *
  265.      * @throws \Exception
  266.     */
  267.     public function contactAction()
  268.     {
  269.         return [];
  270.     }
  271.     /**
  272.      *
  273.      * @Template()
  274.      *
  275.      * @param Request $request
  276.      *
  277.      * @return array
  278.      *
  279.      * @throws \Exception
  280.     */
  281.      public function reciperesultAction()
  282.     {
  283.         return [];
  284.     }
  285.     /**
  286.      *
  287.      * @Template()
  288.      *
  289.      * @param Request $request
  290.      *
  291.      * @return array
  292.      *
  293.      * @throws \Exception
  294.     */
  295.     public function landingPageAction()
  296.     {
  297.         return [];
  298.     }
  299. }