src/Controller/ContentController.php line 46

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