src/ShoppingBundle/Controller/PageController.php line 111

Open in your IDE?
  1. <?php
  2. namespace Shopping\Controller;
  3. use App\Controller\Traits\FunctionsController;
  4. use App\Entity\Association;
  5. use App\Entity\Shop;
  6. use Core\Controller\Traits\BaseController;
  7. use Shopping\Controller\Traits\BaseShoppingController;
  8. use Shopping\Entity\Category;
  9. use Shopping\Entity\Feature;
  10. use Shopping\Entity\FeatureGroup;
  11. use Shopping\Entity\Product;
  12. use Shopping\Entity\ProductFeature;
  13. use Shopping\Entity\ProductGabarit;
  14. use Shopping\Entity\ProductRedirect;
  15. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  16. use Symfony\Component\HttpFoundation\Response;
  17. use User\Controller\Traits\BaseUserController;
  18. use Symfony\Component\HttpFoundation\Request;
  19. /**
  20.  * Controller répondant aux methods "GET" de l'application
  21.  */
  22. class PageController extends AbstractController
  23. {
  24.     use BaseController;
  25.     use BaseUserController;
  26.     use BaseShoppingController;
  27.     use FunctionsController;
  28.     const SHOPPING_PRODUCTS_PAGINATION 9;
  29.     /**
  30.      * Liste de toutes les catégories
  31.      */
  32.     public function category(Request $request)
  33.     {
  34.         // Catégories
  35.         $this->vars['categories'] = $this->getDoctrine()->getRepository(Category::class)->findBy([
  36.             'parent' => NULL,
  37.             'is_enabled' => 1
  38.         ], ['sortorder' => 'ASC']);
  39.         return $this->generateTemplate('@app/shopping/categories', []);
  40.     }
  41.     /**
  42.      * Liste d'une catégorie ( sous-catégories, produits, ... )
  43.      */
  44.     public function products(Request $request)
  45.     {
  46.         // Définition de la page de pagination
  47.         $pagination 1;
  48.         $filters = [];
  49.         if (isset($this->vars['uri']['parameters']['page'])) {
  50.             $pagination $this->vars['uri']['parameters']['page'];
  51.         }
  52.         $filters['order'] = '1';
  53.         if (isset($this->vars['uri']['parameters']['order'])) {
  54.             $filters['order'] = $this->vars['uri']['parameters']['order'];
  55.         }
  56.         foreach ($this->vars['uri']['parameters'] as $key => $value) {
  57.             if ($key != 'page' && $key != 'order') {
  58.                 $default_state 1;
  59.                 $regex "/([0-9]+)_[0-9]+/";
  60.                 preg_match($regex$key$matches);
  61.                 if (count($matches) >= 2) {
  62.                     $key $matches[1];
  63.                 }
  64.                 $item = [
  65.                     "groupe_id" => $key,
  66.                     "feature_designation" => $value,
  67.                     "state" => $default_state,
  68.                 ];
  69.                 $filters['filters'][] = $item;
  70.             }
  71.         }
  72.         // Récupération des filtres pour la catégorie
  73.         $filters['filters_all'] = $this->getFiltersByCategory($this->vars['category']);
  74.         // Produits
  75.         $categories_list $this->getCategoriesChildrenById($this->vars['category']);
  76.         $this->vars['products'] = $products $this->getEntitiesPerPagination(Product::class, $pagination$filtersself::SHOPPING_PRODUCTS_PAGINATIONtrue, [
  77.             'is_enabled' => true,
  78.             'categories' => $categories_list,
  79.             'parent' => null
  80.         ]);
  81.         // Catégories
  82.         $this->vars['categories'] = $this->getDoctrine()->getRepository(Category::class)->findBy([
  83.             'parent' => NULL,
  84.             'is_enabled' => 1
  85.         ], ['sortorder' => 'ASC']);
  86.         return $this->generateTemplate('@app/shopping/products', []);
  87.     }
  88.     /**
  89.      * Affichage d'un produit
  90.      */
  91.     public function product(Request $request)
  92.     {
  93.         // Vérifie l'existance et la mise en ligne du produit
  94.         $redirectionType $this->vars['product']->getRedirect();
  95.         if (is_array($this->vars['product']) || !$this->vars['product']->getIsEnabled() || $redirectionType != ProductRedirect::NO_REDIRECTION) {
  96.             $redirectionURL $this->vars['product']->getRedirectLink();
  97.             if ($redirectionURL == '') {
  98.                 $redirectionURL '/';
  99.             }
  100.             switch ($redirectionType) {
  101.                 case ProductRedirect::NO_REDIRECTION:
  102.                     return $this->redirectNotFoundException($request);
  103.                 case ProductRedirect::TEMPORARY_PRODUCT:
  104.                     return $this->redirect($redirectionURL302);
  105.                 case ProductRedirect::PERMANENT_PRODUCT:
  106.                     return $this->redirect($redirectionURL301);
  107.             }
  108.         }
  109.         $item = new \Shopping\Service\Product\Product($this->getDoctrine(), $this->vars['account']['user']);
  110.         $item->createProduct($this->vars['product']->getId());
  111.         $related_products = [];
  112.         foreach ($this->vars['product']->getRelatedProducts() as $r_object) {
  113.             $r_item = new \Shopping\Service\Product\Product($this->getDoctrine(), $this->vars['account']['user']);
  114.             $r_item->createProduct($r_object->getId());
  115.             $related_products[] = [
  116.                 'product_manager' => $r_item,
  117.                 'product' => $r_object
  118.             ];
  119.         }
  120.         $results $this->getDoctrine()->getRepository(Product::class)->findBy([
  121.         ], [], 8);
  122.         foreach ($results as $object) {
  123.             $element = new \Shopping\Service\Product\Product($this->getDoctrine(), $this->vars['account']['user']);
  124.             $element->createProduct($object->getId());
  125.             $this->vars['slider_products'][] = $element;
  126.         }
  127.         //$this->vars['uri']['alternate'] = [
  128.         //  'fr' => $this->vars['uri']['protocol'] . $this->vars['uri']['host'] . '/fr/produits' . $slugs
  129.         //];
  130.         return $this->generateTemplate('@app/shopping/product', [
  131.             'product_manager' => $item,
  132.             'product' => $item->getProduct(),
  133.             'related_products' => $related_products,
  134.         ]);
  135.     }
  136.     /**
  137.      * Panier
  138.      */
  139.     public function cart(Request $request)
  140.     {
  141.         $this->vars['slider_products'] =  $this->getEntitiesRandom(Product::class);
  142.         return $this->generateTemplate('@app/shopping/cart');
  143.     }
  144.     /**
  145.      * Passage de la commande ( adresses, paiements, ... )
  146.      */
  147.     public function order(Request $request)
  148.     {
  149.         // Redirection vers la page du panier s'il est vide
  150.         if ($this->vars['cart_manager']->getCartTotalProductsCount() <= 0) {
  151.             $uri $this->vars['uri']['protocol'] . $this->vars['uri']['host'] .
  152.                 $this->vars['pages']['list']['page_default_5fb7958391f0c']->translate($this->vars['languages']['locale'])->getUri();
  153.             return $this->redirect($uri);
  154.         }
  155.         $this->setDeliveryPrice();
  156.         // Définition des montants
  157.         $this->updateOrderPrices();
  158.         // Récupération des moyens de livraison
  159.         $this->vars['delivery_methods'] = [];
  160.         $delivery_methods $this->findDeliveryMethods($request);
  161.         foreach ($delivery_methods as $method) {
  162.             $this->vars['delivery_methods'][] = [
  163.                 'method' => $method,
  164.                 'prices' => $this->getDeliveryPrice($method['id'])
  165.             ];
  166.         }
  167.         // Récupération des moyens de paiements
  168.         $this->vars['payment_methods'] = [];
  169.         $this->vars['payment_methods'] = $this->findPaymentMethods($request);
  170.         // Récupération de l'étape de commande
  171. //        $this->vars['order_processus_state'] = $this->session->get('order_processus_state');
  172.         $this->vars['order_processus_state'] = 1;
  173.         //
  174.         $shop $this->vars['order_manager']->getOrder()['delivery_shop'];
  175.         if ($shop != null) {
  176.             $this->vars['order_delivery_shop'] = $this->getDoctrine()->getRepository(Shop::class)->find($shop);
  177.         }
  178.         return $this->generateTemplate('@app/shopping/order', [
  179.             'disable_navigation_cart' => 1,
  180.             'order_processus_state' => 1
  181.         ]);
  182.     }
  183. }