src/Controller/ContentController.php line 46
<?php
namespace App\Controller;
use Pimcore\Controller\FrontendController;
use Pimcore\Bundle\EcommerceFrameworkBundle\Factory;
use Pimcore\Model\DataObject\AbstractObject;
use Pimcore\Model\DataObject\HomeBanner;
use Pimcore\Model\DataObject\Product;
use Pimcore\Model\DataObject\ProductCategory;
// use Pimcore\Model\DataObject\ProductAttribute;
use Pimcore\Model\DataObject\Review;
use Pimcore\Model\DataObject\Recipe;
use Pimcore\Model\DataObject\RecipeDay;
use Pimcore\Model\DataObject\FooterVideo;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\HttpFoundation\Response;
use Pimcore\Bundle\PersonalizationBundle\Targeting\VisitorInfoStorageInterface;
use Pimcore\Model\Tool\Targeting;
use Symfony\Bridge\Twig\Attribute\Template;
use Pimcore\Model\Tool\Targeting\TargetGroup;
use GeoIp2\Database\Reader;
// use Symfony\Component\HttpFoundation\JsonResponse;
/**
*
*@IgnoreAnnotation("Template")
* @author PcCom
*/
class ContentController extends FrontendController {
/**
* @Template
*
* @param Request $request
*
* @return array
*/
/**
* @var LocaleService
*/
private $visitorInfoStorage;
public function __construct(VisitorInfoStorageInterface $visitorInfoStorage) {
$this->visitorInfoStorage = $visitorInfoStorage;
}
public function portalAction() {
ini_set('memory_limit','4048M');
$groups = [];
$code = 'AE';
if (!$this->visitorInfoStorage->hasVisitorInfo()) {
$groups = [];
$code = 'AE';
}else{
$visitorInfo = $this->visitorInfoStorage->getVisitorInfo();
if($visitorInfo instanceof \Pimcore\Targeting\Model\VisitorInfo){
$groups = $visitorInfo->getAssignedTargetGroups();
$city = $visitorInfo->get('geoip');
if($city){
$code = $city['country']['iso_code'];
}
if (!$code) {
$code = 'AE';
}
}
}
$groupids = [];
foreach ($groups as $key => $val) {
$groupids[] = $val->getId();
}
if(!$groupids){
$groupids[] = '22';
}
/*try {
$ipaddress = '';
if (isset($_SERVER['HTTP_CLIENT_IP'])) {
$ipaddress = $_SERVER['HTTP_CLIENT_IP'];
} else if (isset($_SERVER['HTTP_X_FORWARDED_FOR'])) {
$ipaddress = $_SERVER['HTTP_X_FORWARDED_FOR'];
} else if (isset($_SERVER['HTTP_X_FORWARDED'])) {
$ipaddress = $_SERVER['HTTP_X_FORWARDED'];
} else if (isset($_SERVER['HTTP_FORWARDED_FOR'])) {
$ipaddress = $_SERVER['HTTP_FORWARDED_FOR'];
} else if (isset($_SERVER['HTTP_FORWARDED'])) {
$ipaddress = $_SERVER['HTTP_FORWARDED'];
} else if (isset($_SERVER['REMOTE_ADDR'])) {
$ipaddress = $_SERVER['REMOTE_ADDR'];
} else {
$ipaddress = 'UNKNOWN';
}
if ($ipaddress != 'UNKNOWN') {
$ip_info = new Reader(__DIR__ . '/GeoLite2-Country.mmdb');
$record = $ip_info->country($ipaddress);
if ($record) {
$ip = $record->country->isoCode;
}
}
} catch (\Exception $e) {
$ip = '';
}
$code = $ip; // issign country-iso code to code varible
if ($code == 'AE') {
$groupids[] = '29';
} elseif ($code == 'SA') {
$groupids[] = '27';
} elseif ($code == 'OM' || $code == 'QA' || $code == 'KW' || $code == 'BH') {
$groupids[] = '28';
} else {
//$code = 'AE';
$groupids[] = '27';
}*/
// Region wise ip Handler end
$FooterVideo = new FooterVideo\Listing();
$HomeBanner = new HomeBanner\Listing();
$Products = new Product\Listing();
$Products->setLimit('3');
$Products->load();
foreach ($Products as $key => $Product) {
$product[] = $Product;
}
$Recipe = new Recipe\Listing();
$Recipe->setCondition("featured IN (?)", '1');
$Recipe->setLimit('4');
$Recipe->load();
$recipe_reviews = new Review\Listing();
$recipe_reviews->setLimit('10');
$recipe_reviews->load();
$Categories = new ProductCategory\Listing();
$Categories->load();
foreach ($Categories as $key => $Category) {
$category[] = $Category;
}
$catwithpro = [];
foreach ($Categories as $key => $Category) {
for ($i = 0; $i < count($Category->getProducts()); $i++) {
for ($j = 0; $j < count($Category->getProducts()[$i]->getAttributes()); $j++) {
$size[$i][] = $Category->getProducts()[$i]->getAttributes()[$j]->getSize();
}
for ($j = 0; $j < count($Category->getProducts()[$i]->getAttributes()); $j++) {
if ($j == 0) {
$regions = $Category->getProducts()[$i]->getRegions();
$show = false;
if ($regions) {
foreach ($regions as $key => $region) {
if (array_search($region, $groupids) !== false) {
$show = true;
}
}
}
if ($show) :
$regionslinks = $Category->getProducts()[$i]->getAttributes()[0]->getButtonlinks();
$rlink = [];
foreach ($regionslinks as $key => $link) {
if ($link['country']->getData() == $code) {
// if ($link['country']->getData() == 'AE') { //temporary
$rlink = $link;
}
}
if (!$rlink) {
foreach ($regionslinks as $key => $link) {
if ($link['country']->getData() == 'AE') {
$rlink = $link;
}
}
}
$sizesUrl = [];
foreach ($Category->getProducts()[$i]->getAttributes() as $key => $value) {
$sizesUrl[] = $value->getUrl();
}
$catwithpro[$Category->getName()][] = [
$Category->getProducts()[$i]->getName(),
$Category->getProducts()[$i]->getAttributes()[0]->getImages()[0]->getPath() . $Category->getProducts()[$i]->getAttributes()[0]->getImages()[0]->getFilename(),
$size[$i],
$Category->getProducts()[$i]->getId(),
(!empty($rlink['lulu'])) ? $rlink['lulu']->getData() : '',
(!empty($rlink['unioncool'])) ? $rlink['unioncool']->getData() : '',
(!empty($rlink['amazon'])) ? $rlink['amazon']->getData() : '',
(!empty($rlink['carrefour'])) ? $rlink['carrefour']->getData() : '',
(!empty($rlink['c4'])) ? $rlink['c4']->getData() : '',
(!empty($rlink['noon'])) ? $rlink['noon']->getData() : '',
(!empty($rlink['danube'])) ? $rlink['danube']->getData() : '',
(!empty($rlink['tawseel'])) ? $rlink['tawseel']->getData() : '',
(!empty($rlink['sultancenter'])) ? $rlink['sultancenter']->getData() : '',
$Category->getProducts()[$i]->getAttributes()[0]->getUrl(),
$sizesUrl,
// $Category->getProducts()[$i]->getAttributes()[$j]->getLulu(),
// $Category->getProducts()[$i]->getAttributes()[$j]->getUnioncool(),
// $Category->getProducts()[$i]->getAttributes()[$j]->getAmazon(),
// $Category->getProducts()[$i]->getAttributes()[$j]->getCarrefour()
];
endif;
}
}
if ($Category->getProducts()[$i]->getAttributes()) {
}
}
$size = [];
}
$response = new Response();
$response->setContent(json_encode($catwithpro));
return $this->render('content/Portal.html.twig', [
'products' => $product,
'categorydata' => $response->getContent(),
'categories' => $category,
'recipe' => $Recipe,
'homebanners' => $HomeBanner,
'isPortal' => true,
'footervideo' => $FooterVideo,
'country' => $code,
//'country'=>'AE', // temporary basses
'groupids' => $groupids,
'recipe_reviews' => $recipe_reviews,
]);
}
public function redirectAction() {
return $this->redirect('/en', 301);
}
public function sitemapAction() {
$Recipes = new Recipe\Listing();
$Recipes->load();
$Categories = new ProductCategory\Listing();
$Categories->setOrderKey('sort');
$Categories->setOrder('asc');
$Categories->load();
return $this->render('information/sitemap.html.twig', [
'recipes' => $Recipes,
'categories' => $Categories,
]);
}
/**
*
* @Template()
*
* @param Request $request
*
* @return array
*
* @throws \Exception
*/
public function defaultAction()
{
return [];
}
/**
*
* @Template()
*
* @param Request $request
*
* @return array
*
* @throws \Exception
*/
public function contactAction()
{
return [];
}
/**
*
* @Template()
*
* @param Request $request
*
* @return array
*
* @throws \Exception
*/
public function reciperesultAction()
{
return [];
}
/**
*
* @Template()
*
* @param Request $request
*
* @return array
*
* @throws \Exception
*/
public function landingPageAction()
{
return [];
}
}