src/Twig/TwigExtension.php line 195

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace App\Twig;
  4. use Sylius\Component\Core\Repository\PromotionRepositoryInterface;
  5. use Sylius\Component\Registry\ServiceRegistryInterface;
  6. use App\Entity\Customer\Customer;
  7. use App\Services\ShippingService;
  8. use Twig\Extension\AbstractExtension;
  9. use Twig\TwigFunction;
  10. use Symfony\Component\DependencyInjection\ContainerInterface;
  11. // use Sylius\Component\Core\Repository\ProductVariantRepositoryInterface;
  12. // use Doctrine\ORM\EntityManager;
  13. use Doctrine\Persistence\ManagerRegistry;
  14. use App\Entity\SitePageCMSTranslation;
  15. use App\Entity\SiteCollectionTranslation;
  16. final class TwigExtension extends AbstractExtension {
  17.     private const FREE_DELIVERY_PROMOTION_CODE_PREFIX 'FREE_DELIVERY';
  18.     private const CARTE_KDO_CODE 'CART.CAD.WEB.AUTRE';
  19.     private $shippingService;
  20.     private $promotionRepository;
  21.     public function __construct(
  22.         ShippingService $shippingService,
  23.         PromotionRepositoryInterface $promotionRepository,
  24.         ContainerInterface $container,
  25.         ManagerRegistry $doctrine
  26.         
  27.         // ProductVariantRepositoryInterface $productVariantRepository,
  28.         // EntityManager $entityManager
  29.         // ServiceRegistryInterface $ruleRegistry
  30.     ) {
  31.         $this->shippingService $shippingService;
  32.         $this->promotionRepository $promotionRepository;
  33.         $this->container $container;
  34.         // $this->productVariantRepository = $productVariantRepository;
  35.         $this->doctrine $doctrine;
  36.     }
  37.     public function getFunctions(): array
  38.     {
  39.         return [
  40.             new TwigFunction('app_shipping_estimate_start_date', [$this->shippingService'getEstimateStartDate']),
  41.             new TwigFunction('app_shipping_estimate_end_date', [$this->shippingService'getEstimateEndDate']),
  42.             new TwigFunction('app_fidelity_points_earned_from_last_12_month', [$this'getFidelityPointsEarnedFromLast12Month']),
  43.             new TwigFunction('app_getpromotion', [$this'displayPromotion']),
  44.             new TwigFunction('app_collection_look_link', [$this'displayLookLink']),
  45.             new TwigFunction('app_product_accessoires', [$this'isAccessoryInCart']),
  46.             // new TwigFunction('app_user_boutique', [$this, 'displayUserBoutique']),
  47.             new TwigFunction('app_last_product_variants_viewed', [$this'getLastProductVariantsViewed']),
  48.             new TwigFunction('app_guide_level2', [$this'getGuideContent']),
  49.             new TwigFunction('app_encode_filtre', [$this'getEncodeFiltre']),
  50.             new TwigFunction('app_is_shipping_free', [$this'isShippingFree']),
  51.             new TwigFunction('app_show_delivery', [$this'showDelivery']),
  52.             new TwigFunction('app_has_delivery', [$this'hasDelivery']),
  53.             new TwigFunction('app_empty_address', [$this'isEmptyAddress']),
  54.             new TwigFunction('encrypt_sha_256', [$this'encryptSha256']),
  55.             new TwigFunction('app_show_cadeau', [$this'showCadeau']),
  56.             new TwigFunction('app_has_cadeau', [$this'hasCadeau']),
  57.             new TwigFunction('app_is_available_payment', [$this'isAvailablePayment']),
  58.             new TwigFunction('app_get_localurl', [$this'switchLanguage']),
  59.             new TwigFunction('app_percentage_promo', [$this'getPromoPercentage']), 
  60.             new TwigFunction('app_hreflang', [$this'getHreflang']), 
  61.             new TwigFunction('app_show_free_shipping', [$this'showFreeShipping']), 
  62.             new TwigFunction('app_has_return_colissimo', [$this'hasReturnColissimo']), 
  63. ];
  64.     }
  65.     
  66.     public function getFidelityPointsEarnedFromLast12Month(Customer $customer): int
  67.     {
  68.         return 0;
  69.     }
  70.     public function isShippingFree(int $shippingMethodID
  71.     {
  72.         $promotions $this->promotionRepository->findActive();
  73.         $cart $this->container->get('sylius.context.cart')->getCart();
  74.         foreach ($promotions as $promotion) {
  75.             if (str_contains($promotion->getCode(), self::FREE_DELIVERY_PROMOTION_CODE_PREFIX)) {
  76.                 if (!$promotion->hasRules()) {
  77.                     continue;
  78.                 }
  79.                 $response true;
  80.     
  81.                 foreach ($promotion->getRules() as $rule) {
  82.                     
  83.                     if($rule->getType() != "shipping_method") {
  84.                         $checker $this->container->get('sylius.promotion_rule_checker.'.$rule->getType());
  85.                         if (!$checker->isEligible($cart$rule->getConfiguration())) {
  86.                             $response false;
  87.                         }
  88.                     }
  89.                     else {
  90.                         $hasShipping false;
  91.                         foreach($rule->getConfiguration()['shipping_method'] as $shippingMethod) {
  92.                             if($shippingMethod->getId() == $shippingMethodID){
  93.                                 $hasShipping true;
  94.                             }
  95.                         }
  96.                         if($hasShipping && $response) {
  97.                             return true;
  98.                         }
  99.                     }
  100.                 }
  101.             }
  102.         }
  103.         return false;
  104.     }
  105.     public function showFreeShipping() 
  106.     {
  107.         $cart $this->container->get('sylius.context.cart')->getCart();
  108.         $shippingMethodsResolver $this->container->get('sylius.shipping_methods_resolver');
  109.         if(!empty($cart->getShipments()) && !empty($cart->getShipments()[0])) {
  110.             foreach ($shippingMethodsResolver->getSupportedMethods($cart->getShipments()[0]) as $availableShippingMethod) {
  111.                 if($availableShippingMethod->getConfiguration()['ppmc']['amount'] == 0) {
  112.                     return true;
  113.                 }
  114.             }
  115.         }
  116.         
  117.         return false;
  118.     }
  119.     public function showDelivery() {
  120.         //On vérifie si on a que des cartes cadeaux, auquel cas on affiche pas de mode de livraison
  121.         $cart $this->container->get('sylius.context.cart')->getCart();
  122.         $showDelivery false;
  123.         foreach($cart->getItems() as $item){
  124.             if($item->getVariant()->getCode() != self::CARTE_KDO_CODE){
  125.                 $showDelivery true;
  126.                 break;
  127.             }
  128.             
  129.         }
  130.         return $showDelivery;
  131.     }
  132.     public function hasDelivery() {
  133.         //On vérifie si on a que des cartes cadeaux, auquel cas on affiche pas de mode de livraison
  134.         $cart $this->container->get('sylius.context.cart')->getCart();
  135.         return $cart->getShipments()->first();
  136.     }
  137.     public function isEmptyAddress() {
  138.         $user $this->container->get('security.token_storage')->getToken()->getUser();
  139.         // dump($user->getCustomer()->getDefaultAddress()->getId());
  140.         if(empty($user->getCustomer()->getDefaultAddress())){
  141.             return true;
  142.         }
  143.         return false;
  144.     }
  145.     public function showCadeau() {
  146.         $showCadeau false;
  147.         $availablePaymentsMethods $this->container->get('sylius.repository.payment_method')->findBy(['enabled' => true]);
  148.         foreach($availablePaymentsMethods as $availablePaymentsMethod) {
  149.             if($availablePaymentsMethod->getCode() == 'KDO') {
  150.                 $showCadeau true;
  151.                 break;
  152.             }
  153.         }
  154.         return $showCadeau;
  155.     }
  156.     public function hasCadeau() {
  157.         $cart $this->container->get('sylius.context.cart')->getCart();
  158.         $hasCarteKdo false;
  159.         dump($cart->getPayments());
  160.         foreach($cart->getPayments() as $payment) {
  161.             $details $payment->getDetails();
  162.             if(array_key_exists('giftCardCode'$details)) {
  163.                 $hasCarteKdo true;
  164.             }
  165.         }
  166.         return $hasCarteKdo;
  167.     }
  168.     public function encryptSha256($data) {
  169.         return hash('sha256'$data);
  170.     }
  171.     public function isAvailablePayment($code) {
  172.         // dump($code);
  173.         // app.session.get('admin_impersonate_shop_user_id') == app.user.id
  174.         $session $this->container->get('session')->get('admin_impersonate_shop_user_id');
  175.         $cart $this->container->get('sylius.context.cart')->getCart();
  176.         $availablePaymentMethods $this->container->get('sylius.repository.payment_method')->findBy(['enabled' => true]);
  177.         $hasCarteKdo false;
  178.         foreach($cart->getPayments() as $payment) {
  179.             $details $payment->getDetails();
  180.             if(array_key_exists('giftCardCode'$details)) {
  181.                 $hasCarteKdo true;
  182.             }
  183.         }
  184.         $reallyAvailablePaymentMethods = [];
  185.         foreach($availablePaymentMethods as $availablePaymentMethod) {
  186.             if($availablePaymentMethod->getCode() != 'KDO') {
  187.                 $reallyAvailablePaymentMethods[] = $availablePaymentMethod->getCode();
  188.             }
  189.         }
  190.         // app.session.get('admin_impersonate_shop_user_id') == app.user.id
  191.         if($hasCarteKdo) {
  192.             if (($key array_search('VIR'$reallyAvailablePaymentMethods)) !== false) {
  193.                 unset($reallyAvailablePaymentMethods[$key]);
  194.             }
  195.             if (($key array_search('CHQ'$reallyAvailablePaymentMethods)) !== false) {
  196.                 unset($reallyAvailablePaymentMethods[$key]);
  197.             }
  198.         }
  199.         if($session == null) {
  200.             if (($key array_search('TPE_CB'$reallyAvailablePaymentMethods)) !== false) {
  201.                 unset($reallyAvailablePaymentMethods[$key]);
  202.             }
  203.             if (($key array_search('HIPAY_LINK'$reallyAvailablePaymentMethods)) !== false) {
  204.                 unset($reallyAvailablePaymentMethods[$key]);
  205.             }
  206.         }
  207.         if($cart->getTotal() < 5000) {
  208.             if (($key array_search('HIPAY_ALMA'$reallyAvailablePaymentMethods)) !== false) {
  209.                 unset($reallyAvailablePaymentMethods[$key]);
  210.             }
  211.         }
  212.         // dump($cart->getTotal());
  213.         return in_array($code$reallyAvailablePaymentMethods);
  214.     }
  215.     public function displayPromotion($product)
  216.     {
  217.        
  218.         $active 0;
  219.         $quantity2 $this->container->get('sylius.repository.promotion')->findOneByCode('2quantity');
  220.         if($quantity2){
  221.             $quantity2 $quantity2->getRules();
  222.             foreach($quantity2 as $cdt){
  223.                 foreach($cdt->getConfiguration() as $key => $product_promo){
  224.                     if($key == 'product_code' && $product_promo == $product->getCode()){
  225.                         $active 1;
  226.                     }                
  227.                 }
  228.                 if($active == 1){
  229.                     foreach($cdt->getPromotion()->getActions() as $action){
  230.                        
  231.                         if($action->getType() == "unit_percentage_discount"){
  232.                             foreach($action->getConfiguration() as $config){
  233.                                
  234.                                 // $percentage = $config['percentage'];
  235.                                 // $price = $product->getCurrentPrice();
  236.                                 return $cdt->getPromotion()->getName();
  237.     
  238.                             }
  239.                         }                    
  240.                     }
  241.                 }                       
  242.                 
  243.             }
  244.         }      
  245.     
  246.         return;
  247.     }
  248.     public function displayLookLink($id)
  249.     {
  250.         
  251.         $repository $this->container->get('sylius.repository.taxon');
  252.         $taxon $repository->find($id);
  253.         
  254.         if($taxon){
  255.             return $taxon->getSlug();
  256.         }
  257.         return 'aa';
  258.     }
  259.     public function isAccessoryInCart($product): int
  260.     {
  261.         $cart $this->container->get('sylius.context.cart')->getCart();
  262.         foreach($cart->getItems() as $item){
  263.             
  264.             if($product->getId() == $item->getProduct()->getId()){
  265.                 return 1;
  266.             }
  267.             
  268.         }
  269.         
  270.         return 0;
  271.     }
  272.     // public function displayUserBoutique(): string
  273.     // {
  274.         
  275.     //     $user = $this->container->get('security.token_storage')->getToken()->getUser();
  276.     //     if($user->getCustomer()->getFavoriteShop()){
  277.     //         return $user->getCustomer()->getFavoriteShop()->getName();
  278.     //     }
  279.     //     return '';
  280.     // }
  281.     /**
  282.      * Récupère les dernières déclinaisons produit
  283.      */
  284.     public function getLastProductVariantsViewed(int $limit 16): array
  285.     {
  286.         // Récupère les dernières déclinaisons de produits consultées
  287.         $lastViewedProductVariantsIds $this->container->get('session')->get('lastViewedProductVariantsIds', []);
  288.         if (count($lastViewedProductVariantsIds) <= 0) {
  289.             return [];
  290.         }
  291.         $lastViewedProductVariants $this->container->get('sylius.repository.product_variant')
  292.         ->createQueryBuilder('p')
  293.         ->where('p.id IN (:ids)')
  294.         ->andWhere('p.enabled = 1')
  295.         ->setParameter('ids'$lastViewedProductVariantsIds)
  296.         ->setMaxResults($limit)
  297.         ->getQuery()
  298.         ->getResult();
  299.         return $lastViewedProductVariants;
  300.     }
  301.     /**
  302.      * Récupère le dernier article d'une sous catégorie du guide
  303.      */
  304.     public function getGuideContent($slug): array
  305.     {
  306.         $content = array();
  307.         $repository $this->container->get('sylius.repository.taxon');
  308.         $taxon $repository->findOneBySlug($slug,  $this->container->get('sylius.context.locale')->getLocaleCode()); // Get one taxonomy by defined criteria.
  309.         $content['taxon'] = $taxon;
  310.         $taxonsChilds $repository->findChildren($taxon->getCode());
  311.        
  312.         if(is_array($taxonsChilds) && count($taxonsChilds) > 0){
  313.             foreach($taxonsChilds as $souscategorie){
  314.                 $souscategories[$souscategorie->getId()] = $souscategorie;  
  315.                 $content['souscategories'] = $souscategories
  316.               
  317.                 if($taxon->getParent()->getCode() != 'leguide'){
  318.                    
  319.                     $content['souscategorieslast'] = 1;
  320.                     krsort($souscategories);
  321.                     $content['articles'] = $souscategories;
  322.                     $content['article'] = array_slice($souscategories01);
  323.                     
  324.                    
  325.                 }else{
  326.                     $content['souscategorieslast'] = 0;
  327.                     $taxonsChilds2 $repository->findChildren($souscategorie->getCode());
  328.                     if(is_array($taxonsChilds2) && count($taxonsChilds2) > 0){
  329.                         foreach($taxonsChilds2 as $article){
  330.                             $articles[$article->getId()] = $article;    
  331.                         }
  332.                         krsort($articles); 
  333.                         $content['articles'] = $articles;
  334.                         $content['article'] = array_slice($articles01);
  335.                        
  336.                     }
  337.                 }
  338.                 $content['souscategories'] = array();
  339.                 $souscategoriessamelevel $taxon->getParent();
  340.                 $taxonsChilds2 $repository->findChildren($souscategoriessamelevel->getCode());
  341.                 if(is_array($taxonsChilds2) && count($taxonsChilds2) > 0){
  342.                     foreach($taxonsChilds2 as $souscat){
  343.                         $content['souscategories'][] = $souscat
  344.                     }
  345.                                             
  346.                 }
  347.             }
  348.            
  349.         }else{
  350.            
  351.             if($taxon->getParent()->getCode() != 'leguide'){
  352.                 $content['souscategorieslast'] = 1;
  353.                 $souscategoriessamelevel $taxon->getParent();
  354.                 $taxonsChilds2 $repository->findChildren($souscategoriessamelevel->getCode());
  355.                 if(is_array($taxonsChilds2) && count($taxonsChilds2) > 0){
  356.                     foreach($taxonsChilds2 as $souscat){
  357.                         $content['souscategories'][] = $souscat
  358.                     }
  359.                                           
  360.                 }
  361.             }
  362.         }
  363.    
  364.         return $content;
  365.     }  
  366.     public function switchLanguage() {
  367.         
  368.         $actual_link "https://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
  369.         dump($actual_link );
  370.         return '';
  371.     }
  372.  
  373.     
  374.     public function getEncodeFiltre($filtre)
  375.     {
  376.         
  377.     //    dump($filtre);
  378.        return  $this->replaceSpecialChar(strtolower($filtre));
  379.     }
  380.     function replaceSpecialChar($str) {
  381.         $ch0 = array( 
  382.                 "œ"=>"oe",
  383.                 "Œ"=>"OE",
  384.                 "æ"=>"ae",
  385.                 "Æ"=>"AE",
  386.                 "À" => "A",
  387.                 "Á" => "A",
  388.                 "Â" => "A",
  389.                 "à" => "A",
  390.                 "Ä" => "A",
  391.                 "Å" => "A",
  392.                 "&#256;" => "A",
  393.                 "&#258;" => "A",
  394.                 "&#461;" => "A",
  395.                 "&#7840;" => "A",
  396.                 "&#7842;" => "A",
  397.                 "&#7844;" => "A",
  398.                 "&#7846;" => "A",
  399.                 "&#7848;" => "A",
  400.                 "&#7850;" => "A",
  401.                 "&#7852;" => "A",
  402.                 "&#7854;" => "A",
  403.                 "&#7856;" => "A",
  404.                 "&#7858;" => "A",
  405.                 "&#7860;" => "A",
  406.                 "&#7862;" => "A",
  407.                 "&#506;" => "A",
  408.                 "&#260;" => "A",
  409.                 "à" => "a",
  410.                 "á" => "a",
  411.                 "â" => "a",
  412.                 "à" => "a",
  413.                 "ä" => "a",
  414.                 "å" => "a",
  415.                 "&#257;" => "a",
  416.                 "&#259;" => "a",
  417.                 "&#462;" => "a",
  418.                 "&#7841;" => "a",
  419.                 "&#7843;" => "a",
  420.                 "&#7845;" => "a",
  421.                 "&#7847;" => "a",
  422.                 "&#7849;" => "a",
  423.                 "&#7851;" => "a",
  424.                 "&#7853;" => "a",
  425.                 "&#7855;" => "a",
  426.                 "&#7857;" => "a",
  427.                 "&#7859;" => "a",
  428.                 "&#7861;" => "a",
  429.                 "&#7863;" => "a",
  430.                 "&#507;" => "a",
  431.                 "&#261;" => "a",
  432.                 "Ç" => "C",
  433.                 "&#262;" => "C",
  434.                 "&#264;" => "C",
  435.                 "&#266;" => "C",
  436.                 "&#268;" => "C",
  437.                 "ç" => "c",
  438.                 "&#263;" => "c",
  439.                 "&#265;" => "c",
  440.                 "&#267;" => "c",
  441.                 "&#269;" => "c",
  442.                 "Ð" => "D",
  443.                 "&#270;" => "D",
  444.                 "&#272;" => "D",
  445.                 "&#271;" => "d",
  446.                 "&#273;" => "d",
  447.                 "È" => "E",
  448.                 "É" => "E",
  449.                 "Ê" => "E",
  450.                 "Ë" => "E",
  451.                 "&#274;" => "E",
  452.                 "&#276;" => "E",
  453.                 "&#278;" => "E",
  454.                 "&#280;" => "E",
  455.                 "&#282;" => "E",
  456.                 "&#7864;" => "E",
  457.                 "&#7866;" => "E",
  458.                 "&#7868;" => "E",
  459.                 "&#7870;" => "E",
  460.                 "&#7872;" => "E",
  461.                 "&#7874;" => "E",
  462.                 "&#7876;" => "E",
  463.                 "&#7878;" => "E",
  464.                 "è" => "e",
  465.                 "é" => "e",
  466.                 "ê" => "e",
  467.                 "ë" => "e",
  468.                 "&#275;" => "e",
  469.                 "&#277;" => "e",
  470.                 "&#279;" => "e",
  471.                 "&#281;" => "e",
  472.                 "&#283;" => "e",
  473.                 "&#7865;" => "e",
  474.                 "&#7867;" => "e",
  475.                 "&#7869;" => "e",
  476.                 "&#7871;" => "e",
  477.                 "&#7873;" => "e",
  478.                 "&#7875;" => "e",
  479.                 "&#7877;" => "e",
  480.                 "&#7879;" => "e",
  481.                 "&#284;" => "G",
  482.                 "&#286;" => "G",
  483.                 "&#288;" => "G",
  484.                 "&#290;" => "G",
  485.                 "&#285;" => "g",
  486.                 "&#287;" => "g",
  487.                 "&#289;" => "g",
  488.                 "&#291;" => "g",
  489.                 "&#292;" => "H",
  490.                 "&#294;" => "H",
  491.                 "&#293;" => "h",
  492.                 "&#295;" => "h",
  493.                 "Ì" => "I",
  494.                 "Í" => "I",
  495.                 "Î" => "I",
  496.                 "Ï" => "I",
  497.                 "&#296;" => "I",
  498.                 "&#298;" => "I",
  499.                 "&#300;" => "I",
  500.                 "&#302;" => "I",
  501.                 "&#304;" => "I",
  502.                 "&#463;" => "I",
  503.                 "&#7880;" => "I",
  504.                 "&#7882;" => "I",
  505.                 "&#308;" => "J",
  506.                 "&#309;" => "j",
  507.                 "&#310;" => "K",
  508.                 "&#311;" => "k",
  509.                 "&#313;" => "L",
  510.                 "&#315;" => "L",
  511.                 "&#317;" => "L",
  512.                 "&#319;" => "L",
  513.                 "&#321;" => "L",
  514.                 "&#314;" => "l",
  515.                 "&#316;" => "l",
  516.                 "&#318;" => "l",
  517.                 "&#320;" => "l",
  518.                 "&#322;" => "l",
  519.                 "Ñ" => "N",
  520.                 "&#323;" => "N",
  521.                 "&#325;" => "N",
  522.                 "&#327;" => "N",
  523.                 "ñ" => "n",
  524.                 "&#324;" => "n",
  525.                 "&#326;" => "n",
  526.                 "&#328;" => "n",
  527.                 "&#329;" => "n",
  528.                 "Ò" => "O",
  529.                 "Ó" => "O",
  530.                 "Ô" => "O",
  531.                 "Õ" => "O",
  532.                 "Ö" => "O",
  533.                 "Ø" => "O",
  534.                 "&#332;" => "O",
  535.                 "&#334;" => "O",
  536.                 "&#336;" => "O",
  537.                 "&#416;" => "O",
  538.                 "&#465;" => "O",
  539.                 "&#510;" => "O",
  540.                 "&#7884;" => "O",
  541.                 "&#7886;" => "O",
  542.                 "&#7888;" => "O",
  543.                 "&#7890;" => "O",
  544.                 "&#7892;" => "O",
  545.                 "&#7894;" => "O",
  546.                 "&#7896;" => "O",
  547.                 "&#7898;" => "O",
  548.                 "&#7900;" => "O",
  549.                 "&#7902;" => "O",
  550.                 "&#7904;" => "O",
  551.                 "&#7906;" => "O",
  552.                 "ò" => "o",
  553.                 "ó" => "o",
  554.                 "ô" => "o",
  555.                 "õ" => "o",
  556.                 "ö" => "o",
  557.                 "ø" => "o",
  558.                 "&#333;" => "o",
  559.                 "&#335;" => "o",
  560.                 "&#337;" => "o",
  561.                 "&#417;" => "o",
  562.                 "&#466;" => "o",
  563.                 "&#511;" => "o",
  564.                 "&#7885;" => "o",
  565.                 "&#7887;" => "o",
  566.                 "&#7889;" => "o",
  567.                 "&#7891;" => "o",
  568.                 "&#7893;" => "o",
  569.                 "&#7895;" => "o",
  570.                 "&#7897;" => "o",
  571.                 "&#7899;" => "o",
  572.                 "&#7901;" => "o",
  573.                 "&#7903;" => "o",
  574.                 "&#7905;" => "o",
  575.                 "&#7907;" => "o",
  576.                 "ð" => "o",
  577.                 "&#340;" => "R",
  578.                 "&#342;" => "R",
  579.                 "&#344;" => "R",
  580.                 "&#341;" => "r",
  581.                 "&#343;" => "r",
  582.                 "&#345;" => "r",
  583.                 "&#346;" => "S",
  584.                 "&#348;" => "S",
  585.                 "&#350;" => "S",
  586.                 "&#347;" => "s",
  587.                 "&#349;" => "s",
  588.                 "&#351;" => "s",
  589.                 "&#354;" => "T",
  590.                 "&#356;" => "T",
  591.                 "&#358;" => "T",
  592.                 "&#355;" => "t",
  593.                 "&#357;" => "t",
  594.                 "&#359;" => "t",
  595.                 "Ù" => "U",
  596.                 "Ú" => "U",
  597.                 "Û" => "U",
  598.                 "Ü" => "U",
  599.                 "&#360;" => "U",
  600.                 "&#362;" => "U",
  601.                 "&#364;" => "U",
  602.                 "&#366;" => "U",
  603.                 "&#368;" => "U",
  604.                 "&#370;" => "U",
  605.                 "&#431;" => "U",
  606.                 "&#467;" => "U",
  607.                 "&#469;" => "U",
  608.                 "&#471;" => "U",
  609.                 "&#473;" => "U",
  610.                 "&#475;" => "U",
  611.                 "&#7908;" => "U",
  612.                 "&#7910;" => "U",
  613.                 "&#7912;" => "U",
  614.                 "&#7914;" => "U",
  615.                 "&#7916;" => "U",
  616.                 "&#7918;" => "U",
  617.                 "&#7920;" => "U",
  618.                 "ù" => "u",
  619.                 "ú" => "u",
  620.                 "û" => "u",
  621.                 "ü" => "u",
  622.                 "&#361;" => "u",
  623.                 "&#363;" => "u",
  624.                 "&#365;" => "u",
  625.                 "&#367;" => "u",
  626.                 "&#369;" => "u",
  627.                 "&#371;" => "u",
  628.                 "&#432;" => "u",
  629.                 "&#468;" => "u",
  630.                 "&#470;" => "u",
  631.                 "&#472;" => "u",
  632.                 "&#474;" => "u",
  633.                 "&#476;" => "u",
  634.                 "&#7909;" => "u",
  635.                 "&#7911;" => "u",
  636.                 "&#7913;" => "u",
  637.                 "&#7915;" => "u",
  638.                 "&#7917;" => "u",
  639.                 "&#7919;" => "u",
  640.                 "&#7921;" => "u",
  641.                 "&#372;" => "W",
  642.                 "&#7808;" => "W",
  643.                 "&#7810;" => "W",
  644.                 "&#7812;" => "W",
  645.                 "&#373;" => "w",
  646.                 "&#7809;" => "w",
  647.                 "&#7811;" => "w",
  648.                 "&#7813;" => "w",
  649.                 "Ý" => "Y",
  650.                 "&#374;" => "Y",
  651.                 "?" => "Y",
  652.                 "&#7922;" => "Y",
  653.                 "&#7928;" => "Y",
  654.                 "&#7926;" => "Y",
  655.                 "&#7924;" => "Y",
  656.                 "ý" => "y",
  657.                 "ÿ" => "y",
  658.                 "&#375;" => "y",
  659.                 "&#7929;" => "y",
  660.                 "&#7925;" => "y",
  661.                 "&#7927;" => "y",
  662.                 "&#7923;" => "y",
  663.                 "&#377;" => "Z",
  664.                 "&#379;" => "Z",
  665.                 '+'         =>'',
  666.                 "'"        =>'',
  667.                 ' '        =>'-',
  668.                 '.'        =>'-',
  669.                 );
  670.             $str strtr($str,$ch0);
  671.             return $str;
  672.         
  673.     }
  674.     function getPromoPercentage($price$originalPrice){
  675.         // dump($price);
  676.         // dump($originalPrice);
  677.         // dump($product->getProduct()->getPriceOriginal());
  678.         // $productVariantRepo = $this->container->get('sylius.repository.product_variant');
  679.         // $productVariantRepo::hasDiscount($product);
  680.         // return 100 - (($price) * $originalPrice / 100);
  681.         return '- '.round((($price $originalPrice)) / $price  1002) .' %';
  682.     }
  683.     function getHreflang($langue$urlfrom$route$params){
  684.         $entityManager $this->doctrine->getManager();
  685.         $conn $entityManager->getConnection();
  686.        
  687.         $urls = array(
  688.             'fr-fr' => array(
  689.                 '/idees-cadeaux' => 'gift-ideas',
  690.                 '/collections' => 'collections',
  691.             ),
  692.             'en' => array(
  693.                 '/gift-ideas' => 'idees-cadeaux',
  694.                 '/collections' => 'collections',
  695.             ),
  696.         );
  697.         if($langue == 'en'){           
  698.             $locale 'en_US';
  699.             $locale_inverse 'fr_FR';
  700.         }else{
  701.             $locale 'fr_FR';
  702.             $locale_inverse 'en_US';
  703.         }
  704.         $categories = [
  705.             'en_US' => [
  706.                 'enfant' => 'children',
  707.                 'classique' => 'classic',
  708.                 'temporaire' => 'temporary'
  709.             ],
  710.             'fr_FR' => [
  711.                 'children' => 'enfant',
  712.                 'classic' => 'classique',
  713.                 'temporary' => 'temporaire'
  714.             ]
  715.         ];
  716.         $url '';
  717.         
  718.        
  719.         switch ($route ) {
  720.             case 'app_product_variant_show':
  721.                 $sql '
  722.                 SELECT * FROM sylius_product_variant_translation
  723.                 WHERE translatable_id = :translatable_id
  724.                 AND locale = :locale
  725.                 ';
  726.                 $stmt $conn->prepare($sql);
  727.                 $resultSet $stmt->executeQuery([
  728.                     'translatable_id' => $params['id'],
  729.                     'locale' => $locale_inverse,
  730.                 ]);    
  731.                   
  732.                 $result $resultSet->fetchAllAssociative();
  733.                   
  734.                 $url "p/".$result[0]['slug'].'-'.$params['id'];
  735.                 break;
  736.             case 'sylius_shop_product_index':
  737.                 $repository $this->container->get('sylius.repository.taxon');
  738.                 $taxon $repository->findOneBySlug($params['slug'],  $locale);
  739.                 $sql '
  740.                 SELECT * FROM sylius_taxon_translation
  741.                 WHERE translatable_id = :translatable_id
  742.                 AND locale = :locale
  743.                 ';
  744.                 $stmt $conn->prepare($sql);
  745.                 $resultSet $stmt->executeQuery([
  746.                     'translatable_id' => $taxon->getId(),
  747.                     'locale' => $locale_inverse,
  748.                 ]);            
  749.                 $result $resultSet->fetchAllAssociative();
  750.                 $url $result[0]['slug'];
  751.                 break;
  752.             case 'app_page_cms_show':
  753.                     
  754.                 $sitePageCmsRepository =  $entityManager->getRepository(SitePageCMSTranslation::class);
  755.                 $sitePageCmsTranslation $sitePageCmsRepository->findOneBySlug($params['slug']);
  756.                 $sql '
  757.                 SELECT * FROM site_page_cms_translation
  758.                 WHERE translatable_id = :translatable_id
  759.                 AND locale = :locale
  760.                 ';
  761.                 $stmt $conn->prepare($sql);
  762.                 $resultSet $stmt->executeQuery([
  763.                     'translatable_id' => $sitePageCmsTranslation->getTranslatable()->getId(),
  764.                     'locale' => $locale_inverse,
  765.                 ]);                          
  766.                 $result $resultSet->fetchAllAssociative();      
  767.                 if(isset($result[0])){
  768.                     $url "ppmc/".$result[0]['slug'];
  769.                 }  
  770.                 break;
  771.             case 'app_collection_category':              
  772.                 
  773.                 $slugBase '';
  774.                 if(isset($categories[$locale_inverse][$params['slugCategory']])){
  775.                     $slugBase $categories[$locale_inverse][$params['slugCategory']];
  776.                     $url "collections/".$slugBase;
  777.                 }
  778.                 break;  
  779.                 
  780.             case 'app_collection_show':
  781.             
  782.                 if(isset($categories[$locale_inverse][$params['slugCategory']])){
  783.                     $slugBase $categories[$locale_inverse][$params['slugCategory']];
  784.                     $url "collections/".$slugBase;
  785.                     $collectionTranslationRepository $entityManager->getRepository(SiteCollectionTranslation::class);
  786.                     $collectionTranslation $collectionTranslationRepository->findOneBySlug($params['slug']);
  787.     
  788.                     $sql '
  789.                     SELECT * FROM site_collection_translation
  790.                     WHERE translatable_id = :translatable_id
  791.                     AND locale = :locale
  792.                     ';
  793.                     $stmt $conn->prepare($sql);
  794.                     $resultSet $stmt->executeQuery([
  795.                         'translatable_id' => $collectionTranslation->getTranslatable()->getId(),
  796.                         'locale' => $locale_inverse,
  797.                     ]);                          
  798.                     $result $resultSet->fetchAllAssociative();   
  799.                    
  800.                     if(isset($result[0])){
  801.                         $url "collections/".$slugBase."/".$result[0]['slug'];
  802.                     } 
  803.                 }               
  804.                 break;    
  805.             default:
  806.                 if(isset($urls[$langue][$urlfrom])){
  807.                     $url $urls[$langue][$urlfrom];
  808.                 }
  809.                
  810.                 
  811.         }
  812.         return $url;
  813.     }
  814.     function hasReturnColissimo($idOrder) {
  815.         $filepath __DIR__ '/../../data/etiquettes/'.$idOrder.'-etiquette-retour-colissimo.pdf';
  816.         if(file_exists($filepath)) {
  817.             return $filepath;
  818.         }
  819.         return false;
  820.     }
  821. }