src/Service/EcomService.php line 95

Open in your IDE?
  1. <?php
  2. namespace App\Service;
  3. use Symfony\Component\HttpFoundation\RequestStack;
  4. use Doctrine\ORM\EntityManagerInterface;
  5. use Symfony\Component\Security\Core\Security;
  6. use Symfony\Component\HttpFoundation\Session\Session;
  7. class EcomService
  8. {
  9.     private $em;
  10.     private $request;
  11.     private $security;
  12.     public function __construct(EntityManagerInterface $entityManagerSecurity $securityRequestStack $request)
  13.     { 
  14.       $this->em $entityManager;
  15.       $this->request $request;
  16.       $this->security $security;
  17.     }
  18.     
  19.     public function textcontent($path$def='')
  20.     {
  21.         $content $this->em->getRepository('App\Entity\Content')->findOneByPath($path);
  22.         if($content != null)
  23.           return $content->getBody();
  24.         else 
  25.           return $def;
  26.     }
  27.     
  28.     public function imagecontent($path)
  29.     {
  30.         $content $this->em->getRepository('App\Entity\Content')->findOneByPath($path);
  31.         $contentimages $this->em->getRepository('App\Entity\ContentImage')->findByContentId($content->getId());
  32.         if($content != null)
  33.           return array('content'=>$content'images'=>$contentimages);
  34.         else 
  35.           return array('content'=>'''images'=>array());
  36.     }
  37.     
  38.     public function checkphoto($photo)
  39.     {
  40.         $profilepic file_exists('uploads/profile/' $photo)?'uploads/profile/' $photo:'img/profile_def.jpg';
  41.         return $profilepic;
  42.     }
  43.     
  44.     public function productcategories()
  45.     {
  46.       $menu = array();
  47.       $submenu = array();
  48.       $productcategories $this->em->getRepository('App\Entity\ProductCategory')->findByStatus(1);
  49.       return $productcategories;
  50.     }
  51.     
  52.     public function menu()
  53.     {
  54.         $globalcategories $this->em->getRepository('App\Entity\GlobalCategory')->findAll();
  55.         $menu = array();
  56.         $submenu = array();
  57.         $stylemenu = array();
  58.         foreach ($globalcategories as $gc) {
  59.           $productcategories $this->em->getRepository('App\Entity\ProductCategory')->findByGlobalCategory($gc->getId());
  60.           
  61.           $menu[] = array('id'=>$gc->getId(), 'name'=>$gc->getName(), 'type'=>'global_category');
  62.           $submenu[$gc->getId()] =  array();
  63.           foreach ($productcategories as $pc) {
  64.             $submenu[$gc->getId()][] = array('id'=>$pc->getId(), 'name'=>$pc->getName(), 'type'=>'product_category');
  65.             foreach ($productcategories as $pc) {
  66.               $menu[] = array('id'=>$pc->getId(), 'name'=>$pc->getName(), 'type'=>'product_category');
  67.               $styles $this->em->getRepository('App\Entity\Style')->findByProductCategory($pc->getId());
  68.               $stylemenu[$pc->getId()] =  array();
  69.               foreach ($styles as $s) {
  70.                 $stylemenu[$pc->getId()][] = array('id'=>$s->getId(), 'name'=>$s->getName(), 'type'=>'style');
  71.               }
  72.             }
  73.           }
  74.         }
  75.         
  76.         return array('menu'=>$menu'submenu'=>$submenu'stylemenu'=>$stylemenu);
  77.     }
  78.     
  79.     public function cartdetails()
  80.     { 
  81.         $order null;
  82.         $session $this->request->getSession();
  83.         //$session =  $this->container->get('session');
  84.         if($this->security->getUser()) {
  85.           $order $this->em->getRepository('App\Entity\Orders')->findOneBy(['userId'=>$this->security->getUser()->getId(), 'stage'=>['Cart''Checkout''Review''Payment']], ['id'=>'DESC']);
  86.           if($order==null && !empty($session->get('order_id'))) {
  87.             $order $this->em->getRepository('App\Entity\Orders')->findOneBy(['orderId'=>$session->get('order_id')]);
  88.           }
  89.         }
  90.         elseif(!empty($session->get('order_id'))) {
  91.           $order $this->em->getRepository('App\Entity\Orders')->findOneBy(['orderId'=>$session->get('order_id')]);
  92.         }
  93.         if($order != null) {
  94.           $cartcount $this->em->createQuery("SELECT SUM(o.quantity) FROM App\Entity\OrderItem o WHERE o.orderId=:oid")->setParameters(['oid'=>$order->getId()])->getSingleScalarResult();
  95.           $cartitems $this->em->createQuery("SELECT li.id, li.productId, p.title, p.path, u.firstname, u.lastname, li.amount, li.quantity, li.total, pi.image, p.style, s.name stylename, v.color, c.name colorname, v.size, z.name sizename FROM App\Entity\OrderItem li, App\Entity\Product p, App\Entity\User u, App\Entity\Style s, App\Entity\Color c, App\Entity\ProductImage pi, App\Entity\ProductVariation v LEFT JOIN App\Entity\Size z WITH v.size=z.id WHERE p.id=li.productId AND v.id=li.variantId AND p.id=pi.productId AND p.createdBy=u.id AND v.color=c.id AND p.style=s.id AND li.itemType='Product' AND li.orderId=:oid GROUP BY p.id ORDER BY pi.weight")->setParameters(['oid'=>$order->getId()])->getArrayResult();
  96.           $address $this->em->getRepository('App\Entity\Address')->find($order->getShippingAddressId());
  97.         }
  98.         else {
  99.           $cartcount 0;
  100.           $cartitems = array();
  101.           $order = array();
  102.         }
  103.         return array('order'=>$order'cartcount'=>$cartcount'cart'=>$cartitems);
  104.     }
  105.     
  106.     public function locations()
  107.     {
  108.       $countries $this->em->getRepository('App\Entity\CountriesCountry')->findAll();
  109.       $usa_states = array("AA"=>"AA","AE"=>"AE","AP"=>"AP","AL"=>"Alabama","AK"=>"Alaska","AS"=>"American Samoa","AZ"=>"Arizona","AR"=>"Arkansas","CA"=>"California","CO"=>"Colorado","CT"=>"Connecticut","DE"=>"Delaware","DC"=>"District of Columbia","FM"=>"Federated States of Micronesia","FL"=>"Florida","GA"=>"Georgia","GU"=>"Guam","HI"=>"Hawaii","ID"=>"Idaho","IL"=>"Illinois","IN"=>"Indiana","IA"=>"Iowa","KS"=>"Kansas","KY"=>"Kentucky","LA"=>"Louisiana","ME"=>"Maine","MH"=>"Marshall Islands","MD"=>"Maryland","MA"=>"Massachusetts","MI"=>"Michigan","MN"=>"Minnesota","MS"=>"Mississippi","MO"=>"Missouri","MT"=>"Montana","NE"=>"Nebraska","NV"=>"Nevada","NH"=>"New Hampshire","NJ"=>"New Jersey","NM"=>"New Mexico","NY"=>"New York","NC"=>"North Carolina","ND"=>"North Dakota","MP"=>"Northern Mariana Islands","OH"=>"Ohio","OK"=>"Oklahoma","OR"=>"Oregon","PW"=>"Palau","PA"=>"Pennsylvania","PR"=>"Puerto Rico","RI"=>"Rhode Island","SC"=>"South Carolina","SD"=>"South Dakota","TN"=>"Tennessee","TX"=>"Texas","UT"=>"Utah","VT"=>"Vermont","VI"=>"Virgin Islands","VA"=>"Virginia","WA"=>"Washington","WV"=>"West Virginia","WI"=>"Wisconsin","WY"=>"Wyoming");
  110.       return array('countries'=>$countries'states'=>$usa_states);
  111.     }
  112.     
  113.     public function cities()
  114.     {
  115.       $cities $this->em->getRepository('App\Entity\City')->findByStatus(1, ['access'=>'DESC']);
  116.       return $cities;
  117.     }
  118. }