<?php
namespace App\Controller;
use Doctrine\Persistence\ManagerRegistry;
use Symfony\Component\HttpKernel\KernelInterface;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\Extension\Core\Type\PasswordType;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\Form\Extension\Core\Type\TextareaType;
use Symfony\Component\Form\Extension\Core\Type\EmailType;
use Symfony\Component\Form\Extension\Core\Type\FileType;
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
use Symfony\Component\Form\Extension\Core\Type\HiddenType;
use Symfony\Component\Console\Input\ArrayInput;
use Symfony\Bundle\FrameworkBundle\Console\Application;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
use Symfony\Component\Validator\Constraints\DateTime;
use Symfony\Component\Serializer\Normalizer\DateTimeNormalizer;
use Symfony\Component\Serializer\Serializer;
use Symfony\Component\Mailer\MailerInterface;
use Symfony\Component\Mime\Email;
use App\Entity\Address;
use App\Entity\Category;
use App\Entity\Consent;
use App\Entity\Currency;
use App\Entity\CssDesign;
use App\Entity\Delivery;
use App\Entity\Eshop3D;
use App\Entity\Gallery;
use App\Entity\GalleryItem;
use App\Entity\Gallery3D;
use App\Entity\Language;
use App\Entity\Module;
use App\Entity\Payment;
use App\Entity\Paypal;
use App\Entity\Product;
use App\Entity\ProductParameter;
use App\Entity\ProductParameterGroup;
use App\Entity\ProductParameterValue;
use App\Entity\Price;
use App\Entity\PriceLevel;
use App\Entity\Eshop;
use App\Entity\EshopDelivery;
use App\Entity\EshopPayment;
use App\Entity\Order;
use App\Entity\OrderItem;
use App\Entity\Contact;
use App\Entity\Service;
use App\Entity\ServiceExample;
use App\Entity\ReCaptcha;
use App\Entity\User;
use App\Entity\WebPage;
use App\Entity\WireFrame;
use FOS\RestBundle\Controller\Annotations as Rest;
use Psr\Log\LoggerInterface;
use Symfony\Contracts\Translation\TranslatorInterface;
use Twig\Environment;
class EshopController extends DefaultController
{
protected $dynamicEntityManager;
protected $currentEshop;
protected ManagerRegistry $doctrine;
protected TranslatorInterface $translator;
protected $appKernel;
protected MailerInterface $mailer;
protected Environment $twig;
public function __construct(ManagerRegistry $doctrine,
TranslatorInterface $translator,
KernelInterface $appKernel,
MailerInterface $mailer,
Environment $twig)
{
$this->doctrine = $doctrine;
$this->translator = $translator;
$this->appKernel = $appKernel;
$this->mailer = $mailer;
$this->twig = $twig;
}
/**
* @Route("/eshop", name="eshopHome")
*/
public function indexAction(Request $request)
{
/* we load session data */
parent::init($request);
$session = $request->getSession();
/* we load entity managers */
$em = $this->doctrine->getManager();
$dem = $this->doctrine->getManager('dynamic_em');
/* we get demo e-shop */
$eshopId = 1;
$eshop = $em->getRepository(Eshop::class)->getEshop($eshopId);
/* we get current 3D eshop */
$eshop3D = $dem->getRepository(Eshop3D::class)->getEshop3DByEshopId($eshopId);
$user = $em->getRepository(User::class)->getUser($eshop->getUserId());
$userDirs = $this->getUserFolderPathsFromUserId($user->getUserId());
/* we load list of modules for connector service */
$service = $em->getRepository(Service::class)->getService(1);
/* we load examples */
$exampleCollection = $em->getRepository(ServiceExample::class)->getServiceExampleListByService(1, 3);
shuffle($exampleCollection);
//isModule Pack Sale
$module = $em->getRepository(Module::class)->getModule(42);
$isPackSaleModule = $em->getRepository(User::class)->userHasModule($user, $module);
//print('<br>qqw eshop: ');
//\Doctrine\Common\Util\Debug::dump($eshop);
$logger = $this->getLogger(null, 'e-shop 3D');
// we get the gallery
$gallery3DId = 7;
$gallery3D = $em->getRepository(Gallery3D::class)->getGallery3D($gallery3DId);
// we get parent gallery items
$galleryItemCollection = null;
if(!empty($gallery3D) and !empty($gallery3D->getGallery())) {
$galId = $gallery3D->getGallery()->getGalleryId();
$galleryItemCollection = $em->getRepository(GalleryItem::class)->getGalleryItemList($galId);
}
$rootNodes = $dem->getRepository(Category::class)->getRootNodes();
$childNodes = array();
$childNodeImages = array();
$categoryImages = array();
$products = array();
$categoryProducts = array();
$categoryProductImages = array();
$productListTitles = array();
$productDescriptions = array();
$categoryProductPrices = array();
/* we get parent gallery items */
$textureItemCollection = null;
if(!empty($eshop3D) && !empty($eshop3D->getTextureGallery())) {
$textureItemCollection = $dem->getRepository(GalleryItem::class)->getGalleryItemList($eshop3D->getTextureGallery()->getGalleryId());
}
foreach($rootNodes as $cat) {
if($cat->getEshopId() == $eshopId && $cat->getIsActive()) {
$catId = $cat->getCategoryId();
$productList = array();
$childNodes[] = $cat;
$childNodeImages[$catId] = $this->getImageFromText($cat->getCategoryName(), 'orange-black', $userDirs['images'], $userDirs['web'].'/images', 30, 'category_'.$catId, 400, 60, 40, 48);
//getImageFromText($text="", $colorType="default", $imagePath, $imageWebPath, $countCharactersInLine = 30, $imageName="image_name", $imageWidth=400, $imageHeight=60, $fontSize=40, $positionY = 40)
if($cat->getImage1() != "") {
$categoryImagePath = $userDirs['web'].'/images/'.$cat->getImage1();
} else {
$categoryImagePath = '';
}
$categoryImages[$catId] = $categoryImagePath;
/* we get products in the cateory */
$productList = $dem->getRepository(Product::class)->getProductListByCategory($catId);
/* we generate images for product titles */
foreach($productList as $product) {
$productId = $product->getProductId();
$title = $this->getImageFromText($product->getProductName(), 'orange-black', $userDirs['images'], $userDirs['web'].'/images', 30, 'product_'.$productId.'_title', 500, 40, 25, 30);
$description = $this->getImageFromText($product->getProductDescription(), 'orange-black', $userDirs['images'], $userDirs['web'].'/images', 50, 'product_'.$productId.'_description', 500, 27, 12, 40);
$productListTitles[$productId] = $title;
$productDescriptions[$productId] = $description;
$products[$productId] = $product;
}
/*
print('<br>QQW productList in category: '.$cat->getCategoryName());
\Doctrine\Common\Util\Debug::dump($productList);
*/
/* we display products from subfolders */
if(!empty($eshop->isDisplayProductsFromSubfolders()) && $eshop->isDisplayProductsFromSubfolders() == true) {
$catChildNodes = $cat->getChildren();
foreach($catChildNodes as $catChild) {
$subCatId = $catChild->getCategoryId();
$nodeProductList = $dem->getRepository(Product::class)->getProductListByCategory($catChild->getCategoryId());
//$productList = array_merge($productList, $nodeProductList);
$categoryProducts[$catChild->getCategoryId()] = $nodeProductList;
$productIds = [];
foreach($nodeProductList as $product) {
$productId = $product->getProductId();
$title = $this->getImageFromText($product->getProductName(), 'orange-black', $userDirs['images'], $userDirs['web'].'/images', 30, 'product_'.$productId.'_title', 500, 40, 25, 30);
$description = $this->getImageFromText($product->getProductDescription(), 'orange-black', $userDirs['images'], $userDirs['web'].'/images', 50, 'product_'.$productId.'_description', 500, 27, 12, 40);
$productListTitles[$productId] = $title;
$productDescriptions[$productId] = $description;
$products[$productId] = $product;
$productIds[] = $productId;
}
/* we load prices */
$productPriceList = $dem->getRepository(Product::class)->getProductPriceList($productIds);
$defaultCurrency = $em->getRepository(Currency::class)->getCurrency($eshop->getPreferredCurrencyId());
$targetCurrency = $session->get('eshopCurrency');
/* we load currency rated prices */
$productPriceList = $dem->getRepository(Product::class)->getCurrencyRatedProductPriceList($productPriceList, $defaultCurrency, $targetCurrency);
/* we get price(s) to display */
$displayPrice = null;
foreach($productPriceList as $price) {
if($price->getProductId() == $product->getProductId()) {
/* we get default price level */
if($price->getPriceLevelId() == 1) {
//$displayPrice = round($price->getBruttoValue(),$eshop->getRoundPrice());
$displayPrice = round($price->getNettoValue(),$eshop->getRoundPrice());
}
}
}
$categoryProductPrices[$subCatId] = $productPriceList;
//$logger->notice('QQW subCatId: '.,;
//$logger->notice('QQW subCat '.$catChild->getCategoryName().' prices:', ['subCatPrices' => count($productPriceList)]);
}
/*
print('<br>-------------------QQW DisplayProductsFromSubfolders: ');
\Doctrine\Common\Util\Debug::dump($productList);
*/
}
$categoryProducts[$cat->getCategoryId()] = $productList;
/* we generate images for product titles */
$productIds = [];
foreach($productList as $product) {
$productId = $product->getProductId();
$productIds[] = $productId;
$title = $this->getImageFromText($product->getProductName(), 'orange-black', $userDirs['images'], $userDirs['web'].'/images', 30, 'product_'.$productId.'_title', 500, 40, 25, 30);
$description = $this->getImageFromText($product->getProductDescription(), 'orange-black', $userDirs['images'], $userDirs['web'].'/images', 50, 'product_'.$productId.'_description', 500, 27, 12, 40);
$productListTitles[$productId] = $title;
$productDescriptions[$productId] = $description;
$products[$productId] = $product;
}
/* we load prices */
$productPriceList = $dem->getRepository(Product::class)->getProductPriceList($productIds);
$defaultCurrency = $em->getRepository(Currency::class)->getCurrency($eshop->getPreferredCurrencyId());
$targetCurrency = $session->get('eshopCurrency');
// print('targetCurrency: ');
// print_r($targetCurrency);
// die();
if(empty($targetCurrency)) {
$targetCurrency = $defaultCurrency;
}
/* we load currency rated prices */
$productPriceList = $dem->getRepository(Product::class)->getCurrencyRatedProductPriceList($productPriceList, $defaultCurrency, $targetCurrency);
/* we get price(s) to display */
$displayPrice = null;
foreach($productPriceList as $price) {
if($price->getProductId() == $product->getProductId()) {
/* we get default price level */
if($price->getPriceLevelId() == 1) {
//$displayPrice = round($price->getBruttoValue(),$eshop->getRoundPrice());
$displayPrice = round($price->getNettoValue(),$eshop->getRoundPrice());
}
}
}
$categoryProductPrices[$cat->getCategoryId()] = $productPriceList;
//$logger->notice('QQW Cat '.$cat->getCategoryName().' prices:', ['catPrices' => count($productPriceList)]);
}
}
/*
print('<hr>QQW categoryProductPrices: ');
\Doctrine\Common\Util\Debug::dump($categoryProductPrices);
$logger->notice('QQW Hallo logger e-shop 3D: ');
foreach($productListTitles as $tit){
$logger->notice('tit: '.$tit);
}
*/
/*
print('<hr>QQW productList: ');
\Doctrine\Common\Util\Debug::dump($categoryProducts);
print('<hr>');
*/
//die();
if($_SERVER['HTTP_HOST'] != 'localhost') {
$urlPattern = "https://www.virtualrealitycommerce.org/";
} else {
$urlPattern = "http://localhost/webexciter/public/";
}
$debug = 1;
if($request->request->get('header')==='false') {
$isHeader = false;
} else {
$isHeader = true;
}
if(!empty($request->request->get('is_footer')) && $request->request->get('footer')=='false') {
$isFooter = false;
} else {
$isFooter = true;
}
/* we load list of modules for connector service */
$service = $em->getRepository(Service::class)->getService(1);
/* we load examples */
$exampleCollection = $em->getRepository(ServiceExample::class)->getServiceExampleListByService(1, 3);
shuffle($exampleCollection);
/* we render data */
return $this->render('eshopHome.html.twig',
array(
'headerData' => $this -> getPageHeader($request),
'moduleList' => $service->getModules(),
'exampleCollection' => $exampleCollection,
'service' => $service,
'menu' => $this -> adminMenu($request),
'mainMenu' => $this -> adminMainMenu($request),
'eshop' => $eshop,
'user' => $user,
'userDirs' => $userDirs,
'childNodes' => $childNodes,
'childNodeImages' => $childNodeImages,
'categoryImages' => $categoryImages,
'productListTitles' => $productListTitles,
'productDescriptions' => $productDescriptions,
'products' => $products,
'categoryProducts' => $categoryProducts,
'categoryTreeMenu' => $this->categoryTreeMenu($eshop, $request),
'categoryTopMenu' => $this->categoryTopMenu($eshop, $request),
'logger' => $logger,
'urlPattern' => $urlPattern,
'textureItemCollection' => $textureItemCollection,
'categoryProductPrices' => $categoryProductPrices,
'isPackSaleModule' => $isPackSaleModule,
'eshop3D' => $eshop3D,
'gallery3D' => $gallery3D,
'galleryItemCollection' => $galleryItemCollection
)
);
}
/**
* @Route("/eshop/{eshopId}", name="eshop")
*/
public function eshopAction(Request $request, $eshopId)
{
/* we load session data */
parent::init($request);
$session = $request->getSession();
$logger = $this->getLogger(null, 'e-shop');
$logger->notice('E-shop id '.$eshopId.' - logger init');
//print('<br>QQW eshop ID: '.$eshopId);
//\Doctrine\Common\Util\Debug::dump($category);
//print('<br>QQW getLocale: '.$request->getLocale());
//$product->setLocale($lang->getLangKey());
/* we load entity managers */
$em = $this->doctrine->getManager();
$dem = $this->doctrine->getManager('dynamic_em');
/* we get current e-shop */
$eshop = $em->getRepository(Eshop::class)->getEshop($eshopId);
$user = $em->getRepository(User::class)->getUser($eshop->getUserId());
/* we check if eshop exists */
if($eshop === null) {
$this->addFlash('error', 'E-shop with this ID does not exist.');
return $this->redirectToRoute('eshopHome');
}
try {
//print('<br>Twig - adds php functions ...');
$this->twig->addFunction(new \Twig\TwigFunction('deg2rad', 'deg2rad'));
$this->twig->addFunction(new \Twig\TwigFunction('sin', 'sin'));
$this->twig->addFunction(new \Twig\TwigFunction('imagecreatefromstring', 'imagecreatefromstring'));
$this->twig->addFunction(new \Twig\TwigFunction('file_get_contents', 'file_get_contents'));
$this->twig->addFunction(new \Twig\TwigFunction('ImageSX', 'ImageSX'));
$this->twig->addFunction(new \Twig\TwigFunction('ImageSY', 'ImageSY'));
} catch(Exception $e) {
$this->addFlash('error', "Twig functions init error");
}
/* we load header for the current website */
//$product->setLocale($lang->getLangKey());
$eshopHeader = $dem->getRepository(Eshop::class)->getEshopHeader($eshopId);
if(!empty($eshopHeader)) {
$eshopHeader->setLocale($session->get('lang')->getLangKey());
$dem->refresh($eshopHeader);
}
/* we load footer for the current website */
$eshopFooter = $dem->getRepository(Eshop::class)->getEshopFooter($eshopId);
if(!empty($eshopFooter)) {
$eshopFooter->setLocale($session->get('lang')->getLangKey());
$dem->refresh($eshopFooter);
}
/* we load home page for the current website */
$homePage = $dem->getRepository(Eshop::class)->getHomePage($eshopId);
if(!empty($homePage)) {
$homePage->setLocale($session->get('lang')->getLangKey());
$dem->refresh($homePage);
}
// print('<br>qqw homePage: ');
// \Doctrine\Common\Util\Debug::dump($homePage);
$seoData = array();
$seoData['seoTitle'] = '';
$seoData['seoDescription'] = '';
/* we parse the page content for placeholders */
if(!empty($homePage)) {
$homePageContent = $this->parseContent($request, $homePage->getWebPageContent());
$homePage->setWebPageContent($homePageContent);
$seoData['seoTitle'] = $homePage->getSeoTitle();
$seoData['seoDescription'] = $homePage->getSeoDescription();
}
/* we add product(s) to basket - POST form action */
if(!empty($request->request->get('basket'))) {
/* we call method to add to basket */
$this->addToBasket($request, $eshopId, $request->request->get('productId'));
}
/* we get wireframe */
$wireFrame = $em->getRepository(WireFrame::class)->getWireFrame($eshop->getWireFrameId());
$rootNodes = $dem->getRepository(Category::class)->getRootNodes();
$childNodes = array();
$subCats = array();
foreach($rootNodes as $cat) {
if($cat->getEshopId() == $eshopId && $cat->getIsActive()) {
$cat->setLocale($session->get('lang')->getLangKey());
$dem->refresh($cat);
$childNodes[] = $cat;
$subNodes = $cat->getChildren();
$rootCatId = $cat->getCategoryId();
foreach($subNodes as $subNode) {
if($subNode->getEshopId() == $eshop->getEshopId() && $subNode->getIsActive()) {
$subNode->setLocale($session->get('lang')->getLangKey());
$dem->refresh($subNode);
//print('<br>qqw subNode: '.$subNode->getCategoryName());
//\Doctrine\Common\Util\Debug::dump($subNode);
$subCats[$rootCatId][] = $subNode;
}
}
}
}
//we prepare sub categories thumbnails
$categoryThumbs = array();
foreach($childNodes as $cat) {
//print('<hr>QQW cat: '.$cat->getImage1());
$catId = $cat->getCategoryId();
if(!empty($cat->getImage1()) && $cat->getImage1() != "") {
//$imagePath = 'users/'.$user->getUserName().'/images/'.$product->getImage1();
if (strpos($cat->getImage1(), 'http') === false) {
$imagePath = 'users/'.$user->getUserName().'/images/'.$cat->getImage1();
$imageThumbPath = 'users/'.$user->getUserName().'/images/thumb_'.$cat->getImage1();
} else {
$imagePath = $cat->getImage1();
$path = parse_url($imagePath, PHP_URL_PATH);
$imageThumbPath = 'users/'.$user->getUserName().'/images/thumb_'.basename($path);
}
/*
print('<br>qqw imagePath: '.$imagePath);
print('<br>qqw imageThumbPath: '.$imageThumbPath);
*/
$imageThumb = $this->getEshopImageThumb($eshop, $imagePath, $imageThumbPath, true);
$categoryThumbs[$catId] = $imageThumb;
}
//\Doctrine\Common\Util\Debug::dump($cat);
}
/* we render data */
return $this->render('eshop.html.twig',
array( 'headerData' => $this -> getPageHeader($request),
'seoData' => $seoData,
'menu' => $this -> adminMenu($request),'mainMenu' => $this -> adminMainMenu($request),'mainMenu' => $this -> adminMainMenu($request),
'eshop' => $eshop,
'user' => $user,
'wireFrame' => $wireFrame,
'childNodes' => $childNodes,
'categoryTreeMenu' => $this->categoryTreeMenu($eshop, $request),
'categoryTopMenu' => $this->categoryTopMenu($eshop, $request),
'eshopHeader' => $eshopHeader,
'eshopFooter' => $eshopFooter,
'homePage' => $homePage,
'topProducts' => $this->getTopProducts($request, $eshop, 7),
//'topProducts' => $topProducts,
'routeName' => 'eshop'
)
);
}
/**
* @Route("/eshop/{eshopId}/category/{categoryId}", name="eshopCategory")
*/
public function eshopCategoryAction(Request $request, $eshopId, $categoryId)
{
/* we load session data */
parent::init($request);
$session = $request->getSession();
//print('<br>QQW eshop ID: '.$eshopId);
//\Doctrine\Common\Util\Debug::dump($category);
/* we load entity managers */
$em = $this->doctrine->getManager();
$dem = $this->doctrine->getManager('dynamic_em');
/* we get current e-shop */
$eshop = $em->getRepository(Eshop::class)->getEshop($eshopId);
$user = $em->getRepository(User::class)->getUser($eshop->getUserId());
$priceLevelList = $dem->getRepository(PriceLevel::class)->getPriceLevelList();
foreach ($priceLevelList as $priceLevel) {
//print('<br>qqw priceLevel: ');
$priceLevel->setLocale($session->get('lang')->getLangKey());
$dem->refresh($priceLevel);
}
/* we check if eshop exists */
if($eshop === null) {
$this->addFlash('error', 'E-shop with this ID does not exist.');
return $this->redirectToRoute('eshopHome');
}
$category = $dem->getRepository(Eshop::class)->getCategory($categoryId);
$categoryPath = $dem->getRepository(Category::class)->getPath($category);
$childNodes = $category->getChildren();
//print('<br>categoryPath: ');
//\Doctrine\Common\Util\Debug::dump($categoryPath);
foreach($categoryPath as $cat) {
$cat->setLocale($session->get('lang')->getLangKey());
$dem->refresh($cat);
}
$seoData = array();
$seoData['seoTitle'] = $category->getCategoryName().' - '.$eshop->getEshopName();
$seoData['seoDescription'] = $eshop->getEshopName().', '.$category->getCategoryName().(!empty($category->getCategoryDescription())?(' - '.$category->getCategoryDescription()):'');
//we prepare sub categories thumbnails
$categoryThumbs = array();
foreach($childNodes as $cat) {
//print('<hr>QQW cat: '.$cat->getImage1());
$catId = $cat->getCategoryId();
$cat->setLocale($session->get('lang')->getLangKey());
$dem->refresh($cat);
if(!empty($cat->getImage1()) && $cat->getImage1() != "") {
//$imagePath = 'users/'.$user->getUserName().'/images/'.$product->getImage1();
if (strpos($cat->getImage1(), 'http') === false) {
$imagePath = 'users/'.$user->getUserName().'/images/'.$cat->getImage1();
$imageThumbPath = 'users/'.$user->getUserName().'/images/thumb_'.$cat->getImage1();
} else {
$imagePath = $cat->getImage1();
$path = parse_url($imagePath, PHP_URL_PATH);
$imageThumbPath = 'users/'.$user->getUserName().'/images/thumb_'.basename($path);
}
/*
print('<br>qqw imagePath: '.$imagePath);
print('<br>qqw imageThumbPath: '.$imageThumbPath);
*/
$imageThumb = $this->getEshopImageThumb($eshop, $imagePath, $imageThumbPath, true);
$categoryThumbs[$catId] = $imageThumb;
}
//\Doctrine\Common\Util\Debug::dump($cat);
}
$categoryArray = array();
$categoryArray[] = $category;
if(!empty($eshop->isDisplayProductsFromSubfolders()) && $eshop->isDisplayProductsFromSubfolders() == true) {
if ($eshop->getDisplayProductsFromSubfoldersLevel() > 0) {
foreach($childNodes as $cat) {
if($cat->getIsActive()) {
$categoryArray[] = $cat;
if ($eshop->getDisplayProductsFromSubfoldersLevel() > 1) {
$childNodesLevel2 = $cat->getChildren();
foreach($childNodesLevel2 as $catLevel2) {
$categoryArray[] = $catLevel2;
if ($eshop->getDisplayProductsFromSubfoldersLevel() > 2) {
$childNodesLevel3 = $catLevel2->getChildren();
foreach($childNodesLevel3 as $catLevel3) {
$categoryArray[] = $catLevel3;
}
}
}
}
}
}
}
}
/* we get product list */
$productPerPage = $eshop->getCountPerPage();
$page = $request->query->get('page');
$firstRecord = ($page * $productPerPage) - $productPerPage;
if($firstRecord < 1) {
$firstRecord = 0;
}
if(!empty($request->get('sort'))) {
/* we call method to setup sort in session */
$session->set('sort', $request->get('sort'));
} elseif(empty($session->get('sort'))) {
$session->set('sort', 'default');
}
// filters
// add brand filter
$brandFilters = null;
if(!empty($request->get('addBrandFilter'))) {
if(empty($session->get('brandFilters'))) {
$brandFilters = [];
$brandFilters[] = $request->get('addBrandFilter');
} else {
$brandFilters = $session->get('brandFilters');
if (!in_array($request->get('addBrandFilter'), $brandFilters)) {
$brandFilters[] = $request->get('addBrandFilter');
}
}
$session->set('brandFilters', $brandFilters);
// print('<br>QQW adding brand filter: '.$request->get('addBrandFilter'));
// print('<br>QQW brandFilters: ');
// \Doctrine\Common\Util\Debug::dump($brandFilters);
}
// remove brand filter
if(!empty($request->get('removeBrandFilter'))) {
$brandFilters = $session->get('brandFilters');
if (in_array($request->get('removeBrandFilter'), $brandFilters)) {
foreach ($brandFilters as $key => $brand) {
if ($brand == $request->get('removeBrandFilter')) {
unset($brandFilters[$key]);
print('<br>QQW brandFilters X: ');
}
}
}
$session->set('brandFilters', $brandFilters);
// print('<br>QQW removing brand filter: '.$request->get('removeBrandFilter'));
// print('<br>QQW brandFilters: ');
// \Doctrine\Common\Util\Debug::dump($brandFilters);
}
//isModule Pack Sale
$module = $em->getRepository(Module::class)->getModule(42);
$isPackSaleModule = $em->getRepository(User::class)->userHasModule($user, $module);
$productList = $dem->getRepository(Product::class)->getProductListByCategory($categoryArray, $firstRecord, $productPerPage, false, $session->get('sort'), $brandFilters);
$productCount = $dem->getRepository(Product::class)->getProductCountByCategory($categoryArray);
//print('<br>QQW productCount: '.$productCount);
$manufacturerList = $dem->getRepository(Product::class)->getManufacturerListByCategory($categoryArray);
// print('<br>QQW productList: ');
// \Doctrine\Common\Util\Debug::dump($productList);
/* we display products from subfolders */
/*
if(!empty($eshop->getDisplayProductsFromSubfolders()) && $eshop->getDisplayProductsFromSubfolders() == true) {
foreach($childNodes as $cat) {
$nodeProductList = $dem->getRepository(Product::class)->getProductListByCategory($cat->getCategoryId());
$productList = array_merge($productList, $nodeProductList);
}
}
*/
/* we load product ids into array */
/* we setup and validate images */
$productIds = [];
$productImages = [];
$productThumbs = [];
$productVariants = [];
$manufacturers = [];
foreach($productList as $product) {
$pId = $product->getProductId();
$productIds[] = $pId;
if($product->getImage1() != "") {
//$imagePath = 'users/'.$user->getUserName().'/images/'.$product->getImage1();
if (strpos($product->getImage1(), 'http') === false) {
$imagePath = 'users/'.$user->getUserName().'/images/'.$product->getImage1();
$imageThumbPath = 'users/'.$user->getUserName().'/images/'.$product->getImage1();
} else {
$imagePath = $product->getImage1();
$path = parse_url($imagePath, PHP_URL_PATH);
$imageThumbPath = 'users/'.$user->getUserName().'/images/'.basename($path);
}
/*
print('<br>qqw imagePath: '.$imagePath);
print('<br>qqw imageThumbPath: '.$imageThumbPath);
*/
$imageThumb = $this->getEshopImageThumb($eshop, $imagePath, $imageThumbPath, false, $category);
$productThumbs[$pId] = $imageThumb;
}
//print('<br>qqw productName: '.$product->getProductName());
/* we setup product names - if empty then we load multilingual values */
$productName = '';
if(!empty($product->getProductName()) && $product->getProductName() != '') {
$productName = $product->getProductName();
//int('<br>qqw pname 0: '.$productName);
} else {
//we try to get the product name from multilangual fields
foreach($eshop->getLanguages() as $lang) {
$product->setLocale($lang->getLangKey());
$dem->refresh($product);
if(!empty($product->getProductName()) && $product->getProductName() != '') {
$productName = $product->getProductName();
}
}
}
//print('<br>qqw pname 1: '.$productName);
$product->setProductName($productName);
$dem->flush();
//print('<br>qqw pname 2: '.$product->getProductName());
/* we setup product descriptions - if empty then we load multilingual values */
$productDescription = '';
if(!empty($product->getProductDescription()) && $product->getProductDescription() != '') {
$productDescription = $product->getProductDescription();
} else {
//we try to get the product description from multilangual fields
foreach($eshop->getLanguages() as $lang) {
$product->setLocale($lang->getLangKey());
$dem->refresh($product);
if(!empty($product->getProductDescription()) && $product->getProductDescription() != '') {
$productDescription = $product->getProductDescription();
}
}
}
//print('<br>qqw pDescription: '.$productDescription);
$product->setProductDescription($productDescription);
$dem->flush();
// we setup brands
if(!empty($product->getManufacturer())) {
if(!in_array($product->getManufacturer(),$manufacturers)) {
$manufacturers[] = $product->getManufacturer();
}
}
//we check variants
$parentProduct = null;
if(!empty($product->getParentProductId())) {
print('<hr>QQW parent product: '.$product->getParentProductId());
$parentProduct = $dem->getRepository(Product::class)->getProduct($product->getParentProductId());
// we load variants of master product
$productVariantList = $dem->getRepository(Product::class)->getProductVariantList($product->getParentProductId());
} else {
// we load variants of master product
if(is_numeric($pId)) {
$productVariantList = $dem->getRepository(Product::class)->getProductVariantList($pId);
} else {
$productVariantList = $dem->getRepository(Product::class)->getProductVariantListSeo($pId);
}
}
$productVariants[$pId] = $productVariantList;
}
/* we load prices */
$productPriceList = $dem->getRepository(Product::class)->getProductPriceList($productIds);
$defaultCurrency = $em->getRepository(Currency::class)->getCurrency($eshop->getPreferredCurrencyId());
$targetCurrency = $session->get('eshopCurrency');
/* we load currency rated prices */
$productPriceList = $dem->getRepository(Product::class)->getCurrencyRatedProductPriceList($productPriceList, $defaultCurrency, $targetCurrency);
/* we get price(s) to display */
$displayPrice = null;
foreach($productPriceList as $price) {
if($price->getProductId() == $product->getProductId()) {
/* we get default price level */
if($price->getPriceLevelId() == 1) {
//$displayPrice = round($price->getBruttoValue(),$eshop->getRoundPrice());
$displayPrice = round($price->getNettoValue(),$eshop->getRoundPrice());
}
}
}
/* we load pack prices */
$productPackPriceList = array();
if($isPackSaleModule) {
$productPackPriceList = $dem->getRepository(Product::class)->getProductPackPriceList($productIds);
/* we load currency rated prices */
$productPackPriceList = $dem->getRepository(Product::class)->getCurrencyRatedProductPriceList($productPackPriceList, $defaultCurrency, $targetCurrency);
/* we get package price(s) to display */
$displayPackPrice = null;
foreach($productPackPriceList as $price) {
if($price->getProductId() == $product->getProductId()) {
/* we get default price level */
if($price->getPriceLevelId() == 1) {
//$displayPrice = round($price->getBruttoValue(),$eshop->getRoundPrice());
$displayPackPrice = round($price->getNettoValue(),$eshop->getRoundPrice());
}
}
}
}
/* we add product(s) to basket - POST form action */
if(!empty($request->request->get('basket'))) {
/* we call method to add to basket */
$this->addToBasket($request, $eshopId, $request->request->get('productId'));
}
$productView = $eshop->getProductView();
/*
print('<br>qqw eshop: '.$eshop->getWireFrameId());
\Doctrine\Common\Util\Debug::dump($eshop);
*/
/* we load header for the current website */
$eshopHeader = $dem->getRepository(Eshop::class)->getEshopHeader($eshopId);
if(!empty($eshopHeader)) {
$eshopHeader->setLocale($session->get('lang')->getLangKey());
$dem->refresh($eshopHeader);
}
/* we load footer for the current website */
$eshopFooter = $dem->getRepository(Eshop::class)->getEshopFooter($eshopId);
if(!empty($eshopFooter)) {
$eshopFooter->setLocale($session->get('lang')->getLangKey());
$dem->refresh($eshopFooter);
}
/* we load home page for the current website */
$homePage = $dem->getRepository(Eshop::class)->getHomePage($eshopId);
$wireFrame = $em->getRepository(WireFrame::class)->getWireFrame($eshop->getProductListWireFrameId());
//$childNodes = $category->getChildren();
/*
print('<br>qqw childNodes: ');
\Doctrine\Common\Util\Debug::dump($childNodes);
*/
if(!empty($request->query->get('simpleview'))) {
$simpleView = true;
} else {
$simpleView = false;
}
/* we prepare data for view */
$viewData = array( 'headerData' => $this -> getPageHeader($request),
'menu' => $this -> adminMenu($request),'mainMenu' => $this -> adminMainMenu($request),'mainMenu' => $this -> adminMainMenu($request),
'eshop' => $eshop,
'user' => $user,
'productView' => $productView,
'productList' => $productList,
'productPriceList' => $productPriceList,
'productThumbs' => $productThumbs,
'productCount' => $productCount,
'wireFrame' => $wireFrame,
'category' => $category,
'childNodes' => $childNodes,
'categoryPath' => $categoryPath,
'categoryTreeMenu' => $this->categoryTreeMenu($eshop, $request),
'categoryTopMenu' => $this->categoryTopMenu($eshop, $request),
'eshopHeader' => $eshopHeader,
'eshopFooter' => $eshopFooter,
'homePage' => $homePage,
'seoData' => $seoData,
'productPackPriceList' => $productPackPriceList,
'isPackSaleModule' => $isPackSaleModule,
'priceLevelList' => $priceLevelList,
'topProducts' => $this->getTopProducts($request, $eshop, 7),
'manufacturers' => $manufacturerList,
'simpleView' => $simpleView,
'productVariants' => $productVariants
);
if(!empty($request->query->get('REST')) OR !empty($request->query->get('api'))) {
// we output json
return new JsonResponse($viewData);
} else {
// we render template
return $this->render('eshopCategory.html.twig', $viewData);
}
}
public function addToBasket(Request $request, $eshopId, $productId, $isFlashMessage = true)
{
/* we load session data */
parent::init($request);
$session = $request->getSession();
//print('<br>QQW eshop ID: '.$eshopId);
//\Doctrine\Common\Util\Debug::dump($category);
/* we load entity managers */
$em = $this->doctrine->getManager();
$dem = $this->doctrine->getManager('dynamic_em');
/* we get current e-shop */
$eshop = $em->getRepository(Eshop::class)->getEshop($eshopId);
$user = $em->getRepository(User::class)->getUser($eshop->getUserId());
$targetCurrency = $session->get('eshopCurrency');
/* we load product */
$product = $dem->getRepository(Product::class)->getProduct($productId);
$product->setLocale($session->get('lang')->getLangKey());
$dem->refresh($product);
/* if there is no order in basket then we create new order */
if(empty($session->get('order'))) {
//print('<br>QQW Creating New Order');
$order = new Order;
$order->setEshopId($eshopId);
$order->setCurrencyKey($targetCurrency->getCurrencyKey());
$session->set('order', $order);
$session->get('order')->setIp($request->getClientIp());
}
/* we set product units */
$units = 1;
if(!empty($request->request->get('units'))) {
$unitInt = intval($request->request->get('units'));
if($unitInt > 0) {
$units = $request->request->get('units');
} else {
$units = 1;
}
}
//isModule Pack Sale
$module = $em->getRepository(Module::class)->getModule(42);
$isPackSaleModule = $em->getRepository(User::class)->userHasModule($user, $module);
//we set totalprice for order item
$totalOrderItemPrice = $this->getTotalOrderItemPrice($request, $product, $units, $isPackSaleModule);
/* we check if we have this order item in basket already */
$isInBasket = false;
foreach($session->get('order')->getOrderItems() as $orderItem) {
if($orderItem->getProductId() == $product->getProductId()) {
//print('<br>qqw item exists in basket');
$totalOrderItemPrice = $this->getTotalOrderItemPrice($request, $product, ($orderItem->getOrderItemUnits() + $units), $isPackSaleModule);
$orderItem->setOrderItemUnits($orderItem->getOrderItemUnits() + $units);
$orderItem->setOrderItemTotalPrice($totalOrderItemPrice);
$isInBasket = true;
}
}
if(!$isInBasket) {
/* we create order item and load it with product data */
//print('<br>qqw product is NOT in basket yet');
$orderItem = new OrderItem;
$orderItem->setOrderItemTitle($product->getProductName());
//print('<br>qqw units: '.$units);
$orderItem->setOrderItemUnits($units);
$orderItem->setProductId($product->getProductId());
//$itemPrice = $units * $request->request->get('productPrice');
$orderItem->setOrderItemPrice($request->request->get('productPrice'));
$orderItem->setOrderItemTotalPrice($totalOrderItemPrice);
//we set brutto price
if(!empty($request->request->get('orderItemPriceBrutto')) && $request->request->get('orderItemPriceBrutto') > 0) {
$orderItem->setOrderItemPriceBrutto($request->request->get('orderItemPriceBrutto'));
}
//we set order item VAT
if(!empty($request->request->get('orderItemVAT')) && $request->request->get('orderItemVAT') > 0) {
$orderItem->setOrderItemVAT($request->request->get('orderItemVAT'));
}
$orderItem->setCurrencyKey($request->request->get('currencyKey'));
$session->get('order')->addOrderItem($orderItem);
}
$orderItemId = $dem->getRepository(Order::class)->getMaxOrderItemId($session->get('order'));
if ($isFlashMessage) {
$this->addFlash('notice', $this->translator->trans('product.added_to_basket').'<a href="/eshop/'.$eshopId.'/basket" class="viewBasket">'.$this->translator->trans('eshop.basket_view').'</a>');
}
/*
print('<br>qqw basket items: ');
\Doctrine\Common\Util\Debug::dump($session->get('order')->getOrderItems());
*/
}
/**
* @Route("/api/eshop/{eshopId}/product/{productId}", name="apiEshopProduct")
*/
public function getEshopProduct(Request $request, $eshopId, $productId)
{
/* we load session data */
parent::init($request);
$session = $request->getSession();
/* we load users entity manager */
$em = $this->doctrine->getManager();
$dem = $this->doctrine->getManager('dynamic_em');
// we get current e-shop
$eshop = $em->getRepository(Eshop::class)->getEshop($eshopId);
$priceLevelList = $dem->getRepository(PriceLevel::class)->getPriceLevelList();
/*
print('<br>qqw eshop: '.$eshop->getEshopId());
\Doctrine\Common\Util\Debug::dump($eshop);
*/
if(!empty($request->request->get('productId'))) {
// we call method to add to basket
$productId = $request->request->get('productId');
} elseif (!empty($request->get('productId'))) {
$productId = $request->get('productId');
} elseif (!empty($request->attributes->get('productId'))) {
$productId = $request->attributes->get('productId');
}
$product = $dem->getRepository(Product::class)->getProduct($productId);
$product->setLocale($session->get('lang')->getLangKey());
$dem->refresh($product);
//$apiProduct = get_object_vars($product);
//$apiProduct = $product->toArray();
try {
//print('<br>Twig - adds php functions ...');
$this->twig->addFunction(new \Twig\TwigFunction('deg2rad', 'deg2rad'));
$this->twig->addFunction(new \Twig\TwigFunction('sin', 'sin'));
$this->twig->addFunction(new \Twig\TwigFunction('imagecreatefromstring', 'imagecreatefromstring'));
$this->twig->addFunction(new \Twig\TwigFunction('file_get_contents', 'file_get_contents'));
$this->twig->addFunction(new \Twig\TwigFunction('ImageSX', 'ImageSX'));
$this->twig->addFunction(new \Twig\TwigFunction('ImageSY', 'ImageSY'));
} catch(Exception $e) {
$this->addFlash('error', "Twig functions init error");
}
//loads prices
$productIds = [$productId];
$productPriceList = $dem->getRepository(Product::class)->getProductPriceList($productIds);
$defaultCurrency = $em->getRepository(Currency::class)->getCurrency($eshop->getPreferredCurrencyId());
$targetCurrency = $session->get('eshopCurrency');
// loads currency rated prices
$productPriceList = $dem->getRepository(Product::class)->getCurrencyRatedProductPriceList($productPriceList, $defaultCurrency, $targetCurrency);
//gets price(s) to display
$displayPrice = null;
foreach($productPriceList as $price) {
if($price->getProductId() == $product->getProductId()) {
/* we get default price level */
if($price->getPriceLevelId() == 1) {
//$displayPrice = round($price->getBruttoValue(),$eshop->getRoundPrice());
$displayPrice = round($price->getNettoValue(),$eshop->getRoundPrice());
}
}
}
$apiProduct = [
'productName' => $product->getProductName(),
'productKey' => $product->getProductKey(),
'ERPKey' => $product->getERPKey(),
'image1' => $product->getImage1(),
'displayPrice' => $displayPrice,
'productDescription' => $product->getProductDescription(),
];
$limit = 300;
$offset = 0;
$count = 0;
$pages = 10;
$page = 1;
$system = array('code' => 200, 'message' => 'OK');
$metadata = array('count' => $count, 'limit' => 100, 'pages' => $pages, 'page' => $page);
//die();
/* we prepare data for view */
$viewData = array('system' => $system,
'product' => $apiProduct,
'metadata' => $metadata,
);
// we output json
return new JsonResponse($viewData);
}
/**
* @Route("/api/eshop/{eshopId}/getbasket", name="getBasket")
*/
public function getBasket(Request $request, $eshopId)
{
/* we load session data */
parent::init($request);
$session = $request->getSession();
/* we load users entity manager */
$em = $this->doctrine->getManager();
$dem = $this->doctrine->getManager('dynamic_em');
// we get current e-shop
$eshop = $em->getRepository(Eshop::class)->getEshop($eshopId);
/*
print('<br>qqw eshop: '.$eshop->getEshopId());
\Doctrine\Common\Util\Debug::dump($eshop);
*/
$limit = 300;
$offset = 0;
$defaultCurrency = $em->getRepository(Currency::class)->getCurrency($eshop->getPreferredCurrencyId());
$count = 0;
$pages = 10;
$page = 1;
$system = array('code' => 200, 'message' => 'OK');
$metadata = array('count' => $count, 'limit' => 100, 'pages' => $pages, 'page' => $page);
$basketItems = [];
if(!empty($session->get('order'))) {
foreach($session->get('order')->getOrderItems() as $orderItem) {
$basketItem = [];
if(!empty($orderItem->getOrderItemPriceBrutto())) {
$productPriceVAT = $orderItem->getOrderItemPriceBrutto() * $orderItem->getOrderItemUnits();
} else {
$productPriceVAT = $orderItem->getOrderItemPrice() * $orderItem->getOrderItemUnits();
}
$basketItem['productId'] = $orderItem->getProductId();
$basketItem['title'] = $orderItem->getOrderItemTitle();
$basketItem['units'] = $orderItem->getOrderItemUnits();
$basketItem['price'] = $productPriceVAT;
$basketItems[] = $basketItem;
}
}
/* we prepare data for view */
$viewData = array('system' => $system,
'basketItems' => $basketItems,
'metadata' => $metadata,
);
// we output json
return new JsonResponse($viewData);
}
/**
* @Route("/api/eshop/{eshopId}/addbasket", name="addBasket", methods={"POST", "PUT"})
*/
public function addBasket(Request $request, $eshopId)
{
/* we load session data */
parent::init($request);
$session = $request->getSession();
$message = 'Adding product to basket.';
//print('<br>QQW eshop ID: '.$eshopId);
//\Doctrine\Common\Util\Debug::dump($category);
// we load entity managers
$em = $this->doctrine->getManager();
$dem = $this->doctrine->getManager('dynamic_em');
// we get current e-shop and user
$eshop = $em->getRepository(Eshop::class)->getEshop($eshopId);
$user = $em->getRepository(User::class)->getUser($eshop->getUserId());
$productId = 102;
// we add product(s) to basket - POST form action
if(!empty($request->request->get('productId'))) {
// we call method to add to basket
$productId = $request->request->get('productId');
$this->addToBasket($request, $eshopId, $request->request->get('productId'), false);
if(!empty($session->get('order')) && $session->get('order')->getEshopId() == $eshopId) {
$basketCount = count($session->get('order')->getOrderItems());
}
$message = $this->translator->trans('eshop.product_inserted');
}
$count = 0;
$pages = 10;
$page = 1;
$system = array('code' => 200, 'message' => $message);
$metadata = array('count' => $count, 'limit' => 100, 'pages' => $pages, 'page' => $page);
//die();
/* we prepare data for view */
$viewData = array('system' => $system,
'basketCount' => $basketCount,
'metadata' => $metadata,
);
// we output json
return new JsonResponse($viewData);
}
/**
* @Route("/eshop/{eshopId}/product/{productId}", name="eshopProduct")
*/
public function eshopProductDetailAction(Request $request, $eshopId, $productId)
{
/* we load session data */
parent::init($request);
$session = $request->getSession();
//print('<br>QQW eshop ID: '.$eshopId);
//\Doctrine\Common\Util\Debug::dump($category);
/* we load entity managers */
$em = $this->doctrine->getManager();
$dem = $this->doctrine->getManager('dynamic_em');
/* we get current e-shop */
$eshop = $em->getRepository(Eshop::class)->getEshop($eshopId);
$priceLevelList = $dem->getRepository(PriceLevel::class)->getPriceLevelList();
/* we check if eshop exists */
if($eshop === null) {
$this->addFlash('error', 'E-shop with this ID does not exist.');
return $this->redirectToRoute('eshopHome');
}
$user = $em->getRepository(User::class)->getUser($eshop->getUserId());
$userDirs = $this->getUserFolderPathsFromUserId($eshop->getUserId());
if(is_numeric($productId)) {
$product = $dem->getRepository(Product::class)->getProduct($productId);
} else {
$product = $dem->getRepository(Product::class)->findOneBy(['titleSEO'=> $productId]);
}
if(!$product) {
$this->addFlash('error', 'Product does not exists.');
return $this->redirectToRoute('eshop', array('eshopId' => $eshopId));
}
$product->setLocale($session->get('lang')->getLangKey());
$dem->refresh($product);
try {
//print('<br>Twig - adds php functions ...');
$this->twig->addFunction(new \Twig\TwigFunction('deg2rad', 'deg2rad'));
$this->twig->addFunction(new \Twig\TwigFunction('sin', 'sin'));
$this->twig->addFunction(new \Twig\TwigFunction('imagecreatefromstring', 'imagecreatefromstring'));
$this->twig->addFunction(new \Twig\TwigFunction('file_get_contents', 'file_get_contents'));
$this->twig->addFunction(new \Twig\TwigFunction('ImageSX', 'ImageSX'));
$this->twig->addFunction(new \Twig\TwigFunction('ImageSY', 'ImageSY'));
} catch(Exception $e) {
$this->addFlash('error', "Twig functions init error");
}
/* we load VAT */
$productVAT = null;
if(!empty($product) && !empty($product->getProductVAT()) && $product->getProductVAT() > 0) {
/* VAT is derived from productVAT */
$productVAT = $product->getProductVAT();
} elseif(!empty($eshop->getPreferredVAT()) && $eshop->getPreferredVAT() > 0) {
/* VAT is derived from eshop VAT */
$productVAT = $eshop->getPreferredVAT();
}
/* we setup product name - if empty then we load multilingual values */
$productName = '';
if(!empty($product->getProductName()) && $product->getProductName() != '') {
$productName = $product->getProductName();
} else {
//we try to get the product name from multilangual fields
foreach($eshop->getLanguages() as $lang) {
$product->setLocale($lang->getLangKey());
$dem->refresh($product);
if(!empty($product->getProductName()) && $product->getProductName() != '') {
$productName = $product->getProductName();
}
}
}
//print('<br>qqw pname: '.$productName);
$product->setProductName($productName);
$dem->flush();
/* we setup product description - if empty then we load multilingual values */
$productDescription = '';
if(!empty($product->getProductDescription()) && $product->getProductDescription() != '') {
$productDescription = $product->getProductDescription();
} else {
//we try to get the product description from multilangual fields
foreach($eshop->getLanguages() as $lang) {
$product->setLocale($lang->getLangKey());
$dem->refresh($product);
if(!empty($product->getProductDescription()) && $product->getProductDescription() != '') {
$productDescription = $product->getProductDescription();
}
}
}
//print('<br>qqw pdescription: '.$productDescription);
$product->setProductDescription($productDescription);
$dem->flush();
$seoData = array();
$seoData['seoTitle'] = $product->getProductName().' - '.$eshop->getEshopName();
$seoData['seoDescription'] = $eshop->getEshopName().', '.$product->getProductName().(!empty($product->getProductShortDescription())?(' - '.$product->getProductShortDescription()):'');
//isModule Pack Sale
$module = $em->getRepository(Module::class)->getModule(42);
$isPackSaleModule = $em->getRepository(User::class)->userHasModule($user, $module);
/* we load prices */
$productIds = array();
$productIds[] = $productId;
// we load parent product
$parentProduct = null;
if(!empty($product->getParentProductId())) {
//print('<hr>QQW parent product: '.$product->getParentProductId());
$parentProduct = $dem->getRepository(Product::class)->getProduct($product->getParentProductId());
// we load variants of master product
$productVariantList = $dem->getRepository(Product::class)->getProductVariantList($product->getParentProductId());
} else {
// we load variants of master product
if(is_numeric($productId)) {
$productVariantList = $dem->getRepository(Product::class)->getProductVariantList($productId);
} else {
$productVariantList = $dem->getRepository(Product::class)->getProductVariantListSeo($productId);
}
}
// we get 3D gallery
$gallery3d = '';
if(!empty($product->getGallery3dId()) && $product->getGallery3dId() > 0) {
$gallery3d = $this->getGallery3D($product->getGallery3dId(), $request);
}
$galleryItemCollection = [];
if(!empty($product->getImageGallery())) {
foreach($product->getImageGallery() as $imageGallery) {
$galleryId = $imageGallery->getGalleryId();
$galleryItems = $dem->getRepository(GalleryItem::class)->getGalleryItemList($galleryId);
$galleryItemCollection[$galleryId] = $galleryItems;
}
}
/*
print('<hr>QQW productVariantList: '.$productId);
\Doctrine\Common\Util\Debug::dump($productVariantList);
*/
// we get variants parameters
$productVariantParameters = array();
$productVariantParameterValues = array();
$variantTexts = [];
$productParameterList = $dem->getRepository(ProductParameter::class)->getProductParameterList();
//print('<hr>QQW productParameterList : ');
//\Doctrine\Common\Util\Debug::dump($productParameterList);
if(!empty($productVariantList)) {
foreach($productVariantList as $productVariant) {
$productVariant->setLocale($session->get('lang')->getLangKey());
$dem->refresh($productVariant);
$productVariantId = $productVariant->getProductId();
$productIds[] = $productVariantId;
$variantText = '';
$variantParamCount = 0;
foreach($productParameterList as $productParameter) {
$productParameter->setLocale($session->get('lang')->getLangKey());
$dem->refresh($productParameter);
$parameterValue = $dem->getRepository(ProductParameterValue::class)->getProductParameterValueByProduct($productParameter->getProductParameterId(), $productVariantId);
if (!empty($parameterValue) && $parameterValue->getProductParameterValue() !== '') {
$parameterValue->setLocale($session->get('lang')->getLangKey());
$dem->refresh($parameterValue);
if ($variantParamCount > 0) {
$variantText .= ', ';
}
$variantText .= $productParameter->getProductParameterName().': '.$parameterValue->getProductParameterValue();
// print('<hr>QQW productParameter: '.$productParameter->getProductParameterId());
// print('<br>QQW name: '.$productParameter->getProductParameterName());
// print('<br>QQW parameterValue: '.$parameterValue->getProductParameterValue());
// print_r($parameterValue);
//print('<br>QQW parameterValue: '.$variantText);
$variantParamCount++;
}
}
$variantTexts[$productVariantId] = $variantText;
//print('<hr>qqw productVariant (id '.$productVariantId.'): '.$productVariant->getERPKey().' - '.$productVariant->getProductKey());
$productVariantParameterValueList = $dem->getRepository(ProductParameterValue::class)->getProductParameterValueList($productVariantId);
foreach($productVariantParameterValueList as $variantParamVal) {
$variantParamVal->setLocale($session->get('lang')->getLangKey());
$dem->refresh($variantParamVal);
}
$productVariantParameterValues[$productVariantId] = $productVariantParameterValueList;
foreach($productVariantParameterValues as $productVariantParameterValue) {
foreach($productVariantParameterValue as $pvp) {
$pvp->setLocale($session->get('lang')->getLangKey());
$dem->refresh($pvp);
$parameter = $dem->getRepository(ProductParameter::class)->getProductParameter($pvp->getProductParameterId());
$parameter->setLocale($session->get('lang')->getLangKey());
$dem->refresh($parameter);
if(!in_array($parameter, $productVariantParameters)) {
$parameterId = $parameter->getProductParameterId();
$productVariantParameters[$parameterId] = $parameter;
}
}
}
}
}
$productPriceList = $dem->getRepository(Product::class)->getProductPriceList($productIds);
$defaultCurrency = $em->getRepository(Currency::class)->getCurrency($eshop->getPreferredCurrencyId());
$targetCurrency = $session->get('eshopCurrency');
/* we load currency rated prices */
$productPriceList = $dem->getRepository(Product::class)->getCurrencyRatedProductPriceList($productPriceList, $defaultCurrency, $targetCurrency);
/* we load pack prices */
$productPackPriceList = array();
if($isPackSaleModule) {
$productPackPriceList = $dem->getRepository(Product::class)->getProductPackPriceList($productIds);
/* we load currency rated prices */
$productPackPriceList = $dem->getRepository(Product::class)->getCurrencyRatedProductPriceList($productPackPriceList, $defaultCurrency, $targetCurrency);
/* we get package price(s) to display */
/*
$displayPackPrice = null;
foreach($productPackPriceList as $price) {
if($price->getProductId() == $product->getProductId()) {
// we get default price level
if($price->getPriceLevelId() == 1) {
//$displayPrice = round($price->getBruttoValue(),$eshop->getRoundPrice());
$displayPackPrice = round($price->getNettoValue(),$eshop->getRoundPrice());
}
}
}
*/
}
/*
print('<br>qqw defaultCurrency: '.$defaultCurrency->getCurrencyKey());
print('<br>qqw targetCurrency: '.$targetCurrency->getCurrencyKey());
*/
//print('<hr>qqw productIds: ');
//\Doctrine\Common\Util\Debug::dump($productIds);
//print('<hr>qqw productPriceList: ');
//\Doctrine\Common\Util\Debug::dump($productPriceList);
/* we add product(s) to basket - POST form action */
if(!empty($request->request->get('basket'))) {
/* we call method to add to basket */
$this->addToBasket($request, $eshopId, $request->request->get('productId'));
}
$eshopHeader = $dem->getRepository(Eshop::class)->getEshopHeader($eshopId);
if(!empty($eshopHeader)) {
$eshopHeader->setLocale($session->get('lang')->getLangKey());
$dem->refresh($eshopHeader);
}
/* we load footer for the current website */
$eshopFooter = $dem->getRepository(Eshop::class)->getEshopFooter($eshopId);
if(!empty($eshopFooter)) {
$eshopFooter->setLocale($session->get('lang')->getLangKey());
$dem->refresh($eshopFooter);
}
/* we load home page for the current website */
$homePage = $dem->getRepository(Eshop::class)->getHomePage($eshopId);
$wireFrame = $em->getRepository(WireFrame::class)->getWireFrame($eshop->getProductDetailWireFrameId());
$categoryPath = null;
if(!empty($product->getParentProductId())) {
//variant of product - we need to get master product path
//print('<hr>QQW parent product: '.$product->getParentProductId());
$parentProduct = $dem->getRepository(Product::class)->getProduct($product->getParentProductId());
foreach($parentProduct->getCategories() as $cat) {
$categoryPath = $dem->getRepository(Category::class)->getPath($cat);
}
}
else {
foreach($product->getCategories() as $cat) {
$cat->setLocale($session->get('lang')->getLangKey());
$dem->refresh($cat);
$categoryPath = $dem->getRepository(Category::class)->getPath($cat);
}
}
//print('<hr>qqw categoryPath: ');
//\Doctrine\Common\Util\Debug::dump($categoryPath);
$parameterList = $dem->getRepository(ProductParameter::class)->getProductParameterList();
// we load ProductParameterValueList
if(!empty($product->getParentProductId())) {
//print('<br>QQW variant 69: ');
$productParameterValueList = $dem->getRepository(ProductParameterValue::class)->getProductParameterValueList($product->getParentProductId());
} else {
//print('<br>QQW master 69: ');
$productParameterValueList = $dem->getRepository(ProductParameterValue::class)->getProductParameterValueList($productId);
}
//$productParameterValueList = $dem->getRepository(ProductParameterValue::class)->getProductParameterValueList($productId);
$productParameterList = array();
foreach($productParameterValueList as $productParameterValue) {
$parameter = $dem->getRepository(ProductParameter::class)->getProductParameter($productParameterValue->getProductParameterId());
$parameter->setLocale($session->get('lang')->getLangKey());
$dem->refresh($parameter);
$productParameterValue->setLocale($session->get('lang')->getLangKey());
$dem->refresh($productParameterValue);
if(!in_array($parameter, $productParameterList)) {
$productParameterList[] = $parameter;
}
}
/*
print('<hr>QQW productParameterList 2: ');
\Doctrine\Common\Util\Debug::dump($productParameterList);
print('<hr>QQW productParameterValueList: ');
\Doctrine\Common\Util\Debug::dump($productParameterValueList);
*/
/* we load parameter groups */
$productParameterGroupList = $dem->getRepository(ProductParameterGroup::class)->getProductParameterGroupList();
/* we filter only groups with any parameters */
$groupList = array();
foreach($productParameterList as $param) {
//print('<br>QQW param: '.$param->getProductParameterName());
foreach($param->getProductParameterGroups() as $group) {
//print('<br>QQW group: '.$group->getProductParameterGroupName());
if(!in_array($group, $groupList)) {
$groupList[] = $group;
}
}
}
/*
print('<hr>QQW groupList: ');
\Doctrine\Common\Util\Debug::dump($groupList);
*/
/* we remove empty parameter groups from list */
foreach($productParameterGroupList as $key => $group) {
if(!in_array($group, $groupList)) {
unset($productParameterGroupList[$key]);
}
}
// print('<br>QQW topProducts: ');
// \Doctrine\Common\Util\Debug::dump($topProducts);
//$productParameterGroupList = $groupList;
/* we render data */
return $this->render('eshopProduct.html.twig',
array( 'headerData' => $this -> getPageHeader($request),
'menu' => $this -> adminMenu($request),'mainMenu' => $this -> adminMainMenu($request),'mainMenu' => $this -> adminMainMenu($request),
'user' => $user,
'userDirs' => $userDirs,
'eshop' => $eshop,
'product' => $product,
'productVAT' => $productVAT,
'productPriceList' => $productPriceList,
'wireFrame' => $wireFrame,
'categoryPath' => $categoryPath,
'categoryTreeMenu' => $this->categoryTreeMenu($eshop, $request),
'categoryTopMenu' => $this->categoryTopMenu($eshop, $request),
'eshopHeader' => $eshopHeader,
'eshopFooter' => $eshopFooter,
'productParameterList' => $productParameterList,
'productParameterValueList' => $productParameterValueList,
'productParameterGroupList' => $productParameterGroupList,
'homePage' => $homePage,
'seoData' => $seoData,
'productVariantList' => $productVariantList,
'productVariantParameters' => $productVariantParameters,
'productVariantParameterValues' => $productVariantParameterValues,
'parentProduct' => $parentProduct,
'productPackPriceList' => $productPackPriceList,
'isPackSaleModule' => $isPackSaleModule,
'topProducts' => $this->getTopProducts($request, $eshop, 7),
'priceLevelList' => $priceLevelList,
'gallery3d' => $gallery3d,
'galleryItemCollection' => $galleryItemCollection,
'variantTexts' => $variantTexts
)
);
}
/**
* @Route("/eshop/{eshopId}/register", name="eshopRegister")
*/
public function eshopRegisterAction(Request $request, $eshopId)
{
/* we load session data */
parent::init($request);
$session = $request->getSession();
/* we load entity managers */
$em = $this->doctrine->getManager();
$dem = $this->doctrine->getManager('dynamic_em');
/* we get current e-shop */
$eshop = $em->getRepository(Eshop::class)->getEshop($eshopId);
$user = $em->getRepository(User::class)->getUser($eshop->getUserId());
/* we check if eshop exists */
if($eshop === null) {
$this->addFlash('error', 'E-shop with this ID does not exist.');
return $this->redirectToRoute('eshopHome');
}
$eshopHeader = $dem->getRepository(Eshop::class)->getEshopHeader($eshopId);
if(!empty($eshopHeader)) {
$eshopHeader->setLocale($session->get('lang')->getLangKey());
$dem->refresh($eshopHeader);
}
/* we load footer for the current website */
$eshopFooter = $dem->getRepository(Eshop::class)->getEshopFooter($eshopId);
if(!empty($eshopFooter)) {
$eshopFooter->setLocale($session->get('lang')->getLangKey());
$dem->refresh($eshopFooter);
}
/* we load home page for the current website */
$homePage = $dem->getRepository(Eshop::class)->getHomePage($eshopId);
$wireFrame = $em->getRepository(WireFrame::class)->getWireFrame($eshop->getProductDetailWireFrameId());
/* we prepare data for the form */
if(!empty($request->request->get('lastName'))) {
$lastName = $request->request->get('lastName');
} else {
$lastName = '';
}
if(!empty($request->request->get('firstName'))) {
$firstName = $request->request->get('firstName');
} else {
$firstName = '';
}
if(!empty($request->request->get('company'))) {
$company = $request->request->get('company');
} else {
$company = '';
}
if(!empty($request->request->get('email'))) {
$email = $request->request->get('email');
} else {
$email = '';
}
if(!empty($request->request->get('telefon'))) {
$telefon = $request->request->get('telefon');
} else {
$telefon = '';
}
if(!empty($request->request->get('addressStreet'))) {
$addressStreet = $request->request->get('addressStreet');
} else {
$addressStreet = '';
}
if(!empty($request->request->get('addressStreetNumber'))) {
$addressStreetNumber = $request->request->get('addressStreetNumber')[''];
} else {
$addressStreetNumber = '';
}
if(!empty($request->request->get('addressCity'))) {
$addressCity = $request->request->get('addressCity');
} else {
$addressCity = '';
}
if(!empty($request->request->get('addressZipCode'))) {
$addressZipCode = $request->request->get('addressZipCode');
} else {
$addressZipCode = '';
}
if(!empty($request->request->get('addressCountry'))) {
$addressCountry = $request->request->get('addressCountry');
} else {
$addressCountry = '';
}
if(!empty($request->request->get('address'))) {
$address = $request->request->get('address');
} else {
$address = '';
}
if(!empty($request->request->get('username'))) {
$username = $request->request->get('username');
} else {
$username = '';
}
if(!empty($request->request->get('password'))) {
$password = $request->request->get('password');
} else {
$password = '';
}
if(!empty($request->request->get('password_retype'))) {
$password_retype = $request->request->get('password_retype');
} else {
$password_retype = '';
}
if(!empty($request->request->get('businessId'))) {
$businessId = $request->request->get('businessId');
} else {
$businessId = '';
}
if(!empty($request->request->get('DICId'))) {
$DICId = $request->request->get('DICId');
} else {
$DICId = '';
}
/* we build register form */
$contact = new Contact;
$formBuilder = $this->createFormBuilder($contact);
$formBuilder->add('lastName', TextType::class, array(
'required' => true,
'label' => $this->translator->trans('knowledgebase.last_name'),
'attr' => array('class' => 'text_form', 'size' => 35, 'value' => $lastName),
'label_attr' => array('class' => 'form_field_label_required')
));
$formBuilder->add('firstName', TextType::class, array(
'required' => true,
'label' => $this->translator->trans('knowledgebase.first_name'),
'attr' => array('class' => 'text_form', 'size' => 35, 'value' => $firstName),
'label_attr' => array('class' => 'form_field_label_required')
));
$formBuilder->add('email', EmailType::class, array(
'required' => true,
'attr' => array('class' => 'text_form', 'size' => 35, 'value' => $email),
'label_attr' => array('class' => 'form_field_label_required'),
));
$formBuilder->add('contactUserName', TextType::class, array(
'required' => true,
'label' => $this->translator->trans('user.username'),
'empty_data' => '',
'attr' => array('class' => 'text_form', 'size' => 20, 'value' => $username),
'label_attr' => array('class' => 'form_field_label_required'),
));
$formBuilder->add('contactUserPassword', PasswordType::class, array(
'required' => true,
'label' => $this->translator->trans('user.password'),
'attr' => array('class' => 'text_form', 'size' => 20, 'value' => $password),
'label_attr' => array('class' => 'form_field_label_required'),
));
/*
$formBuilder->add('password_retype', PasswordType::class, array(
'required' => true,
'label' => $this->translator->trans('user.password_retype'),
'attr' => array('class' => 'text_form', 'size' => 35, 'value' => $password_retype),
'label_attr' => array('class' => 'form_field_label_required'),
));
*/
$formBuilder->add('phone', TextType::class, array(
'required' => false,
'label' => $this->translator->trans('user.telephone'),
'attr' => array('class' => 'text_form', 'size' => 20, 'value' => $telefon),
'label_attr' => array('class' => 'form_field_label'),
));
/* we add address */
$formBuilder->add('addressStreet', TextType::class, array(
'required' => true,
'mapped' => false,
'label' => $this->translator->trans('address.street'),
'attr' => array('class' => 'text_form', 'size' => 35, 'value' => $addressStreet),
'label_attr' => array('class' => 'form_field_label_required'),
));
$formBuilder->add('addressStreetNumber', TextType::class, array(
'required' => true,
'mapped' => false,
'label' => $this->translator->trans('address.street_number'),
'attr' => array('class' => 'text_form', 'size' => 10, 'value' => $addressStreetNumber),
'label_attr' => array('class' => 'form_field_label_required'),
));
$formBuilder->add('addressZipCode', TextType::class, array(
'required' => true,
'mapped' => false,
'label' => $this->translator->trans('address.zip_code'),
'attr' => array('class' => 'text_form', 'size' => 10, 'value' => $addressZipCode),
'label_attr' => array('class' => 'form_field_label_required'),
));
$formBuilder->add('addressCity', TextType::class, array(
'required' => true,
'mapped' => false,
'label' => $this->translator->trans('address.city'),
'attr' => array('class' => 'text_form', 'size' => 35, 'value' => $addressCity),
'label_attr' => array('class' => 'form_field_label_required'),
));
$formBuilder->add('addressCountry', TextType::class, array(
'required' => true,
'mapped' => false,
'label' => $this->translator->trans('address.country'),
'attr' => array('class' => 'text_form', 'size' => 35, 'value' => $addressCountry),
'label_attr' => array('class' => 'form_field_label_required'),
));
$formBuilder->add('companyName', TextType::class, array(
'required' => false,
'label' => $this->translator->trans('user.company'),
'attr' => array('class' => 'text_form', 'size' => 35, 'value' => $company),
'label_attr' => array('class' => 'form_field_label')
));
$formBuilder->add('businessId', TextType::class, array(
'required' => false,
'label' => $this->translator->trans('user.business_number'),
'attr' => array('class' => 'text_form', 'size' => 20, 'value' => $businessId),
'label_attr' => array('class' => 'form_field_label')
));
$formBuilder->add('DICId', TextType::class, array(
'required' => false,
'label' => $this->translator->trans('user.DIC_number'),
'attr' => array('class' => 'text_form', 'size' => 20, 'value' => $DICId),
'label_attr' => array('class' => 'form_field_label')
));
/*
$formBuilder->add('address', TextareaType::class, array(
'required' => false,
'label' => $this->translator->trans('user.address'),
'attr' => array('class' => 'textarea_form', 'cols' => 33, 'rows' => 2, 'value' => $address),
'label_attr' => array('class' => 'form_textarea_label'),
));
*/
//isModule e-Privacy Consent
$module = $em->getRepository(Module::class)->getModule(30);
$isConsentModule = $em->getRepository(User::class)->userHasModule($user, $module);
$consentList = null;
$consentDescriptions = array();
if($isConsentModule) {
//print('<br>qqw is module e-Privacy Consent');
$consentList = $dem->getRepository(Consent::class)->getConsentList();
$consents = array();
$consentRequired = false;
foreach($consentList as $consent) {
$consent->setLocale($session->get('lang')->getLangKey());
$dem->refresh($consent);
//print('<br>Consent: '.$consent->getConsentName());
if($consent->isBlockOrder()) {
$consentRequired = true;
}
$consents[$consent->getConsentName()] = $consent->getConsentId();
$consentDescriptions[$consent->getConsentId()] = $consent->getConsentDescription();
}
$selectedConsents = array();
$formBuilder->add('consents', ChoiceType::class, array(
'choices' => $consents,
'required' => $consentRequired,
'mapped' => false,
'multiple' => true,
'expanded' => true,
'label_attr' => array('class' => 'consent_label'),
'attr' => array('class' => 'form_field_text'),
'choice_attr' => function($val, $key, $index) {
// adds a class like attending_yes, attending_no, etc
return ['class' => 'choiceBlock5', 'required' => 'required'];
},
'data' => $selectedConsents
));
}
$formBuilder->add('save', SubmitType::class, array('label' => $this->translator->trans('system.create_account'),
'attr' => array('class' => 'butt_big')));
$form = $formBuilder->getForm();
//isModule ReCaptcha
$module = $em->getRepository(Module::class)->getModule(41);
$isReCaptchaModule = $em->getRepository(User::class)->userHasModule($user, $module);
$reCaptcha = null;
if($isReCaptchaModule) {
//we load re-captcha
$reCaptcha = $dem->getRepository(ReCaptcha::class)->findOneBy(['reCaptchaId'=> 1]);
}
$form->handleRequest($request);
if ($request->getMethod() == 'POST') {
//$form->bindRequest($request);
//$this->captchaverify($request->get('g-recaptcha-response')
/*
print('<br>recaptcha-response verify: ');
var_dump($this->captchaVerify($request->get('g-recaptcha-response')));
print('<hr>recaptcha-response: ');
print_r($request->get('g-recaptcha-response'));
var_dump($request->get('g-recaptcha-response'));
*/
//die();
//if ($form->isValid() && $this->captchaVerify($request->get('g-recaptcha-response')) != null) {
if(!$isReCaptchaModule) {
//we load re-captcha
$captchaResponse = "noCaptcha";
} else {
$captchaResponse = $request->get('g-recaptcha-response');
}
//print('<br>Captcha qqw: '.$captchaResponse);
//die();
//if ($form->isValid() && $this->captchaVerify($request->get('g-recaptcha-response')) != null) {
if ($form->isValid() && $captchaResponse) {
// perform some action, such as save the object to the database
$formData = $form->getData();
/* we check if this contact already exists */
$contactExist = $dem->getRepository(Contact::class)->getContactFromUsername($formData->getContactUserName());
// print('<br>qqw contact exists: ');
// \Doctrine\Common\Util\Debug::dump($contactExist);
if($contactExist === null) {
/* we check if the password fields are the same */
//$password = $request->request->get('form')['password'];
//$retypePassword = $request->request->get('form')['password_retype'];
//print('<br>We create new contact');
$password = md5($formData->getContactUserPassword());
/* we load contact data from register form into contact object */
$contact->setFirstName($formData->getFirstName());
$contact->setLastName($formData->getLastName());
$contact->setCompanyName($formData->getCompanyName());
$contact->setContactUserName($formData->getContactUserName());
$contact->setEmail($formData->getEmail());
$contact->setPhone($formData->getPhone());
//$contact->setAddress1($request->request->get('form')['address']);
$contact->setContactUserPassword($password);
$address = $contact->getAddress();
if(empty($address)) {
$address = new Address;
}
$address->setStreet($form['addressStreet']->getData());
$address->setStreetNumber($form['addressStreetNumber']->getData());
$address->setCity($form['addressCity']->getData());
$address->setZipCode($form['addressZipCode']->getData());
$address->setCountry($form['addressCountry']->getData());
$contact->setAddress($address);
$contact->setBusinessId($formData->getBusinessId());
$contact->setDICId($formData->getDICId());
/*
print('<br>qqw user exists: ');
\Doctrine\Common\Util\Debug::dump($contact);
*/
/* we remove old consents */
if(!empty($contact->getConsents())) {
foreach($contact->getConsents() as $consent) {
$contact->removeConsent($consent);
//$dem->refresh($product);
//$dem->persist($cat);
}
}
/* we save consents */
if(!empty($form['consents']->getData())) {
foreach($form['consents']->getData() as $consentId) {
$consent = $dem->getRepository(Consent::class)->getConsent($consentId);
$contact->addConsent($consent);
}
}
/* we persist and save contact */
$dem->persist($contact);
$dem->flush();
$this->addFlash('notice', $this->translator->trans('eshop.contact_new_created'));
/* we load logged contact into session */
$session = $request->getSession();
$session->set('contact', $contact);
/* we prepare emailing about registration */
$name = $eshop->getEshopName();
$to = $user->getEmail();
$subject = $name.' - '.$this->translator->trans('eshop.email_register_subject').': #'.$contact->getContactId();
$message = $this->translator->trans('eshop.email_register_text');
/* we load order email cms text for the current eshop */
$orderEmail = $dem->getRepository(WebPage::class)->getEmailRegister($eshopId);
if(!empty($orderEmail)) {
$message .= $orderEmail->getWebPageContent();
}
/* we load register email cms text for the current eshop */
$emailText = $this->getRegisterEmail($request, $eshop, $contact);
$message .= $emailText;
$from = 'noreply@easycommerc.com';
/*
$headers = "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/html; charset=UTF-8\r\n";
$headers .= "From: {$name} <{$from}>\r\n";
$headers .= "Reply-To: <{$from}>\r\n";
$headers .= "Subject: {$subject}\r\n";
$headers .= "X-Mailer: PHP/".phpversion()."\r\n";
*/
// we send email to eshop owner
if($this->sendEmail($to, $subject, $from, $message)) {
if(!empty($user->getContactPersonEmail())) {
$this->sendEmail($user->getContactPersonEmail(), $subject, $from, $message);
}
$mailToAdminStatus = $this->translator->trans('eshop.email_admin_order_ok').': '.$to;
} else {
$mailToAdminStatus = $this->translator->trans('eshop.email_admin_order_error'.': '.$to);
}
// we send email to customer
$to = $contact->getEmail();
if($this->sendEmail($to, $subject, $from, $message)) {
$mailToCustomerStatus = $this->translator->trans('eshop.email_customer_order_ok').': '.$to;
} else {
$mailToCustomerStatus = $this->translator->trans('eshop.email_customer_order_error'.': '.$to);
}
/*
// we send email to e-shop admin
if(@mail($to, $subject, $message, $headers)) {
//print('<br>Email was sent.');
//we send email to users contact person
if(!empty($user->getContactPersonEmail())) {
mail($user->getContactPersonEmail(), $subject, $message, $headers);
//die('<br>qqw register email to: '.$user->getContactPersonEmail());
}
$mailToAdminStatus = $this->translator->trans('eshop.email_admin_order_ok').': '.$to;
} else {
//print('<br>Email was not sent.');
$mailToAdminStatus = $this->translator->trans('eshop.email_admin_order_error'.': '.$to);
}
// we send email to customer
$to = $contact->getEmail();
if(@mail($to, $subject, $message, $headers)) {
//print('<br>Email was sent.');
$mailToCustomerStatus = $this->translator->trans('eshop.email_customer_order_ok').': '.$to;
} else {
//print('<br>Email was not sent.');
$mailToCustomerStatus = $this->translator->trans('eshop.email_customer_order_error'.': '.$to);
}
*/
return $this->redirectToRoute('eshopHomeContact', array('eshopId' => $eshopId));
}
else {
$this->addFlash('error', $this->translator->trans('eshop.contact_already_exist'));
}
} else {
$this->addFlash('error', $this->translator->trans('system.form_not_valid'));
}
}
/* we render data */
return $this->render('eshopRegister.html.twig',
array( 'headerData' => $this -> getPageHeader($request),
'form' => $formBuilder->getForm()->createView(),
'menu' => $this -> adminMenu($request),'mainMenu' => $this -> adminMainMenu($request),'mainMenu' => $this -> adminMainMenu($request),
'eshop' => $eshop,
'user' => $user,
'wireFrame' => $wireFrame,
'categoryTreeMenu' => $this->categoryTreeMenu($eshop, $request),
'categoryTopMenu' => $this->categoryTopMenu($eshop, $request),
'eshopHeader' => $eshopHeader,
'eshopFooter' => $eshopFooter,
'homePage' => $homePage,
'consentList' => $consentList,
'consentDescriptions' => $consentDescriptions,
'reCaptcha' => $reCaptcha,
)
);
}
/**
* @Route("/eshop/{eshopId}/editContact", name="eshopEditContact")
*/
public function eshopEditContactAction(Request $request, $eshopId)
{
/* we load session data */
parent::init($request);
$session = $request->getSession();
/* we load entity managers */
$em = $this->doctrine->getManager();
$dem = $this->doctrine->getManager('dynamic_em');
/* we get current e-shop */
$eshop = $em->getRepository(Eshop::class)->getEshop($eshopId);
$user = $em->getRepository(User::class)->getUser($eshop->getUserId());
/* we check if eshop exists */
if($eshop === null) {
$this->addFlash('error', 'E-shop with this ID does not exist.');
return $this->redirectToRoute('eshopHome');
}
/* we check if customer exists */
if(empty($session->get('contact'))) {
$this->addFlash('error', 'Customer does not exists.');
return $this->redirectToRoute('eshopHome');
} else {
//$contact = $session->get('contact');
//$contact = $dem->getRepository(Contact::class)->getContactFromUsername($session->get('contact')->getContactUserName());
$contact = $dem->getRepository(Contact::class)->getContact($session->get('contact')->getContactId());
}
$eshopHeader = $dem->getRepository(Eshop::class)->getEshopHeader($eshopId);
if(!empty($eshopHeader)) {
$eshopHeader->setLocale($session->get('lang')->getLangKey());
$dem->refresh($eshopHeader);
}
/* we load footer for the current website */
$eshopFooter = $dem->getRepository(Eshop::class)->getEshopFooter($eshopId);
if(!empty($eshopFooter)) {
$eshopFooter->setLocale($session->get('lang')->getLangKey());
$dem->refresh($eshopFooter);
}
/* we load home page for the current website */
$homePage = $dem->getRepository(Eshop::class)->getHomePage($eshopId);
$wireFrame = $em->getRepository(WireFrame::class)->getWireFrame($eshop->getProductDetailWireFrameId());
/*
print('<br>qqw c address: ');
\Doctrine\Common\Util\Debug::dump($contact->getAddress());
*/
/* we prepare data for the form */
if(!empty($contact->getLastName())) {
$lastName = $contact->getLastName();
} else {
$lastName = '';
}
if(!empty($contact->getFirstName())) {
$firstName = $contact->getFirstName();
} else {
$firstName = '';
}
if(!empty($contact->getCompanyName())) {
$company = $contact->getCompanyName();
} else {
$company = '';
}
if(!empty($contact->getEmail())) {
$email = $contact->getEmail();
} else {
$email = '';
}
if(!empty($contact->getPhone())) {
$telefon = $contact->getPhone();
} else {
$telefon = '';
}
if(!empty($contact->getAddress()) && !empty($contact->getAddress()->getStreet())) {
$addressStreet = $contact->getAddress()->getStreet();
} else {
$addressStreet = '';
}
if(!empty($contact->getAddress()) && !empty($contact->getAddress()->getStreetNumber())) {
$addressStreetNumber = $contact->getAddress()->getStreetNumber();
} else {
$addressStreetNumber = '';
}
if(!empty($contact->getAddress()) && !empty($contact->getAddress()->getCity())) {
$addressCity = $contact->getAddress()->getCity();
} else {
$addressCity = '';
}
if(!empty($contact->getAddress()) && !empty($contact->getAddress()->getZipCode())) {
$addressZipCode = $contact->getAddress()->getZipCode();
} else {
$addressZipCode = '';
}
if(!empty($contact->getAddress()) && !empty($contact->getAddress()->getCountry())) {
$addressCountry = $contact->getAddress()->getCountry();
} else {
$addressCountry = '';
}
if(!empty($contact->getContactUserName())) {
$username = $contact->getContactUserName();
} else {
$username = '';
}
/*
if(!empty($contact->getContactUserPassword())) {
$password = $contact->getContactUserPassword();
} else {
$password = '';
}
*/
if(!empty($contact->getBusinessId())) {
$businessId = $contact->getBusinessId();
} else {
$businessId = '';
}
if(!empty($contact->getDICId())) {
$DICId = $contact->getDICId();
} else {
$DICId = '';
}
/* we build register form */
$formBuilder = $this->createFormBuilder();
$formBuilder->add('contactId', HiddenType::class, [
'data' => $contact->getContactId(),
]);
$formBuilder->add('lastName', TextType::class, array(
'required' => true,
'label' => $this->translator->trans('knowledgebase.last_name'),
'attr' => array('class' => 'text_form', 'size' => 35, 'value' => $lastName),
'label_attr' => array('class' => 'form_field_label_required')
));
$formBuilder->add('firstName', TextType::class, array(
'required' => true,
'label' => $this->translator->trans('knowledgebase.first_name'),
'attr' => array('class' => 'text_form', 'size' => 35, 'value' => $firstName),
'label_attr' => array('class' => 'form_field_label_required')
));
$formBuilder->add('email', EmailType::class, array(
'required' => true,
'attr' => array('class' => 'text_form', 'size' => 35, 'value' => $email),
'label_attr' => array('class' => 'form_field_label_required'),
));
/*
$formBuilder->add('username', TextType::class, array(
'required' => true,
'label' => $this->translator->trans('user.username'),
'empty_data' => '',
'attr' => array('class' => 'text_form', 'size' => 35, 'value' => $username),
'label_attr' => array('class' => 'form_field_label_required'),
));
*/
/*
$formBuilder->add('password', PasswordType::class, array(
'required' => true,
'label' => $this->translator->trans('user.password'),
'attr' => array('class' => 'text_form', 'size' => 35, 'value' => $password),
'label_attr' => array('class' => 'form_field_label_required'),
));
*/
/*
$formBuilder->add('password_retype', PasswordType::class, array(
'required' => true,
'label' => $this->translator->trans('user.password_retype'),
'attr' => array('class' => 'text_form', 'size' => 35, 'value' => $password_retype),
'label_attr' => array('class' => 'form_field_label_required'),
));
*/
$formBuilder->add('telefon', TextType::class, array(
'required' => false,
'label' => $this->translator->trans('user.telephone'),
'attr' => array('class' => 'text_form', 'size' => 35, 'value' => $telefon),
'label_attr' => array('class' => 'form_field_label'),
));
/* we add address */
$formBuilder->add('addressStreet', TextType::class, array(
'required' => true,
'label' => $this->translator->trans('address.street'),
'attr' => array('class' => 'text_form', 'size' => 35, 'value' => $addressStreet),
'label_attr' => array('class' => 'form_field_label_required'),
));
$formBuilder->add('addressStreetNumber', TextType::class, array(
'required' => true,
'label' => $this->translator->trans('address.street_number'),
'attr' => array('class' => 'text_form', 'size' => 10, 'value' => $addressStreetNumber),
'label_attr' => array('class' => 'form_field_label_required'),
));
$formBuilder->add('addressZipCode', TextType::class, array(
'required' => true,
'label' => $this->translator->trans('address.zip_code'),
'attr' => array('class' => 'text_form', 'size' => 10, 'value' => $addressZipCode),
'label_attr' => array('class' => 'form_field_label_required'),
));
$formBuilder->add('addressCity', TextType::class, array(
'required' => true,
'label' => $this->translator->trans('address.city'),
'attr' => array('class' => 'text_form', 'size' => 35, 'value' => $addressCity),
'label_attr' => array('class' => 'form_field_label_required'),
));
$formBuilder->add('addressCountry', TextType::class, array(
'required' => true,
'label' => $this->translator->trans('address.country'),
'attr' => array('class' => 'text_form', 'size' => 35, 'value' => $addressCountry),
'label_attr' => array('class' => 'form_field_label_required'),
));
$formBuilder->add('company', TextType::class, array(
'required' => false,
'label' => $this->translator->trans('user.company'),
'attr' => array('class' => 'text_form', 'size' => 35, 'value' => $company),
'label_attr' => array('class' => 'form_field_label')
));
$formBuilder->add('businessId', TextType::class, array(
'required' => false,
'label' => $this->translator->trans('user.business_number'),
'attr' => array('class' => 'text_form', 'size' => 35, 'value' => $businessId),
'label_attr' => array('class' => 'form_field_label')
));
$formBuilder->add('DICId', TextType::class, array(
'required' => false,
'label' => $this->translator->trans('user.DIC_number'),
'attr' => array('class' => 'text_form', 'size' => 35, 'value' => $DICId),
'label_attr' => array('class' => 'form_field_label')
));
/*
$formBuilder->add('address', TextareaType::class, array(
'required' => false,
'label' => $this->translator->trans('user.address'),
'attr' => array('class' => 'textarea_form', 'cols' => 33, 'rows' => 2, 'value' => $address),
'label_attr' => array('class' => 'form_textarea_label'),
));
*/
$formBuilder->add('save', SubmitType::class, array('label' => $this->translator->trans('form.button.save'),
'attr' => array('class' => 'butt_big')));
$form = $formBuilder->getForm();
$form->handleRequest($request);
if ($request->getMethod() == 'POST') {
//$form->bindRequest($request);
if ($form->isValid()) {
// perform some action, such as save the object to the database
//print('<br>qqw post form 2: ');
/* we check if this contact already exists */
$contact = $dem->getRepository(Contact::class)->getContact($request->request->get('form')['contactId']);
/* we load contact data from register form into contact object */
$contact->setFirstName($request->request->get('form')['firstName']);
$contact->setLastName($request->request->get('form')['lastName']);
$contact->setCompanyName($request->request->get('form')['company']);
//$contact->setContactUserName($request->request->get('form')['username']);
$contact->setEmail($request->request->get('form')['email']);
//$contact->setAddress1($request->request->get('form')['address']);
//$contact->setContactUserPassword($password);
$address = $contact->getAddress();
if(empty($address)) {
$address = new Address;
}
$address->setStreet($request->request->get('form')['addressStreet']);
$address->setStreetNumber($request->request->get('form')['addressStreetNumber']);
$address->setCity($request->request->get('form')['addressCity']);
$address->setZipCode($request->request->get('form')['addressZipCode']);
$address->setCountry($request->request->get('form')['addressCountry']);
$contact->setAddress($address);
$contact->setBusinessId($request->request->get('form')['businessId']);
$contact->setDICId($request->request->get('form')['DICId']);
/* we persist and save contact */
$dem->persist($contact);
$dem->flush();
$this->addFlash('notice', $this->translator->trans('eshop.contact_updated'));
/* we load logged contact into session */
$session = $request->getSession();
$session->set('contact', $contact);
return $this->redirectToRoute('eshopHomeContact', array('eshopId' => $eshopId));
}
}
/* we render data */
return $this->render('eshopEditContact.html.twig',
array( 'headerData' => $this -> getPageHeader($request),
'form' => $formBuilder->getForm()->createView(),
'menu' => $this -> adminMenu($request),'mainMenu' => $this -> adminMainMenu($request),'mainMenu' => $this -> adminMainMenu($request),
'eshop' => $eshop,
'user' => $user,
'wireFrame' => $wireFrame,
'categoryTreeMenu' => $this->categoryTreeMenu($eshop, $request),
'categoryTopMenu' => $this->categoryTopMenu($eshop, $request),
'eshopHeader' => $eshopHeader,
'eshopFooter' => $eshopFooter,
'homePage' => $homePage,
)
);
}
/**
* @Route("/eshop/{eshopId}/logout", name="eshopLogout")
*/
public function eshopLogoutAction(Request $request, $eshopId) {
/* we load session data */
parent::init($request);
/* we unload logged user session */
$session = $request->getSession();
$session->set('contact', null);
$this->addFlash('notice', $this->translator->trans('eshop.customer_logged_out'));
return $this->redirectToRoute('eshop', array('eshopId' => $eshopId));
}
/**
* @Route("/eshop/{eshopId}/login", name="eshopLogin")
*/
public function eshopLoginAction(Request $request, $eshopId)
{
/* we load session data */
parent::init($request);
$session = $request->getSession();
/* we load entity managers */
$em = $this->doctrine->getManager();
$dem = $this->doctrine->getManager('dynamic_em');
/* we get current e-shop */
$eshop = $em->getRepository(Eshop::class)->getEshop($eshopId);
$user = $em->getRepository(User::class)->getUser($eshop->getUserId());
/* we check if eshop exists */
if($eshop === null) {
$this->addFlash('error', 'E-shop with this ID does not exist.');
return $this->redirectToRoute('eshopHome');
}
$eshopHeader = $dem->getRepository(Eshop::class)->getEshopHeader($eshopId);
if(!empty($eshopHeader)) {
$eshopHeader->setLocale($session->get('lang')->getLangKey());
$dem->refresh($eshopHeader);
}
/* we load footer for the current website */
$eshopFooter = $dem->getRepository(Eshop::class)->getEshopFooter($eshopId);
if(!empty($eshopFooter)) {
$eshopFooter->setLocale($session->get('lang')->getLangKey());
$dem->refresh($eshopFooter);
}
/* we load home page for the current website */
$homePage = $dem->getRepository(Eshop::class)->getHomePage($eshopId);
$wireFrame = $em->getRepository(WireFrame::class)->getWireFrame($eshop->getProductDetailWireFrameId());
/* we build login form */
$formBuilder = $this->createFormBuilder();
$formBuilder->add('username', TextType::class, array(
'required' => true,
'mapped' => false,
'label' => $this->translator->trans('user.username'),
'attr' => array('class' => 'text_form', 'size' => 22),
'label_attr' => array('class' => 'form_field_label'),
));
$formBuilder->add('password', PasswordType::class, array(
'required' => true,
'mapped' => false,
'label' => $this->translator->trans('user.password'),
'attr' => array('class' => 'text_form', 'size' => 22),
'label_attr' => array('class' => 'form_field_label'),
));
$formBuilder->add('save', SubmitType::class, array('label' => 'Login',
'attr' => array('class' => 'butt_big')));
$form = $formBuilder->getForm();
$form->handleRequest($request);
if ($request->getMethod() == 'POST') {
//$form->bindRequest($request);
//print('<br>qqw post dude');
//if ($form->isValid()) {
// perform some action, such as save the object to the database
/* we check if this username exists */
$em = $this->doctrine->getManager();
$userName = $form['username']->getData();
$contactExist = $dem->getRepository(Contact::class)->getContactFromLogin($userName, $form['password']->getData());
/*
print('<br>qqw contact exists: ');
\Doctrine\Common\Util\Debug::dump($contactExist);
*/
//die();
if(!empty($contactExist)) {
$contact = $dem->getRepository(Contact::class)->getContact($contactExist->getContactId());
/* we load logged contact into session */
$session = $request->getSession();
//$session->set('contact', $contactExist);
$session->set('contact', $contact);
//print('<br>qqw x contact: ');
//\Doctrine\Common\Util\Debug::dump($contact);
//print('<br>qqw x Street: '.$session->get('contact')->getAddress()->getStreet());
//die();
/*
print('<hr>we set session contact: ');
\Doctrine\Common\Util\Debug::dump($session->get('contact'));
*/
$this->addFlash('notice', $this->translator->trans('system.welcome').' '.$userName.'. '.$this->translator->trans('eshop.customer_logged_in'));
if(!empty($request->request->get('returnRoute'))) {
return $this->redirectToRoute($request->request->get('returnRoute'), array('eshopId' => $eshopId));
} else {
return $this->redirectToRoute('eshopHomeContact', array('eshopId' => $eshopId));
}
}
else {
$this->addFlash('error', 'Login error.');
}
//}
}
/* we render data */
return $this->render('eshopLogin.html.twig',
array( 'headerData' => $this -> getPageHeader($request),
'form' => $formBuilder->getForm()->createView(),
'menu' => $this -> adminMenu($request),'mainMenu' => $this -> adminMainMenu($request),'mainMenu' => $this -> adminMainMenu($request),
'eshop' => $eshop,
'user' => $user,
'wireFrame' => $wireFrame,
'categoryTreeMenu' => $this->categoryTreeMenu($eshop, $request),
'categoryTopMenu' => $this->categoryTopMenu($eshop, $request),
'eshopHeader' => $eshopHeader,
'eshopFooter' => $eshopFooter,
'homePage' => $homePage,
)
);
}
/**
* @Route("/eshop/{eshopId}/forgottenpassword", name="eshopForgottenPassword")
*/
public function eshopForgottenPasswordAction(Request $request, $eshopId)
{
/* we load session data */
parent::init($request);
$session = $request->getSession();
/* we load entity managers */
$em = $this->doctrine->getManager();
$dem = $this->doctrine->getManager('dynamic_em');
/* we get current e-shop */
$eshop = $em->getRepository(Eshop::class)->getEshop($eshopId);
$user = $em->getRepository(User::class)->getUser($eshop->getUserId());
/* we check if eshop exists */
if($eshop === null) {
$this->addFlash('error', 'E-shop with this ID does not exist.');
return $this->redirectToRoute('eshopHome');
}
$eshopHeader = $dem->getRepository(Eshop::class)->getEshopHeader($eshopId);
if(!empty($eshopHeader)) {
$eshopHeader->setLocale($session->get('lang')->getLangKey());
$dem->refresh($eshopHeader);
}
/* we load footer for the current website */
$eshopFooter = $dem->getRepository(Eshop::class)->getEshopFooter($eshopId);
if(!empty($eshopFooter)) {
$eshopFooter->setLocale($session->get('lang')->getLangKey());
$dem->refresh($eshopFooter);
}
/* we load home page for the current website */
$homePage = $dem->getRepository(Eshop::class)->getHomePage($eshopId);
$wireFrame = $em->getRepository(WireFrame::class)->getWireFrame($eshop->getProductDetailWireFrameId());
/* we build login form */
$formBuilder = $this->createFormBuilder();
$formBuilder->add('email', EmailType::class, array(
'required' => true,
'label' => $this->translator->trans('knowledgebase.email'),
'attr' => array('class' => 'text_form', 'size' => 22),
'label_attr' => array('class' => 'form_field_label'),
));
$formBuilder->add('save', SubmitType::class, array('label' => $this->translator->trans('form.send'),
'attr' => array('class' => 'butt_big')));
$form = $formBuilder->getForm();
$form->handleRequest($request);
//phpinfo();
if ($request->getMethod() == 'POST') {
//$form->bindRequest($request);
//print('<br>qqw post dude');
//$email = $request->request->get('form')['email'];
$emailAddress = $form['email']->getData();
$contact = $dem->getRepository(Contact::class)->getContactFromEmail($emailAddress);
if(!empty($contact)) {
//if ($form->isValid()) {
// send emails
/* we check if this username exists */
$em = $this->doctrine->getManager();
/* we prepare emailing */
//print('from: '.$user->getEmail());
//print('<br>to: '.$emailAddress);
$name = $eshop->getEshopName();
$subject = $name.' - '.$this->translator->trans('user.forgotten_password').': '.$eshop->getEshopName();
$messageBody = $this->translator->trans('user.forgotten_password');
$emailText = $this->getForgottenPasswordEmail($request, $eshop, $emailAddress);
$messageBody .= $emailText;
if($this->sendEmail($emailAddress, $subject, $user->getEmail(), $messageBody)) {
$this->addFlash('notice', $this->translator->trans('user.forgotten_password_sent').': '.$emailAddress);
} else {
$this->addFlash('error', $this->translator->trans('user.forgotten_password_sent_error').': '.$emailAddress);
}
//return $this->redirectToRoute('eshopForgottenPassword', array('eshopId' => $eshopId));
/*
print('<br>qqw contact exists: ');
\Doctrine\Common\Util\Debug::dump($contactExist);
*/
} else {
$this->addFlash('error', $this->translator->trans('eshop.contact_new_psw_fields').': '.$email);
}
//}
}
/* we render data */
return $this->render('eshopForgottenPassword.html.twig',
array( 'headerData' => $this -> getPageHeader($request),
'form' => $formBuilder->getForm()->createView(),
'menu' => $this -> adminMenu($request),'mainMenu' => $this -> adminMainMenu($request),'mainMenu' => $this -> adminMainMenu($request),
'eshop' => $eshop,
'user' => $user,
'wireFrame' => $wireFrame,
'categoryTreeMenu' => $this->categoryTreeMenu($eshop, $request),
'categoryTopMenu' => $this->categoryTopMenu($eshop, $request),
'eshopHeader' => $eshopHeader,
'eshopFooter' => $eshopFooter,
'homePage' => $homePage,
)
);
}
/**
* @Route("/eshop/{eshopId}/forgottenpasswordupdate/{customerEmail}", name="eshopForgottenPasswordUpdate")
*/
public function eshopForgottenPasswordUpdateAction(Request $request, $eshopId, $customerEmail)
{
/* we load session data */
parent::init($request);
$session = $request->getSession();
/* we load entity managers */
$em = $this->doctrine->getManager();
$dem = $this->doctrine->getManager('dynamic_em');
/* we get current e-shop */
$eshop = $em->getRepository(Eshop::class)->getEshop($eshopId);
$user = $em->getRepository(User::class)->getUser($eshop->getUserId());
/* we check if eshop exists */
if($eshop === null) {
$this->addFlash('error', 'E-shop with this ID does not exist.');
return $this->redirectToRoute('eshopHome');
}
$contact = $dem->getRepository(Contact::class)->getContactFromEmail($customerEmail);
$eshopHeader = $dem->getRepository(Eshop::class)->getEshopHeader($eshopId);
if(!empty($eshopHeader)) {
$eshopHeader->setLocale($session->get('lang')->getLangKey());
$dem->refresh($eshopHeader);
}
/* we load footer for the current website */
$eshopFooter = $dem->getRepository(Eshop::class)->getEshopFooter($eshopId);
if(!empty($eshopFooter)) {
$eshopFooter->setLocale($session->get('lang')->getLangKey());
$dem->refresh($eshopFooter);
}
/* we load home page for the current website */
$homePage = $dem->getRepository(Eshop::class)->getHomePage($eshopId);
$wireFrame = $em->getRepository(WireFrame::class)->getWireFrame($eshop->getProductDetailWireFrameId());
/* we build login form */
$formBuilder = $this->createFormBuilder();
$formBuilder->add('password_new', TextType::class, array(
'required' => true,
'label' => $this->translator->trans('user.password_new'),
'attr' => array('class' => 'text_form', 'size' => 22),
'label_attr' => array('class' => 'form_field_label'),
));
$formBuilder->add('password_new_retype', TextType::class, array(
'required' => true,
'label' => $this->translator->trans('user.password_new'),
'attr' => array('class' => 'text_form', 'size' => 22),
'label_attr' => array('class' => 'form_field_label'),
));
$formBuilder->add('save', SubmitType::class, array('label' => $this->translator->trans('form.send'),
'attr' => array('class' => 'butt_big')));
$form = $formBuilder->getForm();
$form->handleRequest($request);
if ($request->getMethod() == 'POST') {
//print('<br>qqw post dude');
$psw = $request->request->get('form')['password_new'];
$psw_retype = $request->request->get('form')['password_new_retype'];
if($psw === $psw_retype) {
//print('<br>qqw we change password');
$password = md5($psw);
$contact->setContactUserPassword($password);
$dem->persist($contact);
$dem->flush();
$this->addFlash('notice', $this->translator->trans('user.password_changed'));
} else {
$this->addFlash('error', $this->translator->trans('eshop.contact_new_psw_fields'));
}
}
/* we render data */
return $this->render('eshopForgottenPasswordUpdate.html.twig',
array( 'headerData' => $this -> getPageHeader($request),
'form' => $formBuilder->getForm()->createView(),
'menu' => $this -> adminMenu($request),'mainMenu' => $this -> adminMainMenu($request),'mainMenu' => $this -> adminMainMenu($request),
'eshop' => $eshop,
'user' => $user,
'wireFrame' => $wireFrame,
'categoryTreeMenu' => $this->categoryTreeMenu($eshop, $request),
'categoryTopMenu' => $this->categoryTopMenu($eshop, $request),
'eshopHeader' => $eshopHeader,
'eshopFooter' => $eshopFooter,
'homePage' => $homePage,
)
);
}
/**
* @Route("/eshop/{eshopId}/eshopHomeContact", name="eshopHomeContact")
*/
public function eshopHomeContactAction(Request $request, $eshopId) {
/* we load session data */
parent::init($request);
$session = $request->getSession();
/* we load entity managers */
$em = $this->doctrine->getManager();
$dem = $this->doctrine->getManager('dynamic_em');
/* we get current e-shop */
$eshop = $em->getRepository(Eshop::class)->getEshop($eshopId);
$defaultCurrency = $em->getRepository(Currency::class)->getCurrency($eshop->getPreferredCurrencyId());
$user = $em->getRepository(User::class)->getUser($eshop->getUserId());
$eshopHeader = $dem->getRepository(Eshop::class)->getEshopHeader($eshopId);
if(!empty($eshopHeader)) {
$eshopHeader->setLocale($session->get('lang')->getLangKey());
$dem->refresh($eshopHeader);
}
/* we load footer for the current website */
$eshopFooter = $dem->getRepository(Eshop::class)->getEshopFooter($eshopId);
if(!empty($eshopFooter)) {
$eshopFooter->setLocale($session->get('lang')->getLangKey());
$dem->refresh($eshopFooter);
}
$wireFrame = $em->getRepository(WireFrame::class)->getWireFrame($eshop->getProductDetailWireFrameId());
// no contact logged in - we redirect to eshop login
if(empty($session->get('contact'))) {
return $this->redirectToRoute('eshopLogin', array('eshopId' => $eshopId));
}
$contactId = $session->get('contact')->getContactId();
$contact = $dem->getRepository(Contact::class)->getContact($contactId);
/* we load orders */
$orderList = $dem->getRepository(Order::class)->getOrderListByCustomer($contact,'orderId','DESC');
/* we load order prices */
$orderPrices = array();
foreach($orderList as $order) {
if(!empty($order->getCurrencyKey())) {
$targetCurrency = $em->getRepository(Currency::class)->getCurrencyByKey($order->getCurrencyKey());
} else {
$targetCurrency = $defaultCurrency;
}
$orderPrices[$order->getOrderId()] = $dem->getRepository(Order::class)->getOrderPrice($order->getOrderId(), $targetCurrency, false, $eshop, $defaultCurrency);
}
/*
print('<hr>QQW orderList: ');
\Doctrine\Common\Util\Debug::dump($orderList);
*/
$topProductContent = $this->getProductGroup(1, $request);
//isModule Price Levels
$module = $em->getRepository(Module::class)->getModule(22);
$isPriceLevelModule = $em->getRepository(User::class)->userHasModule($user, $module);
$priceLevelName = null;
if($isPriceLevelModule) {
$priceLevel = $contact->getPriceLevel();
if(!empty($priceLevel)) {
$priceLevel->setLocale($session->get('lang')->getLangKey());
$dem->refresh($priceLevel);
$priceLevelName = $priceLevel->getPriceLevelName();
}
//print('<br>Price Level Id: '.$priceLevel->getPriceLevelId());
//print('<br>qqw is module Price Level: '.$priceLevel->getPriceLevelName());
}
/* we add product(s) to basket - POST form action */
if(!empty($request->request->get('basket'))) {
/* we call method to add to basket */
$this->addToBasket($request, $eshopId, $request->request->get('productId'));
}
//print('<hr>QQW topProductContent: ');
//\Doctrine\Common\Util\Debug::dump($topProductContent);
/* we render data */
return $this->render('eshopHomeContact.html.twig',
array('headerData' => $this -> getPageHeader($request),
'contact' => $contact,
'eshop' => $eshop,
'wireFrame' => $wireFrame,
'categoryTreeMenu' => $this->categoryTreeMenu($eshop, $request),
'categoryTopMenu' => $this->categoryTopMenu($eshop, $request),
'eshopHeader' => $eshopHeader,
'eshopFooter' => $eshopFooter,
'orderList' => $orderList,
'orderPrices' => $orderPrices,
'topProductContent' => $topProductContent,
'priceLevelName' => $priceLevelName
)
);
}
/**
* @Route("/eshop/{eshopId}/eshopOrderContact/{orderId}", name="eshopOrderContact")
*/
public function eshopOrderContactAction(Request $request, $eshopId, $orderId) {
/* we load session data */
parent::init($request);
$session = $request->getSession();
/* we load entity managers */
$em = $this->doctrine->getManager();
$dem = $this->doctrine->getManager('dynamic_em');
/* we get current e-shop */
$eshop = $em->getRepository(Eshop::class)->getEshop($eshopId);
$eshopCurrency = $em->getRepository(Currency::class)->getCurrency($eshop->getPreferredCurrencyId());
$eshopHeader = $dem->getRepository(Eshop::class)->getEshopHeader($eshopId);
if(!empty($eshopHeader)) {
$eshopHeader->setLocale($session->get('lang')->getLangKey());
$dem->refresh($eshopHeader);
}
/* we load footer for the current website */
$eshopFooter = $dem->getRepository(Eshop::class)->getEshopFooter($eshopId);
if(!empty($eshopFooter)) {
$eshopFooter->setLocale($session->get('lang')->getLangKey());
$dem->refresh($eshopFooter);
}
$wireFrame = $em->getRepository(WireFrame::class)->getWireFrame($eshop->getProductDetailWireFrameId());
$contactId = $session->get('contact')->getContactId();
$contact = $dem->getRepository(Contact::class)->getContact($contactId);
/* we load order */
$order = $dem->getRepository(Order::class)->getOrder($orderId);
if(!empty($order->getCurrencyKey())) {
$targetCurrency = $em->getRepository(Currency::class)->getCurrencyByKey($order->getCurrencyKey());
} else {
$targetCurrency = $eshopCurrency;
}
$orderPrice = $dem->getRepository(Order::class)->getOrderPrice($order->getOrderId(), $targetCurrency, false, $eshop, $eshopCurrency);
$orderPriceVAT = $dem->getRepository(Order::class)->getOrderPrice($order->getOrderId(), $targetCurrency, true, $eshop, $eshopCurrency);
if(!empty($order->getEshopDelivery())) {
//we set delivery cost in selected currency
$deliveryCost = $dem->getRepository(Price::class)->getCurrencyRatedPrice($order->getEshopDelivery()->getCost(), $eshopCurrency, $targetCurrency);
$order->getEshopDelivery()->setCost(round($deliveryCost, 2));
}
if(!empty($order->getEshopDelivery())) {
//we set payment cost in selected currency
$paymentCost = $dem->getRepository(Price::class)->getCurrencyRatedPrice($order->getEshopPayment()->getCost(), $eshopCurrency, $targetCurrency);
$order->getEshopPayment()->setCost(round($paymentCost, 2));
}
//print('<hr>QQW order '.$orderId.': ');
//\Doctrine\Common\Util\Debug::dump($order);
/* we render data */
return $this->render('eshopOrderContact.html.twig',
array('headerData' => $this -> getPageHeader($request),
'contact' => $contact,
'eshop' => $eshop,
'wireFrame' => $wireFrame,
'categoryTreeMenu' => $this->categoryTreeMenu($eshop, $request),
'categoryTopMenu' => $this->categoryTopMenu($eshop, $request),
'eshopHeader' => $eshopHeader,
'eshopFooter' => $eshopFooter,
'order' => $order,
'orderPrice' => $orderPrice,
'orderPriceVAT' => $orderPriceVAT,
)
);
}
/**
* @Route("/eshop/{eshopId}/basket", name="eshopBasket")
*/
public function eshopBasketAction(Request $request, $eshopId) {
/* we load session data */
parent::init($request);
$session = $request->getSession();
/* we load entity managers */
$em = $this->doctrine->getManager();
$dem = $this->doctrine->getManager('dynamic_em');
/* we get current e-shop */
$eshop = $em->getRepository(Eshop::class)->getEshop($eshopId);
$user = $em->getRepository(User::class)->getUser($eshop->getUserId());
$userDirs = $this->getUserFolderPathsFromUserId($eshop->getUserId());
$eshopHeader = $dem->getRepository(Eshop::class)->getEshopHeader($eshopId);
if(!empty($eshopHeader)) {
$eshopHeader->setLocale($session->get('lang')->getLangKey());
$dem->refresh($eshopHeader);
}
/* we load footer for the current website */
$eshopFooter = $dem->getRepository(Eshop::class)->getEshopFooter($eshopId);
if(!empty($eshopFooter)) {
$eshopFooter->setLocale($session->get('lang')->getLangKey());
$dem->refresh($eshopFooter);
}
/* we load home page for the current website */
$homePage = $dem->getRepository(Eshop::class)->getHomePage($eshopId);
//$wireFrame = $em->getRepository(WireFrame::class)->getWireFrame($eshop->getProductDetailWireFrameId());
/* removing basket item */
if(!empty($request->query->get('removeBasketItem'))) {
//print('<br>qqw removing item: '.$request->query->get('removeBasketItem'));
$processResult = false;
foreach($session->get('order')->getOrderItems() as $orderItem) {
if($orderItem->getProductId() == $request->query->get('removeBasketItem')) {
//print('<br>qqw item exists in basket');
$session->get('order')->removeOrderItem($orderItem);
$processResult = true;
}
}
if($processResult) {
$this->addFlash('notice', $this->translator->trans('eshop.basket_item_removed'));
}
}
/* we update product(s) in basket - POST form action */
if(!empty($request->request->get('updateBasket'))) {
// print('<br>qqw updating basket:');
$newUnits = $request->request->all('basketItemUnit');
$processResult = true;
foreach($session->get('order')->getOrderItems() as $orderItem) {
$productId = $orderItem->getProductId();
$productUnits = $orderItem->getOrderItemUnits();
//print('<br>qqw product id: '.$productId.' :: units: '.$productUnits);
if(!empty($newUnits[$productId])) {
//print(' :: qqw new units: '.$newUnits[$productId]);
$orderItem->setOrderItemUnits($newUnits[$productId]);
}
}
if($processResult) {
$this->addFlash('notice', $this->translator->trans('eshop.basket_item_updated'));
}
}
//print('<br>qqw session order: ');
//\Doctrine\Common\Util\Debug::dump($session->get('order'));
/* we remove session order if it exists and if basket is empty */
if(!empty($session->get('order')) && count($session->get('order')->getOrderItems()) == 0) {
$session->remove('order');
}
$productThumbs = array();
$products = array();
if(!empty($session->get('order')) && $session->get('order')->getEshopId() == $eshopId) {
foreach($session->get('order')->getOrderItems() as $orderItem) {
$pId = $orderItem->getProductId();
$product = $dem->getRepository(Product::class)->getProduct($pId);
if(!empty($product)) {
$products[$pId] = $product;
}
if(!empty($product) && $product->getImage1() != "") {
//$imagePath = 'users/'.$user->getUserName().'/images/'.$product->getImage1();
if (strpos($product->getImage1(), 'http') === false) {
$imagePath = 'users/'.$user->getUserName().'/images/'.$product->getImage1();
$imageThumbPath = 'users/'.$user->getUserName().'/images/thumb_'.$product->getImage1();
} else {
$imagePath = $product->getImage1();
$path = parse_url($imagePath, PHP_URL_PATH);
$imageThumbPath = 'users/'.$user->getUserName().'/images/thumb_'.basename($path);
}
//$imageThumbPath = 'users/'.$user->getUserName().'/images/thumb_'.$product->getImage1();
$imageThumb = $this->getEshopImageThumb($eshop, $imagePath, $imageThumbPath);
$productThumbs[$pId] = $imageThumb;
}
}
}
/* we render data */
return $this->render('eshopBasket.html.twig',
array('headerData' => $this -> getPageHeader($request),
'eshop' => $eshop,
'wireFrame' => null,
'categoryTreeMenu' => $this->categoryTreeMenu($eshop, $request),
'categoryTopMenu' => $this->categoryTopMenu($eshop, $request),
'eshopHeader' => $eshopHeader,
'eshopFooter' => $eshopFooter,
'homePage' => $homePage,
'products' => $products,
'productThumbs' => $productThumbs,
'userDirs' => $userDirs,
)
);
}
/**
* @Route("/eshop/{eshopId}/payment", name="payment")
*/
public function eshopPaymentAction(Request $request, $eshopId) {
/* we load session data */
parent::init($request);
$session = $request->getSession();
/* we load entity managers */
$em = $this->doctrine->getManager();
$dem = $this->doctrine->getManager('dynamic_em');
/* we get current e-shop */
$eshop = $em->getRepository(Eshop::class)->getEshop($eshopId);
$userId = $eshop->getUserId();
$user = $em->getRepository(User::class)->getUser($userId);
$defaultCurrency = $em->getRepository(Currency::class)->getCurrency($eshop->getPreferredCurrencyId());
$targetCurrency = $session->get('eshopCurrency');
$eshopHeader = $dem->getRepository(Eshop::class)->getEshopHeader($eshopId);
if(!empty($eshopHeader)) {
$eshopHeader->setLocale($session->get('lang')->getLangKey());
$dem->refresh($eshopHeader);
}
/* we load footer for the current website */
$eshopFooter = $dem->getRepository(Eshop::class)->getEshopFooter($eshopId);
if(!empty($eshopFooter)) {
$eshopFooter->setLocale($session->get('lang')->getLangKey());
$dem->refresh($eshopFooter);
}
/* we add delivery to order - POST form action */;
if(!empty($request->request->get('delivery'))) {
//print("<br>qqw setting order delivery 2: ".$request->request->get('delivery'));
$eshopDelivery = $dem->getRepository(EshopDelivery::class)->getEshopDelivery($request->request->get('delivery'));
$session->get('order')->setEshopDelivery($eshopDelivery);
/*
print('<br>qqw orderEshopDelivery 0: ');
\Doctrine\Common\Util\Debug::dump($eshopDelivery);
*/
}
/* we add payment to order - POST form action */;
if(!empty($request->request->get('paymentSubmit'))) {
//print('<br>qqw payment submit: '.$request->request->get('payment'));
//$eshopPayment = $dem->getRepository(EshopPayment::class)->getEshopPayment($request->request->get('payment'));
$eshopPayment = $dem->getRepository(EshopPayment::class)->getEshopPaymentFromPayment($request->request->get('payment'));
//$eshopPayment = $dem->getRepository(EshopPayment::class)->getEshopPayment(1);
//\Doctrine\Common\Util\Debug::dump($eshopPayment);
$session->get('order')->setEshopPayment($eshopPayment);
if(!empty($eshopPayment)) {
return $this->redirectToRoute('customer', array('eshopId' => $eshopId));
} else {
$this->addFlash('error', $this->translator->trans('eshop.select_payment'));
}
}
//$wireFrame = $em->getRepository(WireFrame::class)->getWireFrame($eshop->getProductDetailWireFrameId());
//$orderPrice = $dem->getRepository(Order::class)->getOrderPrice($session->get('order')->getOrderId());
$totalPrice = 0;
foreach($session->get('order')->getOrderItems() as $orderItem) {
//print('<br>qqw basket order item: ');
//\Doctrine\Common\Util\Debug::dump($orderItem);
if(empty($orderItem->getOrderItemPrice())) {
$orderItem->setOrderItemPrice(0);
}
$productPrice = $orderItem->getOrderItemPrice() * $orderItem->getOrderItemUnits();
if(empty($productPrice)) {
$productPrice = 0;
}
$totalPrice = $totalPrice + $productPrice;
}
//print('<br>qqw totalPrice 0: '.$totalPrice);
/* we get delivery list from master db */
$deliveryList = $em->getRepository(Delivery::class)->getDeliveryList();
/* we get delivery list of this e-shop */
$eshopDeliveryList = array();
foreach($deliveryList as $delivery) {
$eshopDelivery = $dem->getRepository(EshopDelivery::class)->getEshopDeliveryFromDelivery($delivery->getDeliveryId());
if(!empty($eshopDelivery)) {
$eshopDelivery->setLocale($session->get('lang')->getLangKey());
$dem->refresh($eshopDelivery);
//print('<br>QQW delivery 2: ');
//\Doctrine\Common\Util\Debug::dump($deshopDelivery);
//we check limits from and to order price
if(!empty($eshopDelivery->getEnableFromOrderPrice())) {
$fromLimit = $eshopDelivery->getEnableFromOrderPrice();
} else {
$fromLimit = 0;
}
if(!empty($eshopDelivery->getEnableToOrderPrice())) {
$toLimit = $eshopDelivery->getEnableToOrderPrice();
} else {
$toLimit = 999999999;
}
//print('<br>QQW totalPrice: '.$totalPrice);
if(($totalPrice > $fromLimit && $totalPrice < $toLimit) || $totalPrice == 0) {
//we set cost in selected currency
$deliveryCost = $dem->getRepository(Price::class)->getCurrencyRatedPrice($eshopDelivery->getCost(), $defaultCurrency, $targetCurrency);
$eshopDelivery->setCost(round($deliveryCost, 2));
$eshopDeliveryList[$delivery->getDeliveryId()] = $eshopDelivery;
}
//print('<br>qqw '.$eshopDelivery->getEshopDeliveryName().' limit from: '.$eshopDelivery->getEnableFromOrderPrice());
//print('<br>qqw deliveryCost: '.$deliveryCost);
}
}
/* we get payment list from master db */
$paymentList = $em->getRepository(Payment::class)->getPaymentList();
/* we get payment list of this e-shop */
$eshopPaymentList = array();
foreach($paymentList as $payment) {
$eshopPayment = $dem->getRepository(EshopPayment::class)->getEshopPaymentFromPayment($payment->getPaymentId());
if(!empty($eshopPayment)) {
$eshopPayment->setLocale($session->get('lang')->getLangKey());
$dem->refresh($eshopPayment);
//we set cost in selected currency
$paymentCost = $dem->getRepository(Price::class)->getCurrencyRatedPrice($eshopPayment->getCost(), $defaultCurrency, $targetCurrency);
$eshopPayment->setCost(round($paymentCost, 2));
if(!empty($session->get('order')->getEshopDelivery())) {
/* we add to payment list only if it is payment associated with selected delivery */
foreach($session->get('order')->getEshopDelivery()->getEshopPayments() as $orderEshopPayment) {
if($orderEshopPayment->getEshopPaymentId() == $eshopPayment->getEshopPaymentId()) {
$eshopPaymentList[$payment->getPaymentId()] = $eshopPayment;
}
}
} else {
$eshopPaymentList[$payment->getPaymentId()] = $eshopPayment;
}
}
}
/* we render data */
return $this->render('eshopPayment.html.twig',
array('headerData' => $this -> getPageHeader($request),
'eshop' => $eshop,
'user' => $user,
'wireFrame' => null,
'deliveryList' => $deliveryList,
'eshopDeliveryList' => $eshopDeliveryList,
'paymentList' => $paymentList,
'eshopPaymentList' => $eshopPaymentList,
'orderEshopDelivery' => $session->get('order')->getEshopDelivery(),
'orderEshopPayment' => $session->get('order')->getEshopPayment(),
'categoryTreeMenu' => $this->categoryTreeMenu($eshop, $request),
'categoryTopMenu' => $this->categoryTopMenu($eshop, $request),
'eshopHeader' => $eshopHeader,
'eshopFooter' => $eshopFooter,
)
);
}
/**
* @Route("/eshop/{eshopId}/search", name="search")
*/
public function eshopSearchAction(Request $request, $eshopId) {
/* we load session data */
parent::init($request);
$session = $request->getSession();
/* we load entity managers */
$em = $this->doctrine->getManager();
$dem = $this->doctrine->getManager('dynamic_em');
/* we get current e-shop */
$eshop = $em->getRepository(Eshop::class)->getEshop($eshopId);
$eshopHeader = $dem->getRepository(Eshop::class)->getEshopHeader($eshopId);
if(!empty($eshopHeader)) {
$eshopHeader->setLocale($session->get('lang')->getLangKey());
$dem->refresh($eshopHeader);
}
/* we load footer for the current website */
$eshopFooter = $dem->getRepository(Eshop::class)->getEshopFooter($eshopId);
if(!empty($eshopFooter)) {
$eshopFooter->setLocale($session->get('lang')->getLangKey());
$dem->refresh($eshopFooter);
}
$user = $em->getRepository(User::class)->getUser($eshop->getUserId());
$productList = [];
$displayPrice = null;
$productPriceList = [];
$productThumbs = null;
$productCount = 0;
$categoryList = [];
/* we search according to searchString */;
$searchString = '';
if(!empty($request->get('searchstring'))) {
$searchString = $request->get('searchstring');
} elseif(!empty($request->request->get('searchstring'))) {
$searchString = $request->request->get('searchstring');
}
if ($searchString != '') {
/* we get category list */
$categoryList = $dem->getRepository(Eshop::class)->getCategoryListBySearch($eshopId, trim($searchString));
/* we get product list */
$productPerPage = $eshop->getCountPerPage();
$page = $request->query->get('page');
$firstRecord = ($page * $productPerPage) - $productPerPage;
if($firstRecord < 1) {
$firstRecord = 0;
}
$productList = $dem->getRepository(Product::class)->getProductListBySearch($eshopId, trim($searchString));
/*
foreach($productList as $product) {
print('<br>QQW product: ');
\Doctrine\Common\Util\Debug::dump($product->getProductName());
}
*/
$productCount = count($productList);
/* we load product ids into array */
/* we setup and validate images */
$productIds = array();
$productImages = array();
$productThumbs = array();
foreach($productList as $product) {
$pId = $product->getProductId();
$productIds[] = $pId;
if($product->getImage1() != "") {
//$imagePath = 'users/'.$user->getUserName().'/images/'.$product->getImage1();
if (strpos($product->getImage1(), 'http') === false) {
$imagePath = 'users/'.$user->getUserName().'/images/'.$product->getImage1();
$imageThumbPath = 'users/'.$user->getUserName().'/images/thumb_'.$product->getImage1();
} else {
$imagePath = $product->getImage1();
$path = parse_url($imagePath, PHP_URL_PATH);
$imageThumbPath = 'users/'.$user->getUserName().'/images/thumb_'.basename($path);
}
/*
print('<br>qqw imagePath: '.$imagePath);
print('<br>qqw imageThumbPath: '.$imageThumbPath);
*/
$imageThumb = $this->getEshopImageThumb($eshop, $imagePath, $imageThumbPath);
$productThumbs[$pId] = $imageThumb;
}
//print('<br>qqw productName: '.$product->getProductName());
/* we setup product names - if empty then we load multilingual values */
$productName = '';
if(!empty($product->getProductName()) && $product->getProductName() != '') {
$productName = $product->getProductName();
} else {
//we try to get the product name from multilangual fields
foreach($eshop->getLanguages() as $lang) {
$product->setLocale($lang->getLangKey());
$dem->refresh($product);
if(!empty($product->getProductName()) && $product->getProductName() != '') {
$productName = $product->getProductName();
}
}
}
//print('<br>qqw pname 1: '.$productName);
$product->setProductName($productName);
$dem->flush();
//print('<br>qqw pname 2: '.$product->getProductName());
/* we setup product descriptions - if empty then we load multilingual values */
$productDescription = '';
if(!empty($product->getProductDescription()) && $product->getProductDescription() != '') {
$productDescription = $product->getProductDescription();
} else {
//we try to get the product description from multilangual fields
foreach($eshop->getLanguages() as $lang) {
$product->setLocale($lang->getLangKey());
$dem->refresh($product);
if(!empty($product->getProductDescription()) && $product->getProductDescription() != '') {
$productDescription = $product->getProductDescription();
}
}
}
//print('<br>qqw pDescription: '.$productDescription);
$product->setProductDescription($productDescription);
$dem->flush();
}
/* we load prices */
$productPriceList = $dem->getRepository(Product::class)->getProductPriceList($productIds);
$defaultCurrency = $em->getRepository(Currency::class)->getCurrency($eshop->getPreferredCurrencyId());
$targetCurrency = $session->get('eshopCurrency');
/* we load currency rated prices */
$productPriceList = $dem->getRepository(Product::class)->getCurrencyRatedProductPriceList($productPriceList, $defaultCurrency, $targetCurrency);
/* we get price(s) to display */
$displayPrice = null;
foreach($productPriceList as $price) {
if($price->getProductId() == $product->getProductId()) {
/* we get default price level */
if($price->getPriceLevelId() == 1) {
//$displayPrice = round($price->getBruttoValue(),$eshop->getRoundPrice());
$displayPrice = round($price->getNettoValue(),$eshop->getRoundPrice());
}
}
}
}
/* we add product(s) to basket - POST form action */
if(!empty($request->request->get('basket'))) {
/* we call method to add to basket */
$this->addToBasket($request, $eshopId, $request->request->get('productId'));
return $this->redirectToRoute('eshopBasket', array('eshopId' => $eshopId));
}
$productView = $eshop->getProductView();
//isModule Pack Sale
$module = $em->getRepository(Module::class)->getModule(42);
$isPackSaleModule = $em->getRepository(User::class)->userHasModule($user, $module);
/* we render data */
return $this->render('eshopSearch.html.twig',
array('headerData' => $this -> getPageHeader($request),
'eshop' => $eshop,
'user' => $user,
'productView' => $productView,
'productList' => $productList,
'displayPrice' => $displayPrice,
'productPriceList' => $productPriceList,
'productThumbs' => $productThumbs,
'productCount' => $productCount,
'wireFrame' => null,
'categoryTreeMenu' => $this->categoryTreeMenu($eshop, $request),
'categoryTopMenu' => $this->categoryTopMenu($eshop, $request),
'eshopHeader' => $eshopHeader,
'eshopFooter' => $eshopFooter,
'searchString' => $searchString,
'categoryList' => $categoryList,
'isPackSaleModule' => false,
)
);
}
/**
* @Route("/eshop/{eshopId}/customer", name="customer")
*/
public function eshopCustomerAction(Request $request, $eshopId) {
/* we load session data */
parent::init($request);
$session = $request->getSession();
/* we load entity managers */
$em = $this->doctrine->getManager();
$dem = $this->doctrine->getManager('dynamic_em');
/* we get current e-shop */
$eshop = $em->getRepository(Eshop::class)->getEshop($eshopId);
$eshopHeader = $dem->getRepository(Eshop::class)->getEshopHeader($eshopId);
if(!empty($eshopHeader)) {
$eshopHeader->setLocale($session->get('lang')->getLangKey());
$dem->refresh($eshopHeader);
}
/* we load footer for the current website */
$eshopFooter = $dem->getRepository(Eshop::class)->getEshopFooter($eshopId);
if(!empty($eshopFooter)) {
$eshopFooter->setLocale($session->get('lang')->getLangKey());
$dem->refresh($eshopFooter);
}
$user = $em->getRepository(User::class)->getUser($eshop->getUserId());
//we set contact from db to session
if(!empty($session->get('contact'))) {
$contact = $dem->getRepository(Contact::class)->getContactFromUsername($session->get('contact')->getContactUserName());
$session->set('contact', $contact);
}
//isModule PayPal
$module = $em->getRepository(Module::class)->getModule(9);
$isPayPalModule = $em->getRepository(User::class)->userHasModule($user, $module);
/* we prepare data for the form */
if(!empty($request->request->get('firstName'))) {
$firstName = $request->request->get('firstName');
} elseif(!empty($session->get('contact'))) {
$firstName = $session->get('contact')->getFirstName();
} else {
$firstName = '';
}
if(!empty($request->request->get('lastName'))) {
$lastName = $request->request->get('lastName');
} elseif(!empty($session->get('contact'))) {
$lastName = $session->get('contact')->getLastName();
} else {
$lastName = '';
}
if(!empty($request->request->get('companyName'))) {
$company = $request->request->get('companyName');
} elseif(!empty($session->get('contact'))) {
$company = $session->get('contact')->getCompanyName();
} else {
$company = '';
}
if(!empty($request->request->get('email'))) {
$email = $request->request->get('email');
} elseif(!empty($session->get('contact'))) {
$email = $session->get('contact')->getEmail();
} else {
$email = '';
}
if(!empty($request->request->get('phone'))) {
$telefon = $request->request->get('phone');
} elseif(!empty($session->get('contact'))) {
$telefon = $session->get('contact')->getPhone();
} else {
$telefon = '';
}
if(!empty($request->request->get('addressStreet'))) {
$addressStreet = $request->request->get('addressStreet');
} elseif(!empty($session->get('contact')) && !empty($session->get('contact')->getAddress())) {
$addressStreet = $session->get('contact')->getAddress()->getStreet();
} else {
$addressStreet = '';
}
if(!empty($request->request->get('addressStreetNumber'))) {
$addressStreetNumber = $request->request->get('addressStreetNumber');
} elseif(!empty($session->get('contact')) && !empty($session->get('contact')->getAddress())) {
$addressStreetNumber = $session->get('contact')->getAddress()->getStreetNumber();
} else {
$addressStreetNumber = '';
}
if(!empty($request->request->get('addressCity'))) {
$addressCity = $request->request->get('addressCity');
} elseif(!empty($session->get('contact')) && !empty($session->get('contact')->getAddress())) {
$addressCity = $session->get('contact')->getAddress()->getCity();
} else {
$addressCity = '';
}
if(!empty($request->request->get('addressZipCode'))) {
$addressZipCode = $request->request->get('addressZipCode');
} elseif(!empty($session->get('contact')) && !empty($session->get('contact')->getAddress())) {
$addressZipCode = $session->get('contact')->getAddress()->getZipCode();
} else {
$addressZipCode = '';
}
if(!empty($request->request->get('addressCountry'))) {
$addressCountry = $request->request->get('addressCountry');
} elseif(!empty($session->get('contact')) && !empty($session->get('contact')->getAddress())) {
$addressCountry = $session->get('contact')->getAddress()->getCountry();
} else {
$addressCountry = '';
}
if(!empty($request->request->get('address'))) {
$address = $request->request->get('address');
} elseif(!empty($session->get('contact'))) {
$address = $session->get('contact')->getAddress1();
} else {
$address = '';
}
if(!empty($request->request->get('contactUserName'))) {
$username = $request->request->get('contactUserName');
} elseif(!empty($session->get('contact'))) {
$username = $session->get('contact')->getContactUserName();
} else {
$username = '';
}
if(!empty($request->request->get('contactUserPassword'))) {
$password = $request->request->get('contactUserPassword');
} elseif(!empty($session->get('contact'))) {
$password = $session->get('contact')->getContactUserPassword();
} else {
$password = '';
}
if(!empty($request->request->get('password_retype'))) {
$password_retype = $request->request->get('password_retype');
} elseif(!empty($session->get('contact'))) {
$password_retype = $session->get('contact')->getContactUserPassword();
} else {
$password_retype = '';
}
if(!empty($request->request->get('businessId'))) {
$businessId = $request->request->get('businessId');
} elseif(!empty($session->get('contact'))) {
$businessId = $session->get('contact')->getBusinessId();
} else {
$businessId = '';
}
if(!empty($request->request->get('DICId'))) {
$DICId = $request->request->get('DICId');
} elseif(!empty($session->get('contact'))) {
$DICId = $session->get('contact')->getDICId();
} else {
$DICId = '';
}
/* we build register form */
$contact = new Contact;
$formBuilder = $this->createFormBuilder($contact);
$formBuilder->add('lastName', TextType::class, array(
'required' => true,
'label' => $this->translator->trans('knowledgebase.last_name'),
'attr' => array('class' => 'text_form', 'size' => 35, 'value' => $lastName),
'label_attr' => array('class' => 'form_field_label_required')
));
$formBuilder->add('firstName', TextType::class, array(
'required' => true,
'label' => $this->translator->trans('knowledgebase.first_name'),
'attr' => array('class' => 'text_form', 'size' => 35, 'value' => $firstName),
'label_attr' => array('class' => 'form_field_label_required')
));
$formBuilder->add('email', EmailType::class, array(
'required' => true,
'attr' => array('class' => 'text_form', 'size' => 35, 'value' => $email),
'label_attr' => array('class' => 'form_field_label_required'),
));
$formBuilder->add('contactUserName', TextType::class, array(
'required' => true,
'label' => $this->translator->trans('user.username'),
'empty_data' => '',
'attr' => array('class' => 'text_form', 'size' => 35, 'value' => $username),
'label_attr' => array('class' => 'form_field_label_required'),
));
$formBuilder->add('contactUserPassword', PasswordType::class, array(
'required' => true,
'label' => $this->translator->trans('user.password'),
'attr' => array('class' => 'text_form', 'size' => 35, 'value' => $password),
'label_attr' => array('class' => 'form_field_label_required'),
));
$formBuilder->add('phone', TextType::class, array(
'required' => false,
'label' => $this->translator->trans('user.telephone'),
'attr' => array('class' => 'text_form', 'size' => 35, 'value' => $telefon),
'label_attr' => array('class' => 'form_field_label'),
));
/* we add address */
$formBuilder->add('addressStreet', TextType::class, array(
'required' => true,
'mapped' => false,
'label' => $this->translator->trans('address.street'),
'attr' => array('class' => 'text_form', 'size' => 35, 'value' => $addressStreet),
'label_attr' => array('class' => 'form_field_label_required'),
));
$formBuilder->add('addressStreetNumber', TextType::class, array(
'required' => true,
'mapped' => false,
'label' => $this->translator->trans('address.street_number'),
'attr' => array('class' => 'text_form', 'size' => 10, 'value' => $addressStreetNumber),
'label_attr' => array('class' => 'form_field_label_required'),
));
$formBuilder->add('addressZipCode', TextType::class, array(
'required' => true,
'mapped' => false,
'label' => $this->translator->trans('address.zip_code'),
'attr' => array('class' => 'text_form', 'size' => 10, 'value' => $addressZipCode),
'label_attr' => array('class' => 'form_field_label_required'),
));
$formBuilder->add('addressCity', TextType::class, array(
'required' => true,
'mapped' => false,
'label' => $this->translator->trans('address.city'),
'attr' => array('class' => 'text_form', 'size' => 35, 'value' => $addressCity),
'label_attr' => array('class' => 'form_field_label_required'),
));
$formBuilder->add('addressCountry', TextType::class, array(
'required' => true,
'mapped' => false,
'label' => $this->translator->trans('address.country'),
'attr' => array('class' => 'text_form', 'size' => 35, 'value' => $addressCountry),
'label_attr' => array('class' => 'form_field_label_required'),
));
$formBuilder->add('companyName', TextType::class, array(
'required' => false,
'label' => $this->translator->trans('user.company'),
'attr' => array('class' => 'text_form', 'size' => 35, 'value' => $company),
'label_attr' => array('class' => 'form_field_label')
));
$formBuilder->add('businessId', TextType::class, array(
'required' => false,
'label' => $this->translator->trans('user.business_number'),
'attr' => array('class' => 'text_form', 'size' => 35, 'value' => $businessId),
'label_attr' => array('class' => 'form_field_label')
));
$formBuilder->add('DICId', TextType::class, array(
'required' => false,
'label' => $this->translator->trans('user.DIC_number'),
'attr' => array('class' => 'text_form', 'size' => 35, 'value' => $DICId),
'label_attr' => array('class' => 'form_field_label')
));
/*
$formBuilder->add('address', TextareaType::class, array(
'required' => false,
'label' => $this->translator->trans('user.address'),
'attr' => array('class' => 'textarea_form', 'cols' => 33, 'rows' => 2, 'value' => $address),
'label_attr' => array('class' => 'form_textarea_label'),
'data' => $address,
));
*/
/*
$formBuilder->add('password_retype', PasswordType::class, array(
'required' => true,
'label' => $this->translator->trans('user.password_retype'),
'attr' => array('class' => 'text_form', 'size' => 35, 'value' => $password_retype),
'label_attr' => array('class' => 'form_field_label_required'),
));
*/
//isModule e-Privacy Consent
$module = $em->getRepository(Module::class)->getModule(30);
$isConsentModule = $em->getRepository(User::class)->userHasModule($user, $module);
$consentList = null;
$consentDescriptions = array();
if($isConsentModule) {
//print('<br>qqw is module e-Privacy Consent');
$consentList = $dem->getRepository(Consent::class)->getConsentList();
$consents = array();
$consentRequired = false;
foreach($consentList as $consent) {
//print('<br>Consent: '.$consent->getConsentName());
$consent->setLocale($session->get('lang')->getLangKey());
$dem->refresh($consent);
if($consent->isBlockOrder()) {
$consentRequired = true;
}
$consents[$consent->getConsentName()] = $consent->getConsentId();
$consentDescriptions[$consent->getConsentId()] = $consent->getConsentDescription();
}
$selectedConsents = array();
$formBuilder->add('consents', ChoiceType::class, array(
'choices' => $consents,
'required' => $consentRequired,
'mapped' => false,
'multiple' => true,
'expanded' => true,
'label_attr' => array('class' => 'consent_label'),
'attr' => array('class' => 'form_field_text'),
'choice_attr' => function($val, $key, $index) {
// adds a class like attending_yes, attending_no, etc
return ['class' => 'choiceBlock5', 'required' => 'required'];
},
'data' => $selectedConsents
));
}
$formBuilder->add('save', SubmitType::class, array('label' => $this->translator->trans('eshop.complete_order'),
'attr' => array('class' => 'completeOrderButton')));
$form = $formBuilder->getForm();
$form->handleRequest($request);
if ($request->getMethod() == 'POST') {
//$form->bindRequest($request);
if ($form->isValid()) {
$formData = $form->getData();
/* we check if this contact already exists */
$contactExist = $dem->getRepository(Contact::class)->getContactFromUsername($formData->getContactUsername());
/*
print('<br>qqw contact exists: ');
\Doctrine\Common\Util\Debug::dump($contactExist);
*/
/* we create new contact
if($contactExist === null) {
/* we check if the password fields are the same */
$password = $formData->getContactUserPassword();
//$retypePassword = $request->request->get('form')['password_retype'];
if(!empty($session->get('contact'))) {
/* */
$contact = $dem->getRepository(Contact::class)->getContactFromUsername($formData->getContactUsername());
$password = $formData->getContactUserPassword();
} else {
print('<br>We create new contact');
//$contact = new Contact;
$password = md5($formData->getContactUserPassword());
}
/* we load contact data from register form into contact object */
$contact->setFirstName($formData->getFirstName());
$contact->setLastName($formData->getLastName());
$contact->setCompanyName($formData->getCompanyName());
$contact->setContactUserName($formData->getContactUserName());
$contact->setEmail($formData->getEmail());
$contact->setPhone($formData->getPhone());
$contact->setContactUserPassword($password);
//$address = $contact->getAddress();
if(empty($contact->getAddress())) {
$address = new Address;
} else {
$address = $contact->getAddress();
}
$address->setStreet($form['addressStreet']->getData());
$address->setStreetNumber($form['addressStreetNumber']->getData());
$address->setCity($form['addressCity']->getData());
$address->setZipCode($form['addressZipCode']->getData());
$address->setCountry($form['addressCountry']->getData());
$contact->setAddress($address);
$contact->setBusinessId($formData->getBusinessId());
$contact->setDICId($formData->getDICId());
/* we remove old consents */
if(!empty($contact->getConsents())) {
foreach($contact->getConsents() as $consent) {
$contact->removeConsent($consent);
//$dem->refresh($product);
//$dem->persist($cat);
}
}
/* we save consents */
if(!empty($form['consents']->getData())) {
foreach($form['consents']->getData() as $consentId) {
$consent = $dem->getRepository(Consent::class)->getConsent($consentId);
$contact->addConsent($consent);
}
}
/* we persist and save contact */
$dem->persist($contact);
$dem->flush();
//$this->addFlash('notice', $this->translator->trans('eshop.contact_new_created'));
/* we load logged contact into session */
$session = $request->getSession();
$session->set('contact', $contact);
/* we load logged user into order
//$session->get('order')->setEshopContact($contact);
/*
print('<br>qqw contact: ');
\Doctrine\Common\Util\Debug::dump($session->get('contact'));
*/
return $this->redirectToRoute('thankyou', array('eshopId' => $eshopId));
}
else {
$this->addFlash('error', 'E-shop account with this username already exists.');
}
}
/* we setup wireframe and layout extensoin */
if(!empty($wireFrame)) {
$wireFrameFile = $wireFrame->getWireFrameFile();
} else {
$wireFrameFile = 'eshopLayoutFlat.html.twig';
}
$currentUserId = $eshop->getUserId();
$paypalList = $dem->getRepository(Paypal::class)->getPaypalListByUser($currentUserId);
$userPaypal = null;
foreach($paypalList as $paypal) {
$userPaypal = $dem->getRepository(Paypal::class)->getPaypal($paypal->getPaypalId());
}
/*
print('<br>qqw paypalList: ');
\Doctrine\Common\Util\Debug::dump($paypalList);
print('<br>qqw paypal: ');
\Doctrine\Common\Util\Debug::dump($userPaypal);
*/
/* we render data */
return $this->render('eshopCustomer.html.twig',
array('headerData' => $this -> getPageHeader($request),
'form' => $formBuilder->getForm()->createView(),
'formRaw' => $formBuilder->getForm(),
'eshop' => $eshop,
'wireFrame' => null,
'wireFrameFile' => $wireFrameFile,
'categoryTreeMenu' => $this->categoryTreeMenu($eshop, $request),
'categoryTopMenu' => $this->categoryTopMenu($eshop, $request),
'eshopHeader' => $eshopHeader,
'eshopFooter' => $eshopFooter,
'isConsentModule' => $isConsentModule,
'consentList' => $consentList,
'consentDescriptions' => $consentDescriptions,
'isPayPalModule' => $isPayPalModule,
'paypal' => $userPaypal
)
);
}
/**
* @Route("/eshop/{eshopId}/thankyou", name="thankyou")
*/
public function thankyouAction(Request $request, $eshopId) {
/* we load session data */
parent::init($request);
$session = $request->getSession();
/* we load entity managers */
$em = $this->doctrine->getManager();
$dem = $this->doctrine->getManager('dynamic_em');
/* we get current e-shop */
$eshop = $em->getRepository(Eshop::class)->getEshop($eshopId);
$eshopHeader = $dem->getRepository(Eshop::class)->getEshopHeader($eshopId);
if(!empty($eshopHeader)) {
$eshopHeader->setLocale($session->get('lang')->getLangKey());
$dem->refresh($eshopHeader);
}
/* we load footer for the current website */
$eshopFooter = $dem->getRepository(Eshop::class)->getEshopFooter($eshopId);
if(!empty($eshopFooter)) {
$eshopFooter->setLocale($session->get('lang')->getLangKey());
$dem->refresh($eshopFooter);
}
/* we get user */
$user = $em->getRepository(User::class)->getUser($eshop->getUserId());
if(empty($session->get('order'))) {
$this->addFlash('error', 'Order session timed out.');
return $this->redirectToRoute('eshopHome');
}
/* we setup order fields */
$dateTimeNow = new \DateTime("now");
$session->get('order')->setDateCreated($dateTimeNow);
$order = $session->get('order');
/* we get new order id */
$getMaxOrderId = $dem->getRepository(Order::class)->getMaxOrderId() + 1;
/* we persist order items into db */
$orderItems = $session->get('order')->getOrderItems();
foreach($orderItems as $orderItem) {
$orderItem->setOrderId($getMaxOrderId);
$dem->persist($orderItem);
}
//print('<br>qqw del id: '.$session->get('order')->getEshopDelivery()->getDeliveryId());
/* we persist delivery */
//$orderDelivery = $em->getRepository(Delivery::class)->getDelivery($session->get('order')->getEshopDelivery()->getDeliveryId());
$orderDelivery = $dem->getRepository(EshopDelivery::class)->getEshopDelivery($session->get('order')->getEshopDelivery()->getEshopDeliveryId());
$order->setEshopDelivery($orderDelivery);
$orderPayment = $dem->getRepository(EshopPayment::class)->getEshopPayment($session->get('order')->getEshopPayment()->getEshopPaymentId());
$order->setEshopPayment($orderPayment);
//$dem->persist($orderDelivery);
/*
print('<br>qqw orderDelivery: ');
\Doctrine\Common\Util\Debug::dump($orderDelivery);
*/
//die('<br>qqw Delivery x');
//$orderDelivery = $session->get('order')->getEshopDelivery();
//$dem->persist($orderDelivery);
//$orderPayment = $session->get('order')->getEshopPayment();
//$dem->persist($orderPayment);
/* we persist customer */
if(!empty($session->get('contact'))) {
//print('<br>qqw existing customer');
$orderContact = $dem->getRepository(Contact::class)->getContact($session->get('contact')->getContactId());
if(empty($orderContact)) {
$orderContact = $session->get('contact');
}
$order->setEshopContact($orderContact);
} else {
$orderContact = $session->get('order')->getEshopContact();
}
/*
print('<br>qqw orderContact: ');
\Doctrine\Common\Util\Debug::dump($orderContact);
print('<br>qqw contact: ');
\Doctrine\Common\Util\Debug::dump($session->get('contact'));
*/
$order->setIp($request->getClientIp());
$dem->persist($orderContact);
/* we persist order into db */
$dem->persist($order);
$dem->flush();
/* we remove the order from session */
$session->remove('order');
/* we prepare emailing */
$name = $eshop->getEshopName();
$to = $user->getEmail();
$subject = $name.' - '.$this->translator->trans('eshop.email_order_subject').': #'.$order->getOrderId();
$message = $this->translator->trans('eshop.email_order_text');
/* we load order email cms text for the current eshop */
$orderEmail = $dem->getRepository(WebPage::class)->getEmailOrder($eshopId);
if(!empty($orderEmail)) {
$message .= $orderEmail->getWebPageContent();
}
/* we load order email cms text for the current eshop */
/* we get order prices */
$eshopCurrency = $em->getRepository(Currency::class)->getCurrency($eshop->getPreferredCurrencyId());
if(!empty($order->getCurrencyKey())) {
$targetCurrency = $em->getRepository(Currency::class)->getCurrencyByKey($order->getCurrencyKey());
} else {
$targetCurrency = $eshopCurrency;
}
$orderPrice = $dem->getRepository(Order::class)->getOrderPrice($order->getOrderId(), $targetCurrency, false, $eshop, $eshopCurrency);
$orderPriceVAT = $dem->getRepository(Order::class)->getOrderPrice($order->getOrderId(), $targetCurrency, true, $eshop, $eshopCurrency);
$orderEmailText = $this->getOrderEmail($request, $eshop, $order, $orderPrice, $orderPriceVAT);
$message .= $orderEmailText;
$from = 'noreply@virtualrealitycommerce.cz';
/*
$headers = "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/html; charset=UTF-8\r\n";
$headers .= "From: {$name} <{$from}>\r\n";
$headers .= "Reply-To: <{$from}>\r\n";
$headers .= "Subject: {$subject}\r\n";
$headers .= "X-Mailer: PHP/".phpversion()."\r\n";
*/
// we send email to eshop owner
if($this->sendEmail($to, $subject, $from, $message)) {
if(!empty($user->getContactPersonEmail())) {
$this->sendEmail($user->getContactPersonEmail(), $subject, $from, $message);
}
$mailToAdminStatus = $this->translator->trans('eshop.email_admin_order_ok').': '.$to;
} else {
$mailToAdminStatus = $this->translator->trans('eshop.email_admin_order_error'.': '.$to);
}
// we send email to customer
$to = $orderContact->getEmail();
if($this->sendEmail($to, $subject, $from, $message)) {
$mailToCustomerStatus = $this->translator->trans('eshop.email_customer_order_ok').': '.$to;
} else {
$mailToCustomerStatus = $this->translator->trans('eshop.email_customer_order_error'.': '.$to);
}
/*
// we send email to e-shop admin - sendmail, sendemail
if(@mail($to, $subject, $message, $headers)) {
//print('<br>Email was sent.');
//we send email to users contact person
if(!empty($user->getContactPersonEmail())) {
mail($user->getContactPersonEmail(), $subject, $message, $headers);
}
} else {
//print('<br>Email was not sent.');
$mailToAdminStatus = $this->translator->trans('eshop.email_admin_order_error'.': '.$to);
}
// we send email to customer
$to = $orderContact->getEmail();
if(@mail($to, $subject, $message, $headers)) {
//print('<br>Email was sent.');
$mailToCustomerStatus = $this->translator->trans('eshop.email_customer_order_ok').': '.$to;
} else {
//print('<br>Email was not sent.');
$mailToCustomerStatus = $this->translator->trans('eshop.email_customer_order_error'.': '.$to);
}
*/
/* we render data */
return $this->render('eshopThankYou.html.twig',
array('headerData' => $this -> getPageHeader($request),
'eshop' => $eshop,
'order' => $order,
'user' => $user,
'wireFrame' => null,
'categoryTreeMenu' => $this->categoryTreeMenu($eshop, $request),
'categoryTopMenu' => $this->categoryTopMenu($eshop, $request),
'eshopHeader' => $eshopHeader,
'eshopFooter' => $eshopFooter,
'mailToAdminStatus' => $mailToAdminStatus,
'mailToCustomerStatus' => $mailToCustomerStatus,
)
);
}
public function getOrderEmail(Request $request, $eshop, $order, $orderPrice=null, $orderPriceVAT=null)
{
/* we load session data */
parent::init($request);
$session = $request->getSession();
/* we load entity managers */
$em = $this->doctrine->getManager();
$dem = $this->doctrine->getManager('dynamic_em');
/* we get user */
$user = $em->getRepository(User::class)->getUser($eshop->getUserId());
$defaultCurrency = $em->getRepository(Currency::class)->getCurrency($eshop->getPreferredCurrencyId());
if(!empty($order->getCurrencyKey())) {
$targetCurrency = $em->getRepository(Currency::class)->getCurrencyByKey($order->getCurrencyKey());
} else {
$targetCurrency = $session->get('eshopCurrency');
}
if(!empty($order->getDateCreated())) {
$dateCreated = $order->getDateCreated()->format('Y\-m\-d\ H:i:s');
} else {
$dateCreated = '';
}
$emailText = '<h3>'.$this->translator->trans('eshop.order_detail').'</h3>';
$emailText .= '<table width="100%" style="background-color: #EFEFEF; color: Black;font-family: Arial;font-size: 14px;border:Gray solid 1px;" cellspacing="0" cellpadding="3">
<tr>
<td><strong>'.$this->translator->trans('eshop.order').':</strong></td>
<td>'.$order->getOrderId().'</td>
</tr>
<tr>
<td><strong>'.$this->translator->trans('system.date_created').':</strong></td>
<td>'.$dateCreated.'</td>
</tr></table> ';
$emailText .= '<h3>'.$this->translator->trans('eshop.order_items').'</h3>
<table width="100%" style="background-color: #EFEFEF; color: Black;font-family: Arial;font-size: 14px;border:Gray solid 1px;" cellspacing="0" cellpadding="3">
<tr>
<th style="text-align:left;background-color: LightGray;">id#</th>
<th style="text-align:left;background-color: LightGray;">'.$this->translator->trans('product.name').'</th>
<th style="text-align:left;background-color: LightGray;">'.$this->translator->trans('product.key').'</th>
<th style="text-align:left;background-color: LightGray;">'.$this->translator->trans('system.units').'</th>
<th style="text-align:left;background-color: LightGray;">'.$this->translator->trans('eshop.price_piece').'</th>
<th style="text-align:left;background-color: LightGray;">'.$this->translator->trans('eshop.price').'</th>
</tr> ';
$totalPrice = 0;
$totalPriceVAT = 0;
foreach($order->getOrderItems() as $orderItem) {
if(empty($orderItem->getOrderItemPrice())) {
$orderItem->setOrderItemPrice(0);
}
$productKey = "";
if(!empty($orderItem->getProductId())) {
$product = $dem->getRepository(Product::class)->getProduct($orderItem->getProductId());
$productKey = $product->getERPKey();
}
$productPrice = $orderItem->getOrderItemPrice() * $orderItem->getOrderItemUnits();
if(!empty($orderItem->getOrderItemPriceBrutto())) {
$productPriceVAT = $orderItem->getOrderItemPriceBrutto() * $orderItem->getOrderItemUnits();
} else {
$productPriceVAT = $orderItem->getOrderItemPrice() * $orderItem->getOrderItemUnits();
}
if(empty($productPrice)) {
$productPrice = 0;
}
$totalPrice = $totalPrice + $productPrice;
$totalPriceVAT = $totalPriceVAT + $productPriceVAT;
$emailText .= '<tr>
<td>'.$orderItem->getOrderItemId().'</td>
<td>
<strong>'.$orderItem->getOrderItemTitle().'</strong>
</td>
<td>'.$productKey.'</td>
<td>'.$orderItem->getOrderItemUnits().'</td>
<td>'.$orderItem->getOrderItemPrice().' '.$orderItem->getCurrencyKey().'</td>
<td>'.($orderItem->getOrderItemUnits()*$orderItem->getOrderItemPrice()).' '.$orderItem->getCurrencyKey().'</td>
</tr>';
}
$emailText .= '</table>';
$emailText .= '<h3>'.$this->translator->trans('eshop.customer').'</h3>
<table width="100%" style="background-color: #EFEFEF; color: Black;font-family: Arial;font-size: 14px;border:Gray solid 1px;" cellspacing="0" cellpadding="3">
<tr>
<th style="text-align:left;background-color: LightGray;">id#</th>
<th style="text-align:left;background-color: LightGray;">'.$this->translator->trans('knowledgebase.first_name').'</th>
<th style="text-align:left;background-color: LightGray;">'.$this->translator->trans('knowledgebase.last_name').'</th>
<th style="text-align:left;background-color: LightGray;">'.$this->translator->trans('knowledgebase.company_name').'</th>
<th style="text-align:left;background-color: LightGray;">'.$this->translator->trans('knowledgebase.email').'</th>
<th style="text-align:left;background-color: LightGray;">'.$this->translator->trans('knowledgebase.phone').'</th>
<th style="text-align:left;background-color: LightGray;">'.$this->translator->trans('address.street').'</th>
<th style="text-align:left;background-color: LightGray;">'.$this->translator->trans('address.street_number').'</th>
<th style="text-align:left;background-color: LightGray;">'.$this->translator->trans('address.city').'</th>
<th style="text-align:left;background-color: LightGray;">'.$this->translator->trans('address.zip_code').'</th>
<th style="text-align:left;background-color: LightGray;">'.$this->translator->trans('address.country').'</th>
</tr>
<tr>
<td>'.$order->getEshopContact()->getContactId().'</td>
<td>'.$order->getEshopContact()->getFirstName().'</td>
<td>'.$order->getEshopContact()->getLastName().'</td>
<td>'.$order->getEshopContact()->getCompanyName().'</td>
<td>'.$order->getEshopContact()->getEmail().'</td>
<td>'.$order->getEshopContact()->getPhone().'</td>
<td>'.(!empty($order->getEshopContact()->getAddress())?$order->getEshopContact()->getAddress()->getStreet():"").'</td>
<td>'.(!empty($order->getEshopContact()->getAddress())?$order->getEshopContact()->getAddress()->getStreetNumber():"").'</td>
<td>'.(!empty($order->getEshopContact()->getAddress())?$order->getEshopContact()->getAddress()->getCity():"").'</td>
<td>'.(!empty($order->getEshopContact()->getAddress())?$order->getEshopContact()->getAddress()->getZipCode():"").'</td>
<td>'.(!empty($order->getEshopContact()->getAddress())?$order->getEshopContact()->getAddress()->getCountry():"").'</td>
</tr>
</table>';
if($order->getEshopContact()->getBusinessId()) {
$emailText .= '<div style="padding: 2px;"><strong>'.$this->translator->trans('user.business_number').': </strong>'.$order->getEshopContact()->getBusinessId().'</div>';
}
if($order->getEshopContact()->getDICId()) {
$emailText .= '<div style="padding: 2px;"><strong>'.$this->translator->trans('user.DIC_number').': </strong>'.$order->getEshopContact()->getDICId().'</div>';
}
/* we display delivery and price */
$emailText .= '<h3>'.$this->translator->trans('eshop.delivery_payment').'</h3>';
$emailText .= '<table width="100%" style="background-color: #EFEFEF; color: Black;font-family: Arial;font-size: 14px;border:Gray solid 1px;" cellspacing="0" cellpadding="3">';
$emailText .= '<tr><td><strong>'.$this->translator->trans('eshop.delivery').':</strong>';
$emailText .= '</td><td>';
if(!empty($order->getEshopDelivery())) {
//we set cost in selected currency
$deliveryCost = $dem->getRepository(Price::class)->getCurrencyRatedPrice($order->getEshopDelivery()->getCost(), $defaultCurrency, $targetCurrency);
$order->getEshopDelivery()->setCost(round($deliveryCost, 2));
$emailText .= $order->getEshopDelivery()->getEshopDeliveryName();
$emailText .= '<span> [ '.$order->getEshopDelivery()->getCost().' '.$targetCurrency->getCurrencyKey().' ]</span>';
}
$emailText .= '</td></tr>
<tr><td><strong>'.$this->translator->trans('eshop.payment').':</strong>';
$emailText .= '</td><td>';
if(!empty($order->getEshopPayment())) {
//we set cost in selected currency
$paymentCost = $dem->getRepository(Price::class)->getCurrencyRatedPrice($order->getEshopPayment()->getCost(), $defaultCurrency, $targetCurrency);
$order->getEshopPayment()->setCost(round($paymentCost, 2));
$emailText .= $order->getEshopPayment()->getEshopPaymentName();
$emailText .= '<span> [ '.$order->getEshopPayment()->getCost().' '.$targetCurrency->getCurrencyKey().' ]</span>';
if ($order->getEshopPayment()->getPaymentId() == 2) {
// we add sellers bank account info into email
$bankAccountInfo = $user->getBankAccount();
$emailText .= '<br>'.$this->translator->trans('eshop.email_bank_account').': '.$bankAccountInfo;
}
}
$emailText .= '</td></tr>
</table>';
/* we display total price */
$emailText .= '<br>
<table width="100%" style="background-color: #EFEFEF; color: Black;font-family: Arial;font-size: 14px;border:Gray solid 1px;" cellspacing="0" cellpadding="3">
<tr><td>'.$this->translator->trans('eshop.price_product_total').':</td><td>'.$totalPrice.' '.$targetCurrency->getCurrencyKey().'</td></tr>
<tr><td>'.$this->translator->trans('product.price_with_VAT').':</td><td>'.$totalPriceVAT.' '.$targetCurrency->getCurrencyKey().'</td></tr>';
if(!empty($orderPrice)) {
$emailText .= '<tr><td><strong>'.$this->translator->trans('eshop.price_total').':</strong></td>';
$emailText .= '<td><strong>'.$orderPrice.' '.$targetCurrency->getCurrencyKey().'</strong></td>';
$emailText .= '</tr>';
}
if(!empty($orderPriceVAT)) {
$emailText .= '<tr><td><strong>'.$this->translator->trans('eshop.price_total_VAT').':</strong></td>';
$emailText .= '<td><strong>'.$orderPriceVAT.' '.$targetCurrency->getCurrencyKey().'</strong></td>';
$emailText .= '</tr>';
}
$emailText .= '</table>';
return $emailText;
}
public function getRegisterEmail(Request $request, $eshop, $contact)
{
$emailText = '<h1>'.$this->translator->trans('eshop.register').' #'.$contact->getContactId().'</h1>';
$emailText .= '<h3>'.$this->translator->trans('eshop.customer').'</h3>
<table style="color: Black;font-family: Arial;font-size: 14px;border-top:DarkGray solid 2px;border-bottom: DarkGray solid 2px;" cellspacing="0" cellpadding="0">
<tr>
<th style="padding: 3px;text-align:left;background-color: LightGray;">id</th>
<th style="padding: 3px;text-align:left;background-color: LightGray;">'.$this->translator->trans('knowledgebase.first_name').'</th>
<th style="padding: 3px;text-align:left;background-color: LightGray;">'.$this->translator->trans('knowledgebase.last_name').'</th>
<th style="padding: 3px;text-align:left;background-color: LightGray;">'.$this->translator->trans('knowledgebase.company_name').'</th>
<th style="padding: 3px;text-align:left;background-color: LightGray;">'.$this->translator->trans('knowledgebase.email').'</th>
<th style="padding: 3px;text-align:left;background-color: LightGray;">'.$this->translator->trans('knowledgebase.phone').'</th>
<th style="padding: 3px;text-align:left;background-color: LightGray;">'.$this->translator->trans('knowledgebase.user_name').'</th>
</tr>
<tr>
<td style="padding: 3px;">'.$contact->getContactId().'</td>
<td style="padding: 3px;">'.$contact->getFirstName().'</td>
<td style="padding: 3px;">'.$contact->getLastName().'</td>
<td style="padding: 3px;">'.$contact->getCompanyName().'</td>
<td style="padding: 3px;">'.$contact->getEmail().'</td>
<td style="padding: 3px;">'.$contact->getPhone().'</td>
<td style="padding: 3px;">'.$contact->getContactUserName().'</td>
</tr>
</table>';
return $emailText;
}
public function getEshopRequestEmail(Request $request, $eshop, $eshopRequestEmail, $eshopRequestSubject, $eshopRequestMessage, $eshopRequestTelephone)
{
$emailText = '<h1>'.$this->translator->trans('eshop.request').'</h1>';
$dateTimeNow = new \DateTime("now");
$dateCreated = $dateTimeNow->format('Y\-m\-d\ H:i:s');
$emailText = '<h3>'.$this->translator->trans('eshop.request_detail').'</h3>';
$emailText .= '<table width="100%" style="background-color: #EFEFEF; color: Black;font-family: Arial;font-size: 14px;border:Gray solid 1px;" cellspacing="0" cellpadding="3">
<tr>
<td><strong>'.$this->translator->trans('system.date_created').':</strong></td>
<td>'.$dateCreated.'</td>
</tr>
<tr>
<td><strong>Email:</strong></td>
<td>'.$eshopRequestEmail.'</td>
</tr>
<tr>
<td><strong>'.$this->translator->trans('user.telephone').':</strong></td>
<td>'.$eshopRequestTelephone.'</td>
</tr>
<tr>
<td><strong>'.$this->translator->trans('eshop.request_subject').':</strong></td>
<td>'.$eshopRequestSubject.'</td>
</tr>
<tr>
<td><strong>'.$this->translator->trans('eshop.request_message').':</strong></td>
<td>'.$eshopRequestMessage.'</td>
</tr>
</table> ';
return $emailText;
}
public function getForgottenPasswordEmail(Request $request, $eshop, $email)
{
$link = 'https://'.$_SERVER['HTTP_HOST'].'/eshop/'.$eshop->getEshopId().'/forgottenpasswordupdate/'.$email;
$emailText = '<h1>'.$this->translator->trans('user.forgotten_password').'</h1>';
$emailText .= $this->translator->trans('user.forgotten_password_link').'
<a href="'.$link.'" target="_blank" style="padding: 3px;">'.$link.'</a>
';
return $emailText;
}
/**
* @Route("/eshopAdmin", name="eshopAdmin")
*/
public function eshopAdminAction(Request $request)
{
/* we load session data */
parent::init($request);
$session = $request->getSession();
// we check if any user is logged in
if(!$this->isLoggedUser($request)) {
return $this->redirectToRoute('login');
}
/* we load entity managers */
$em = $this->doctrine->getManager();
$dem = $this->doctrine->getManager('dynamic_em');
/* we get current user */
$currentUserId = $session->get('user')->getUserId();
$user = $em->getRepository(User::class)->getUser($currentUserId);
/* setting current eshop */
if(!empty($request->query->get('setCurrent'))) {
$eshop = $em->getRepository(Eshop::class)->getEshop($request->query->get('setCurrent'));
$em->getRepository(Eshop::class)->setCurrentEshop($currentUserId, $request->query->get('setCurrent'));
$session->set('eshop', $eshop);
$this->addFlash('notice', 'The eshop '.$eshop->getEshopName().' was set as current one.');
return $this->redirectToRoute('eshopAdmin');
}
/* we get current e-shop */
// print('<br>qqw currentUserId: '.$currentUserId);
$currentEshop = $em->getRepository(Eshop::class)->getCurrentEshop($currentUserId);
if(!empty($currentEshop)) {
$defaultCurrency = $em->getRepository(Currency::class)->getCurrency($currentEshop->getPreferredCurrencyId());
} else {
$defaultCurrency = null;
}
/*
print('<br>qqw currentEshop: ');
\Doctrine\Common\Util\Debug::dump($currentEshop->getEshopId());
*/
/* we load list of eshops for logged user */
$eshopList = $em->getRepository(Eshop::class)->getEshopListByUser($currentUserId);
//we create new e-shop if there is none
if(count($eshopList) == 0) {
$this->eshopCreate($request);
return $this->redirectToRoute('eshopAdmin');
}
if(!empty($currentEshop)) {
/* we load list of web pages for the current eshop */
$webPageList = $dem->getRepository(WebPage::class)->getWebPageListByEshop($currentEshop->getEshopId());
$eshopHeader = $dem->getRepository(Eshop::class)->getEshopHeader($currentEshop->getEshopId());
if(!empty($eshopHeader)) {
$eshopHeader->setLocale($session->get('lang')->getLangKey());
$dem->refresh($eshopHeader);
}
/* we load footer for the current website */
$eshopFooter = $dem->getRepository(Eshop::class)->getEshopFooter($currentEshop->getEshopId());
if(!empty($eshopFooter)) {
$eshopFooter->setLocale($session->get('lang')->getLangKey());
$dem->refresh($eshopFooter);
}
} else {
$webPageList = array();
//$webMenuList = array();
$eshopHeader = null;
$eshopFooter = null;
}
/* we load list of wireframes */
$wireFrameList = $em->getRepository(WireFrame::class)->getWireFrameList();
/* we prepare array of wireframes */
$wireFrameArray = array();
foreach($wireFrameList as $wireFrame) {
$wireFrameArray[$wireFrame->getWireFrameId()] = $wireFrame;
}
/* we prepare array of count(products) */
$productCountArray = array();
/*
foreach($websiteList as $website) {
$productCountArray[$website->getWebsiteId()] = $dem->getRepository(WebPage::class)->getWebPageCountByWebsite($website->getWebsiteId());
}
*/
/* we load list of modules for e-shop service */
$service = $em->getRepository(Service::class)->getService(1);
/* we load recent orders */
$orderList = $dem->getRepository(Order::class)->getOrderList("orderId", "DESC", 10);
/* we load order prices */
$orderPrices = array();
if(!empty($defaultCurrency)) {
foreach($orderList as $order) {
if(!empty($order->getCurrencyKey())) {
$targetCurrency = $em->getRepository(Currency::class)->getCurrencyByKey($order->getCurrencyKey());
} else {
$targetCurrency = $defaultCurrency;
}
$orderPrices[$order->getOrderId()] = $dem->getRepository(Order::class)->getOrderPrice($order->getOrderId(), $targetCurrency, false, $currentEshop, $defaultCurrency);
}
}
//$moduleCollection = $em->getRepository(Module::class)->getModuleList();
/*
print('<br>qqw moduleCollection: ');
\Doctrine\Common\Util\Debug::dump($moduleCollection);
print('<hr>qqw userModuleCollection: ');
\Doctrine\Common\Util\Debug::dump($user->getModules()); ());
*/
/* we render data */
return $this->render('eshopAdmin.html.twig',
array('headerData' => $this -> getPageHeader($request),
'eshopList' => $eshopList,
'eshopHeader' => $eshopHeader,
'eshopFooter' => $eshopFooter,
'webPageList' => $webPageList,
'moduleList' => $service->getModules(),
'userModuleList' => $user->getModules(),
'wireFrameArray' => $wireFrameArray,
'productCountArray' => $productCountArray,
'orderList' => $orderList,
'orderPrices' => $orderPrices,
'user' => $user,
'menu' => $this -> adminMenu($request),
'mainMenu' => $this -> adminMainMenu($request)
)
);
}
/**
* @Route("/categorynew", name="categoryNew")
*/
public function categoryNewAction(Request $request)
{
/* we load session data */
parent::init($request);
$session = $request->getSession();
$em = $this->doctrine->getManager();
$dem = $this->doctrine->getManager('dynamic_em');
$currentUserId = $session->get('user')->getUserId();
$user = $em->getRepository(User::class)->getUser($currentUserId);
/* we get current e-shop */
$eshop = $em->getRepository(Eshop::class)->getCurrentEshop($currentUserId);
$categoryCollection = $dem->getRepository(Eshop::class)->getCategoryListByEshop($eshop->getEshopId());
/* we build login form */
$category = new Category;
$formBuilder = $this->createFormBuilder($category);
$formBuilder->add('categoryName', TextType::class, array(
'required' => true,
'label' => $this->translator->trans('eshop.category_name'),
'attr' => array('class' => 'text_form', 'size' => 22),
'label_attr' => array('class' => 'form_field_label'),
));
/* we add category list */
$categories = array();
$categories['RootX'] = 0;
foreach($categoryCollection as $cat)
{
$catId = $cat->getCategoryId();
//print('<br>qqw cat: '.$catId);
$cat->setLocale($session->get('lang')->getLangKey());
$dem->refresh($cat);
$catName = $cat->getCategoryName();
$categories[$catName] = $catId;
}
/*
print('<hr>qqw categories ');
\Doctrine\Common\Util\Debug::dump($categories);
print('<hr>qqw categories 2');
\Doctrine\Common\Util\Debug::dump($categories2);
*/
$formBuilder->add('categories', ChoiceType::class, array(
'choices' => $categories,
'mapped' => false,
'attr' => array('class' => 'selector'),
'label' => $this->translator->trans('eshop.parent_category'),
'label_attr' => array('class' => 'form_field_label')
));
$formBuilder->add('save', SubmitType::class, array('label' => $this->translator->trans('form.button.save'),
'attr' => array('class' => 'butt_big')));
$form = $formBuilder->getForm();
$form->handleRequest($request);
if ($request->getMethod() == 'POST') {
if ($form->isValid()) {
$formData = $form->getData();
/* we load users entity manager */
$dem = $this->doctrine->getManager('dynamic_em');
//$userName = $request->request->get('form')['username'];
//$userExist = $em->getRepository(User::class)->getUserFromLogin($userName, $request->request->get('form')['password']);
$root = $dem->getRepository(Eshop::class)->getCategory(1);
$dem->persist($eshop);
$category->setCategoryName($formData->getCategoryName());
$category->setIsActive(1);
$category->setEshopId($eshop->getEshopId());
if(intval($form['categories']->getData()) == 0) {
$parentCategory = null;
} else {
$parentCategory = $dem->getRepository(Eshop::class)->getCategory(intval($form['categories']->getData()));
}
$category->setParent($parentCategory);
/* we persist and save category */
$dem->persist($category);
$dem->flush();
$this->addFlash('notice', 'New category was created.');
return $this->redirectToRoute('categoryEdit', array('categoryId' => $category->getCategoryId()));
}
}
/* we render data */
return $this->render('categoryNew.html.twig',
array('form' => $formBuilder->getForm()->createView(),
'headerData' => $this -> getPageHeader($request),
'user' => $user,
'menu' => $this -> adminMenu($request),'mainMenu' => $this -> adminMainMenu($request),'mainMenu' => $this -> adminMainMenu($request),
)
);
}
/**
* @Route("/categories", name="categories")
*/
public function categoriesAction(Request $request)
{
/* we load session data */
parent::init($request);
$session = $request->getSession();
// we check if any user is logged in
if(!$this->isLoggedUser($request)) {
return $this->redirectToRoute('login');
}
/* we load entity managers */
$em = $this->doctrine->getManager();
$dem = $this->doctrine->getManager('dynamic_em');
$currentUserId = $session->get('user')->getUserId();
$user = $em->getRepository(User::class)->getUser($currentUserId);
/* we get current e-shop */
$eshop = $em->getRepository(Eshop::class)->getCurrentEshop($currentUserId);
/* we do a action with selected products */
if (!empty($request->request->get('selectCategoriesSubmit'))) {
// print('<br>qqw selectedCategories:');
set_time_limit(60);
$productIds = [];
foreach ($request->request->all('selectedCategories') as $cId) {
// print('<br>qqw cID: '.$cId);
$categoryIds[] = $cId;
/* we get product and remove it */
// $category = $dem->getRepository(Eshop::class)->getCategory($cId);
$category = $dem->getRepository(Category::class)->findOneBy(['categoryId'=> $cId]);
if (!empty($category)) {
$dem->remove($category);
$em->persist($category);
$dem->flush();
}
}
/* we remove product prices */
$productPriceList = $dem->getRepository(Product::class)->getProductPriceList($productIds);
foreach($productPriceList as $price) {
//print('<br>qqw removing price: ');
$dem->remove($price);
$dem->flush();
}
$this->addFlash('notice', $this->translator->trans('category.removed'));
}
$categoryList = $dem->getRepository(Eshop::class)->getCategoryListByEshop($eshop->getEshopId());
$root = $dem->getRepository(Eshop::class)->getCategory(1);
if(isset($GLOBALS['request']) && $GLOBALS['request']) {
$locale = $GLOBALS['request']->getLocale();
//print('<br>qqw locale: '.$locale);
}
foreach($categoryList as $cat) {
$cat->setLocale('en');
//$cat->setLocale($locale);
$dem->refresh($cat);
//print('<br>qqw cat (id '.$cat->getCategoryId().'): '.$cat->getCategoryName());
}
/* category name - multilangual fields */
/*
foreach($eshop->getLanguages() as $lang) {
//$fieldLabel = $this->translator->trans('eshop.category_name').' ['.$lang->getLangKey().']';
$category->setLocale($lang->getLangKey());
$dem->refresh($category);
$fieldValue = $category->getCategoryName();
}
*/
//$vegetables = $dem->getRepository(Eshop::class)->getCategory(9);
/*
$food = new Category();
$food->setCategoryName('Food');
$food->setParent($root);
$fruits = new Category();
$fruits->setCategoryName('Fruits');
$fruits->setParent($food);
$vegetables = new Category();
$vegetables->setCategoryName('Vegetables');
$vegetables->setParent($food);
$carrots = new Category();
$carrots->setCategoryName('Carrots');
$carrots->setParent($vegetables);
$dem->persist($fruits);
$dem->persist($vegetables);
$dem->persist($carrots);
$dem->persist($food);
$dem->flush();
*/
//$repo = $em->getRepository('Entity\Category');
$repo = $dem->getRepository(Category::class);
$this->dynamicEntityManager = $dem;
$this->currentEshop = $eshop;
$options = array(
'decorate' => true,
'rootOpen' => '<ul>',
'rootClose' => '</ul>',
'childOpen' => function($node) {
//print('<br>QQW node: ');
//\Doctrine\Common\Util\Debug::dump($node);
if($node['eshopId'] == $this->currentEshop->getEshopId()) {
return '<li>';
} else {
return '<li class="treeItemHidden">';
}
/*
print('<br>QQW getEshop: '.$cat->getEshop()->getEshopId());
print('<br>QQW currentEshop: '.$this->currentEshop->getEshopId());
if($cat->getEshop()->getEshopId() == $this->currentEshop->getEshopId()) {
return '<li>currShop';
} else {
return '<li>';
}
print('<hr>QQW cat: ');
print('<hr>QQW cat: ');
\Doctrine\Common\Util\Debug::dump($cat);
*/
/*
if($node['categoryName'] == "Nokia") {
return '<h1>QQW NOKIA</h1><ul>';
} else {
return '<ul>';
}
*/
return '<li>';
},
'childClose' => '</li>',
'nodeDecorator' => function($node) {
return '<a href="./categoryedit/'.$node['categoryId'].'" class="treeNodeLink">'.$node['categoryName'].'</a>[<a href="./categoryedit/'.$node['categoryId'].'" class="treeLinkLeft">'.$this->translator->trans('system.edit').'</a>][<a href="./categoryremove/'.$node['categoryId'].'" class="treeLink">'.$this->translator->trans('system.remove').'</a>]';
}
);
/*
$options = array(
'decorate' => true,
'rootOpen' => '<ul>',
'rootClose' => '</ul>',
'childOpen' => '<li>',
'childClose' => '</li>',
'nodeDecorator' => function($node) {
return '<a href="./categoryedit/'.$node['categoryId'].'" class="treeNodeLink">'.$node['categoryName'].'</a>[<a href="./categoryedit/'.$node['categoryId'].'" class="treeLinkLeft">'.$this->translator->trans('system.edit').'</a>][<a href="./categoryremove/'.$node['categoryId'].'" class="treeLink">'.$this->translator->trans('system.remove').'</a>]';
}
);
*/
/*
$arrayTree = $repo->childrenHierarchy();
print("<hr>qqw arrayTree: ");
print_r($arrayTree);
*/
/*
$rootNodes = $repo->getRootNodes();
print("<hr>qqw Root Nodes: ");
print_r($rootNodes);
*/
$htmlTree = $repo->childrenHierarchy(
null,
false,
$options
);
//$children = $repo->children($vegetables, false, null, 'ASC', false);
//echo "<br>qqw childCount: ".$repo->childCount($root);
/*
$fruits = new Category();
$fruits->setCategoryName('Fruits');
$fruits->setParent($food);
$vegetables = new Category();
$vegetables->setCategoryName('Vegetables');
$vegetables->setParent($food);
$carrots = new Category();
$carrots->setCategoryName('Carrots');
$carrots->setParent($vegetables);
$dem->persist($food);
$dem->persist($fruits);
$dem->persist($vegetables);
$dem->persist($carrots);
$dem->flush();
*/
//echo $request->attributes->get('_route');
//echo $request->getPathInfo();
/* we render data */
return $this->render('categories.html.twig',
array( 'headerData' => $this -> getPageHeader($request),
'categoryList' => $categoryList,
'htmlTree' => $htmlTree,
'user' => $user,
'menu' => $this -> adminMenu($request),'mainMenu' => $this -> adminMainMenu($request),'mainMenu' => $this -> adminMainMenu($request),
)
);
}
/**
* @Route("/categoryedit/{categoryId}", name="categoryEdit")
*/
public function categoryEditAction(Request $request, $categoryId)
{
/* we load session data */
parent::init($request);
$session = $request->getSession();
// we check if any user is logged in
if(!$this->isLoggedUser($request)) {
return $this->redirectToRoute('login');
}
/* we load entity managers */
$em = $this->doctrine->getManager();
$dem = $this->doctrine->getManager('dynamic_em');
$userId = $session->get('user')->getUserId();
$user = $em->getRepository(User::class)->getUser($userId);
/* we get current e-shop */
$eshop = $em->getRepository(Eshop::class)->getCurrentEshop($userId);
$category = $dem->getRepository(Eshop::class)->getCategory($categoryId);
$categoryCollection = $dem->getRepository(Eshop::class)->getCategoryListByEshop($eshop->getEshopId());
//$serviceCollection = $em->getRepository(Service::class)->getServiceList();
/*
print('<br>QQW cat ID: '.$categoryId);
\Doctrine\Common\Util\Debug::dump($category);
*/
/* we build category edit form */
$formBuilder = $this->createFormBuilder($category);
$formBuilder->add('save', SubmitType::class, array('label' => $this->translator->trans('form.button.save'),
'attr' => array('class' => 'butt_big')));
/* category name - multilangual fields */
foreach($eshop->getLanguages() as $lang) {
$fieldLabel = $this->translator->trans('eshop.category_name').' ['.$lang->getLangKey().']';
$category->setLocale($lang->getLangKey());
$dem->refresh($category);
$fieldValue = $category->getCategoryName();
$formBuilder->add('categoryName_'.$lang->getLangKey(), TextType::class, array(
'required' => false,
'mapped' => false,
'label' => $fieldLabel,
'attr' => array('class' => 'text_form', 'size' => 35, 'value' => $fieldValue),
'label_attr' => array('class' => 'form_field_label')
));
}
/* we add category list */
$categories = array();
$categories['Root'] = 0;
foreach($categoryCollection as $cat)
{
$catId = $cat->getCategoryId();
$cat->setLocale($session->get('lang')->getLangKey());
$dem->refresh($cat);
//print('<br>qqw cat: '.$catId);
$categories[$cat->getCategoryName()] = $catId;
}
if($category->getParent() === null) {
$selectedCategory = 0;
} else {
$selectedCategory = $category->getParent()->getCategoryId();
}
$formBuilder->add('parentCategoryId', ChoiceType::class, array(
'choices' => $categories,
'mapped' => false,
'label' => $this->translator->trans('eshop.parent_category'),
'attr' => array('class' => 'selector'),
'label_attr' => array('class' => 'form_field_label'),
'data' => $selectedCategory
));
$formBuilder->add('categoryKey', TextType::class, array(
'required' => false,
'label' => $this->translator->trans('eshop.category_key'),
'attr' => array('class' => 'text_form', 'size' => 35, 'value' => $category->getCategoryKey()),
'label_attr' => array('class' => 'form_field_label')
));
$formBuilder->add('ERPKey', TextType::class, array(
'required' => false,
'label' => $this->translator->trans('system.erp_key'),
'attr' => array('class' => 'text_form', 'size' => 35, 'value' => $category->getERPKey()),
'label_attr' => array('class' => 'form_field_label')
));
$formBuilder->add('isActive', ChoiceType::class, array(
'choices' => array(
'Yes' => true,
'No' => false
),
'required' => false,
'mapped' => false,
'multiple' => false,
'expanded' => false,
'placeholder' => false,
'attr' => array('class' => 'selector'),
'label_attr' => array('class' => 'form_field_label'),
'data' => ($category->getIsActive()=="0"?0:1)
));
$formBuilder->add('priority', TextType::class, array(
'required' => false,
'label' => $this->translator->trans('system.priority'),
'attr' => array('class' => 'text_form', 'size' => 10, 'value' => $category->getPriority()),
'label_attr' => array('class' => 'form_field_label')
));
$image1Label = $this->translator->trans('image.main');
if(!empty($category->getImage1())) {
$image1Label .= " [ ".$category->getImage1()." ]";
}
$formBuilder->add('image1', FileType::class, array(
'required' => false,
'data_class' => null,
'label' => $image1Label,
'attr' => array('class' => 'text_form_file', 'size' => 22, 'value' => 'vvx2'),
'label_attr' => array('class' => 'form_field_label_block'),
));
/* product description - multilangual fields */
foreach($eshop->getLanguages() as $lang) {
$fieldLabel = $this->translator->trans('eshop.category_description').' ['.$lang->getLangKey().']';
$category->setLocale($lang->getLangKey());
$dem->refresh($category);
$fieldValue = $category->getCategoryDescription();
$formBuilder->add('categoryDescription_'.$lang->getLangKey(), TextareaType::class, array(
'required' => false,
'mapped' => false,
'label' => $fieldLabel,
'attr' => array('class' => 'textarea_form', 'cols' => 69, 'rows' => 7, 'value' => $fieldValue),
'label_attr' => array('class' => 'form_textarea_label2'),
'data' => $fieldValue,
));
}
/* we set default width of image thumbnail */
$formBuilder->add('imageThumbWidth', TextType::class, array(
'required' => false,
'label' => $this->translator->trans('product.products').' - '.$this->translator->trans('image.thumb_width'),
'attr' => array('class' => 'text_form', 'size' => 10, 'value' => $category->getImageThumbWidth()),
'label_attr' => array('class' => 'form_field_label')
));
/* we set default height of image thumbnail */
$formBuilder->add('imageThumbHeight', TextType::class, array(
'required' => false,
'label' => $this->translator->trans('product.products').' - '.$this->translator->trans('image.thumb_height'),
'attr' => array('class' => 'text_form', 'size' => 10, 'value' => $category->getImageThumbHeight()),
'label_attr' => array('class' => 'form_field_label')
));
/*
print('<hr>qqw categories ');
\Doctrine\Common\Util\Debug::dump($categories);
print('<hr>qqw categories 2');
\Doctrine\Common\Util\Debug::dump($categories2);
*/
$formBuilder->add('save2', SubmitType::class, array('label' => $this->translator->trans('form.button.save'),
'attr' => array('class' => 'butt_big')));
$form = $formBuilder->getForm();
$form->handleRequest($request);
if ($request->getMethod() == 'POST') {
if ($form->isValid()) {
$formData = $form->getData();
//print('<br>We create new user');
//$user = new User;
/* we load and set parent category */
$parentCategory = $dem->getRepository(Eshop::class)->getCategory($form['parentCategoryId']->getData());
$category->setParent($parentCategory);
/*
print('<br>QQW parentCategoryId: '.$request->request->get('form')['parentCategoryId']);
\Doctrine\Common\Util\Debug::dump($parentCategory);
*/
/* multilangual fields */
foreach($eshop->getLanguages() as $lang) {
$category->setLocale($lang->getLangKey());
$dem->refresh($category);
$category->setCategoryName($form['categoryName_' . $lang->getLangKey()]->getData());
$category->setCategoryDescription($form['categoryDescription_' . $lang->getLangKey()]->getData());
$dem->persist($category);
$dem->flush();
}
/* we handle images */
$image1 = $request->files->get('form')['image1'];
/* we check user folder for user files */
if(!$this->isUserFolder($request)) {
$this->createUserFolder($request);
}
$userDirs = $this->getUserFolderPaths($request);
/* image 1 */
if(!empty($image1)) {
$fileName1 = md5(uniqid()).'.'.$image1->guessExtension();
$image1->move($userDirs['images'], $fileName1);
$category->setImage1($fileName1);
}
/* we remove old service associations */
/*
foreach($user->getServices() as $service) {
$user->removeService($service);
}
*/
/* we load user services */
/*
if(!empty($request->request->get('form')['services'])) {
foreach($request->request->get('form')['services'] as $serviceId) {
$addService = $em->getRepository(Service::class)->getService($serviceId);
$user->addService($addService);
}
}
*/
//print('<br>QQW categoryKey: '.$form['categoryKey']->getData());
/* we load user data from register form into user object */
$category->setCategoryKey($form['categoryKey']->getData());
$category->setERPKey($form['ERPKey']->getData());
//$category->setIsActive($request->request->get('form')['isActive']);
$category->setIsActive($form['isActive']->getData());
$category->setPriority($form['priority']->getData());
$category->setImageThumbWidth($formData->getImageThumbWidth());
$category->setImageThumbHeight($formData->getImageThumbHeight());
//print('<br>QQW priority: '.$form['priority']->getData());
//\Doctrine\Common\Util\Debug::dump($category);
//die();
/* we persist and save */
//$em->persist($user);
$dem->persist($category);
$dem->flush();
$this->addFlash('notice', 'Category was updated.');
return $this->redirectToRoute('categoryEdit', array('categoryId' => $category->getCategoryId()));
}
}
/* we render data */
return $this->render('categoryEdit.html.twig',
array( 'headerData' => $this -> getPageHeader($request),
'form' => $formBuilder->getForm()->createView(),
'category' => $category,
'user' => $user,
'menu' => $this -> adminMenu($request),'mainMenu' => $this -> adminMainMenu($request),'mainMenu' => $this -> adminMainMenu($request),
)
);
}
/**
* @Route("/categoryremove/{categoryId}", name="categoryRemove")
*/
public function categoryRemoveAction(Request $request, $categoryId)
{
/* we load session data */
parent::init($request);
$session = $request->getSession();
/* we load entity managers */
$em = $this->doctrine->getManager();
$dem = $this->doctrine->getManager('dynamic_em');
$userId = $session->get('user')->getUserId();
/* we get current e-shop */
$eshop = $em->getRepository(Eshop::class)->getCurrentEshop($userId);
$category = $dem->getRepository(Eshop::class)->getCategory($categoryId);
/*
print('<hr>qqw category: ');
\Doctrine\Common\Util\Debug::dump($category);
*/
$repo = $dem->getRepository(Category::class);
//$repo->removeFromTree($category);
$dem->remove($category);
//$em->persist($user);
$dem->flush();
$this->addFlash('notice', 'Category was removed.');
return $this->redirectToRoute('categories');
//die();
}
/**
* @Route("/eshopConfig", name="eshopConfig")
*/
public function eshopConfigAction(Request $request)
{
/* we load session data */
parent::init($request);
$session = $request->getSession();
// we check if any user is logged in
if(!$this->isLoggedUser($request)) {
return $this->redirectToRoute('login');
}
/* we load master entity manager */
$em = $this->doctrine->getManager();
$dem = $this->doctrine->getManager('dynamic_em');
$currentUserId = $session->get('user')->getUserId();
$user = $em->getRepository(User::class)->getUser($currentUserId);
/* we get current e-shop */
$eshop = $em->getRepository(Eshop::class)->getCurrentEshop($currentUserId);
$userId = $session->get('user')->getUserId();
/* we get css designs */
$cssDesignCollection = $dem->getRepository(CssDesign::class)->getCssDesignList();
if(count($cssDesignCollection) == 0) {
print('we create new css file');
$cssDesign = new CssDesign;
$cssDesign->setCssDesignName($user->getUserName());
$cssDesign->setCssDesignFile($user->getUserName().".css");
/* we persist and save */
$dem->persist($cssDesign);
$dem->flush();
$this->addFlash('notice', $this->translator->trans('module.cssDesigner_created'));
return $this->redirectToRoute('webConfig');
}
/* we get languages */
$langCollection = $em->getRepository(Language::class)->getLanguageList();
/* we get currencies */
$currencyCollection = $em->getRepository(Currency::class)->getCurrencyList();
/* we get css designs */
$cssDesignCollection = $dem->getRepository(CssDesign::class)->getCssDesignList();
/* we get wireframes */
$wireFrameCollection = $em->getRepository(WireFrame::class)->getWireFrameListByService(1);
/* we get galleries */
$galleryCollection = $dem->getRepository(Gallery::class)->getGalleryListByUser($userId);
/* we build register form */
$formBuilder = $this->createFormBuilder($eshop);
$formBuilder->add('eshopName', TextType::class, array(
'required' => false,
'label' => $this->translator->trans('eshop.name'),
'attr' => array('class' => 'text_form', 'size' => 35, 'value' => $eshop->getEshopName()),
'label_attr' => array('class' => 'form_field_label')
));
/* we add language list */
$languages = array();
foreach($langCollection as $lang)
{
$langId = $lang->getLangId();
$languages[$lang->getLangName()] = $lang->getLangId();
}
$selectedLanguages = array();
if (!empty($eshop->getLanguages())) {
foreach($eshop->getLanguages() as $lang) {
$selectedLanguages[] = $lang->getLangId();
}
}
$formBuilder->add('languages', ChoiceType::class, array(
'choices' => $languages,
'required' => false,
'mapped' => false,
'multiple' => true,
'expanded' => true,
'label_attr' => array('class' => 'form_field_label'),
'attr' => array('class' => 'form_field_text'),
'data' => $selectedLanguages
));
$formBuilder->add('preferredLanguageId', ChoiceType::class, array(
'choices' => $languages,
'required' => true,
'mapped' => false,
'multiple' => false,
'placeholder' => false,
'expanded' => true,
'label_attr' => array('class' => 'form_field_label'),
'attr' => array('class' => 'form_field_text'),
'data' => $eshop->getPreferredLanguageId()
));
/* we add currency list */
$currencies = array();
foreach($currencyCollection as $currency) {
$currencyId = $currency->getCurrencyId();
$currencies[$currency->getCurrencyName()] = $currency->getCurrencyId();
}
$selectedCurrencies = array();
foreach($eshop->getCurrencies() as $currency) {
$selectedCurrencies[] = $currency->getCurrencyId();
}
$formBuilder->add('currencies', ChoiceType::class, array(
'choices' => $currencies,
'required' => false,
'mapped' => false,
'multiple' => true,
'expanded' => true,
'label_attr' => array('class' => 'form_field_label'),
'attr' => array('class' => 'form_field_text'),
'data' => $selectedCurrencies
));
$formBuilder->add('preferredCurrencyId', ChoiceType::class, array(
'choices' => $currencies,
'required' => true,
'mapped' => false,
'multiple' => false,
'placeholder' => false,
'expanded' => true,
'label_attr' => array('class' => 'form_field_label'),
'attr' => array('class' => 'form_field_text'),
'data' => $eshop->getPreferredCurrencyId()
));
/* we add css designs list */
$cssDesigns = array();
$selectedCss = '';
foreach($cssDesignCollection as $cssDesign)
{
$cssDesignId = $cssDesign->getCssDesignId();
$cssDesigns[$cssDesign->getCssDesignName()] = $cssDesignId;
/* we look for selected css design of the e-shop */
if($cssDesign->getCssDesignFile() == $eshop->getEshopCss()) {
$selectedCss = $cssDesign->getCssDesignId();
}
}
$formBuilder->add('cssDesigns', ChoiceType::class, array(
'choices' => $cssDesigns,
'required' => true,
'mapped' => false,
'multiple' => false,
'expanded' => true,
'placeholder' => false,
'label_attr' => array('class' => 'form_field_label'),
'attr' => array('class' => 'form_field_text'),
'data' => $selectedCss,
));
/* we select product list view */
$productViews = array("LIST"=>"LIST", "GRID"=>"GRID", "B2BLIST"=>"B2BLIST");
$selectedProductView = $eshop->getProductView();
//print("<br>qqw ProductView: ".$eshop->getProductView());
$formBuilder->add('productViews', ChoiceType::class, array(
'choices' => $productViews,
'required' => true,
'mapped' => false,
'multiple' => false,
'expanded' => true,
'placeholder' => false,
'label_attr' => array('class' => 'form_field_label'),
'attr' => array('class' => 'form_field_text'),
'data' => $selectedProductView,
));
/* we set count product per page */
$formBuilder->add('countPerPage', TextType::class, array(
'required' => false,
'label' => $this->translator->trans('product.count_per_page'),
'attr' => array('class' => 'text_form', 'size' => 10, 'value' => $eshop->getCountPerPage()),
'label_attr' => array('class' => 'form_field_label')
));
/* we display Products From Subfolders */
$formBuilder->add('displayProductsFromSubfolders', ChoiceType::class, array(
'choices' => array('Yes' => true, 'No' => false),
'required' => false,
'mapped' => false,
'multiple' => false,
'expanded' => true,
'placeholder' => false,
'label_attr' => array('class' => 'form_field_label'),
'attr' => array('class' => 'form_field_text'),
'data' => $eshop->isDisplayProductsFromSubfolders(),
));
/* we display Products From Subfolders - level */
$formBuilder->add('displayProductsFromSubfoldersLevel', TextType::class, array(
'required' => false,
'label' => $this->translator->trans('eshop.products_subfolders_level'),
'attr' => array('class' => 'text_form', 'size' => 10, 'value' => $eshop->getDisplayProductsFromSubfoldersLevel()),
'label_attr' => array('class' => 'form_field_label')
));
/* we set preferred VAT */
$formBuilder->add('preferredVAT', TextType::class, array(
'required' => false,
'label' => $this->translator->trans('eshop.preferred_VAT'),
'attr' => array('class' => 'text_form', 'size' => 10, 'value' => $eshop->getPreferredVAT()),
'label_attr' => array('class' => 'form_field_label')
));
$formBuilder->add('displayNettoPrices', ChoiceType::class, array(
'choices' => array('Yes' => true, 'No' => false),
'required' => false,
'mapped' => false,
'multiple' => false,
'expanded' => true,
'placeholder' => false,
'label_attr' => array('class' => 'form_field_label'),
'attr' => array('class' => 'form_field_text'),
'data' => $eshop->isDisplayNettoPrices(),
));
$formBuilder->add('isStock', ChoiceType::class, array(
'choices' => array('Yes' => true, 'No' => false),
'required' => false,
'mapped' => false,
'multiple' => false,
'expanded' => true,
'placeholder' => false,
'label' => $this->translator->trans('eshop.view_stock'),
'label_attr' => array('class' => 'form_field_label'),
'attr' => array('class' => 'form_field_text'),
'data' => $eshop->isIsStock(),
));
/* we set cut of long descriptions in product list */
$formBuilder->add('cutLongDescription', TextType::class, array(
'required' => false,
'label' => $this->translator->trans('eshop.cut_long_description'),
'attr' => array('class' => 'text_form', 'size' => 10, 'value' => $eshop->getCutLongDescription()),
'label_attr' => array('class' => 'form_field_label')
));
/* we set price rounding */
$formBuilder->add('roundPrice', TextType::class, array(
'required' => false,
'label' => $this->translator->trans('eshop.price_round'),
'attr' => array('class' => 'text_form', 'size' => 10, 'value' => $eshop->getRoundPrice()),
'label_attr' => array('class' => 'form_field_label')
));
/* we set default width of image thumbnail */
$formBuilder->add('imageThumbWidth', TextType::class, array(
'required' => false,
'label' => $this->translator->trans('image.thumb_width'),
'attr' => array('class' => 'text_form', 'size' => 10, 'value' => $eshop->getImageThumbWidth()),
'label_attr' => array('class' => 'form_field_label')
));
/* we set default height of image thumbnail */
$formBuilder->add('imageThumbHeight', TextType::class, array(
'required' => false,
'label' => $this->translator->trans('image.thumb_height'),
'attr' => array('class' => 'text_form', 'size' => 10, 'value' => $eshop->getImageThumbHeight()),
'label_attr' => array('class' => 'form_field_label')
));
/* we set default width of category image thumbnail */
$formBuilder->add('categoryImageThumbWidth', TextType::class, array(
'required' => false,
'label' => $this->translator->trans('image.category_thumb_width'),
'attr' => array('class' => 'text_form', 'size' => 10, 'value' => $eshop->getCategoryImageThumbWidth()),
'label_attr' => array('class' => 'form_field_label')
));
$formBuilder->add('isAsynchrounousShopping', ChoiceType::class, array(
'choices' => array('Yes' => true, 'No' => false),
'required' => false,
'mapped' => false,
'multiple' => false,
'expanded' => true,
'placeholder' => false,
'label' => $this->translator->trans('eshop.is_asynchrounous_shopping'),
'label_attr' => array('class' => 'form_field_label'),
'attr' => array('class' => 'form_field_text'),
'data' => $eshop->isIsAsynchrounousShopping(),
));
$formBuilder->add('isVirtualReality', ChoiceType::class, array(
'choices' => array('Yes' => true, 'No' => false),
'required' => false,
'mapped' => false,
'multiple' => false,
'expanded' => true,
'placeholder' => false,
'label' => $this->translator->trans('eshop.is_virtual_reality'),
'label_attr' => array('class' => 'form_field_label'),
'attr' => array('class' => 'form_field_text'),
'data' => $eshop->isIsVirtualReality(),
));
/* we add home wireframe */
$wireFrames = array();
$selectedWireFrame = '';
foreach($wireFrameCollection as $wireFrame)
{
$wireFrameId = $wireFrame->getWireFrameId();
$wireFrames[$wireFrame->getWireFrameName()] = $wireFrameId;
/* we look for selected wireframe of the eshop */
if($wireFrame->getWireFrameId() == $eshop->getWireFrameId()) {
$selectedWireFrame = $wireFrame->getWireFrameId();
}
}
$formBuilder->add('wireFrame', ChoiceType::class, array(
'choices' => $wireFrames,
'required' => true,
'mapped' => false,
'multiple' => false,
'expanded' => true,
'placeholder' => false,
'label' => $this->translator->trans('eshop.wireframe_home'),
'label_attr' => array('class' => 'form_field_label'),
'attr' => array('class' => 'form_field_text'),
'data' => $selectedWireFrame,
));
/* we add product list wireframe */
$wireFrames = array();
$selectedWireFrame = '';
foreach($wireFrameCollection as $wireFrame)
{
$wireFrameId = $wireFrame->getWireFrameId();
$wireFrames[$wireFrame->getWireFrameName()] = $wireFrameId;
/* we look for selected wireframe of the eshop */
if($wireFrame->getWireFrameId() == $eshop->getProductListWireFrameId()) {
$selectedWireFrame = $wireFrame->getWireFrameId();
}
}
$formBuilder->add('wireFrameProductList', ChoiceType::class, array(
'choices' => $wireFrames,
'required' => true,
'mapped' => false,
'multiple' => false,
'expanded' => true,
'placeholder' => false,
'label' => $this->translator->trans('eshop.wireframe_product_list'),
'label_attr' => array('class' => 'form_field_label'),
'attr' => array('class' => 'form_field_text'),
'data' => $selectedWireFrame,
));
/* we add product detail wireframe */
$wireFrames = array();
$selectedWireFrame = '';
foreach($wireFrameCollection as $wireFrame)
{
$wireFrameId = $wireFrame->getWireFrameId();
$wireFrames[$wireFrame->getWireFrameName()] = $wireFrameId;
/* we look for selected wireframe of the eshop */
if($wireFrame->getWireFrameId() == $eshop->getProductDetailWireFrameId()) {
$selectedWireFrame = $wireFrame->getWireFrameId();
}
}
$formBuilder->add('wireFrameProductDetail', ChoiceType::class, array(
'choices' => $wireFrames,
'required' => true,
'mapped' => false,
'multiple' => false,
'expanded' => true,
'placeholder' => false,
'label' => $this->translator->trans('eshop.wireframe_product_detail'),
'label_attr' => array('class' => 'form_field_label'),
'attr' => array('class' => 'form_field_text'),
'data' => $selectedWireFrame,
));
$formBuilder->add('save', SubmitType::class, array('label' => $this->translator->trans('form.send'),
'attr' => array('class' => 'butt_big')));
$form = $formBuilder->getForm();
$form->handleRequest($request);
if ($request->getMethod() == 'POST') {
//$form->bindRequest($request);
if ($form->isValid()) {
$formData = $form->getData();
/* we load eshop data from form into object */
$eshop->setEshopName($formData->getEshopName());
/* we remove old language associations */
if(!empty($eshop->getLanguages())) {
foreach ($eshop->getLanguages() as $lang) {
$eshop->removeLanguage($lang);
}
}
/* we load eshop languages */
if(!empty($form['languages']->getData()) and is_array($form['languages']->getData())) {
foreach($form['languages']->getData() as $langId) {
print('<br>lang id: '.$langId);
$addLang = $em->getRepository(Language::class)->getLanguage($langId);
print('<br>lang id 2: '.$addLang->getLangId());
$eshop->addLanguage($addLang);
//$->get('user')->addService($addService);
}
}
/* we set default language */
$eshop->setPreferredLanguageId($form['preferredLanguageId']->getData());
/* we remove old currency associations */
foreach($eshop->getCurrencies() as $currency) {
$eshop->removeCurrency($currency);
}
/* we load eshop currencies */
if(!empty($form['currencies']->getData())) {
foreach($form['currencies']->getData() as $currencyId) {
$addCurrency = $em->getRepository(Currency::class)->getCurrency($currencyId);
$eshop->addCurrency($addCurrency);
}
}
/* we set default currency */
$eshop->setPreferredCurrencyId($form['preferredCurrencyId']->getData());
/* we set css design */
if(!empty($form['cssDesigns']->getData())) {
$cssDesign = $dem->getRepository(CssDesign::class)->getCssDesign($form['cssDesigns']->getData());
$eshop->setEshopCss($cssDesign->getCssDesignFile());
}
$eshop->setProductView($formData->getProductView());
$eshop->setCountPerPage($formData->getCountPerPage());
$eshop->setPreferredVAT($formData->getPreferredVAT());
$eshop->setImageThumbWidth($formData->getImageThumbWidth());
$eshop->setImageThumbHeight($formData->getImageThumbHeight());
$eshop->setCategoryImageThumbWidth($formData->getCategoryImageThumbWidth());
$eshop->setRoundPrice($formData->getRoundPrice());
$eshop->setCutLongDescription($formData->getCutLongDescription());
if(!empty($form['displayProductsFromSubfolders']->getData())) {
$eshop->setDisplayProductsFromSubfolders($form['displayProductsFromSubfolders']->getData());
}
if(!empty($form['displayProductsFromSubfoldersLevel']->getData())) {
$eshop->setDisplayProductsFromSubfoldersLevel($form['displayProductsFromSubfoldersLevel']->getData());
}
if(!empty($form['displayNettoPrices']->getData())) {
$eshop->setDisplayNettoPrices($form['displayNettoPrices']->getData());
}
$eshop->setIsStock($form['isStock']->getData());
$eshop->setIsAsynchrounousShopping($form['isAsynchrounousShopping']->getData());
$eshop->setIsVirtualReality($form['isVirtualReality']->getData());
/* home wireframe setting */
$eshop->setWireFrameId($form['wireFrame']->getData());
/* product list wireframe setting */
$eshop->setProductListWireFrameId($form['wireFrameProductList']->getData());
/* product detail wireframe setting */
$eshop->setProductDetailWireFrameId($form['wireFrameProductDetail']->getData());
//setEshopName($request->request->get('form')['eshopName']);
/*
print('<br>qqw user exists: ');
\Doctrine\Common\Util\Debug::dump($user);
*/
/* we persist and save user */
$em->persist($eshop);
$em->flush();
$this->addFlash('notice', 'Eshop was updated.');
return $this->redirectToRoute('eshopConfig');
}
}
/* we render data */
return $this->render('eshopConfig.html.twig',
array( 'headerData' => $this -> getPageHeader($request),
'form' => $formBuilder->getForm()->createView(),
'menu' => $this -> adminMenu($request),
'mainMenu' => $this -> adminMainMenu($request),
'user' => $user,
)
);
}
/**
* @Route("/eshopnew", name="eshopNew")
*/
public function eshopNewAction(Request $request)
{
/* we load session data */
parent::init($request);
$session = $request->getSession();
/* we load entity managers */
$em = $this->doctrine->getManager();
$dem = $this->doctrine->getManager('dynamic_em');
$userId = $session->get('user')->getUserId();
$user = $em->getRepository(User::class)->getUser($userId);
/* we build login form */
$formBuilder = $this->createFormBuilder();
$formBuilder->add('eshopName', TextType::class, array(
'required' => true,
'label' => $this->translator->trans('eshop.name'),
'attr' => array('class' => 'text_form', 'size' => 50),
'label_attr' => array('class' => 'form_field_label'),
));
$formBuilder->add('save', SubmitType::class, array('label' => $this->translator->trans('form.button.save'),
'attr' => array('class' => 'butt_big')));
$form = $formBuilder->getForm();
$form->handleRequest($request);
if ($request->getMethod() == 'POST') {
if ($form->isValid()) {
// create and persist e-shop
$this->eshopCreate($request, $form['eshopName']->getData());
return $this->redirectToRoute('eshopAdmin');
}
}
/* we render data */
return $this->render('eshopNew.html.twig',
array( 'form' => $formBuilder->getForm()->createView(),
'user' => $user,
'headerData' => $this -> getPageHeader($request),
'menu' => $this -> adminMenu($request),'mainMenu' => $this -> adminMainMenu($request),'mainMenu' => $this -> adminMainMenu($request),
)
);
}
public function eshopCreate(Request $request, $eshopName = "Test shop")
{
/* we load session data */
parent::init($request);
$session = $request->getSession();
$em = $this->doctrine->getManager();
$dem = $this->doctrine->getManager('dynamic_em');
//print('qqw creating eshop...');
$eshop = new Eshop;
$eshop->setEshopName($eshopName);
$eshop->setUserId($session->get('user')->getUserId());
// we set default currency
$eshop->setPreferredCurrencyId(1);
// we set default language
$eshop->setPreferredLanguageId(1);
// wireframe setting
$eshop->setWireFrameId(5);
$eshop->setProductListWireFrameId(5);
$eshop->setProductDetailWireFrameId(5);
// we add currency
$addCurrency = $em->getRepository(Currency::class)->getCurrency(1);
$eshop->addCurrency($addCurrency);
// we add language
$addLang = $em->getRepository(Language::class)->getLanguage(1);
$eshop->addLanguage($addLang);
// we add price level
$priceLevel = new PriceLevel;
$priceLevel->setPriceLevelName('default');
/* we persist and save */
$dem->persist($priceLevel);
// we set this eshop as current one
$em->getRepository(Eshop::class)->unsetCurrentEshop($session->get('user')->getUserId());
$eshop->setEshopCurrent(true);
// we persist and save
$em->persist($eshop);
$em->flush();
// we insert data fixtures
//@todo uncomment
//$this->eshopDataFixtures($request);
//die();
$this->addFlash('notice', $this->translator->trans('eshop.created'));
//return $this->redirectToRoute('eshopAdmin');
}
/**
* we insert default data into e-shop from basicdemo account
*/
public function eshopDataFixtures(Request $request)
{
/* we load session data */
parent::init($request);
$session = $request->getSession();
$em = $this->doctrine->getManager();
$dem = $this->doctrine->getManager('dynamic_em');
$demo_em = $this->doctrine->getManager('eshop_demo_em');
print('qqw eshop data fixtures...');
$userId = $session->get('user')->getUserId();
/* we get current e-shop */
$currenteshop = $em->getRepository(Eshop::class)->getCurrentEshop($userId);
/* we get basicdemo e-shop */
$demoUserId = 97; //demobasic user id
$demoshop = $em->getRepository(Eshop::class)->getCurrentEshop($demoUserId);
print('<br>qqw current eshop id: '.$demoshop->getEshopId());
$demoCategoryCollection = $demo_em->getRepository(Eshop::class)->getCategoryListByEshop($demoshop->getEshopId());
$demoProductCollection = $demo_em->getRepository(Product::class)->getProductListByEshop($demoshop->getEshopId(), 300, 0);
//$cat->setLocale($session->get('lang')->getLangKey());
foreach($demoCategoryCollection as $cat)
{
$catId = $cat->getCategoryId();
// print('<br>qqw cat: '.$catId);
// \Doctrine\Common\Util\Debug::dump($cat);
//we update or create e-shop category
$category = $dem->getRepository(Eshop::class)->getCategoryByErpKey($cat->getCategoryKey());
if(empty($category)) {
$category = new Category;
}
//$category = $cat;
$category->setIsActive($cat->getIsActive());
$category->setEshopId($currenteshop->getEshopId());
$category->setCategoryKey($cat->getCategoryKey());
$category->setErpKey($cat->getCategoryKey());
$parentCategory = null;
$category->setParent($parentCategory);
$category->setCategoryName($cat->getCategoryName());
$category->setCategoryDescription($cat->getCategoryDescription());
/*
// multilangual fields
foreach($demoshop->getLanguages() as $lang) {
$cat->setLocale($lang->getLangKey());
$category->setLocale($lang->getLangKey());
$demo_em->refresh($cat);
$dem->refresh($category);
$session->get('lang')->getLangKey()
print('<br>qqw cat name ('.$lang->getLangKey().'): '.$cat->getCategoryName());
$category->setCategoryName($cat->getCategoryName());
$category->setCategoryDescription($cat->getCategoryDescription());
//print('<br>qqw cat['.$lang->getLangKey().']: '.$category->getCategoryName());
$dem->persist($category);
$dem->flush();
}
*/
// we persist and save category
$dem->persist($category);
$dem->flush();
//we load product for this category
$categoryArray = array();
$categoryArray[] = $cat;
$demoProductCollection = $demo_em->getRepository(Product::class)->getProductListByCategory($categoryArray, 0, 200, false);
foreach($demoProductCollection as $prod) {
$prodId = $prod->getProductId();
// print('<hr>qqw product: '.$prodId);
// \Doctrine\Common\Util\Debug::dump($prod);
//we update or create e-shop category
$product = $dem->getRepository(Product::class)->getProductByErpKey($prod->getProductKey());
if(empty($product)) {
$product = new Product;
$product->addCategory($category);
// we add product prices
if(!empty($prod->getPrices())) {
foreach($prod->getPrices() as $priceDemo) {
$price = new Price;
$price->setNettoValue($priceDemo->getNettoValue());
$price->setBruttoValue($priceDemo->getBruttoValue());
//$price->setProductId($product->getProductId());
$price->setPriceLevelId(1);
$dem->persist($price);
$dem->flush();
$product->addPrice($price);
}
}
}
$product->setIsActive($prod->getIsActive());
//$product->setEshopId($currenteshop->getEshopId());
$product->setProductKey($prod->getProductKey());
$product->setErpKey($prod->getProductKey());
$product->setProductName($prod->getProductName());
$product->setProductDescription($prod->getProductDescription());
/*
// multilangual fields
foreach($demoshop->getLanguages() as $lang) {
$prod->setLocale($lang->getLangKey());
$product->setLocale($lang->getLangKey());
$demo_em->refresh($prod);
//$dem->refresh($category);
print('<br>qqw prod name ('.$lang->getLangKey().'): '.$prod->getProductName());
$product->setProductName($prod->getProductName());
$product->setProductDescription($prod->getProductDescription());
$dem->persist($product);
$dem->flush();
}
*/
// we persist and save product
$dem->persist($product);
$dem->flush();
}
}
/*
foreach($demoProductCollection as $prod)
{
$prodId = $prod->getProductId();
print('<hr>qqw product: '.$prodId);
\Doctrine\Common\Util\Debug::dump($prod);
//we update or create e-shop category
$product = $dem->getRepository(Product::class)->getProductByErpKey($prod->getProductKey());
//getCategoryByErpKey($cat->getCategoryKey());
if(empty($product)) {
$product = new Product;
}
$product->setIsActive($prod->getIsActive());
//$product->setEshopId($currenteshop->getEshopId());
$product->setProductKey($prod->getProductKey());
$product->setErpKey($prod->getProductKey());
$parentCategory = null;
$product->setParent($parentCategory);
// multilangual fields
foreach($demoshop->getLanguages() as $lang) {
$prod->setLocale($lang->getLangKey());
$product->setLocale($lang->getLangKey());
$demo_em->refresh($prod);
//$dem->refresh($category);
print('<br>qqw prod name ('.$lang->getLangKey().'): '.$prod->getProductName());
$product->setProductName($prod->getProductName());
$product->setProductDescription($prod->getProductDescription());
$dem->persist($product);
$dem->flush();
}
// we persist and save product
$dem->persist($product);
$dem->flush();
}
*/
}
public function categoryTreeMenu($eshop, Request $request)
{
/* we load session data */
parent::init($request);
$session = $request->getSession();
/* we load entity managers */
$em = $this->doctrine->getManager();
$dem = $this->doctrine->getManager('dynamic_em');
$userId = $eshop->getUserId();
$session->set('eshop', $eshop);
/* we get current e-shop */
//$eshop = $em->getRepository(Eshop::class)->getCurrentEshop($currentUserId);
$repo = $dem->getRepository(Category::class);
$this->dynamicEntityManager = $dem;
$this->currentEshop = $eshop;
$options = array(
'decorate' => true,
'rootOpen' => '<ul class="tree">',
'rootClose' => '</ul>',
'childOpen' => function($node) {
/*
print('<br>QQW node: ');
\Doctrine\Common\Util\Debug::dump($node);
*/
if($node['eshopId'] == $this->currentEshop->getEshopId() && !empty($node['isActive']) && $node['isActive']) {
return '<li class="treeItem">';
} else {
return '<li class="treeItemHidden">';
}
return '<li class="treeItem">';
},
'childClose' => '</li>',
'nodeDecorator' => function($node) {
$url = $this->generateUrl('eshop',array('eshopId'=>$this->currentEshop->getEshopId()));
return '<a href="'.$url.'/category/'.$node['categoryId'].'" class="treeNodeLink">'.$node['categoryName'].'</a>';
}
);
$htmlTree = $repo->childrenHierarchy(
null,
false,
$options
);
return $htmlTree;
}
public function categoryTopMenu($eshop, Request $request)
{
/* we load session data */
parent::init($request);
$session = $request->getSession();
/* we load entity managers */
$em = $this->doctrine->getManager();
$dem = $this->doctrine->getManager('dynamic_em');
// print('<br>eshop id:'.$eshop->getEshopId());
// $categoryList = $dem->getRepository(Eshop::class)->getRootCategoryListByEshop($eshop->getEshopId());
// foreach($categoryList as $cat) {
//
// print('<hr>QQW cat: ');
// \Doctrine\Common\Util\Debug::dump($cat);
// }
$rootNodes = $dem->getRepository(Category::class)->getRootNodes();
$childNodes = array();
foreach($rootNodes as $cat) {
if($cat->getEshopId() == $eshop->getEshopId() && $cat->getIsActive()) {
$catName = $cat->getCategoryName();
$cat->setLocale($session->get('lang')->getLangKey());
$dem->refresh($cat);
if ($cat->getCategoryName() == '') {
$cat->setCategoryName($catName);
}
if ($cat->getCategoryName() != '') {
$childNodes[] = $cat;
}
// print('<hr>QQW category: ');
// \Doctrine\Common\Util\Debug::dump($cat);
}
}
// print('<br>QQW categoryTopMenu: ');
// \Doctrine\Common\Util\Debug::dump($childNodes);
return $childNodes;
}
/**
* @Route("/eshop/{eshopId}/eshopNewlang", name="eshopNewlang")
*/
public function eshopNewlangAction(Request $request, $eshopId) {
/* we load session data */
parent::init($request);
$em = $this->doctrine->getManager();
$session = $request->getSession();
/* setting new language for e-shop */
if(!empty($request->query->get('newlang'))) {
//print("<br>QQW setting new e-shop language: ".$request->query->get('newlang'));
$lang = $em->getRepository(Language::class)->getLanguageByKey($request->query->get('newlang'));
$changeLangMessage = $this->translator->trans('system.language_changed_to', [], 'messages', $lang->getLangKey());
if(!empty($lang)) {
$session->set('lang', $lang);
$this->addFlash('notice', $changeLangMessage.' '.$lang->getLangName().'.');
}
}
/*
$referer = $request->headers->get('referer');
$lastPath = substr($referer, strpos($referer, $request->getBaseUrl()));
$lastPath = str_replace($request->getBaseUrl(), '', $lastPath);
$matcher = $this->get('router')->getMatcher();
$parameters = $matcher->match($lastPath);
$route = $parameters['_route'];
print("<br>QQW newlangAction: ");
\Doctrine\Common\Util\Debug::dump($session->get('lang'));
die();
*/
//print('<br>qqw eshopId: '.$eshopId);
//return $this->redirectToRoute($route);
return $this->redirectToRoute('eshop', array('eshopId' => $eshopId));
}
/**
* @Route("/eshop/{eshopId}/eshopNewcurr", name="eshopNewcurr")
*/
public function eshopNewcurrAction(Request $request, $eshopId) {
/* we load session data */
parent::init($request);
$em = $this->doctrine->getManager();
$session = $request->getSession();
/* setting new currency for e-shop */
if(!empty($request->query->get('newEshopCurrency'))) {
//print("<br>QQW setting new e-shop currency: ".$request->query->get('newEshopCurrency'));
$curr = $em->getRepository(Currency::class)->getCurrencyByKey($request->query->get('newEshopCurrency'));
if(!empty($curr)) {
$session->set('eshopCurrency', $curr);
$this->addFlash('notice', $this->translator->trans('system.currency_changed_to').' '.$curr->getCurrencyName().'.');
}
}
/*
$referer = $request->headers->get('referer');
$lastPath = substr($referer, strpos($referer, $request->getBaseUrl()));
$lastPath = str_replace($request->getBaseUrl(), '', $lastPath);
$matcher = $this->get('router')->getMatcher();
$parameters = $matcher->match($lastPath);
$route = $parameters['_route'];
print("<br>QQW newlangAction: ");
\Doctrine\Common\Util\Debug::dump($session->get('lang'));
die();
*/
//return $this->redirectToRoute($route);
return $this->redirectToRoute('eshop', array('eshopId' => $eshopId));
}
/**
* @Route("/orderlist", name="orderList")
*/
public function orderListAction(Request $request)
{
/* we load session data */
parent::init($request);
$session = $request->getSession();
// we check if any user is logged in
if(!$this->isLoggedUser($request)) {
return $this->redirectToRoute('login');
}
/* we load users entity manager */
$em = $this->doctrine->getManager();
$dem = $this->doctrine->getManager('dynamic_em');
/* we get current user */
$userId = $session->get('user')->getUserId();
$user = $em->getRepository(User::class)->getUser($userId);
/* we get current e-shop */
$eshop = $em->getRepository(Eshop::class)->getCurrentEshop($userId);
$defaultCurrency = $em->getRepository(Currency::class)->getCurrency($eshop->getPreferredCurrencyId());
$orderList = $dem->getRepository(Order::class)->getOrderList("orderId", "DESC");
/* we load order prices */
$orderPrices = array();
foreach($orderList as $order) {
if(!empty($order->getCurrencyKey())) {
$targetCurrency = $em->getRepository(Currency::class)->getCurrencyByKey($order->getCurrencyKey());
} else {
$targetCurrency = $defaultCurrency;
}
$orderPrices[$order->getOrderId()] = $dem->getRepository(Order::class)->getOrderPrice($order->getOrderId(), $targetCurrency, false, $eshop, $defaultCurrency);
}
/* we render data */
return $this->render('orderList.html.twig',
array('headerData' => $this -> getPageHeader($request),
'orderList' => $orderList,
'orderPrices' => $orderPrices,
'menu' => $this -> adminMenu($request),'mainMenu' => $this -> adminMainMenu($request),
'mainMenu' => $this -> adminMainMenu($request),
'user' => $user,
)
);
}
/**
* @Route("/orderedit/{orderId}", name="orderEdit")
*/
public function orderEditAction(Request $request, $orderId)
{
/* we load session data */
parent::init($request);
$session = $request->getSession();
/* we load entity managers */
$em = $this->doctrine->getManager();
$dem = $this->doctrine->getManager('dynamic_em');
$userId = $session->get('user')->getUserId();
$user = $em->getRepository(User::class)->getUser($userId);
/* we get current e-shop */
$eshop = $em->getRepository(Eshop::class)->getCurrentEshop($userId);
$eshopCurrency = $em->getRepository(Currency::class)->getCurrency($eshop->getPreferredCurrencyId());
$order = $dem->getRepository(Order::class)->getOrder($orderId);
if(!empty($order->getCurrencyKey())) {
$targetCurrency = $em->getRepository(Currency::class)->getCurrencyByKey($order->getCurrencyKey());
} else {
$targetCurrency = $eshopCurrency;
}
$orderPrice = $dem->getRepository(Order::class)->getOrderPrice($order->getOrderId(), $targetCurrency, false, $eshop, $eshopCurrency);
$orderPriceVAT = $dem->getRepository(Order::class)->getOrderPrice($order->getOrderId(), $targetCurrency, true, $eshop, $eshopCurrency);
$deliveryCost = $dem->getRepository(Price::class)->getCurrencyRatedPrice($order->getEshopDelivery()->getCost(), $eshopCurrency, $targetCurrency);
$order->getEshopDelivery()->setCost(round($deliveryCost, 2));
$paymentCost = $dem->getRepository(Price::class)->getCurrencyRatedPrice($order->getEshopPayment()->getCost(), $eshopCurrency, $targetCurrency);
$order->getEshopPayment()->setCost(round($paymentCost, 2));
//print('<br>QQW orderPrice: '.$orderPrice);
//print('<br>QQW orderPrice VAT: '.$orderPriceVAT);
//\Doctrine\Common\Util\Debug::dump($orderPrice);
/* we render data */
return $this->render('orderEdit.html.twig',
array('headerData' => $this -> getPageHeader($request),
'order' => $order,
'orderPrice' => $orderPrice,
'orderPriceVAT' => $orderPriceVAT,
'menu' => $this -> adminMenu($request),'mainMenu' => $this -> adminMainMenu($request),'mainMenu' => $this -> adminMainMenu($request),
'eshopCurrency' => $eshopCurrency,
'eshop' => $eshop,
'user' => $user,
)
);
}
/**
* @Route("/eshop/{eshopId}/page/{pageId}", name="eshopPage")
*/
public function pageAction(Request $request, $eshopId, $pageId)
{
/* we load session data */
parent::init($request);
$session = $request->getSession();
//print('<br>QQW page ID: '.$pageId);
/* we load entity managers */
$em = $this->doctrine->getManager();
$dem = $this->doctrine->getManager('dynamic_em');
/* we get current e-shop */
$eshop = $em->getRepository(Eshop::class)->getEshop($eshopId);
$eshopHeader = $dem->getRepository(Eshop::class)->getEshopHeader($eshopId);
if(!empty($eshopHeader)) {
$eshopHeader->setLocale($session->get('lang')->getLangKey());
$dem->refresh($eshopHeader);
}
/* we load footer for the current website */
$eshopFooter = $dem->getRepository(Eshop::class)->getEshopFooter($eshopId);
if(!empty($eshopFooter)) {
$eshopFooter->setLocale($session->get('lang')->getLangKey());
$dem->refresh($eshopFooter);
}
/* we get wireframe */
$wireFrame = $em->getRepository(WireFrame::class)->getWireFrame($eshop->getWireFrameId());
/* we load page for the current webpage */
$page = $dem->getRepository(WebPage::class)->getWebPage($pageId);
$page->setLocale($session->get('lang')->getLangKey());
$dem->refresh($page);
/*
print('<br>qqw page id: '.$pageId);
\Doctrine\Common\Util\Debug::dump($page);
*/
/* we parse the page content for placeholders */
$pageContent = $this->parseContent($request, $page->getWebPageContent());
$page->setWebPageContent($pageContent);
/*
print('<br>qqw webMenuVertical: ');
\Doctrine\Common\Util\Debug::dump($webMenuVertical);
*/
/* we render data */
return $this->render('eshopPage.html.twig',
array( 'headerData' => $this -> getPageHeader($request),
'eshop' => $eshop,
'wireFrame' => $wireFrame,
'categoryTreeMenu' => $this->categoryTreeMenu($eshop, $request),
'categoryTopMenu' => $this->categoryTopMenu($eshop, $request),
'eshopHeader' => $eshopHeader,
'eshopFooter' => $eshopFooter,
'page' => $page,
)
);
}
/**
* @Route("/eshop/{eshopId}/request", name="eshopRequest")
*/
public function eshopRequestAction(Request $request, $eshopId)
{
/* we load session data */
parent::init($request);
$session = $request->getSession();
/* we load entity managers */
$em = $this->doctrine->getManager();
$dem = $this->doctrine->getManager('dynamic_em');
/* we get current e-shop */
$eshop = $em->getRepository(Eshop::class)->getEshop($eshopId);
/* we get current user */
$user = $em->getRepository(User::class)->getUser($eshop->getUserId());
$eshopHeader = $dem->getRepository(Eshop::class)->getEshopHeader($eshopId);
if(!empty($eshopHeader)) {
$eshopHeader->setLocale($session->get('lang')->getLangKey());
$dem->refresh($eshopHeader);
}
/* we load footer for the current website */
$eshopFooter = $dem->getRepository(Eshop::class)->getEshopFooter($eshopId);
if(!empty($eshopFooter)) {
$eshopFooter->setLocale($session->get('lang')->getLangKey());
$dem->refresh($eshopFooter);
}
/* we get wireframe */
$wireFrame = $em->getRepository(WireFrame::class)->getWireFrame($eshop->getWireFrameId());
$subject = $request->query->get('subject');
$email = '';
$telephone = '';
$message = '';
/* we get product info */
if(!empty($request->query->get('productId'))) {
//print('<br>qqw loading productId: '.$request->query->get('productId'));
$productId = $request->query->get('productId');
$product = $dem->getRepository(Product::class)->getProduct($productId);
$message .= $product->getProductName().' (ID: '.$product->getProductKey().' | ERP: '.$product->getERPKey().' | EAN: '.$product->getEAN().')';
//\Doctrine\Common\Util\Debug::dump($product);
}
/* we check if customer exists */
if(!empty($session->get('contact'))) {
$contact = $dem->getRepository(Contact::class)->getContact($session->get('contact')->getContactId());
$email = $contact->getEmail();
$telephone = $contact->getPhone();
}
//isModule ReCaptcha
$module = $em->getRepository(Module::class)->getModule(41);
$isReCaptchaModule = $em->getRepository(User::class)->userHasModule($user, $module);
$reCaptcha = null;
if($isReCaptchaModule) {
//we load re-captcha
$reCaptcha = $dem->getRepository(ReCaptcha::class)->findOneBy(['reCaptchaId'=> 1]);
}
//print('<br>qqw subject: '.$subject);
/*
print('<br>qqw webMenuVertical: ');
\Doctrine\Common\Util\Debug::dump($webMenuVertical);
*/
/* we build login form */
$formBuilder = $this->createFormBuilder();
$formBuilder->add('request_subject', TextType::class, array(
'required' => true,
'label' => $this->translator->trans('eshop.request_subject'),
'attr' => array('class' => 'text_form', 'size' => 60, 'value' => $subject),
'label_attr' => array('class' => 'form_field_label'),
));
$formBuilder->add('request_email', EmailType::class, array(
'required' => true,
'label' => $this->translator->trans('eshop.request_email'),
'attr' => array('class' => 'text_form', 'size' => 60, 'value' => $email),
'label_attr' => array('class' => 'form_field_label'),
));
$formBuilder->add('request_telephone', TextType::class, array(
'required' => true,
'label' => $this->translator->trans('eshop.request_telephone'),
'attr' => array('class' => 'text_form', 'size' => 60, 'value' => $telephone),
'label_attr' => array('class' => 'form_field_label'),
));
$formBuilder->add('request_message', TextareaType::class, array(
'required' => false,
'label' => $this->translator->trans('eshop.request_message'),
'attr' => array('class' => 'inputTextArea', 'cols' => 70, 'rows' => 15, 'value' => $message),
'label_attr' => array('class' => 'form_textarea_label'),
'data' => $message,
));
$formBuilder->add('save', SubmitType::class, array('label' => $this->translator->trans('eshop.request_send'),
'attr' => array('class' => 'requestFormButton')));
$form = $formBuilder->getForm();
$form->handleRequest($request);
$mailToAdminStatus = '';
if ($request->getMethod() == 'POST') {
//we prepare captcha
if(!$isReCaptchaModule) {
$captchaResponse = "noCaptcha";
} else {
$captchaResponse = $request->get('g-recaptcha-response');
}
if ($form->isValid() && $captchaResponse != "") {
// perform some action, such as save the object to the database
//print('<br>sending email request from: '.$request->request->get('form')['request_email']);
/* we load html template */
//$emailText = $this->getRegisterEmail($request, $eshop, $contact);
$emailText = $this->getEshopRequestEmail($request, $eshop, $request->request->get('form')['request_email'], $request->request->get('form')['request_subject'], $request->request->get('form')['request_message'], $request->request->get('form')['request_telephone'] );
/* we prepare request emailing */
$name = $eshop->getEshopName();
$toSuperadmin = 'easycommerc@gmail.com';
$to = $user->getEmail();
$subject = $name.' - '.$subject;
$message = $emailText;
$from = 'noreply@easycommerc.com';
$headers = "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/html; charset=UTF-8\r\n";
$headers .= "From: {$name} <{$from}>\r\n";
$headers .= "Reply-To: <{$from}>\r\n";
$headers .= "Subject: {$subject}\r\n";
$headers .= "X-Mailer: PHP/".phpversion()."\r\n";
/* we send email to e-shop admin */
if(@mail($to, $subject, $message, $headers)) {
//print('<br>Email was sent.');
//we send email to users contact person
if(!empty($user->getContactPersonEmail())) {
mail($user->getContactPersonEmail(), $subject, $message, $headers);
}
$mailToAdminStatus = $this->translator->trans('eshop.email_request_sent').': '.$to;
$this->addFlash('notice', $mailToAdminStatus);
} else {
//print('<br>Email was not sent.');
$mailToAdminStatus = $this->translator->trans('eshop.email_admin_order_error'.': '.$to);
}
// we send email to super admin
/*
if(@mail($toSuperadmin, $subject, $message, $headers)) {
//print('<br>Email was sent.');
//$mailToAdminStatus = $this->translator->trans('eshop.email_request_sent').': '.$to;
//$this->addFlash('notice', $mailToAdminStatus);
} else {
//print('<br>Email was not sent.');
//$mailToAdminStatus = $this->translator->trans('eshop.email_admin_order_error'.': '.$to);
}
*/
/*
print('<br>qqw contact exists: ');
\Doctrine\Common\Util\Debug::dump($contactExist);
*/
//die();
}
else {
$this->addFlash('error', $this->translator->trans('system.form_not_valid'));
}
}
/* we render data */
return $this->render('eshopRequest.html.twig',
array( 'headerData' => $this -> getPageHeader($request),
'eshop' => $eshop,
'form' => $formBuilder->getForm()->createView(),
'wireFrame' => $wireFrame,
'categoryTreeMenu' => $this->categoryTreeMenu($eshop, $request),
'categoryTopMenu' => $this->categoryTopMenu($eshop, $request),
'eshopHeader' => $eshopHeader,
'eshopFooter' => $eshopFooter,
'subject' => $subject,
'mailToAdminStatus' => $mailToAdminStatus,
'reCaptcha' => $reCaptcha,
)
);
}
/**
* @Route("/eshop/{eshopId}/page/{pageId}", name="eshopPage")
*/
/*
public function pageAction(Request $request, $eshopId, $pageId)
{
// we load session data
parent::init($request);
$session = $request->getSession();
//print('<br>QQW page ID: '.$pageId);
// we load entity managers
$em = $this->doctrine->getManager();
$dem = $this->doctrine->getManager('dynamic_em');
// we get current e-shop
$eshop = $em->getRepository(Eshop::class)->getEshop($eshopId);
*/
/**
* @Route("/eshop/{eshopId}/api/products", name="APIProducts")
*/
public function APIProductsAction(Request $request, $eshopId)
{
/* we load session data */
parent::init($request);
$session = $request->getSession();
/* we load users entity manager */
$em = $this->doctrine->getManager();
$dem = $this->doctrine->getManager('dynamic_em');
// we get current e-shop
$eshop = $em->getRepository(Eshop::class)->getEshop($eshopId);
//print('<br>qqw eshop: '.$eshop->getEshopId());
//\Doctrine\Common\Util\Debug::dump($eshop);
$limit = 300;
$offset = 0;
$defaultCurrency = $em->getRepository(Currency::class)->getCurrency($eshop->getPreferredCurrencyId());
$productList = $dem->getRepository(Product::class)->getProductListByEshop($eshop->getEshopId(), $limit, $offset);
$productListAPI = array();
foreach ($productList as $product) {
//print('<br>qqw product: ');
//\Doctrine\Common\Util\Debug::dump($product);
$productAPI = array();
$productAPI['productId'] = $product->getProductId();
$productAPI['productKey'] = $product->getProductKey();
$productAPI['EAN'] = $product->getEAN();
$productAPI['productName'] = $product->getProductName();
$productAPI['productDescription'] = $product->getProductDescription();
$productListAPI[] = $productAPI;
}
//die('qqw API close');
//products
$count = count($productListAPI);
$pages = 10;
$page = 1;
$system = array('code' => 200, 'message' => 'OK');
$metadata = array('count' => $count, 'limit' => 100, 'pages' => $pages, 'page' => $page);
//die();
/* we prepare data for view */
$viewData = array('system' => $system,
'data' => $productListAPI,
'metadata' => $metadata,
);
// we output json
return new JsonResponse($viewData);
}
public function getTopProducts(Request $request, $eshop, $topProductLimit = 7)
{
/* we load users entity manager */
$em = $this->doctrine->getManager();
$dem = $this->doctrine->getManager('dynamic_em');
$session = $request->getSession();
$topProductList = $dem->getRepository(OrderItem::class)->getTopProductList($topProductLimit);
$productIds = [];
$topProducts = [];
foreach($topProductList as $orderItem) {
$pId = $orderItem['productId'];
$topProduct = $orderItem;
$product = $dem->getRepository(Product::class)->getProduct($pId);
if($product) {
$topProducts[$pId] = $topProduct;
$productIds[] = $pId;
}
}
// we load prices
$productPriceList = $dem->getRepository(Product::class)->getProductPriceList($productIds);
$defaultCurrency = $em->getRepository(Currency::class)->getCurrency($eshop->getPreferredCurrencyId());
$targetCurrency = $session->get('eshopCurrency');
$currencyKey = $targetCurrency->getCurrencyKey();
// we load currency rated prices
$productPriceList = $dem->getRepository(Product::class)->getCurrencyRatedProductPriceList($productPriceList, $defaultCurrency, $targetCurrency);
foreach($topProductList as $orderItem) {
$pId = $orderItem['productId'];
/* we get price(s) to display */
$displayPrice = null;
foreach($productPriceList as $price) {
if($price->getProductId() == $pId) {
/* we get default price level */
if($price->getPriceLevelId() == 1) {
//$displayPrice = round($price->getBruttoValue(),$eshop->getRoundPrice());
$displayPrice = round($price->getNettoValue(),$eshop->getRoundPrice());
$topProducts[$pId]['displayPrice'] = $displayPrice;
$topProducts[$pId]['currencyKey'] = $currencyKey;
}
}
}
}
//print('<br>QQW topProductList: ');
//\Doctrine\Common\Util\Debug::dump($topProductList);
// print('<br>QQW topProducts: ');
// \Doctrine\Common\Util\Debug::dump($topProducts);
// print('<hr>QQW topProducts PriceList: ');
// \Doctrine\Common\Util\Debug::dump($productPriceList);
return $topProducts;
}
public function adminMenu(Request $request)
{
$menuItems = array(
1 => array('link' => 'eshopAdmin', 'langKey' => 'eshop.admin', 'routeName' => 'eshopAdmin'),
2 => array('link' => 'orderlist', 'langKey' => 'eshop.orders', 'routeName' => 'orderList'),
3 => array('link' => 'productedit', 'langKey' => 'eshop.products', 'routeName' => 'productListEdit'),
4 => array('link' => 'productnew', 'langKey' => 'eshop.new_product', 'routeName' => 'productNew'),
5 => array('link' => 'categories', 'langKey' => 'eshop.categories', 'routeName' => 'categories'),
6 => array('link' => 'categorynew', 'langKey' => 'eshop.new_category', 'routeName' => 'categoryNew'),
7 => array('link' => 'contacts', 'langKey' => 'knowledgebase.contacts', 'routeName' => 'contacts'),
8 => array('link' => 'eshopnew', 'langKey' => 'eshop.new_eshop', 'routeName' => 'eshopNew'),
9 => array('link' => 'eshopConfig', 'langKey' => 'eshop.config', 'routeName' => 'eshopConfig'),
);
return $menuItems;
}
}