<?php
namespace App\Controller;
use Pimcore\Controller\FrontendController;
use Symfony\Component\HttpFoundation\Request;
use Pimcore\Translation\Translator;
use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\Component\Routing\Annotation\Route;
use AppBundle\Services\WebsiteSetting;
use Pimcore\Model\DataObject;
// use \Pimcore\Model\WebsiteSetting;
use App\Validator\Validator;
use Pimcore\Model\Notification\Service\NotificationService;
use Pimcore\Model\Document;
use App\Helper\DocumentHelper;
use Pimcore\Model\Document\Editable;
use Symfony\Component\HttpFoundation\Response;
class HomeController extends FrontendController
{
private $request;
private $validator;
private $translator;
public function __construct(RequestStack $requestStack, Validator $validator, Translator $translator)
{
$this->request = $requestStack->getCurrentRequest();
$this->validator = $validator;
$this->translator = $translator;
}
/**
* @Route("/api/home", name="api-home")
*/
public function homeAction(Request $request){
$document = DocumentHelper::getDataByPath('/');
return $this->json([ 'data' => $document]);
}
/**
* @Route("/api/about-us", name="api-about-us")
*/
public function aboutUs()
{
$documentAbout = \Pimcore\Model\Document::getById(9);
$type = $this->request->get('type');
if ($type == 'aboutAgent') {
$documentAbout = \Pimcore\Model\Document::getById(15);
}
$aboutUs = $documentAbout->getEditable('aboutUs');
return $this->json([
'content' => $aboutUs->getData()
]);
}
/**
* @Route("/api/search", name="api-search")
*/
public function search()
{
$images = [];
$search = $this->request->get('search');
$products = ProductRepo::finds([
'search' => $this->request->get('search'),
'limit' => $this->request->get('7'),
], true);
$news = NewsRepo::finds([
'search' => $this->request->get('search'),
'limit' => $this->request->get('3'),
], true);
$data = [
'product' => $products['data'],
'news' => $news['data'],
];
return $this->json($data);
}
}