src/Controller/MarketPlace/ArticleMarketPlaceController.php line 666

Open in your IDE?
  1. <?php
  2. namespace App\Controller\MarketPlace;
  3. use App\Entity\Articles\Article;
  4. use App\Entity\Articles\ArticleCategorie;
  5. use App\Entity\Articles\Ean;
  6. use App\Entity\MarketPlace\ArticleMarketPlace;
  7. use App\Entity\MarketPlace\ArticleMarketPlaceCaracteristique;
  8. use App\Entity\MarketPlace\ArticleMarketPlaceImage;
  9. use App\Entity\MarketPlace\Caracteristiques;
  10. use App\Entity\MarketPlace\CategorieErpCategorieMarketPlace;
  11. use App\Entity\MarketPlace\CompteMarketPlace;
  12. use App\Entity\MarketPlace\HistoriqueArticleMarketPlace;
  13. use App\Entity\MarketPlace\MarketPlace;
  14. use App\Entity\MarketPlace\StatutArticle;
  15. use App\Entity\Taxes\RegleTaxe;
  16. use App\Entity\Traductions\Langue;
  17. use App\Entity\Traductions\Traduction;
  18. use App\Entity\Vehicules\Application;
  19. use App\Entity\Vehicules\Marque;
  20. use App\Entity\Vehicules\Modele;
  21. use App\Entity\Vehicules\Type;
  22. use App\Form\Articles\StockArticleAnnonceType;
  23. use App\Form\MarketPlace\ArticleMarketPlaceType;
  24. use App\Form\MarketPlace\DeplacerArticleMarketPlaceType;
  25. use App\Form\MarketPlace\DupliquerArticleMarketPlaceType;
  26. use App\Form\MarketPlace\MarketPlaceType;
  27. use App\Form\MarketPlace\SupprimerArticleMarketPlaceType;
  28. use App\Library\Datatable\Util\Datatable;
  29. use App\Security\Voter\EntityVoter;
  30. use App\Service\Articles\ArticleService;
  31. use App\Service\MarketPlace\ArticleMarketPlaceService;
  32. use Doctrine\ORM\EntityManagerInterface;
  33. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  34. use Symfony\Component\Form\FormError;
  35. use Symfony\Component\HttpFoundation\JsonResponse;
  36. use Symfony\Component\HttpFoundation\Request;
  37. use Symfony\Component\HttpFoundation\Response;
  38. use Symfony\Component\Routing\Annotation\Route;
  39. use Symfony\Component\Validator\Validator\ValidatorInterface;
  40. use Symfony\Contracts\Translation\TranslatorInterface;
  41. class ArticleMarketPlaceController extends AbstractController
  42. {
  43.     /**
  44.      * @Route("/mp/charger-tableau/{id}/{idmarket}", name="dtc_mp_article_charger_tableau")
  45.      */
  46.     public function chargerTableauAction(Request             $requestArticle $articleCompteMarketPlace $idmarket$parametres = [], EntityManagerInterface $em,
  47.                                          TranslatorInterface $translatorValidatorInterface $validator
  48.     ) {
  49.         $rendu $this->renderView('MarketPlace/ArticleMarketPlace/charger_tableau.html.twig', ['article' => $article'market' => $idmarket'parametres' => $parametres]);
  50.         return new JsonResponse(['rendu' => $rendu], 200, ['Content-Type' => 'application/json']);
  51.     }
  52.     /**
  53.      * @Route("/article/marketplace/statut-en-ligne/{id}", name="dtc_article_market_place_changer_statut_en_ligne")
  54.      */
  55.     public function changeStatutEnLigneAction(Request $requestArticleMarketPlace $articleMarketPlaceEntityManagerInterface $em)
  56.     {
  57.         $repo_statut_article_market_place $em->getRepository(StatutArticle::class);
  58.         if ( ! is_object($articleMarketPlace->getStatutArticleMarketPlace())) {
  59.             $statutAPublierAnnonce $repo_statut_article_market_place->find(1);
  60.             //echo "toto ".$articleMarketPlace->getId()." ".$statutAPublierAnnonce->getLibelle();
  61.             $articleMarketPlace->setStatutArticleMarketPlace($statutAPublierAnnonce);
  62.             $articleMarketPlace->setDateDemandePublicationMarketPlace(new \Datetime());
  63.             $articleMarketPlace->setEnvoyerUniquementStock(0);
  64.             //$em->persist($articleMarketPlace);
  65.             //$em->flush();
  66.             //exit;
  67.         } else {
  68.             if ($articleMarketPlace->getStatutArticleMarketPlace()->getId() == 1) {
  69.                 $articleMarketPlace->setStatutArticleMarketPlace(null);
  70.                 $articleMarketPlace->setEnvoyerImageAmazon(false);
  71.                 //$em->persist($articleMarketPlace);
  72.                 //$em->flush();
  73.             } elseif ($articleMarketPlace->getStatutArticleMarketPlace()->getId() == 2) {
  74.                 $statutAPublierAnnonce $repo_statut_article_market_place->find(1);
  75.                 $articleMarketPlace->setStatutArticleMarketPlace($statutAPublierAnnonce);
  76.                 //$em->persist($articleMarketPlace);
  77.                 //$em->flush();
  78.             }
  79.         }
  80.         if ($articleMarketPlace->getStatut() == 1) {
  81.             $articleMarketPlace->setStatut(0);
  82.         } else {
  83.             $articleMarketPlace->setStatut(1);
  84.         }
  85.         $em->persist($articleMarketPlace);
  86.         $em->flush();
  87.         $headers = [
  88.             'Content-Type'                 => 'application/json',
  89.             'Access-Control-Allow-Origin'  => '*',
  90.             'Access-Control-Allow-Methods' => 'POST',
  91.         ];
  92.         return new JsonResponse(['data' => '1''statut_annonce' => $articleMarketPlace->getId()]);
  93.     }
  94.     /**
  95.      * @Route("/article/marketplace/statut/{id}", name="dtc_article_market_place_changer_statut")
  96.      */
  97.     public function changeStatutAction(Request $requestArticleMarketPlace $articleMarketPlaceEntityManagerInterface $emArticleMarketPlaceService $service_article_market_place)
  98.     {
  99.         $repo_statut_article_market_place $em->getRepository(StatutArticle::class);
  100.         if ( ! is_object($articleMarketPlace->getStatutArticleMarketPlace())) {
  101.             $statutAPublierAnnonce $repo_statut_article_market_place->find(1);
  102.             $articleMarketPlace->setStatutArticleMarketPlace($statutAPublierAnnonce);
  103.             $articleMarketPlace->setDateDemandePublicationMarketPlace(new \Datetime());
  104.             $articleMarketPlace->setEnvoyerUniquementStock(0);
  105.             $em->persist($articleMarketPlace);
  106.             $em->flush();
  107.             //exit;
  108.             $service_article_market_place->creerHistorique($articleMarketPlace3);
  109.         } else {
  110.             if ($articleMarketPlace->getStatutArticleMarketPlace()->getId() == 1) {
  111.                 $articleMarketPlace->setStatutArticleMarketPlace(null);
  112.                 $articleMarketPlace->setEnvoyerImageAmazon(false);
  113.                 $em->persist($articleMarketPlace);
  114.                 $em->flush();
  115.                 $service_article_market_place->creerHistorique($articleMarketPlace4);
  116.             } elseif ($articleMarketPlace->getStatutArticleMarketPlace()->getId() == 2) {
  117.                 $statutAPublierAnnonce $repo_statut_article_market_place->find(1);
  118.                 $articleMarketPlace->setStatutArticleMarketPlace($statutAPublierAnnonce);
  119.                 $em->persist($articleMarketPlace);
  120.                 $em->flush();
  121.                 $service_article_market_place->creerHistorique($articleMarketPlace3);
  122.             }
  123.         }
  124.         $headers = [
  125.             'Content-Type'                 => 'application/json',
  126.             'Access-Control-Allow-Origin'  => '*',
  127.             'Access-Control-Allow-Methods' => 'POST',
  128.         ];
  129.         return new JsonResponse(['data' => '1'], 200$headers);
  130.     }
  131.     public function slugify($text)
  132.     {
  133.         // replace non letter or digits by -
  134.         $text preg_replace('~[^\pL\d]+~u''-'$text);
  135.         // transliterate
  136.         $text iconv('utf-8''us-ascii//TRANSLIT'$text);
  137.         // remove unwanted characters
  138.         $text preg_replace('~[^-\w]+~'''$text);
  139.         // trim
  140.         $text trim($text'-');
  141.         // remove duplicate -
  142.         $text preg_replace('~-+~''-'$text);
  143.         // lowercase
  144.         $text strtolower($text);
  145.         if (empty($text)) {
  146.             return 'n-a';
  147.         }
  148.         return $text;
  149.     }
  150.     /**
  151.      * @Route("/article/marketplace/{article}/{compteMarketPlace}/nouveau", name="dtc_article_market_place_ajouter_modal")
  152.      */
  153.     public function ajouterModalAction(Request             $requestArticle $articleCompteMarketPlace $compteMarketPlace$parametres = [], EntityManagerInterface $em,
  154.                                        TranslatorInterface $translatorValidatorInterface $validator
  155.     ) {
  156.         $titre_modal "Nouvelle offre ";
  157.         $user        $this->getUser();
  158.         $repo_regle_taxe $em->getRepository(RegleTaxe::class);
  159.         $regle_taxe      $repo_regle_taxe->find(1);
  160.         $articleMarketPlace = new ArticleMarketPlace;
  161.         $articleMarketPlace->setCompteMarketPlace($compteMarketPlace);
  162.         $articleMarketPlace->setArticle($article);
  163.         $articleMarketPlace->setLibelle($article->getLibelle());
  164.         $articleMarketPlace->setStock($article->getStock());
  165.         //$articleMarketPlace->setTitreSeo($article->getLibelle());
  166.         $articleMarketPlace->setPrixvente($article->getPrixvente());
  167.         $articleMarketPlace->setResume($article->getDescriptionCourte());
  168.         if ($article->getDescription() != "") {
  169.             $articleMarketPlace->setDescription($article->getDescription());
  170.         } else {
  171.             $articleMarketPlace->setDescription($article->getDescriptionCourte());
  172.         }
  173.         //$articleMarketPlace->setUrlRewriting($this->slugify($article->getLibelle()));
  174.         $articleMarketPlace->setRegleTaxe($regle_taxe);
  175.         $articleMarketPlace->setVisible(false);
  176.         $repo_article_categorie $em->getRepository(ArticleCategorie::class);
  177.         $repo_article_market_place_image $em->getRepository(ArticleMarketPlaceImage::class);
  178.         $repo_traduction $em->getRepository(Traduction::class);
  179.         $repo_langue     $em->getRepository(Langue::class);
  180.         $repo_article_market_place $em->getRepository(ArticleMarketPlace::class);
  181.         $em->persist($articleMarketPlace);
  182.         $em->flush();
  183.         $em->refresh($articleMarketPlace);
  184.         if (count($article->getImages()) > 0) {
  185.             foreach ($article->getImages() as $img) {
  186.                 $articleMarketPlaceImage = new ArticleMarketPlaceImage();
  187.                 $articleMarketPlaceImage->setArticleMArketPlace($articleMarketPlace);
  188.                 $articleMarketPlaceImage->setImage($img);
  189.                 $em->persist($articleMarketPlaceImage);
  190.             }
  191.             $em->flush();
  192.         }
  193.         $categorieMarket $repo_article_categorie->findBy(["article" => $article"marketPlace" => $compteMarketPlace->getMarketPlace()]);
  194.         //echo "TOTO".count($categorieMarket);
  195.         if (count($categorieMarket) > 0) {
  196.             foreach ($categorieMarket as $cm) {
  197.                 $articleCategorie = new ArticleCategorie();
  198.                 $articleCategorie->setArticleMarketPlace($articleMarketPlace);
  199.                 $articleCategorie->setCategorie($cm->getCategorie());
  200.                 $em->persist($articleCategorie);
  201.             }
  202.             $em->flush();
  203.         } else {
  204.             if (is_object($articleMarketPlace->getCompteMarketPlace()) && is_object($articleMarketPlace->getCompteMarketPlace()->getMarketPlace())) {
  205.                 $catErp $repo_article_categorie->getCategorieErpArticle($article);
  206.                 $continuer_recherche_cat true;
  207.                 if (count($catErp) > 0) {
  208.                     foreach ($catErp as $ce) {
  209.                         if ($continuer_recherche_cat) {
  210.                             if (is_object($ce->getCategorie())) {
  211.                                 //echo "<div>CAT ".$ce->getCategorie()."</div>";
  212.                                 $repo_CategorieErpCategorieMarketPlace $em->getRepository(CategorieErpCategorieMarketPlace::class);
  213.                                 $cateCorrespondance                    $repo_CategorieErpCategorieMarketPlace->findOneBy(
  214.                                     ["categorieErp" => $ce->getCategorie(), "compteMarketPlace" => $articleMarketPlace->getCompteMarketPlace()]
  215.                                 );
  216.                                 if (is_object($cateCorrespondance) && is_object($cateCorrespondance->getCategorieMarketPlace())) {
  217.                                     $articleCategorie = new ArticleCategorie();
  218.                                     $articleCategorie->setArticleMarketPlace($articleMarketPlace);
  219.                                     $articleCategorie->setCategorie($cateCorrespondance->getCategorieMarketPlace());
  220.                                     $em->persist($articleCategorie);
  221.                                     $continuer_recherche_cat false;
  222.                                 }
  223.                                 /*
  224.                                 if($articleMarketPlace->getCompteMarketPlace()->getMarketPlace()->getId() == "8") {
  225.                                     //Wordpress
  226.                                     if(is_object($ce->getCategorie()->getCategorieWordpress())) {
  227.                                         $articleCategorie = new ArticleCategorie;
  228.                                         $articleCategorie->setArticleMarketPlace($articleMarketPlace);
  229.                                         $articleCategorie->setCategorie($ce->getCategorie()->getCategorieWordpress());
  230.                                         $em->persist($articleCategorie);
  231.                                     }
  232.                                 }
  233.                                 else if($articleMarketPlace->getCompteMarketPlace()->getMarketPlace()->getId() == "5") {
  234.                                     // Prestashop
  235.                                     if(is_object($ce->getCategorie()->getCategoriePrestahop())) {
  236.                                         $articleCategorie = new ArticleCategorie;
  237.                                         $articleCategorie->setArticleMarketPlace($articleMarketPlace);
  238.                                         $articleCategorie->setCategorie($ce->getCategorie()->getCategoriePrestahop());
  239.                                         $em->persist($articleCategorie);
  240.                                     }
  241.                                 }
  242.                                 */
  243.                             }
  244.                             //echo $ce->getCategorie()->getLibelle();
  245.                         }
  246.                     }
  247.                     $em->flush();
  248.                 }
  249.             }
  250.         }
  251.         $form $this->createForm(ArticleMarketPlaceType::class, $articleMarketPlace);
  252.         $get $request->query->all();
  253.         $langues $repo_langue->findAll();
  254.         $repo_caracteristique $em->getRepository(Caracteristiques::class);
  255.         $errors "";
  256.         $form->handleRequest($request);
  257.         if ( ! $form->isSubmitted()) {
  258.         }
  259.         if ($form->isSubmitted()) {
  260.             if ($form->isValid()) {
  261.                 $erreur_image                    false;
  262.                 $erreur_categorie_priceminister  false;
  263.                 $erreur_image_annonce            false;
  264.                 $erreur_sku_priceminister        false;
  265.                 $erreur_sku_priceminister_existe false;
  266.                 $erreur_sku_ean                  false;
  267.                 $erreur_sku_ean_existe           false;
  268.                 $temp_sku                        "";
  269.                 $post                $request->request->all();
  270.                 $caracteristiques_ps $repo_caracteristique->findBy(["marketPlace" => $articleMarketPlace->getCompteMarketPlace()->getMarketPlace()]);
  271.                 if (count($caracteristiques_ps) > 0) {
  272.                     foreach ($caracteristiques_ps as $carac) {
  273.                         //caracteristique_17860
  274.                         if (array_key_exists('caracteristique_'.$carac->getId(), $post)) {
  275.                             if (is_array($post['caracteristique_'.$carac->getId()])) {
  276.                                 foreach ($post['caracteristique_'.$carac->getId()] as $key => $value) {
  277.                                     $articleMarketPlaceCaracteristique = new ArticleMarketPlaceCaracteristique();
  278.                                     $articleMarketPlaceCaracteristique->setArticleMarketPlace($articleMarketPlace);
  279.                                     $articleMarketPlaceCaracteristique->setCaracteristique($carac);
  280.                                     $articleMarketPlaceCaracteristique->setValeur($value);
  281.                                     $em->persist($articleMarketPlaceCaracteristique);
  282.                                 }
  283.                             }
  284.                             $em->flush();
  285.                         }
  286.                     }
  287.                 }
  288.                 if (is_object($articleMarketPlace->getArticle()) && count($articleMarketPlace->getArticle()->getImages()) == 0) {
  289.                     $erreur_image true;
  290.                 }
  291.                 //if(is_object($articleMarketPlace->getCompteMarketPlace()) and is_object($articleMarketPlace->getCompteMarketPlace()->getMarketPlace()) and ($articleMarketPlace->getCompteMarketPlace()->getMarketPlace()->getId() == "4" or $articleMarketPlace->getCompteMarketPlace()->getMarketPlace()->getId() == "2" or $articleMarketPlace->getCompteMarketPlace()->getMarketPlace()->getId() == "3")) {
  292.                 if (is_object($articleMarketPlace->getCompteMarketPlace()) and is_object($articleMarketPlace->getCompteMarketPlace()->getMarketPlace())) {
  293.                     $imagesAnnonce $repo_article_market_place_image->findBy(["articleMarketPlace" => $articleMarketPlace]);
  294.                     if (count($imagesAnnonce) == 0) {
  295.                         //$erreur_image_annonce = true;
  296.                     }
  297.                     if (count($articleMarketPlace->getArticleCategorie()) == and ($articleMarketPlace->getIdImport() == null or $articleMarketPlace->getIdImport() == "")) {
  298.                         $erreur_categorie_priceminister true;
  299.                     }
  300.                     if (($articleMarketPlace->getSku() == "" or $articleMarketPlace->getSku() == null) and ($articleMarketPlace->getIdImport() == "" or $articleMarketPlace->getIdImport(
  301.                             ) == null)) {
  302.                         $erreur_sku_priceminister true;
  303.                     }
  304.                     if ($articleMarketPlace->getSku() != "") {
  305.                         $articleMarketPlaceSku $repo_article_market_place->findBy(
  306.                             ["compteMarketPlace" => $articleMarketPlace->getCompteMarketPlace(), "sku" => $articleMarketPlace->getSku()]
  307.                         );
  308.                         if (count($articleMarketPlaceSku) > 1) {
  309.                             $erreur_sku_priceminister_existe true;
  310.                             $temp_sku                        $articleMarketPlace->getSku();
  311.                             $articleMarketPlace->setSku("");
  312.                         } else {
  313.                             foreach ($articleMarketPlaceSku as $ampsku) {
  314.                                 if ($ampsku->getId() != $articleMarketPlace->getId()) {
  315.                                     $erreur_sku_priceminister_existe true;
  316.                                     $temp_sku                        $articleMarketPlace->getSku();
  317.                                     $articleMarketPlace->setSku("");
  318.                                 }
  319.                             }
  320.                         }
  321.                     }
  322.                     // echo "<div>EAN ".$articleMarketPlace->getEan()."</div>";
  323.                     if ($articleMarketPlace->getEan() != "") {
  324.                         $articleMarketPlaceSku $repo_article_market_place->findBy(
  325.                             ["ean" => $articleMarketPlace->getEan(), "compteMarketPlace" => $articleMarketPlace->getCompteMarketPlace()]
  326.                         );
  327.                         //echo "<div><COUNT ".count($articleMarketPlaceSku)."</div>";
  328.                         if (count($articleMarketPlaceSku) > 1) {
  329.                             $erreur_sku_ean_existe true;
  330.                             $temp_sku              $articleMarketPlace->getSku();
  331.                             $articleMarketPlace->setEan("");
  332.                             $articleMarketPlace->setEanObjet(null);
  333.                         } else {
  334.                             foreach ($articleMarketPlaceSku as $ampsku) {
  335.                                 if ($ampsku->getId() != $articleMarketPlace->getId()) {
  336.                                     $erreur_sku_ean_existe true;
  337.                                     //$temp_sku =  $articleMarketPlace->getSku();
  338.                                     $articleMarketPlace->setEan("");
  339.                                     $articleMarketPlace->setEanObjet(null);
  340.                                 }
  341.                             }
  342.                         }
  343.                     }
  344.                     if (($articleMarketPlace->getIdImport() == "" or $articleMarketPlace->getIdImport() == null) and ($articleMarketPlace->getEan() == null or $articleMarketPlace->getEan(
  345.                             ) == "")) {
  346.                         //if(($articleMarketPlace->getIdImport() == "" or $articleMarketPlace->getIdImport() == NULL) and ($articleMarketPlace->getArticle()->getCodeProduit() == NULL or $articleMarketPlace->getArticle()->getCodeProduit() == "")) {
  347.                         //$erreur_sku_ean = true;
  348.                     }
  349.                 }
  350.                 $postForm $request->request->all();
  351.                 //print_r($postForm);
  352.                 $postForm $request->request->all();
  353.                 //print_r($postForm);
  354.                 if (count($langues) > 0) {
  355.                     foreach ($langues as $l) {
  356.                         $trad $repo_traduction->findOneBy(["articleMarketPlace" => $articleMarketPlace"langue" => $l]);
  357.                         if ( ! is_object($trad)) {
  358.                             $trad = new Traduction();
  359.                             $trad->setArticleMarketPlace($articleMarketPlace);
  360.                             $trad->setlangue($l);
  361.                         }
  362.                         if (array_key_exists('libelle_'.$l->getId(), $postForm)) {
  363.                             $trad->setLibelle($postForm['libelle_'.$l->getId()]);
  364.                         }
  365.                         if (array_key_exists('descriptionCourte_'.$l->getId(), $postForm)) {
  366.                             $trad->setDescriptionCourte($postForm['descriptionCourte_'.$l->getId()]);
  367.                         }
  368.                         if (array_key_exists('altImg_'.$l->getId(), $postForm)) {
  369.                             $trad->setaltImg($postForm['altImg_'.$l->getId()]);
  370.                         }
  371.                         if (array_key_exists('titreSeo_'.$l->getId(), $postForm)) {
  372.                             $trad->setTitreSeo($postForm['titreSeo_'.$l->getId()]);
  373.                         }
  374.                         if (array_key_exists('description_'.$l->getId(), $postForm)) {
  375.                             $trad->setDescription($postForm['description_'.$l->getId()]);
  376.                         }
  377.                         if (array_key_exists('urlRewriting_'.$l->getId(), $postForm)) {
  378.                             $trad->setUrlRewriting($postForm['urlRewriting_'.$l->getId()]);
  379.                         }
  380.                         if (array_key_exists('metaDescription_'.$l->getId(), $postForm)) {
  381.                             $trad->setMetaDescription($postForm['metaDescription_'.$l->getId()]);
  382.                         }
  383.                         $em->persist($trad);
  384.                     }
  385.                 }
  386.                 $statutArticleMarketPlace $em->getRepository(StatutArticle::class)->find(1);
  387.                 if ((count($article->getArticleCategorie()) > || $articleMarketPlace->getCompteMarketPlace()->getMarketPlace()->getId() == 1) && $articleMarketPlace->getLibelle(
  388.                     ) != "" && $articleMarketPlace->getDescription(
  389.                     ) != "" && ! $erreur_image and ! $erreur_sku_ean_existe and ! $erreur_sku_ean and ! $erreur_sku_priceminister_existe and ! $erreur_sku_priceminister and ! $erreur_image_annonce and ! $erreur_categorie_priceminister and $articleMarketPlace->getPrixVente(
  390.                     ) > and ($articleMarketPlace->getAnnonceSupprime() == null or $articleMarketPlace->getAnnonceSupprime() == 0)) {
  391.                     $articleMarketPlace->setDateDemandePublicationMarketPlace(new \Datetime());
  392.                     $articleMarketPlace->setStatutArticleMarketPlace($statutArticleMarketPlace);
  393.                     $articleMarketPlace->setEnvoyerUniquementStock(0);
  394.                     if (array_key_exists('supprimer'$postForm) and $postForm["supprimer"] == "1" and is_object($articleMarketPlace->getCompteMarketPlace()) and is_object(
  395.                                                                                                                                                                       $articleMarketPlace->getCompteMarketPlace(
  396.                                                                                                                                                                       )->getMarketPlace()
  397.                                                                                                                                                                   ) and $articleMarketPlace->getCompteMarketPlace(
  398.                         )->getMarketPlace()->getId() == "4") {
  399.                         $articleMarketPlace->setAnnonceSupprime(1);
  400.                     }
  401.                     if ($articleMarketPlace->getArret() == true) {
  402.                         $articleMarketPlace->setStatut(false);
  403.                     }
  404.                 } else {
  405.                     $articleMarketPlace->setDateDemandePublicationMarketPlace(null);
  406.                     $articleMarketPlace->setStatutArticleMarketPlace(null);
  407.                 }
  408.                 $em->persist($articleMarketPlace);
  409.                 $em->flush();
  410.                 $conn $em->getConnection();
  411.                 $em->flush();
  412.                 $erreur_construit "";
  413.                 if ($erreur_image_annonce) {
  414.                     $erreur_construit .= "<br/>Merci de choisir une image !";
  415.                 }
  416.                 if ($erreur_categorie_priceminister and != 1) {
  417.                     $erreur_construit .= "<br/>Merci de choisir une catégorie market place !";
  418.                 }
  419.                 if (trim($articleMarketPlace->getPrixVente()) == "" or is_null(trim($articleMarketPlace->getPrixVente()))) {
  420.                     $erreur_construit .= "<br/>Merci de définir un prix de vente !";
  421.                 }
  422.                 if ($erreur_sku_priceminister) {
  423.                     $erreur_construit .= "<br/>Merci de définir un SKU !";
  424.                 }
  425.                 if ($erreur_sku_priceminister_existe) {
  426.                     $erreur_construit .= "<br/>SKU (".$temp_sku.") non disponible, il déja attribué à une autre offre ".$articleMarketPlace->getCompteMarketPlace()->getMarketPlace(
  427.                         )->getLibelle()." !";
  428.                 }
  429.                 if ($erreur_sku_ean) {
  430.                     $erreur_construit .= "<br/>Merci de définir un code EAN !";
  431.                 }
  432.                 if ($erreur_sku_ean_existe) {
  433.                     $erreur_construit .= "<br/>Code EAN déja utilisé !";
  434.                 }
  435.                 if ($erreur_image) {
  436.                     $erreur_construit .= "<br/>Merci d'uploader au moins une image !";
  437.                 }
  438.                 if (count($article->getArticleCategorie()) == and != 1) {
  439.                     $erreur_construit .= "<br/>Merci de choisir une catégorie pour la fiche produit";
  440.                 }
  441.                 if ($articleMarketPlace->getLibelle() == "") {
  442.                     $erreur_construit .= "<br/>Merci de définir un libellé";
  443.                 }
  444.                 if ($articleMarketPlace->getDescription() == "" and != 1) {
  445.                     $erreur_construit .= "<br/>Merci de définir une description";
  446.                 }
  447.                 if ($erreur_construit == "") {
  448.                     if ($articleMarketPlace->getAnnonceSupprime() == null or $articleMarketPlace->getAnnonceSupprime() == 0) {
  449.                         $articleMarketPlace->setVisible(true);
  450.                         $em->persist($articleMarketPlace);
  451.                         $em->flush();
  452.                         $em->refresh($articleMarketPlace);
  453.                         $this->addFlash('notice''Offre modifiée avec succès !');
  454.                         //'Annonce modifiée avec succès ! Elle sera publiée dans un délai moyen de 15 minutes'
  455.                     }
  456.                 } else {
  457.                     $this->addFlash(
  458.                         'warning',
  459.                         $erreur_construit
  460.                     );
  461.                     $rendu $this->renderView(
  462.                         'MarketPlace/ArticleMarketPlace/ajouter_modal.html.twig',
  463.                         ['article' => $article'articleMarketPlace' => $articleMarketPlace'errors' => $errors'form' => $form->createView()]
  464.                     );
  465.                     return new JsonResponse(['rendu' => $rendu'valide' => '0''url' => '''titre' => $titre_modal]);
  466.                 }
  467.                 $url $this->generateUrl('dtc_article_modifier', ['id' => $article->getId(), 'tab' => 'm'.$articleMarketPlace->getCompteMarketPlace()->getId()]);
  468.                 return new JsonResponse(['rendu' => ""'valide' => '1''url' => $url'titre' => $titre_modal]);
  469.                 //return $this->redirectToRoute('dtc_article_modifier',array("id"=>$article->getId(),'amp'=>$articleMarketPlace->getId() ,'tab'=>"m".$articleMarketPlace->getCompteMarketPlace()->getId()));
  470.             } else {
  471.                 $errors $validator->validate($articleMarketPlace);
  472.                 $this->addFlash(
  473.                     'warning',
  474.                     'formulaire non valide !'
  475.                 );
  476.                 foreach ($errors as $error) {
  477.                     $this->addFlash(
  478.                         'warning',
  479.                         $error
  480.                     );
  481.                 }
  482.             }
  483.         }
  484.         $action_form $this->generateUrl(
  485.             'dtc_article_market_place_modifier',
  486.             ['article' => $article->getId(), 'id' => $articleMarketPlace->getId(), 'tab' => 'm'.$articleMarketPlace->getCompteMarketPlace()->getId()]
  487.         );
  488.         $rendu $this->renderView(
  489.             'MarketPlace/ArticleMarketPlace/ajouter_modal.html.twig',
  490.             ['nouveau' => '1''article' => $article'articleMarketPlace' => $articleMarketPlace'errors' => $errors'form' => $form->createView()]
  491.         );
  492.         return new JsonResponse(
  493.             ['link' => $action_form'rendu' => $rendu'valide' => '0''url' => '''titre' => $titre_modal]
  494.         );
  495.     }
  496.     /**
  497.      * @Route("/article/marketplace/{article}/annonce/{id}", name="dtc_article_market_place_modifier")
  498.      */
  499.     public function modifierModalAction(Request            $requestArticle $articleArticleMarketPlace $articleMarketPlace$parametres = [], EntityManagerInterface $em,
  500.                                         ValidatorInterface $validatorArticleMarketPlaceService $articleMarketPlaceService
  501.     ) {
  502.         $titre_modal "Modifier offre ";
  503.         $user        $this->getUser();
  504.         if ( ! is_object($articleMarketPlace)) {
  505.             $articleMarketPlace = new ArticleMarketPlace;
  506.         }
  507.         $repo_statut_article_market_place $em->getRepository(StatutArticle::class);
  508.         $statutAPublierAnnonce            $repo_statut_article_market_place->find(1);
  509.         $repo_langue $em->getRepository(Langue::class);
  510.         $langues     $repo_langue->findAll();
  511.         $repo_article_market_place       $em->getRepository(ArticleMarketPlace::class);
  512.         $repo_article_market_place_image $em->getRepository(ArticleMarketPlaceImage::class);
  513.         $repo_caracteristique $em->getRepository(Caracteristiques::class);
  514.         if (is_array($request->query->get('parametres'))) {
  515.             $parametres $request->query->get('parametres');
  516.         }
  517.         $form $this->createForm(ArticleMarketPlaceType::class, $articleMarketPlace);
  518.         $errors       "";
  519.         $renouvelable true;
  520.         $termine      false;
  521.         $date         = new \Datetime;
  522.         $nouveau      "";
  523.         $form->handleRequest($request);
  524.         if ($form->isSubmitted()) {
  525.             if ($form->isValid()) {
  526.                 $post     $request->request->all();
  527.                 $postForm $request->request->all();
  528.                 if (array_key_exists('nouveau'$postForm) && $postForm["nouveau"] == "1") {
  529.                     $nouveau 1;
  530.                 }
  531.                 $caracteristiques_ps $repo_caracteristique->findBy(["marketPlace" => $articleMarketPlace->getCompteMarketPlace()->getMarketPlace()]);
  532.                 //echo "ttc :".count($caracteristiques_ps);
  533.                 //print_r($post);
  534.                 $compteur_carac 0;
  535.                 if (count($caracteristiques_ps) > 0) {
  536.                     foreach ($caracteristiques_ps as $carac) {
  537.                         //caracteristique_17860
  538.                         if (array_key_exists('carac_'.$carac->getId(), $post)) {
  539.                             if ($compteur_carac == 0) {
  540.                                 $conn $em->getConnection();
  541.                                 $sql  "DELETE FROM market_place__article_market_place_caracteristique where article_market_place_id = ".$articleMarketPlace->getId();;
  542.                                 //echo "<div>".$sql."</div>";
  543.                                 $stmt $conn->executeQuery($sql);
  544.                                 //exit;
  545.                             }
  546.                             $compteur_carac++;
  547.                         }
  548.                         if (array_key_exists('carac_'.$carac->getId(), $post) && $post['carac_'.$carac->getId()] != "") {
  549.                             $articleMarketPlaceCaracteristique = new ArticleMarketPlaceCaracteristique();
  550.                             $articleMarketPlaceCaracteristique->setArticleMarketPlace($articleMarketPlace);
  551.                             $articleMarketPlaceCaracteristique->setCaracteristique($carac);
  552.                             $articleMarketPlaceCaracteristique->setValeur($post['carac_'.$carac->getId()]);
  553.                             $em->persist($articleMarketPlaceCaracteristique);
  554.                         }
  555.                     }
  556.                 }
  557.                 $em->flush();
  558.                 $erreur_image                    false;
  559.                 $erreur_categorie_priceminister  false;
  560.                 $erreur_image_annonce            false;
  561.                 $erreur_sku_priceminister        false;
  562.                 $erreur_sku_priceminister_existe false;
  563.                 $erreur_sku_ean                  false;
  564.                 $erreur_sku_ean_existe           false;
  565.                 $temp_sku                        "";
  566.                 if (is_object($articleMarketPlace->getArticle()) && count($articleMarketPlace->getArticle()->getImages()) == 0) {
  567.                     $erreur_image true;
  568.                 }
  569.                 //if(is_object($articleMarketPlace->getCompteMarketPlace()) and is_object($articleMarketPlace->getCompteMarketPlace()->getMarketPlace()) and ($articleMarketPlace->getCompteMarketPlace()->getMarketPlace()->getId() == "4" or $articleMarketPlace->getCompteMarketPlace()->getMarketPlace()->getId() == "2" or $articleMarketPlace->getCompteMarketPlace()->getMarketPlace()->getId() == "3")) {
  570.                 if (is_object($articleMarketPlace->getCompteMarketPlace()) and is_object($articleMarketPlace->getCompteMarketPlace()->getMarketPlace())) {
  571.                     $imagesAnnonce $repo_article_market_place_image->findBy(["articleMarketPlace" => $articleMarketPlace]);
  572.                     if (count($imagesAnnonce) == 0) {
  573.                         //$erreur_image_annonce = true;
  574.                     }
  575.                     if (count($articleMarketPlace->getArticleCategorie()) == and ($articleMarketPlace->getIdImport() == null or $articleMarketPlace->getIdImport() == "")) {
  576.                         $erreur_categorie_priceminister true;
  577.                     }
  578.                     if (($articleMarketPlace->getSku() == "" or $articleMarketPlace->getSku() == null) and ($articleMarketPlace->getIdImport() == "" or $articleMarketPlace->getIdImport(
  579.                             ) == null)) {
  580.                         $erreur_sku_priceminister true;
  581.                     }
  582.                     if ($articleMarketPlace->getSku() != "") {
  583.                         $articleMarketPlaceSku $repo_article_market_place->findBy(
  584.                             ["compteMarketPlace" => $articleMarketPlace->getCompteMarketPlace(), "sku" => $articleMarketPlace->getSku()]
  585.                         );
  586.                         if (count($articleMarketPlaceSku) > 1) {
  587.                             $erreur_sku_priceminister_existe true;
  588.                             $temp_sku                        $articleMarketPlace->getSku();
  589.                             $articleMarketPlace->setSku("");
  590.                         } else {
  591.                             foreach ($articleMarketPlaceSku as $ampsku) {
  592.                                 if ($ampsku->getId() != $articleMarketPlace->getId()) {
  593.                                     $erreur_sku_priceminister_existe true;
  594.                                     $temp_sku                        $articleMarketPlace->getSku();
  595.                                     $articleMarketPlace->setSku("");
  596.                                 }
  597.                             }
  598.                         }
  599.                     }
  600.                     // echo "<div>EAN ".$articleMarketPlace->getEan()."</div>";
  601.                     if ($articleMarketPlace->getEan() != "") {
  602.                         $articleMarketPlaceSku $repo_article_market_place->findBy(
  603.                             ["ean" => $articleMarketPlace->getEan(), "compteMarketPlace" => $articleMarketPlace->getCompteMarketPlace()]
  604.                         );
  605.                         //echo "<div><COUNT ".count($articleMarketPlaceSku)."</div>";
  606.                         if (count($articleMarketPlaceSku) > 1) {
  607.                             $erreur_sku_ean_existe true;
  608.                             $temp_sku              $articleMarketPlace->getSku();
  609.                             $articleMarketPlace->setEan("");
  610.                             $articleMarketPlace->setEanObjet(null);
  611.                         } else {
  612.                             foreach ($articleMarketPlaceSku as $ampsku) {
  613.                                 if ($ampsku->getId() != $articleMarketPlace->getId()) {
  614.                                     $erreur_sku_ean_existe true;
  615.                                     //$temp_sku =  $articleMarketPlace->getSku();
  616.                                     $articleMarketPlace->setEan("");
  617.                                     $articleMarketPlace->setEanObjet(null);
  618.                                 }
  619.                             }
  620.                         }
  621.                     }
  622.                     if (($articleMarketPlace->getIdImport() == "" or $articleMarketPlace->getIdImport() == null) and ($articleMarketPlace->getEan() == null or $articleMarketPlace->getEan(
  623.                             ) == "")) {
  624.                         //if(($articleMarketPlace->getIdImport() == "" or $articleMarketPlace->getIdImport() == NULL) and ($articleMarketPlace->getArticle()->getCodeProduit() == NULL or $articleMarketPlace->getArticle()->getCodeProduit() == "")) {
  625.                         //$erreur_sku_ean = true;
  626.                     }
  627.                 }
  628.                 $statutArticleMarketPlace $em->getRepository(StatutArticle::class)->find(1);
  629.                 if ((count($article->getArticleCategorie()) > || $articleMarketPlace->getCompteMarketPlace()->getMarketPlace()->getId() == 1) && $articleMarketPlace->getLibelle(
  630.                     ) != "" && $articleMarketPlace->getDescription(
  631.                     ) != "" && ! $erreur_image and ! $erreur_sku_ean_existe and ! $erreur_sku_ean and ! $erreur_sku_priceminister_existe and ! $erreur_sku_priceminister and ! $erreur_image_annonce and ! $erreur_categorie_priceminister and $articleMarketPlace->getPrixVente(
  632.                     ) > and ($articleMarketPlace->getAnnonceSupprime() == null or $articleMarketPlace->getAnnonceSupprime() == 0)) {
  633.                     //$articleMarketPlace->setDateDemandePublicationMarketPlace(new \Datetime());
  634.                     //$articleMarketPlace->setStatutArticleMarketPlace($statutArticleMarketPlace);
  635.                     //$articleMarketPlace->setEnvoyerUniquementStock(0);
  636.                     if (array_key_exists('supprimer'$postForm) and $postForm["supprimer"] == "1" and is_object($articleMarketPlace->getCompteMarketPlace()) and is_object(
  637.                                                                                                                                                                       $articleMarketPlace->getCompteMarketPlace(
  638.                                                                                                                                                                       )->getMarketPlace()
  639.                                                                                                                                                                   ) and $articleMarketPlace->getCompteMarketPlace(
  640.                         )->getMarketPlace()->getId() == "4") {
  641.                         $articleMarketPlace->setAnnonceSupprime(1);
  642.                     }
  643.                     if ($articleMarketPlace->getArret() == true) {
  644.                         $articleMarketPlace->setStatut(false);
  645.                     }
  646.                 } else {
  647.                     //$articleMarketPlace->setDateDemandePublicationMarketPlace(NULL);
  648.                     //$articleMarketPlace->setStatutArticleMarketPlace(NULL);
  649.                 }
  650.                 $em->persist($articleMarketPlace);
  651.                 $em->flush();
  652.                 $conn $em->getConnection();
  653.                 $em->flush();
  654.                 $erreur_construit "";
  655.                 if ($erreur_image_annonce) {
  656.                     $erreur_construit .= "<br/>Merci de choisir une image !";
  657.                 }
  658.                 if ($erreur_categorie_priceminister and != 1) {
  659.                     $erreur_construit .= "<br/>Merci de choisir une catégorie market place !";
  660.                 }
  661.                 if (trim($articleMarketPlace->getPrixVente()) == "" or trim($articleMarketPlace->getPrixVente()) == "0" or is_null(trim($articleMarketPlace->getPrixVente()))) {
  662.                     $erreur_construit .= "<br/>Merci de définir un prix de vente ! ";
  663.                 }
  664.                 if ($erreur_sku_priceminister) {
  665.                     $erreur_construit .= "<br/>Merci de définir un SKU !";
  666.                 }
  667.                 if ($erreur_sku_priceminister_existe) {
  668.                     $erreur_construit .= "<br/>SKU (".$temp_sku.") non disponible, il déja attribué à une autre offre ".$articleMarketPlace->getCompteMarketPlace()->getMarketPlace(
  669.                         )->getLibelle()." !";
  670.                 }
  671.                 if ($erreur_sku_ean) {
  672.                     $erreur_construit .= "<br/>Merci de définir un code EAN !";
  673.                 }
  674.                 if ($erreur_sku_ean_existe) {
  675.                     $erreur_construit .= "<br/>Code EAN déja utilisé !";
  676.                 }
  677.                 if ($erreur_image && ($articleMarketPlace->getIdImport() == "" or is_null($articleMarketPlace->getIdImport()))) {
  678.                     $erreur_construit .= "<br/>Merci d'uploader au moins une image !";
  679.                 }
  680.                 if (count($article->getArticleCategorie()) == and != 1) {
  681.                     $erreur_construit .= "<br/>Merci de choisir une catégorie pour la fiche produit";
  682.                 }
  683.                 if ($articleMarketPlace->getLibelle() == "") {
  684.                     $erreur_construit .= "<br/>Merci de définir un libellé";
  685.                 }
  686.                 if ($articleMarketPlace->getDescription() == "" and != 1) {
  687.                     $erreur_construit .= "<br/>Merci de définir une description";
  688.                 }
  689.                 if ($erreur_construit == "") {
  690.                     if ($articleMarketPlace->getAnnonceSupprime() == null or $articleMarketPlace->getAnnonceSupprime() == 0) {
  691.                         $articleMarketPlace->setVisible(true);
  692.                         $em->persist($articleMarketPlace);
  693.                         $em->flush();
  694.                         $em->refresh($articleMarketPlace);
  695.                         $annonce_en_cours_de_publication false;
  696.                         if (($articleMarketPlace->getVisible() or is_null($articleMarketPlace->getVisible()))) {
  697.                             //$articleMarketPlace->setDateDemandePublicationMarketPlace(new \Datetime());
  698.                             //$articleMarketPlace->setStatutArticleMarketPlace($statutAPublierAnnonce);
  699.                             $em->persist($articleMarketPlace);
  700.                             $em->flush();
  701.                             $message_maj $articleMarketPlaceService->majStockAnnonce($articleMarketPlace->getArticle()->getId(), $articleMarketPlace->getId());
  702.                             if (is_array($message_maj)) {
  703.                                 if (array_key_exists('notice'$message_maj) && $message_maj["notice"] != "") {
  704.                                     $annonce_en_cours_de_publication true;
  705.                                     $this->addFlash('notice'$message_maj["notice"]);
  706.                                 }
  707.                                 if (array_key_exists('warning'$message_maj) && $message_maj["warning"] != "") {
  708.                                     $this->addFlash('warning'$message_maj["warning"]);
  709.                                 }
  710.                             }
  711.                         }
  712.                         $nouveau "";
  713.                         if (array_key_exists('nouveau'$postForm) && $postForm["nouveau"] == "1") {
  714.                             $this->addFlash('notice''Offre créée avec succès !');
  715.                             $message                         = [];
  716.                             $message["message"]              = "";
  717.                             $message["en_cours_publication"] = $annonce_en_cours_de_publication;
  718.                             $articleMarketPlaceService->creerHistorique($articleMarketPlace12$message);
  719.                         } else {
  720.                             $this->addFlash('notice''Offre modifiée avec succès !');
  721.                             $message                         = [];
  722.                             $message["message"]              = "Modification manuelle de l'offre";
  723.                             $message["en_cours_publication"] = $annonce_en_cours_de_publication;
  724.                             $articleMarketPlaceService->creerHistorique($articleMarketPlace3$message);
  725.                         }
  726.                     }
  727.                 } else {
  728.                     $this->addFlash('warning'$erreur_construit);
  729.                     $rendu $this->renderView(
  730.                         'MarketPlace/ArticleMarketPlace/ajouter_modal.html.twig',
  731.                         [
  732.                             'nouveau'            => $nouveau,
  733.                             'article'            => $article,
  734.                             'articleMarketPlace' => $articleMarketPlace,
  735.                             'errors'             => $errors,
  736.                             'form'               => $form->createView(),
  737.                         ]
  738.                     );
  739.                     return new JsonResponse(['rendu' => $rendu'valide' => '0''url' => '''titre' => $titre_modal]);
  740.                 }
  741.                 $url $this->generateUrl('dtc_article_modifier', ['id' => $article->getId(), 'tab' => 'm'.$articleMarketPlace->getCompteMarketPlace()->getId()]);
  742.                 return new JsonResponse(['rendu' => ""'valide' => '1''url' => '''titre' => $titre_modal]);
  743.                 //return $this->redirectToRoute('dtc_article_modifier',array("id"=>$article->getId(),'amp'=>$articleMarketPlace->getId() ,'tab'=>"m".$articleMarketPlace->getCompteMarketPlace()->getId()));
  744.             } else {
  745.                 $errors $validator->validate($articleMarketPlace);
  746.                 $this->addFlash('warning''formulaire non valide!!!');
  747.                 foreach ($errors as $error) {
  748.                     $this->addFlash('warning'$error);
  749.                 }
  750.             }
  751.         }
  752.         $rendu $this->renderView(
  753.             'MarketPlace/ArticleMarketPlace/ajouter_modal.html.twig',
  754.             ['nouveau' => $nouveau'article' => $article'articleMarketPlace' => $articleMarketPlace'errors' => $errors'form' => $form->createView()]
  755.         );
  756.         return new JsonResponse(['rendu' => $rendu'valide' => '0''url' => '''titre' => $titre_modal]);
  757.     }
  758.     /**
  759.      * @Route("", name="")
  760.      */
  761.     public function listerAction(Request $requestArticle $articleCompteMarketPlace $compteMarketPlace$parametres = [], Datatable $datatable)
  762.     {
  763.         $articleMarketPlace = new ArticleMarketPlace();
  764.         $articleMarketPlace->setCompteMarketPlace($compteMarketPlace);
  765.         $this->datatableEnfants($datatable$compteMarketPlace$article);
  766.         return $this->render(
  767.             'MarketPlace/ArticleMarketPlace/lister.html.twig',
  768.             [
  769.                 "articleMarketPlace" => $articleMarketPlace,
  770.                 "compteMarketPlace"  => $compteMarketPlace,
  771.                 "article"            => $article,
  772.             ]
  773.         );
  774.     }
  775.     /**
  776.      * @Route("/article/marketplace/{article}/{compteMarketPlace}", name="dtc_article_market_place_ajouter")
  777.      */
  778.     public function ajouterAction(Request            $requestArticle $articleCompteMarketPlace $compteMarketPlace$parametres = [], EntityManagerInterface $em,
  779.                                   ValidatorInterface $validatorArticleMarketPlaceService $service_article_market_placeDatatable $datatable
  780.     ) {
  781.         $repo_article_market_place       $em->getRepository(ArticleMarketPlace::class);
  782.         $repo_article_market_place_image $em->getRepository(ArticleMarketPlaceImage::class);
  783.         if (is_array($request->query->get('parametres'))) {
  784.             $parametres $request->query->get('parametres');
  785.         }
  786.         if (array_key_exists('mp'$parametres) && $parametres["mp"] == $compteMarketPlace->getId()) {
  787.             if ($request->isMethod('POST')) {
  788.                 $articleMarketPlace $repo_article_market_place->find($request->request->get('articleMarketPlaceId'));
  789.             } elseif ( ! $request->isMethod('POST') && array_key_exists('amp'$parametres) && $parametres["amp"] == "new") {
  790.                 //echo "erreurerreurerreurerreurerreurerreur";
  791.                 $articleMarketPlaceParent $repo_article_market_place->findOneBy(["article" => $article"compteMarketPlace" => $compteMarketPlace"articleMarketPlaceParent" => null]
  792.                 );
  793.                 $articleMarketPlaceSource "";
  794.                 if (array_key_exists('source'$parametres) && $parametres["source"] != "") {
  795.                     $articleMarketPlaceSource $repo_article_market_place->find($parametres["source"]);
  796.                 }
  797.                 if ( ! is_object($articleMarketPlaceSource)) {
  798.                     $articleMarketPlaceSource $repo_article_market_place->findOneBy(["article" => $article"compteMarketPlace" => $compteMarketPlace], ["id" => "desc"]);
  799.                 }
  800.                 $articleMarketPlace = new ArticleMarketPlace;
  801.                 $articleMarketPlace->setArticle($article);
  802.                 if (is_object($articleMarketPlaceSource)) {
  803.                     $articleMarketPlace->setLibelle($articleMarketPlaceSource->getLibelle());
  804.                     $articleMarketPlace->setPrixVente($articleMarketPlaceSource->getPrixVente());
  805.                     $articleMarketPlace->setTitreDescription($articleMarketPlaceSource->getTitreDescription());
  806.                     $articleMarketPlace->setRenouvellementAuto(true);
  807.                 } else {
  808.                     $articleMarketPlace->setLibelle($article->getLibelle());
  809.                 }
  810.                 if (is_object($articleMarketPlaceSource)) {
  811.                     $articleMarketPlace->setDescription($articleMarketPlaceSource->getDescription());
  812.                 } else {
  813.                     $articleMarketPlace->setDescription("");
  814.                 }
  815.                 if (is_object($articleMarketPlaceSource) and count($articleMarketPlaceSource->getArticleCategorie()) > 0) {
  816.                     foreach ($articleMarketPlaceSource->getArticleCategorie() as $c) {
  817.                         $ArticleCategorie = new ArticleCategorie;
  818.                         $ArticleCategorie->setCategorie($c->getCategorie());
  819.                         $ArticleCategorie->setArticleMarketPlace($articleMarketPlace);
  820.                         $em->persist($ArticleCategorie);
  821.                     }
  822.                 }
  823.                 if (is_object($articleMarketPlaceSource)) {
  824.                     $imagesAnnonceSource $repo_article_market_place_image->findBy(["articleMarketPlace" => $articleMarketPlaceSource]);
  825.                     if (count($imagesAnnonceSource) > 0) {
  826.                         foreach ($imagesAnnonceSource as $imgSource) {
  827.                             $articleMarketPlaceImage = new ArticleMarketPlaceImage();
  828.                             $articleMarketPlaceImage->setArticleMarketPlace($articleMarketPlace);
  829.                             $articleMarketPlaceImage->setImage($imgSource->getImage());
  830.                             $em->persist($articleMarketPlaceImage);
  831.                         }
  832.                     }
  833.                 }
  834.                 $articleMarketPlace->setStock(100);
  835.                 $articleMarketPlace->setCompteMarketPlace($compteMarketPlace);
  836.                 $repo_ean $em->getRepository(Ean::class);
  837.                 $ean      $repo_ean->findOneBy(['libre' => true]);
  838.                 if (is_object($ean)) {
  839.                     $articleMarketPlace->setEan($ean->getCode());
  840.                     $articleMarketPlace->setEanObjet($ean);
  841.                     $ean->setLibre(false);
  842.                     $em->persist($ean);
  843.                 }
  844.                 if (is_object($articleMarketPlaceParent)) {
  845.                     $articleMarketPlace->setArticleMarketPlaceParent($articleMarketPlaceParent);
  846.                 }
  847.                 $em->persist($articleMarketPlace);
  848.                 $em->flush();
  849.                 $em->refresh($articleMarketPlace);
  850.                 if ($article->getCodeProduit() != "") {
  851.                     //echo "AAAA";
  852.                     $skuGen "AMA".$compteMarketPlace->getId().str_replace(" """$article->getCodeProduit());
  853.                     $testAnnonceSku $repo_article_market_place->findOneBy(["article" => $article"compteMarketPlace" => $compteMarketPlace"sku" => $skuGen]);
  854.                     if ( ! is_object($testAnnonceSku)) {
  855.                         $articleMarketPlace->setSku($skuGen);
  856.                     } else {
  857.                         for ($l 1$l <= 100$l++) {
  858.                             $skuGen         "AMA".$compteMarketPlace->getId().str_replace(" """$article->getCodeProduit());
  859.                             $skuGen         .= "/".$l;
  860.                             $testAnnonceSku $repo_article_market_place->findOneBy(["article" => $article"compteMarketPlace" => $compteMarketPlace"sku" => $skuGen]);
  861.                             if ( ! is_object($testAnnonceSku)) {
  862.                                 $articleMarketPlace->setSku($skuGen);
  863.                                 break;
  864.                             }
  865.                         }
  866.                     }
  867.                 }
  868.             } elseif (array_key_exists('amp'$parametres)) {
  869.                 //echo "okokokok";
  870.                 $articleMarketPlace $repo_article_market_place->find($parametres["amp"]);
  871.             }
  872.         } else {
  873.             //$articleMarketPlace = $repo_article_market_place->findOneBy(array("article"=>$article,"compteMarketPlace"=>$compteMarketPlace, 'visible'=>true));
  874.             $articleMarketPlace $repo_article_market_place->listerAnnonnceArticle($article$compteMarketPlace);
  875.         }
  876.         if (array_key_exists('amp'$parametres) && $parametres["amp"] != "new") {
  877.             //echo "TESTETS".$parametres["amp"];
  878.             $articleMarketPlaceTemp $repo_article_market_place->find($parametres["amp"]);
  879.             if (is_object($articleMarketPlaceTemp) && $articleMarketPlaceTemp->getCompteMarketPlace()->getId() == $compteMarketPlace->getId()) {
  880.                 $articleMarketPlace $articleMarketPlaceTemp;
  881.             }
  882.         }
  883.         //print_r($parametres);
  884.         if ( ! is_object($articleMarketPlace)) {
  885.             //echo "NOUVEAU";
  886.             $repo_regle_taxe $em->getRepository(RegleTaxe::class);
  887.             $regle_taxe      $repo_regle_taxe->find(1);
  888.             $articleMarketPlace = new ArticleMarketPlace;
  889.             $articleMarketPlace->setArticle($article);
  890.             $articleMarketPlace->setStatut(false);
  891.             $articleMarketPlace->setCompteMarketPlace($compteMarketPlace);
  892.             $articleMarketPlace->setVisible(false);
  893.             $articleMarketPlace->setLibelle($article->getLibelle());
  894.             $articleMarketPlace->setStock($article->getStock());
  895.             $articleMarketPlace->setTitreSeo($article->getLibelle());
  896.             $articleMarketPlace->setPrixvente($article->getPrixvente());
  897.             $articleMarketPlace->setResume($article->getDescriptionCourte());
  898.             $articleMarketPlace->setUrlRewriting($this->slugify($article->getLibelle()));
  899.             $articleMarketPlace->setRegleTaxe($regle_taxe);
  900.             $em->persist($articleMarketPlace);
  901.             $em->flush();
  902.             $em->refresh($articleMarketPlace);
  903.             if ($article->getCodeProduit() != "") {
  904.                 $skuGen "AMA".$compteMarketPlace->getId().str_replace(" """$article->getCodeProduit()).$articleMarketPlace->getId();
  905.                 if (array_key_exists('amp'$parametres) && $parametres["amp"] == "new") {
  906.                     //$annonceEan = $repo_article_market_place->findOneBy(array("article"=>$article->getCodeProduit(),"compteMarketPlace"=>$compteMarketPlace));
  907.                 }
  908.                 $articleMarketPlace->setSku($skuGen);
  909.                 $annonceEan $repo_article_market_place->findOneBy(["ean" => $article->getCodeProduit(), "compteMarketPlace" => $compteMarketPlace]);
  910.                 if ( ! is_object($annonceEan)) {
  911.                     $articleMarketPlace->setEan($article->getCodeProduit());
  912.                     // TODO FIX THIS
  913.                     if (is_object($article->getEan())) {
  914.                         $articleMarketPlace->setEanObjet($article->getEan());
  915.                     }
  916.                 }
  917.             }
  918.             $articleMarketPlace->setLibelle($article->getLibelle());
  919.             $articleMarketPlace->setStatut(false);
  920.             $articleMarketPlace->setDescription($article->getDescription());
  921.         } else {
  922.             //echo "ANCIEN";
  923.             if ($articleMarketPlace->getLibelle() == "") {
  924.                 $articleMarketPlace->setLibelle($article->getLibelle());
  925.             }
  926.             if ($articleMarketPlace->getDescription() == "") {
  927.                 $articleMarketPlace->setDescription($article->getDescription());
  928.             }
  929.             if ($articleMarketPlace->getSku() == "" and $article->getCodeProduit() != "") {
  930.                 //$skuGen = "AMA".$compteMarketPlace->getId().str_replace(" ","",$article->getCodeProduit());
  931.                 //$articleMarketPlace->setSku($skuGen);
  932.             }
  933.             if ($articleMarketPlace->getEan() == "" and $article->getCodeProduit() != "" and $articleMarketPlace->getIdImport() == "") {
  934.                 /*
  935.                 $annonceEan = $repo_article_market_place->findOneBy(array("ean"=>$article->getCodeProduit(),"compteMarketPlace"=>$compteMarketPlace));
  936.                 if(!is_object($annonceEan)) {
  937.                     $articleMarketPlace->setEan($article->getCodeProduit());
  938.                     if(is_object($article->getEan())) {
  939.                          $articleMarketPlace->setEanObjet($article->getEan());
  940.                     }
  941.                 }
  942.                 */
  943.             }
  944.         }
  945.         //exit;
  946.         //$conn = $em->getConnection();
  947.         //$sql = "DELETE FROM market_place__article where idImport is null and article_market_place_parent_id is not null and date_publication_market_place is null and article_id = ".$article->getId()." AND compte_market_place_id = ".$compteMarketPlace->getId()." AND id != ".$articleMarketPlace->getId();
  948.         //echo "<div>".$sql."</div>";
  949.         //$stmt = $conn->query($sql);
  950.         //$stmt->execute();
  951.         $form $this->createForm(ArticleMarketPlaceType::class, $articleMarketPlace);
  952.         $errors       "";
  953.         $renouvelable true;
  954.         $termine      false;
  955.         $date         = new \Datetime;
  956.         $endTime      $articleMarketPlace->getEndTime();
  957.         if (is_object($endTime) && $date $endTime) {
  958.             $termine true;
  959.             $diff    $date->diff($endTime);
  960.             if ($diff->format('%a') > 90) {
  961.                 $renouvelable false;
  962.             }
  963.         }
  964.         $form->handleRequest($request);
  965.         if ($form->isSubmitted()) {
  966.             if ($form->isValid()) {
  967.                 /*
  968.                 if($articleMarketPlace->getEan() != "") {
  969.                     $repo_ean = $em->getRepository('DTCArticlesBundle:Ean');
  970.                     $ean_obj = $repo_ean->findOneBy(array('code'=>$articleMarketPlace->getEan()));
  971.                     if(is_object($ean_obj) && $ean_obj->getLibre() == true) {
  972.                         $ean_obj->setLibre(false);
  973.                         $em->persist($ean_obj);
  974.                         $articleMarketPlace->setEanObjet($ean_obj);
  975.                     }
  976.                     else {
  977.                         $repo_ean = $em->getRepository('DTCArticlesBundle:Ean');
  978.                         $ean = $repo_ean->findOneBy(array('libre'=>true));
  979.                         $articleMarketPlace->setEan("");
  980.                         if(is_object($ean)) {
  981.                             $ean->setLibre(false);
  982.                             $em->persist($ean);
  983.                             $articleMarketPlace->setEan($ean->getCode());
  984.                             $articleMarketPlace->setEanObjet($ean);
  985.                         }
  986.                     }
  987.                 }
  988.                 */
  989.                 $erreur_image                    false;
  990.                 $erreur_categorie_priceminister  false;
  991.                 $erreur_image_annonce            false;
  992.                 $erreur_sku_priceminister        false;
  993.                 $erreur_sku_priceminister_existe false;
  994.                 $erreur_sku_ean                  false;
  995.                 $erreur_sku_ean_existe           false;
  996.                 $temp_sku                        "";
  997.                 if (is_object($articleMarketPlace->getArticle()) && count($articleMarketPlace->getArticle()->getImages()) == 0) {
  998.                     $erreur_image true;
  999.                 }
  1000.                 //if(is_object($articleMarketPlace->getCompteMarketPlace()) and is_object($articleMarketPlace->getCompteMarketPlace()->getMarketPlace()) and ($articleMarketPlace->getCompteMarketPlace()->getMarketPlace()->getId() == "4" or $articleMarketPlace->getCompteMarketPlace()->getMarketPlace()->getId() == "2" or $articleMarketPlace->getCompteMarketPlace()->getMarketPlace()->getId() == "3")) {
  1001.                 if (is_object($articleMarketPlace->getCompteMarketPlace()) and is_object($articleMarketPlace->getCompteMarketPlace()->getMarketPlace())) {
  1002.                     $imagesAnnonce $repo_article_market_place_image->findBy(["articleMarketPlace" => $articleMarketPlace]);
  1003.                     if (count($imagesAnnonce) == 0) {
  1004.                         //$erreur_image_annonce = true;
  1005.                     }
  1006.                     if (count($articleMarketPlace->getArticleCategorie()) == and ($articleMarketPlace->getIdImport() == null or $articleMarketPlace->getIdImport() == "")) {
  1007.                         $erreur_categorie_priceminister true;
  1008.                     }
  1009.                     if (($articleMarketPlace->getSku() == "" or $articleMarketPlace->getSku() == null) and ($articleMarketPlace->getIdImport() == "" or $articleMarketPlace->getIdImport(
  1010.                             ) == null)) {
  1011.                         $erreur_sku_priceminister true;
  1012.                     }
  1013.                     if ($articleMarketPlace->getSku() != "") {
  1014.                         $articleMarketPlaceSku $repo_article_market_place->findBy(
  1015.                             ["compteMarketPlace" => $articleMarketPlace->getCompteMarketPlace(), "sku" => $articleMarketPlace->getSku()]
  1016.                         );
  1017.                         if (count($articleMarketPlaceSku) > 1) {
  1018.                             $erreur_sku_priceminister_existe true;
  1019.                             $temp_sku                        $articleMarketPlace->getSku();
  1020.                             $articleMarketPlace->setSku("");
  1021.                         } else {
  1022.                             foreach ($articleMarketPlaceSku as $ampsku) {
  1023.                                 if ($ampsku->getId() != $articleMarketPlace->getId()) {
  1024.                                     $erreur_sku_priceminister_existe true;
  1025.                                     $temp_sku                        $articleMarketPlace->getSku();
  1026.                                     $articleMarketPlace->setSku("");
  1027.                                 }
  1028.                             }
  1029.                         }
  1030.                     }
  1031.                     // echo "<div>EAN ".$articleMarketPlace->getEan()."</div>";
  1032.                     if ($articleMarketPlace->getEan() != "" and != 1) {
  1033.                         $articleMarketPlaceSku $repo_article_market_place->findBy(
  1034.                             ["ean" => $articleMarketPlace->getEan(), "compteMarketPlace" => $articleMarketPlace->getCompteMarketPlace()]
  1035.                         );
  1036.                         //echo "<div><COUNT ".count($articleMarketPlaceSku)."</div>";
  1037.                         if (count($articleMarketPlaceSku) > 1) {
  1038.                             $erreur_sku_ean_existe true;
  1039.                             $temp_sku              $articleMarketPlace->getSku();
  1040.                             $articleMarketPlace->setEan("");
  1041.                             $articleMarketPlace->setEanObjet(null);
  1042.                         } else {
  1043.                             foreach ($articleMarketPlaceSku as $ampsku) {
  1044.                                 if ($ampsku->getId() != $articleMarketPlace->getId()) {
  1045.                                     $erreur_sku_ean_existe true;
  1046.                                     //$temp_sku =  $articleMarketPlace->getSku();
  1047.                                     $articleMarketPlace->setEan("");
  1048.                                     $articleMarketPlace->setEanObjet(null);
  1049.                                 }
  1050.                             }
  1051.                         }
  1052.                     }
  1053.                     if (($articleMarketPlace->getIdImport() == "" or $articleMarketPlace->getIdImport() == null) and ($articleMarketPlace->getEan() == null or $articleMarketPlace->getEan(
  1054.                             ) == "")) {
  1055.                         //if(($articleMarketPlace->getIdImport() == "" or $articleMarketPlace->getIdImport() == NULL) and ($articleMarketPlace->getArticle()->getCodeProduit() == NULL or $articleMarketPlace->getArticle()->getCodeProduit() == "")) {
  1056.                         //$erreur_sku_ean = true;
  1057.                     }
  1058.                 }
  1059.                 $postForm $request->request->all();
  1060.                 //print_r($postForm);
  1061.                 $statutArticleMarketPlace $em->getRepository(StatutArticle::class)->find(1);
  1062.                 if ((count($article->getArticleCategorie()) > || $articleMarketPlace->getCompteMarketPlace()->getMarketPlace()->getId() == 1) && $articleMarketPlace->getLibelle(
  1063.                     ) != "" && $articleMarketPlace->getDescription(
  1064.                     ) != "" && ! $erreur_image and ! $erreur_sku_ean_existe and ! $erreur_sku_ean and ! $erreur_sku_priceminister_existe and ! $erreur_sku_priceminister and ! $erreur_image_annonce and ! $erreur_categorie_priceminister and $articleMarketPlace->getPrixVente(
  1065.                     ) > and ($articleMarketPlace->getAnnonceSupprime() == null or $articleMarketPlace->getAnnonceSupprime() == 0)) {
  1066.                     $articleMarketPlace->setDateDemandePublicationMarketPlace(new \Datetime());
  1067.                     $articleMarketPlace->setStatutArticleMarketPlace($statutArticleMarketPlace);
  1068.                     $articleMarketPlace->setEnvoyerUniquementStock(0);
  1069.                     if (array_key_exists('supprimer'$postForm) and $postForm["supprimer"] == "1" and is_object($articleMarketPlace->getCompteMarketPlace()) and is_object(
  1070.                                                                                                                                                                       $articleMarketPlace->getCompteMarketPlace(
  1071.                                                                                                                                                                       )->getMarketPlace()
  1072.                                                                                                                                                                   ) and $articleMarketPlace->getCompteMarketPlace(
  1073.                         )->getMarketPlace()->getId() == "4") {
  1074.                         $articleMarketPlace->setAnnonceSupprime(1);
  1075.                     }
  1076.                     if ($articleMarketPlace->getArret() == true) {
  1077.                         $articleMarketPlace->setStatut(false);
  1078.                     }
  1079.                 } else {
  1080.                     $articleMarketPlace->setDateDemandePublicationMarketPlace(null);
  1081.                     $articleMarketPlace->setStatutArticleMarketPlace(null);
  1082.                 }
  1083.                 //recuperer le texte brut
  1084.                 $soumission $request->request->get('soumission');
  1085.                 if ($soumission == "recuperer") {
  1086.                     if (is_object($articleMarketPlace)) {
  1087.                         $idImport $articleMarketPlace->getIdImport();
  1088.                         if ($idImport != '') {
  1089.                             $response $service_article_market_place->getItem($idImport);
  1090.                             if ($response->Ack !== 'Failure') {
  1091.                                 $description      $service_article_market_place->nettoyer($response->Item->Description);
  1092.                                 $titreDescription $articleMarketPlace->getLibelle();
  1093.                                 $articleMarketPlace->setDescription($description);
  1094.                                 $articleMarketPlace->setTitreDescription($titreDescription);
  1095.                                 $this->addFlash('notice''Récupération du texte brut');
  1096.                             } else {
  1097.                                 $message '';
  1098.                                 if (isset($response->Errors)) {
  1099.                                     foreach ($response->Errors as $error) {
  1100.                                         /*
  1101.                                     printf(
  1102.                                         "%s: %s\n%s\n\n",
  1103.                                         $error->SeverityCode === Enums\SeverityCodeType::C_ERROR ? 'Error' : 'Warning',
  1104.                                         $error->ShortMessage,
  1105.                                         $error->LongMessage
  1106.                                     );
  1107.                                      *
  1108.                                      */
  1109.                                         $message .= '<br>'.$error->SeverityCode;
  1110.                                         $message .= '<br>'.$error->ShortMessage;
  1111.                                         $message .= '<br>'.$error->LongMessage;
  1112.                                     }
  1113.                                 }
  1114.                                 $this->addFlash('warning''Problème de récupération du texte brut.'.$message);
  1115.                             }
  1116.                         }
  1117.                     }
  1118.                 }
  1119.                 $em->persist($articleMarketPlace);
  1120.                 $em->flush();
  1121.                 $conn $em->getConnection();
  1122.                 /*
  1123.                 $sql = 'DELETE FROM market_place__article_market_place_caracteristique WHERE article_market_place_id="'.$articleMarketPlace->getId().'"';
  1124.                 $stmt = $conn->query($sql);
  1125.                 $stmt->execute();
  1126.                   */
  1127.                 /*
  1128.                   if(count($articleMarketPlace->getArticleCategorie())>0) {
  1129.                     foreach($articleMarketPlace->getArticleCategorie() as $articleCategorie) {
  1130.                         $caracteristiques = $serviceCategories->getCaracteristiqueCategorie($articleCategorie->getCategorie());
  1131.                         foreach($caracteristiques as $car) {
  1132.                             if (array_key_exists('carac_'.$car->getId(), $postForm)) {
  1133.                               //echo "<div>okokokok ".$car->getLibelle()."==> ".$postForm['carac_'.$car->getId()]."</div>";
  1134.                               //carac_{{carac.id}}_libre
  1135.                               $valeur = $postForm['carac_'.$car->getId()];
  1136.                               if (array_key_exists('carac_'.$car->getId().'_libre', $postForm) && $postForm['carac_'.$car->getId().'_libre'] != "") {
  1137.                                   $valeur = $postForm['carac_'.$car->getId().'_libre'];
  1138.                               }
  1139.                               $articleMarketPlaceCaracteristique = new ArticleMarketPlaceCaracteristique();
  1140.                               $articleMarketPlaceCaracteristique->setValeur($valeur);
  1141.                               $articleMarketPlaceCaracteristique->setCaracteristique($car);
  1142.                               $articleMarketPlaceCaracteristique->setArticleMarketPlace($articleMarketPlace);
  1143.                               $em->persist($articleMarketPlaceCaracteristique);
  1144.                             }
  1145.                         }
  1146.                     }
  1147.                   }
  1148.                   */
  1149.                 $em->flush();
  1150.                 //Mise à jour de la couleur de ligne
  1151.                 //$article = $articleMarketPlace->getArticle();
  1152.                 //$couleur = $articleService->couleurLigne($article->getId());
  1153.                 //$article->setCouleurLigne($couleur);
  1154.                 //$em->persist($article);
  1155.                 $em->flush();
  1156.                 $erreur_construit "";
  1157.                 if ($erreur_image_annonce) {
  1158.                     $erreur_construit .= "<br/>Merci de choisir une image !";
  1159.                 }
  1160.                 if ($erreur_categorie_priceminister and != 1) {
  1161.                     $erreur_construit .= "<br/>Merci de choisir une catégorie market place !";
  1162.                 }
  1163.                 if (trim($articleMarketPlace->getPrixVente()) == "" or is_null(trim($articleMarketPlace->getPrixVente()))) {
  1164.                     $erreur_construit .= "<br/>Merci de définir un prix de vente !";
  1165.                 }
  1166.                 if ($erreur_sku_priceminister) {
  1167.                     $erreur_construit .= "<br/>Merci de définir un SKU !";
  1168.                 }
  1169.                 if ($erreur_sku_priceminister_existe) {
  1170.                     $erreur_construit .= "<br/>SKU (".$temp_sku.") non disponible, il déjà attribué à une autre offre ".$articleMarketPlace->getCompteMarketPlace()->getMarketPlace(
  1171.                         )->getLibelle()." !";
  1172.                 }
  1173.                 if ($erreur_sku_ean) {
  1174.                     $erreur_construit .= "<br/>Merci de définir un code EAN !";
  1175.                 }
  1176.                 if ($erreur_sku_ean_existe) {
  1177.                     $erreur_construit .= "<br/>Code EAN déja utilisé !";
  1178.                 }
  1179.                 if ($erreur_image) {
  1180.                     $erreur_construit .= "<br/>Merci d'uploader au moins une image !";
  1181.                 }
  1182.                 if (count($article->getArticleCategorie()) == and != 1) {
  1183.                     $erreur_construit .= "<br/>Merci de choisir une catégorie pour la fiche produit";
  1184.                 }
  1185.                 if ($articleMarketPlace->getLibelle() == "") {
  1186.                     $erreur_construit .= "<br/>Merci de définir un libellé";
  1187.                 }
  1188.                 if ($articleMarketPlace->getDescription() == "" and != 1) {
  1189.                     $erreur_construit .= "<br/>Merci de définir une description";
  1190.                 }
  1191.                 if ($erreur_construit == "") {
  1192.                     if ($articleMarketPlace->getAnnonceSupprime() == null or $articleMarketPlace->getAnnonceSupprime() == 0) {
  1193.                         $this->addFlash('notice''Offre modifiée avec succès !!');
  1194.                     }
  1195.                 } else {
  1196.                     $this->addFlash('warning'$erreur_construit);
  1197.                 }
  1198.                 //echo "amp==>".$articleMarketPlace->getId();
  1199.                 //exit;
  1200.                 //Mofifier les prix des autres annonces
  1201.                 $annoncesAmodifier $repo_article_market_place->findBy([
  1202.                                                                             'article'                  => $articleMarketPlace->getArticle(),
  1203.                                                                             'prixVente'                => null,
  1204.                                                                             'statutArticleMarketPlace' => null,
  1205.                                                                             'idImport'                 => null,
  1206.                                                                         ]);
  1207.                 if (count($annoncesAmodifier)) {
  1208.                     $prixVente $articleMarketPlace->getPrixVente();
  1209.                     foreach ($annoncesAmodifier as $annonceAmodifier) {
  1210.                         $annonceAmodifier->setPrixVente($prixVente);
  1211.                         $em->persist($annonceAmodifier);
  1212.                     }
  1213.                     $em->flush();
  1214.                 }
  1215.                 return $this->redirectToRoute(
  1216.                     'dtc_article_modifier',
  1217.                     ["id" => $article->getId(), 'amp' => $articleMarketPlace->getId(), 'tab' => "m".$articleMarketPlace->getCompteMarketPlace()->getId()]
  1218.                 );
  1219.             } else {
  1220.                 $errors $validator->validate($articleMarketPlace);
  1221.                 $this->addFlash('warning''formulaire non valide !');
  1222.                 foreach ($errors as $error) {
  1223.                     $this->addFlash('warning'$error);
  1224.                 }
  1225.                 //echo "HHHHH";
  1226.                 //\Doctrine\Common\Util\Debug::dump($errors);
  1227.                 //return $this->redirectToRoute('dtc_article_modifier',array("id"=>$article->getId(),'amp'=>$articleMarketPlace->getId() ,'tab'=>"m".$articleMarketPlace->getCompteMarketPlace()->getId()));
  1228.             }
  1229.         }
  1230.         if (array_key_exists('mp'$parametres) && $parametres["mp"] == $compteMarketPlace->getId() && is_object($articleMarketPlace->getArticleMarketPlaceParent())) {
  1231.             $this->datatableEnfants($datatable$articleMarketPlace$article);
  1232.         } else {
  1233.             $this->datatableEnfants($datatable$articleMarketPlace$article);
  1234.         }
  1235.         return $this->render('MarketPlace/ArticleMarketPlace/ajouter.html.twig', [
  1236.             'form'               => $form->createView(),
  1237.             "articleMarketPlace" => $articleMarketPlace,
  1238.             "article"            => $article,
  1239.             "compteMarketPlace"  => $compteMarketPlace,
  1240.             "parametres"         => $parametres,
  1241.             'renouvelable'       => $renouvelable,
  1242.             'termine'            => $termine,
  1243.         ]);
  1244.     }
  1245.     /**
  1246.      * @Route("/article/marketplace/enfants/grid/{id}/{article}", name="dtc_article_market_place_enfants_grid")
  1247.      */
  1248.     public function gridEnfantsAction(Request $requestCompteMarketPlace $compteMarketPlaceArticle $articleDatatable $datatable)
  1249.     {
  1250.         return $this->datatableEnfants($datatable$compteMarketPlace$article)->execute();
  1251.     }
  1252.     public function datatableEnfants(Datatable $datatable$compteMarketPlace$article)
  1253.     {
  1254.         $datatable->setDatatableId('dta-enfants-'.$compteMarketPlace->getId())
  1255.                   ->setEntity(ArticleMarketPlace::class, "x")
  1256.                   ->setFields(
  1257.                       [
  1258.                           "ID"             => 'x.id',
  1259.                           "Sku"            => 'x.sku',
  1260.                           "EAN"            => 'x.ean',
  1261.                           "Id Import"      => 'x.idImport',
  1262.                           "Libellé"        => 'x.libelle',
  1263.                           "Prix"           => 'x.prixVente',
  1264.                           "Stock"          => 'x.stock',
  1265.                           "En ligne"       => 'x.statut',
  1266.                           "En publication" => 'x.id',
  1267.                           "Langue"         => 'x.siteMarketPlace',
  1268.                           "Actions"        => 'x.id',
  1269.                           "_identifier_"   => 'x.id',
  1270.                       ]
  1271.                   )
  1272.                   ->addJoin('x.compteMarketPlace''cmp'\Doctrine\ORM\Query\Expr\Join::LEFT_JOIN)
  1273.                   ->addJoin('x.article''a'\Doctrine\ORM\Query\Expr\Join::LEFT_JOIN)
  1274.             //->addJoin('x.contact', 'c', \Doctrine\ORM\Query\Expr\Join::LEFT_JOIN)
  1275.                   ->setWhere(
  1276.                   'cmp.id = :compteMarketPlace and a.id = :article and (x.visible = 1 or x.visible is null) and (x.annonceSupprime = 0 or x.annonceSupprime is null) and x.articleMarketPlaceNouvelleAnnonce IS NULL'
  1277.                 , [
  1278.                       'compteMarketPlace' => $compteMarketPlace->getId(),
  1279.                       'article'           => $article->getId(),
  1280.                   ]
  1281.             )
  1282.             /*
  1283.                      ->setWhere(
  1284.                             '(x.articleMarketPlaceParent = :articleMarketPlaceParent or x.id = :articleMarketPlaceParent)'
  1285.                             ,array('articleMarketPlaceParent'=>$articleMarketPlaceParent)
  1286.                      )
  1287.                      */
  1288.                   ->setGroupBy('x.id')
  1289.                   ->setRenderers(
  1290.                       [
  1291.                           5  => [
  1292.                               'view'   => 'FO/DataTable/prix.html.twig',
  1293.                               'params' => [
  1294.                                   'edit_route'     => 'dtc_article_market_place_changer_statut_en_ligne',
  1295.                                   'afficher_total' => false,
  1296.                               ],
  1297.                           ],
  1298.                           7  => [
  1299.                               'view'   => 'FO/DataTable/statut_id_import.html.twig',
  1300.                               'params' => [
  1301.                                   'edit_route' => 'dtc_article_market_place_changer_statut_en_ligne',
  1302.                               ],
  1303.                           ],
  1304.                           8  => [
  1305.                               'view'   => 'FO/DataTable/statut_publication_article_market_place.html.twig',
  1306.                               'params' => [
  1307.                                   //'edit_route'    => 'dtc_erreur_article_market_place_changer_statut',
  1308.                                   'edit_route' => 'dtc_article_market_place_changer_statut',
  1309.                                   //'compteMarketPlaceId' => 5
  1310.                               ],
  1311.                           ],
  1312.                           9  => ['view' => 'FO/DataTable/siteMarketPlace.html.twig'],
  1313.                           10 => [
  1314.                               'view'   => 'FO/DataTable/actions_article_market_place.html.twig',
  1315.                               'params' => [
  1316.                                   // 'edit_route'  => 'dtc_market_place_modifier_modal',
  1317.                                   'supprimer_route'  => 'dtc_article_market_place_supprimer',
  1318.                                   'historique_route' => 'dtc_article_market_place_historique',
  1319.                                   'deplacer_route'   => 'dtc_article_market_place_historique',
  1320.                                   'table'            => 'dta-enfants-'.$compteMarketPlace->getId(),
  1321.                                   // 'id'    => $objet->getId(),
  1322.                                   // 'type'    => $type,
  1323.                                   // 'entite'    => 'adresse',
  1324.                                   // 'objet' => "DTCMarketPlaceBundle:ArticleMarketPlace"
  1325.                               ],
  1326.                           ],
  1327.                           /*
  1328.                             1 => array(
  1329.                                 'view' => 'FO/DataTable/actions_modal.html.twig',
  1330.                                 'params' => array(
  1331.                                         'edit_route'  => 'dtc_note_modifier',
  1332.                                         'supprimer_route'  => 'dtc_note_supprimer',
  1333.                                         'id'    => $client->getId(),
  1334.                                         'type'    => "client",
  1335.                                         'objet'    => "DTCClientsBundle:Note",
  1336.                                         'width_modal'    => 900,
  1337.                                     ),
  1338.                             ),
  1339.                             */
  1340.                       ]
  1341.                   )
  1342.             //->setOrder("x.dateSaisie", "desc")
  1343.                   ->setSearch(true)
  1344.                   ->setSearchFields([12])/*
  1345.                      ->setMultiple(
  1346.                         array(
  1347.                             'delete' => array(
  1348.                                 'title' => 'Dupliquer',
  1349.                                 'route' => 'dtc_article_market_place_dupliquer'
  1350.                             ),
  1351.                         )
  1352.                     )
  1353.                     */
  1354.         ;
  1355.         //$where = "x.client = :client AND (x.prive = :prive OR x.prive IS NULL or x.utilisateur = :utilisateur)";
  1356.         //$parameters = array("prive"=>0,"utilisateur"=>$user,'client'=>$client);
  1357.         //$datatable->setWhere($where, $parameters);
  1358.         return $datatable;
  1359.     }
  1360.     /**
  1361.      * @Route("/article/marketplace/actiondupliquer", name="dtc_article_market_place_action_dupliquer")
  1362.      */
  1363.     public function dupliquerAction(Request $request)
  1364.     {
  1365.         return new JsonResponse(['type' => 'dupliquer''valide' => '1']);
  1366.     }
  1367.     /**
  1368.      * @Route("/article/marketplace/dupliquer", name="dtc_article_market_place_dupliquer")
  1369.      */
  1370.     public function dupliquerModalAction(Request $requestEntityManagerInterface $emValidatorInterface $validatorArticleMarketPlaceService $service_article_market_place)
  1371.     {
  1372.         $titre_modal                      "Duplication d'annonces";
  1373.         $user                             $this->getUser();
  1374.         $articleMarketPlace               = new ArticleMarketPlace;
  1375.         $get                              $request->query->all();
  1376.         $repo_article_market_place        $em->getRepository(ArticleMarketPlace::class);
  1377.         $repo_article_market_place_image  $em->getRepository(ArticleMarketPlaceImage::class);
  1378.         $repo_statut_article_market_place $em->getRepository(StatutArticle::class);
  1379.         $repo_compte_market_place         $em->getRepository(CompteMarketPlace::class);
  1380.         $repo_article_categorie           $em->getRepository(ArticleCategorie::class);
  1381.         $repo_article_market_place_caracteristique $em->getRepository(ArticleMarketPlaceCaracteristique::class);
  1382.         $nb_en_publications   "0";
  1383.         $annonces_a_dupliquer $repo_article_market_place->getAnnoncesIn($get["ids"]);
  1384.         $comptes_market_place $repo_compte_market_place->findAll();
  1385.         $nbAnnoncesCrees 0;
  1386.         $marketCourant   "";
  1387.         $article "";
  1388.         foreach ($annonces_a_dupliquer as $a) {
  1389.             $article       $a->getArticle();
  1390.             $marketCourant $a->getCompteMarketPlace();
  1391.             break;
  1392.         }
  1393.         //print_r($get["ids"]);
  1394.         $form   $this->createForm(DupliquerArticleMarketPlaceType::class, $articleMarketPlace);
  1395.         $errors "";
  1396.         $form->handleRequest($request);
  1397.         if ($form->isSubmitted()) {
  1398.             $post        $request->request->all();
  1399.             $dateAnnonce = new \Datetime();
  1400.             $listeCompteMarketPlaceId $post["compteMarketPlace"];
  1401.             if ($form->isValid()) {
  1402.                 $repo_ean $em->getRepository(Ean::class);
  1403.                 $construction_erreur   = [];
  1404.                 $creation_erreur       = [];
  1405.                 $statutAPublierAnnonce $repo_statut_article_market_place->find(1);
  1406.                 for ($o 0$o count($listeCompteMarketPlaceId); $o++) {
  1407.                     $compteMarketPlaceDestination $repo_compte_market_place->find($listeCompteMarketPlaceId[$o]);
  1408.                     foreach ($annonces_a_dupliquer as $a) {
  1409.                         $erreur_categorie   true;
  1410.                         $erreur_image       true;
  1411.                         $erreur_libelle     false;
  1412.                         $erreur_description false;
  1413.                         $erreur_prix        false;
  1414.                         $erreur_ean         false;
  1415.                         $erreur_stock       false;
  1416.                         if ($a->getLibelle() == "") {
  1417.                             $erreur_libelle true;
  1418.                         }
  1419.                         if ($a->getDescription() == "") {
  1420.                             $erreur_description true;
  1421.                         }
  1422.                         if ($a->getPrixVente() == "") {
  1423.                             $erreur_prix true;
  1424.                         }
  1425.                         if ($a->getStock() == "") {
  1426.                             $erreur_stock true;
  1427.                         }
  1428.                         $images $repo_article_market_place_image->findBy(["articleMarketPlace" => $a]);
  1429.                         if (count($images) > 0) {
  1430.                             foreach ($images as $i) {
  1431.                                 $erreur_image false;
  1432.                             }
  1433.                         }
  1434.                         $categorie_annonce $repo_article_categorie->findBy(["article" => $article"marketPlace" => $compteMarketPlaceDestination->getMarketPlace()]);
  1435.                         if (count($categorie_annonce) > 0) {
  1436.                             foreach ($categorie_annonce as $categ) {
  1437.                                 $erreur_categorie false;
  1438.                             }
  1439.                         }
  1440.                         if ($erreur_categorie) {
  1441.                             $annonce_du_compte_destination $repo_article_market_place->findBy(["article" => $article"compteMarketPlace" => $compteMarketPlaceDestination]);
  1442.                             if (count($annonce_du_compte_destination) > 0) {
  1443.                                 foreach ($annonce_du_compte_destination as $andc) {
  1444.                                     if (count($andc->getArticleCategorie()) > 0) {
  1445.                                         $erreur_categorie false;
  1446.                                         break;
  1447.                                     }
  1448.                                 }
  1449.                             }
  1450.                         }
  1451.                         if ( ! $erreur_categorie && ! $erreur_image && ! $erreur_libelle && ! $erreur_description && ! $erreur_prix && ! $erreur_stock) {
  1452.                             $a_au_moins_une_image     false;
  1453.                             $a_au_moins_une_categorie false;
  1454.                             $article                    $a->getArticle();
  1455.                             $articleMarketPlaceDuplique = new ArticleMarketPlace;
  1456.                             if ($article->getCodeProduit() != "") {
  1457.                                 $skuGen         "AMA".$compteMarketPlaceDestination->getId().str_replace(" """$article->getCodeProduit());
  1458.                                 $testAnnonceSku $repo_article_market_place->findOneBy(["article" => $article"compteMarketPlace" => $compteMarketPlaceDestination"sku" => $skuGen]);
  1459.                                 if ( ! is_object($testAnnonceSku)) {
  1460.                                     $articleMarketPlaceDuplique->setSku($skuGen);
  1461.                                 } else {
  1462.                                     for ($l 1$l <= 100$l++) {
  1463.                                         $skuGen         "AMA".$compteMarketPlaceDestination->getId().str_replace(" """$article->getCodeProduit());
  1464.                                         $skuGen         .= "/".$l;
  1465.                                         $testAnnonceSku $repo_article_market_place->findOneBy(
  1466.                                             ["article" => $article"compteMarketPlace" => $compteMarketPlaceDestination"sku" => $skuGen]
  1467.                                         );
  1468.                                         if ( ! is_object($testAnnonceSku)) {
  1469.                                             $articleMarketPlaceDuplique->setSku($skuGen);
  1470.                                             break;
  1471.                                         }
  1472.                                     }
  1473.                                 }
  1474.                             }
  1475.                             $articleMarketPlaceDuplique->setLibelle($a->getLibelle());
  1476.                             $description $a->getDescription();
  1477.                             if ($compteMarketPlaceDestination->getId() == "1") {
  1478.                                 $description $service_article_market_place->formatTexteAnnonceEbay($description);
  1479.                                 $articleMarketPlaceDuplique->setRenouvellementAuto(1);
  1480.                             }
  1481.                             $articleMarketPlaceDuplique->setDescription($description);
  1482.                             $articleMarketPlaceDuplique->setPrixVente($a->getPrixVente());
  1483.                             $articleMarketPlaceDuplique->setPrixVente($a->getPrixVente());
  1484.                             $articleMarketPlaceDuplique->setStock(100);
  1485.                             $articleMarketPlaceDuplique->setDate($dateAnnonce);
  1486.                             $articleMarketPlaceDuplique->setStatut($a->getStatut());
  1487.                             $articleMarketPlaceDuplique->setVisible($a->getVisible());
  1488.                             $articleMarketPlaceDuplique->setEnvoyerImageAmazon(0);
  1489.                             $articleMarketPlaceDuplique->setArticle($article);
  1490.                             $articleMarketPlaceDuplique->setCompteMarketPlace($compteMarketPlaceDestination);
  1491.                             $ean $repo_ean->findOneBy(['libre' => true]);
  1492.                             if (is_object($ean)) {
  1493.                                 $articleMarketPlaceDuplique->setEan($ean->getCode());
  1494.                                 $articleMarketPlaceDuplique->setEanObjet($ean);
  1495.                                 $ean->setLibre(false);
  1496.                                 $em->persist($ean);
  1497.                             }
  1498.                             $nbAnnoncesCrees++;
  1499.                             $em->persist($articleMarketPlaceDuplique);
  1500.                             $em->flush();
  1501.                             $em->refresh($articleMarketPlaceDuplique);
  1502.                             $images $repo_article_market_place_image->findBy(["articleMarketPlace" => $a]);
  1503.                             if (count($images) > 0) {
  1504.                                 foreach ($images as $i) {
  1505.                                     $a_au_moins_une_image    true;
  1506.                                     $articleMarketPlaceImage = new ArticleMarketPlaceImage();
  1507.                                     $articleMarketPlaceImage->setImage($i->getImage());
  1508.                                     $articleMarketPlaceImage->setOrdre($i->getOrdre());
  1509.                                     $articleMarketPlaceImage->setArticleMarketPlace($articleMarketPlaceDuplique);
  1510.                                     $articleMarketPlaceImage->setDate($dateAnnonce);
  1511.                                     $em->persist($articleMarketPlaceImage);
  1512.                                 }
  1513.                             }
  1514.                             $em->flush();
  1515.                             $categorie_annonce $repo_article_categorie->findBy(["article" => $article"marketPlace" => $compteMarketPlaceDestination->getMarketPlace()]);
  1516.                             if (count($categorie_annonce) > 0) {
  1517.                                 foreach ($categorie_annonce as $categ) {
  1518.                                     $a_au_moins_une_categorie true;
  1519.                                     $articleCategorie         = new ArticleCategorie();
  1520.                                     $articleCategorie->setArticleMarketPlace($articleMarketPlaceDuplique);
  1521.                                     $articleCategorie->setCategorie($categ->getCategorie());
  1522.                                     $em->persist($articleCategorie);
  1523.                                 }
  1524.                             }
  1525.                             if ( ! $a_au_moins_une_categorie) {
  1526.                                 $annonce_du_compte_destination $repo_article_market_place->findBy(["article" => $article"compteMarketPlace" => $compteMarketPlaceDestination]);
  1527.                                 if (count($annonce_du_compte_destination) > 0) {
  1528.                                     foreach ($annonce_du_compte_destination as $andc) {
  1529.                                         if (count($andc->getArticleCategorie()) > 0) {
  1530.                                             $a_au_moins_une_categorie true;
  1531.                                             foreach ($andc->getArticleCategorie() as $categ) {
  1532.                                                 $a_au_moins_une_categorie true;
  1533.                                                 $articleCategorie         = new ArticleCategorie();
  1534.                                                 $articleCategorie->setArticleMarketPlace($articleMarketPlaceDuplique);
  1535.                                                 $articleCategorie->setCategorie($categ->getCategorie());
  1536.                                                 $em->persist($articleCategorie);
  1537.                                             }
  1538.                                             break;
  1539.                                         }
  1540.                                     }
  1541.                                 }
  1542.                             }
  1543.                             $caracteristiques $repo_article_market_place_caracteristique->findBy(["article" => $article]);
  1544.                             if (count($caracteristiques) > 0) {
  1545.                                 foreach ($caracteristiques as $cara) {
  1546.                                     $articleMarketPlaceCaracteristique = new ArticleMarketPlaceCaracteristique();
  1547.                                     $articleMarketPlaceCaracteristique->setCaracteristique($cara->getCaracteristique());
  1548.                                     $articleMarketPlaceCaracteristique->setValeur($cara->getValeur());
  1549.                                     $articleMarketPlaceCaracteristique->setArticleMarketPlace($articleMarketPlaceDuplique);
  1550.                                     $em->persist($articleMarketPlaceCaracteristique);
  1551.                                 }
  1552.                             }
  1553.                             $em->flush();
  1554.                             $sans_erreur              true;
  1555.                             $construction_erreur_temp "";
  1556.                             if ( ! $a_au_moins_une_categorie) {
  1557.                                 $sans_erreur              false;
  1558.                                 $construction_erreur_temp .= "<div>Catégorie manquante</div>";
  1559.                             }
  1560.                             if ( ! $a_au_moins_une_image) {
  1561.                                 $sans_erreur              false;
  1562.                                 $construction_erreur_temp .= "<div>Image manquante</div>";
  1563.                             }
  1564.                             if ($articleMarketPlaceDuplique->getLibelle() == "") {
  1565.                                 $sans_erreur              false;
  1566.                                 $construction_erreur_temp .= "<div>Libellé manquant</div>";
  1567.                             }
  1568.                             if ($articleMarketPlaceDuplique->getDescription() == "") {
  1569.                                 $sans_erreur              false;
  1570.                                 $construction_erreur_temp .= "<div>Description manquante</div>";
  1571.                             }
  1572.                             if ($articleMarketPlaceDuplique->getPrixVente() == "") {
  1573.                                 $sans_erreur              false;
  1574.                                 $construction_erreur_temp .= "<div>Prix de vente manquant</div>";
  1575.                             }
  1576.                             if ($articleMarketPlaceDuplique->getEan() == "") {
  1577.                                 $sans_erreur              false;
  1578.                                 $construction_erreur_temp .= "<div>Ean manquant</div>";
  1579.                             }
  1580.                             if ($articleMarketPlaceDuplique->getStock() == "") {
  1581.                                 $sans_erreur              false;
  1582.                                 $construction_erreur_temp .= "<div>Stock manquant</div>";
  1583.                             }
  1584.                             if ($construction_erreur_temp != "") {
  1585.                                 $construction_erreur[$articleMarketPlaceDuplique->getId()] = $construction_erreur_temp;
  1586.                             }
  1587.                             if ($sans_erreur && ($articleMarketPlaceDuplique->getVisible() or is_null($articleMarketPlaceDuplique->getVisible()))) {
  1588.                                 $articleMarketPlaceDuplique->setDateDemandePublicationMarketPlace($dateAnnonce);
  1589.                                 $articleMarketPlaceDuplique->setStatutArticleMarketPlace($statutAPublierAnnonce);
  1590.                                 $em->persist($articleMarketPlaceDuplique);
  1591.                                 $nb_en_publications++;
  1592.                             }
  1593.                             $em->flush();
  1594.                         } else {
  1595.                             $construction_erreur_temp "";
  1596.                             if ($erreur_categorie) {
  1597.                                 $sans_erreur              false;
  1598.                                 $construction_erreur_temp .= "<div>Catégorie manquante</div>";
  1599.                             }
  1600.                             if ($erreur_image) {
  1601.                                 $sans_erreur              false;
  1602.                                 $construction_erreur_temp .= "<div>Image manquante</div>";
  1603.                             }
  1604.                             if ($erreur_libelle) {
  1605.                                 $sans_erreur              false;
  1606.                                 $construction_erreur_temp .= "<div>Libellé manquant</div>";
  1607.                             }
  1608.                             if ($erreur_description) {
  1609.                                 $sans_erreur              false;
  1610.                                 $construction_erreur_temp .= "<div>Description manquante</div>";
  1611.                             }
  1612.                             if ($erreur_prix) {
  1613.                                 $sans_erreur              false;
  1614.                                 $construction_erreur_temp .= "<div>Prix de vente manquant</div>";
  1615.                             }
  1616.                             if ($erreur_stock) {
  1617.                                 $sans_erreur              false;
  1618.                                 $construction_erreur_temp .= "<div>Stock manquant</div>";
  1619.                             }
  1620.                             if ($construction_erreur_temp != "") {
  1621.                                 if (array_key_exists($a->getId(), $creation_erreur)) {
  1622.                                     $creation_erreur[$a->getId()] .= "Impossible de dupliquer l'offre ".$a->getSku()." pour le market place ".$compteMarketPlaceDestination->getLibelle(
  1623.                                         )." ".$construction_erreur_temp;
  1624.                                 } else {
  1625.                                     $creation_erreur[$a->getId()] = "Impossible de dupliquer l'offre ".$a->getSku()." pour le market place ".$compteMarketPlaceDestination->getLibelle(
  1626.                                         )." ".$construction_erreur_temp;
  1627.                                 }
  1628.                             }
  1629.                         }
  1630.                     }
  1631.                 }
  1632.                 //echo "<div>NEW ANNONCE ID ".$articleMarketPlaceDuplique->getId()."</div>";
  1633.                 $messageErreur "";
  1634.                 if (count($construction_erreur) > 0) {
  1635.                     $messageErreur "";
  1636.                     foreach ($construction_erreur as $key => $value) {
  1637.                         $messageErreur .= "<div>Impossible de lancer la publication de la nouvelle offre id : ".$key."</div>";
  1638.                         $messageErreur .= $value;
  1639.                     }
  1640.                 }
  1641.                 if (count($creation_erreur) > 0) {
  1642.                     $messageErreur "";
  1643.                     foreach ($creation_erreur as $key => $value) {
  1644.                         //$messageErreur .= "<div>Impossible de lancer la publication de la nouvelle annonce id : ".$key."</div>";
  1645.                         $messageErreur .= $value;
  1646.                     }
  1647.                 }
  1648.                 if ($messageErreur != "") {
  1649.                     $this->addFlash(
  1650.                         'warning',
  1651.                         $messageErreur
  1652.                     );
  1653.                 }
  1654.                 $this->addFlash(
  1655.                     'notice',
  1656.                     $nbAnnoncesCrees.' offre(s) créées avec succès ! '.$nb_en_publications.' sont en cours de publication'
  1657.                 );
  1658.                 $url $this->generateUrl('dtc_article_modifier', ['id' => $article->getId()]);
  1659.                 return new JsonResponse(['rendu' => '''valide' => '1''url' => $url]);
  1660.             } else {
  1661.                 $errors $validator->validate($articleMarketPlace);
  1662.                 $rendu  $this->renderView(
  1663.                     'MarketPlace/ArticleMarketPlace/dupliquer.html.twig',
  1664.                     [
  1665.                         'marketCourant'        => $marketCourant,
  1666.                         'comptes_market_place' => $comptes_market_place,
  1667.                         'annonces_a_dupliquer' => $annonces_a_dupliquer,
  1668.                         'form'                 => $form->createView(),
  1669.                         'errors'               => $errors,
  1670.                         'type'                 => '',
  1671.                         'objet'                => '',
  1672.                     ]
  1673.                 );
  1674.                 return new JsonResponse(['rendu' => $rendu'valide' => '0''url' => '''titre' => $titre_modal]);
  1675.             }
  1676.         }
  1677.         $rendu $this->renderView(
  1678.             'MarketPlace/ArticleMarketPlace/dupliquer.html.twig',
  1679.             [
  1680.                 'marketCourant'        => $marketCourant,
  1681.                 'comptes_market_place' => $comptes_market_place,
  1682.                 'annonces_a_dupliquer' => $annonces_a_dupliquer,
  1683.                 'form'                 => $form->createView(),
  1684.                 'errors'               => $errors,
  1685.                 'type'                 => '',
  1686.                 'objet'                => '',
  1687.             ]
  1688.         );
  1689.         return new JsonResponse(['rendu' => $rendu'valide' => '0''url' => '''titre' => $titre_modal]);
  1690.     }
  1691.     /**
  1692.      * @Route("", name="")
  1693.      */
  1694.     public function modifierAction(Request $requestMarketPlace $marketPlaceEntityManagerInterface $emValidatorInterface $validator)
  1695.     {
  1696.         $user $this->getUser();
  1697.         $marketPlace->setUtilisateur($user);
  1698.         $form   $this->createForm(MarketPlaceType::class, $marketPlace);
  1699.         $errors "";
  1700.         $form->handleRequest($request);
  1701.         if ($form->isSubmitted()) {
  1702.             $droit $this->isGranted(EntityVoter::UPDATEMarketPlace::class);
  1703.             if ( ! $droit) {
  1704.                 return $this->redirectToRoute('dtc_market_place_modifier', ["id" => $marketPlace->getId()]);
  1705.             }
  1706.             if ($form->isValid()) {
  1707.                 $em->persist($marketPlace);
  1708.                 $em->flush();
  1709.                 $em->flush();
  1710.                 $this->addFlash(
  1711.                     'notice',
  1712.                     'Market Place modifié avec succès !'
  1713.                 );
  1714.                 return $this->redirectToRoute('dtc_market_place_modifier', ["id" => $marketPlace->getId()]);
  1715.             } else {
  1716.                 $errors $validator->validate($marketPlace);
  1717.             }
  1718.         }
  1719.         return $this->render('MarketPlace/MarketPlace/ajouter.html.twig', ['form' => $form->createView(), 'errors' => $errors'marketPlace' => $marketPlace]);
  1720.     }
  1721.     /**
  1722.      * @Route("/marketplace/description", name="dtc_market_place_supprimer_description")
  1723.      */
  1724.     public function SupprimerDescriptionAction(Request $requestEntityManagerInterface $em)
  1725.     {
  1726.         $repo_article_market_place $em->getRepository(ArticleMarketPlace::class);
  1727.         $repoArticle               $em->getRepository(Article::class);
  1728.         $Articles                  $repoArticle->findBy(['mouvemente' => 1]);
  1729.         //$MKArticles = $repoArticle->findAll();
  1730.         $compte 0;
  1731.         $String "MODES DE PAIEMENTS PAYPAL Nous acceptons les paiements par PAYPAL.Le paiement doit &ecirc;tre effectu&eacute; dans 7 jours apr&egrave;s l'ench&egrave;re soit finie. CHEQUE BANCAIRE Nous acceptons les paiements par CHEQUE BANCAIRE.Nos coordonn&eacute;es sont visible sur le r&eacute;capitulatif de la vente. VIREMENT BANCAIRE Nous acceptons les paiements par VIREMENT BANCAIRE. Nos coordonn&eacute;es bancaires vous seront envoy&eacute;s sur simple demande. AUTRES, NOUS CONSULTER Tous nos produits sont neuf dans leurs emballages d'origine Exp&eacute;dition en colissimo suivi 48 /72 Heures d&egrave;s r&eacute;ception de votre paiement. Nous fournissons facture et documents de garantie (si l'objet est garantie) Cr&eacute;&eacute; par eBay Turbo Lister L'outil de mise en vente gratuit. Mettez vos objets en vente rapidement et en toute simplicit&eacute;, et g&eacute;rez vos annonces en cours.";
  1732.         foreach ($Articles as $Article) {
  1733.             $description null;
  1734.             $description str_replace($String""$Article->getDescription());
  1735.             $Article->setDescription($description);
  1736.             if ($description != null) {
  1737.                 $compte += 1;
  1738.                 $em->persist($Article);
  1739.             }
  1740.         }
  1741.         $em->flush();
  1742.         return new Response($compte);
  1743.     }
  1744.     /**
  1745.      * @Route("/marketplace/commentaire/scan", name="dtc_market_scan_commentaire")
  1746.      */
  1747.     public function ScanCommentaireAction(Request $requestEntityManagerInterface $em)
  1748.     {
  1749.         $idAnnonce trim($request->query->get('annonce'));
  1750.         //$repoMK_Article = $em->getRepository('DTCMarketPlaceBundle:ArticleMarketPlace');
  1751.         //$repoArticle = $em->getRepository('DTCArticlesBundle:Article');
  1752.         $repoMK_Article $em->getRepository(ArticleMarketPlace::class);
  1753.         if ($request->isMethod('POST')) {
  1754.             if ($idAnnonce != "") {
  1755.                 $commentaire $request->get('texte');
  1756.                 $commentaire str_replace(" ""&nbsp;"$commentaire);
  1757.                 $articleMK $repoMK_Article->find($idAnnonce);
  1758.                 if (is_object($articleMK) and is_object($articleMK->getArticle())) {
  1759.                     $articleMK->setCommentaire(nl2br($commentaire));
  1760.                     $em->persist($articleMK);
  1761.                     $em->flush();
  1762.                 }
  1763.                 $em->flush();
  1764.                 $this->addFlash(
  1765.                     'notice',
  1766.                     'Commentaire enregistré'
  1767.                 );
  1768.                 return $this->redirectToRoute('dtc_market_scan_commentaire', []);
  1769.             } else {
  1770.                 $article     trim($request->get('articlescan'));
  1771.                 $commentaire $request->get('commentaire');
  1772.                 $nbArticleMK $repoMK_Article->findBy(['idImport' => $article]);
  1773.                 if (count($nbArticleMK) > 1) {
  1774.                     $message_erreur "Plusieurs annonces correspondent à cette référence : ".$article;
  1775.                     return $this->render('GestionComerciale/Annonce/ScanCommentaire.html.twig', ['erreur' => $message_erreur]);
  1776.                 }
  1777.                 $articleMK $repoMK_Article->findOneBy(['idImport' => $article]);
  1778.                 if ($article == "") {
  1779.                     return $this->render('GestionComerciale/Annonce/ScanCommentaire.html.twig', ['erreur' => "Id import non reconnu"]);
  1780.                 }
  1781.                 if ($articleMK == null) {
  1782.                     $articleMK $repoMK_Article->findOneBy(['idImport' => $article]);
  1783.                     if ($articleMK == null) {
  1784.                         return $this->render('GestionComerciale/Annonce/ScanCommentaire.html.twig', ['erreur' => "Annonce inconnue"]);
  1785.                     }
  1786.                 }
  1787.                 $commentaire $articleMK->getCommentaire();
  1788.                 $commentaire str_replace("&nbsp;"" "$commentaire);
  1789.                 return $this->redirectToRoute('dtc_market_scan_commentaire', ["annonceObj" => $articleMK"annonce" => $articleMK->getId(), "commentaire" => $commentaire]);
  1790.             }
  1791.             //$articleMK->setPointageAmazon(1);
  1792.             //$articleMK->setDatePointage(new \Datetime());
  1793.             //$em->persist($articleMK);
  1794.             /*
  1795.             $em->flush();
  1796.             $this->addFlash(
  1797.                     'notice',
  1798.                     'Article pointé'
  1799.             );
  1800.             */
  1801.             return $this->render('GestionComerciale/Annonce/ScanCommentaire.html.twig', ['erreur' => ""]);
  1802.         } else {
  1803.             if ($idAnnonce != "") {
  1804.                 $articleMK $repoMK_Article->find($idAnnonce);
  1805.                 if (is_object($articleMK)) {
  1806.                     return $this->render(
  1807.                         'GestionComerciale/Annonce/ScanCommentaire.html.twig',
  1808.                         ["annonceObj" => $articleMK'erreur' => """annonce" => $articleMK->getId(), "commentaire" => $articleMK->getCommentaire()]
  1809.                     );
  1810.                     //return $this->redirectToRoute('dtc_market_scan_commentaire',array("annonce"=>$articleMK->getId(),"commentaire"=>$articleMK->getArticle()->getCommentairePonctuel()));
  1811.                 } else {
  1812.                     //return $this->redirectToRoute('dtc_market_scan_commentaire',array());
  1813.                 }
  1814.             } else {
  1815.                 return $this->render('GestionComerciale/Annonce/ScanCommentaire.html.twig', ['erreur' => ""]);
  1816.             }
  1817.         }
  1818.     }
  1819.     /**
  1820.      * @Route("/marketplace/amazon/scan", name="dtc_market_scan_amazon")
  1821.      */
  1822.     public function ScanAmazonAction(Request $requestEntityManagerInterface $em)
  1823.     {
  1824.         //$repoMK_Article = $em->getRepository('DTCMarketPlaceBundle:ArticleMarketPlace');
  1825.         //$repoArticle = $em->getRepository('DTCArticlesBundle:Article');
  1826.         if ($request->isMethod('POST')) {
  1827.             $article        $request->get('articlescan');
  1828.             $repoMK_Article $em->getRepository(ArticleMarketPlace::class);
  1829.             $repoArticle    $em->getRepository(Article::class);
  1830.             $repoCompteMK   $em->getRepository(CompteMarketPlace::class);
  1831.             $Amazon         $repoCompteMK->findOneBy(['id' => 3]);
  1832.             $articleMK $repoMK_Article->findOneBy(['idImport' => $article'compteMarketPlace' => $Amazon]);
  1833.             if ($article == "") {
  1834.                 return $this->render('GestionComerciale/Annonce/ScanAmazon.html.twig', ['erreur' => "Id import non reconnu"]);
  1835.             }
  1836.             if ($articleMK == null) {
  1837.                 $articleMK $repoMK_Article->findOneBy(['idImport' => $article]);
  1838.                 if ($articleMK == null) {
  1839.                     return $this->render('GestionComerciale/Annonce/ScanAmazon.html.twig', ['erreur' => "Annonce inconnue"]);
  1840.                 }
  1841.                 if ($articleMK->getCompteMarketPlace()->getId() != 3) {
  1842.                     return $this->render('GestionComerciale/Annonce/ScanAmazon.html.twig', ['erreur' => "Cette annonce n'est pas un produit Amazon"]);
  1843.                 }
  1844.             }
  1845.             if ($articleMK->getPointageAmazon() == 1) {
  1846.                 return $this->render(
  1847.                     'GestionComerciale/Annonce/ScanAmazon.html.twig',
  1848.                     [
  1849.                         'erreur' => "Cette annonce a été pointée le ".date_format($articleMK->getDatePointage(), 'd-m-Y')." à ".date_format(
  1850.                                 $articleMK->getDatePointage(),
  1851.                                 'H:i'
  1852.                             ),
  1853.                     ]
  1854.                 );
  1855.             }
  1856.             $articleMK->setPointageAmazon(1);
  1857.             $articleMK->setDatePointage(new \Datetime());
  1858.             $em->persist($articleMK);
  1859.             $em->flush();
  1860.             $this->addFlash(
  1861.                 'notice',
  1862.                 'Produit pointé'
  1863.             );
  1864.             return $this->render('GestionComerciale/Annonce/ScanAmazon.html.twig', ['erreur' => ""]);
  1865.         } else {
  1866.             return $this->render('GestionComerciale/Annonce/ScanAmazon.html.twig', ['erreur' => ""]);
  1867.         }
  1868.     }
  1869.     /**
  1870.      * @Route("/marketplace/annuler/{id}", name="dtc_depointage")
  1871.      */
  1872.     public function DepointageAction(Request $requestEntityManagerInterface $em)
  1873.     {
  1874.         $articleMK $request->get('id');
  1875.         $repoMK_Article $em->getRepository(ArticleMarketPlace::class);
  1876.         $annonce        $repoMK_Article->findOneBy(['id' => $articleMK]);
  1877.         $annonce->setPointageAmazon(null);
  1878.         $em->persist($annonce);
  1879.         $em->flush();
  1880.         $this->addFlash(
  1881.             'notice',
  1882.             "l'article Amazon est dépointé"
  1883.         );
  1884.         return $this->redirecttoRoute('dtc_article_modifier', ['id' => $annonce->getArticle()->getId()]);
  1885.     }
  1886.     /**
  1887.      * @Route("/annonce/supprimer/{id}/{market}", name="dtc_article_market_place_supprimer")
  1888.      */
  1889.     public function supprimerAction(Request                   $requestArticleMarketPlace $articleMarketPlace$marketEntityManagerInterface $emValidatorInterface $validator,
  1890.                                     ArticleMarketPlaceService $service_article_market_place
  1891.     ) {
  1892.         $titre_modal "Demande de confirmation ";
  1893.         $user        $this->getUser();
  1894.         $get         $request->query->all();
  1895.         $form        $this->createForm(SupprimerArticleMarketPlaceType::class, $articleMarketPlace);
  1896.         $errors      "";
  1897.         $form->handleRequest($request);
  1898.         $messageModal "Attention : Cette suppression n'entraine pas la suppression de l'offre auprès du market place ! <br/><br/>Confirmez la suppression ?";
  1899.         if ($form->isSubmitted()) {
  1900.             if ($form->isValid()) {
  1901.                 $articleMarketPlace->setAnnonceSupprime(true);
  1902.                 $articleMarketPlace->setStatutArticleMarketPlace(null);
  1903.                 $articleMarketPlace->setDateSuppression(new \Datetime());
  1904.                 $em->persist($articleMarketPlace);
  1905.                 $em->flush();
  1906.                 $service_article_market_place->creerHistorique($articleMarketPlace13$message = []);
  1907.                 $url $this->generateUrl('dtc_article_modifier', ['id' => $articleMarketPlace->getArticle()->getId(), 'tab' => 'm'.$market]);
  1908.                 if (array_key_exists('table'$get) && $get["table"] != "") {
  1909.                     $url "";
  1910.                     return new JsonResponse(['rendu' => '''valide' => '1''url' => $url'type' => 'recharger_datatable''id_datatable' => $get["table"]]);
  1911.                 } else {
  1912.                     $this->addFlash('notice''Offre supprimée avec succès !');
  1913.                     return new JsonResponse(['rendu' => '''valide' => '1''url' => ''], 200, ['Content-Type' => 'application/json']);
  1914.                 }
  1915.             } else {
  1916.                 $errors $validator->validate($articleMarketPlace);
  1917.                 $rendu  $this->renderView(
  1918.                     'FO/Supprimer/supprimer.html.twig',
  1919.                     [
  1920.                         'messageModal' => $messageModal,
  1921.                         'form'         => $form->createView(),
  1922.                         'errors'       => $errors,
  1923.                         'id'           => $articleMarketPlace->getArticle()->getId(),
  1924.                         'type'         => '',
  1925.                         'objet'        => '',
  1926.                     ]
  1927.                 );
  1928.                 return new JsonResponse(['rendu' => $rendu'valide' => '0''url' => '''titre' => $titre_modal]);
  1929.             }
  1930.         }
  1931.         $rendu $this->renderView(
  1932.             'FO/Supprimer/supprimer.html.twig',
  1933.             [
  1934.                 'messageModal' => $messageModal,
  1935.                 'form'         => $form->createView(),
  1936.                 'errors'       => $errors,
  1937.                 'id'           => $articleMarketPlace->getArticle()->getId(),
  1938.                 'type'         => '',
  1939.                 'objet'        => '',
  1940.             ]
  1941.         );
  1942.         return new JsonResponse(['rendu' => $rendu'valide' => '0''url' => '''titre' => $titre_modal]);
  1943.     }
  1944.     /**
  1945.      * @Route("/article/marketplace/stock/{id}", name="dtc_article_market_place_stock")
  1946.      */
  1947.     public function stockAction(Request $requestArticle $articleEntityManagerInterface $emValidatorInterface $validatorArticleService $articleService)
  1948.     {
  1949.         $titre_modal "Changer le stock des offres";
  1950.         $user        $this->getUser();
  1951.         $form   $this->createForm(StockArticleAnnonceType::class, $article);
  1952.         $errors "";
  1953.         $form->handleRequest($request);
  1954.         $repo_article_market_place $em->getRepository(ArticleMarketPlace::class);
  1955.         $errorsSup                 = [];
  1956.         $annonces_a_modifier       $repo_article_market_place->getAnnoncePourMajStock($article);
  1957.         $dateAnnonceStock   = new \Datetime();
  1958.         $nb_en_publications 0;
  1959.         $message_erreur "";
  1960.         if ($form->isSubmitted()) {
  1961.             $post $request->request->all();
  1962.             if ($post["stock"] == "" or $post["stock"] < or ! is_numeric($post["stock"])) {
  1963.                 $errorsSup[] = "Merci de définir un stock";
  1964.                 $error       = new FormError("Merci de définir un stock valide");
  1965.                 $form->get('accept')->addError($error);
  1966.             }
  1967.             if ( ! array_key_exists('annonces'$post)) {
  1968.                 $errorsSup[] = "Merci de sélectionner au moins une offre";
  1969.                 $error       = new FormError("Merci de sélectionner au moins une offre");
  1970.                 $form->get('accept')->addError($error);
  1971.             }
  1972.             if ($form->isValid()) {
  1973.                 //print_r($post);
  1974.                 $repo_statut_article_market_place $em->getRepository(StatutArticle::class);
  1975.                 $statutAPublierAnnonce            $repo_statut_article_market_place->find(1);
  1976.                 //echo "<div>COUNT ".count($post['annonces'])."</div>";
  1977.                 if (array_key_exists('annonces'$post)) {
  1978.                     for ($i 0$i count($post['annonces']); $i++) {
  1979.                         //echo "<div>".$post['annonces'][$i]."</div>";
  1980.                         $articleMarketPlaceStock $repo_article_market_place->find($post['annonces'][$i]);
  1981.                         if (is_object($articleMarketPlaceStock)) {
  1982.                             if ($articleMarketPlaceStock->getCompteMarketPlace()->getId() == and $articleMarketPlaceStock->getSku() == "") {
  1983.                                 $message_erreur .= "<div>Impossible de changer le stock de l'offre Priceminister id : ".$articleMarketPlaceStock->getId(
  1984.                                     )." idImport : ".$articleMarketPlaceStock->getIdImport()." car le sku est vide</div>";
  1985.                             } else {
  1986.                                 $articleMarketPlaceStock->setStock(trim($post['stock']));
  1987.                                 $articleMarketPlaceStock->setDateDemandePublicationMarketPlace($dateAnnonceStock);
  1988.                                 $articleMarketPlaceStock->setStatutArticleMarketPlace($statutAPublierAnnonce);
  1989.                                 $articleMarketPlaceStock->setEnvoyerUniquementStock(1);
  1990.                                 if (trim($post['stock']) == "0") {
  1991.                                     $articleMarketPlaceStock->setStatut(0);
  1992.                                 } elseif (trim($post['stock']) > "0") {
  1993.                                     $articleMarketPlaceStock->setStatut(1);
  1994.                                 }
  1995.                                 $em->persist($articleMarketPlaceStock);
  1996.                                 $nb_en_publications++;
  1997.                             }
  1998.                         }
  1999.                     }
  2000.                     if ($nb_en_publications 0) {
  2001.                         $couleur $articleService->couleurLigne($article->getId());
  2002.                         $article->setCouleurLigne($couleur);
  2003.                         $em->persist($article);
  2004.                         $em->flush();
  2005.                     }
  2006.                 }
  2007.                 //print_r($post);
  2008.                 //$articleMarketPlace->setVisible(false);
  2009.                 //$articleMarketPlace->setDateSuppression(new \Datetime());
  2010.                 //$em->persist($articleMarketPlace);
  2011.                 //$em->flush();
  2012.                 if ($message_erreur) {
  2013.                     $this->addFlash(
  2014.                         'warning',
  2015.                         $message_erreur
  2016.                     );
  2017.                 }
  2018.                 $this->addFlash(
  2019.                     'notice',
  2020.                     'Stock des offres modifiées avec succès !'
  2021.                 );
  2022.                 $url $this->generateUrl('dtc_article_modifier', ['id' => $article->getId()]);
  2023.                 return new JsonResponse(['rendu' => '''valide' => '1''url' => $url]);
  2024.             } else {
  2025.                 $errors $validator->validate($article);
  2026.                 $rendu  $this->renderView(
  2027.                     'MarketPlace/ArticleMarketPlace/stock.html.twig',
  2028.                     [
  2029.                         'errorsSup'           => $errorsSup,
  2030.                         'annonces_a_modifier' => $annonces_a_modifier,
  2031.                         'form'                => $form->createView(),
  2032.                         'errors'              => $errors,
  2033.                         'article'             => $article->getId(),
  2034.                     ]
  2035.                 );
  2036.                 return new JsonResponse(['rendu' => $rendu'valide' => '0''url' => '''titre' => $titre_modal]);
  2037.             }
  2038.         }
  2039.         $rendu $this->renderView(
  2040.             'MarketPlace/ArticleMarketPlace/stock.html.twig',
  2041.             [
  2042.                 'errorsSup'           => $errorsSup,
  2043.                 'annonces_a_modifier' => $annonces_a_modifier,
  2044.                 'form'                => $form->createView(),
  2045.                 'errors'              => $errors,
  2046.                 'article'             => $article->getId(),
  2047.             ]
  2048.         );
  2049.         return new JsonResponse(['rendu' => $rendu'valide' => '0''url' => '''titre' => $titre_modal]);
  2050.     }
  2051.     /**
  2052.      * @Route("/article-marketplace/historique/{id}", name="dtc_article_market_place_historique")
  2053.      */
  2054.     public function historiqueAction(Request $requestArticleMarketPlace $articleMarketPlaceEntityManagerInterface $emTranslatorInterface $translator)
  2055.     {
  2056.         $titre_modal $translator->trans("Historique de l'offre");
  2057.         $historiques $em->getRepository(HistoriqueArticleMarketPlace::class)->findBy([
  2058.                                                                                            'articleMarketPlace' => $articleMarketPlace,
  2059.                                                                                        ], ['date' => 'DESC']);
  2060.         $rendu $this->renderView('MarketPlace/ArticleMarketPlace/historique.html.twig', [
  2061.             'historiques' => $historiques,
  2062.         ]);
  2063.         return new JsonResponse(['rendu' => $rendu'valide' => '0''url' => '''titre' => $titre_modal'width' => 900]);
  2064.     }
  2065.     /**
  2066.      * @Route("/article-marketplace/deplacer/{id}", name="dtc_article_market_place_deplacer")
  2067.      */
  2068.     public function deplacerAction(Request            $requestArticleMarketPlace $articleMarketPlaceEntityManagerInterface $emArticleMarketPlaceService $service_article_market_place,
  2069.                                    ValidatorInterface $validator
  2070.     ) {
  2071.         $titre_modal "Déplacement de l'offre vers un autre produit";
  2072.         $user        $this->getUser();
  2073.         //$articleMarketPlace->setArticle(NULL);
  2074.         $form $this->createForm(DeplacerArticleMarketPlaceType::class, $articleMarketPlace);
  2075.         $form->get('precedent')->setData($articleMarketPlace->getArticle()->getId());
  2076.         $form->get('article')->setData(null);
  2077.         $errors    "";
  2078.         $errorsSup = [];
  2079.         $form->handleRequest($request);
  2080.         if ($form->isSubmitted()) {
  2081.             if ( ! is_object($articleMarketPlace->getArticle())) {
  2082.                 $error = new FormError("Merci de choisir un produit de destination");
  2083.                 $form->get('article')->addError($error);
  2084.                 $errorsSup[] = "Merci de choisir un produit de destination";
  2085.             }
  2086.             if ($form->isValid()) {
  2087.                 $repo_article              $em->getRepository(Article::class);
  2088.                 $ref_article_precedent_obj $repo_article->find($form->get('precedent')->getData());
  2089.                 $deplace_img $form->get('deplacerimages')->getData();
  2090.                 //echo "<div>deplace_img ".$deplace_img."</div>";
  2091.                 if ($deplace_img == 1) {
  2092.                     //echo "ON DEPLACE";
  2093.                     $repo_article_market_place_image $em->getRepository(ArticleMarketPlaceImage::class);
  2094.                     $images_annonces                 $repo_article_market_place_image->findBy(["articleMarketPlace" => $articleMarketPlace]);
  2095.                     //echo "<div>TOTALIMG = ".count($images_annonces)."</div>";
  2096.                     if (count($images_annonces) > 0) {
  2097.                         foreach ($images_annonces as $imageAnnonce) {
  2098.                             $image        $imageAnnonce->getImage();
  2099.                             $image_parent = clone $image;
  2100.                             $image_parent->setArticle($articleMarketPlace->getArticle());
  2101.                             $image_parent->setDate(new \Datetime());
  2102.                             $em->persist($image_parent);
  2103.                             $em->flush();
  2104.                             $liaison $repo_article_market_place_image->findOneBy(["articleMarketPlace" => $articleMarketPlace"image" => $image_parent]);
  2105.                             if ( ! is_object($liaison)) {
  2106.                                 $ArticleMarketPlaceImage = new ArticleMarketPlaceImage();
  2107.                                 $ArticleMarketPlaceImage->setImage($image_parent);
  2108.                                 $ArticleMarketPlaceImage->setArticleMarketPlace($articleMarketPlace);
  2109.                                 $em->persist($ArticleMarketPlaceImage);
  2110.                             }
  2111.                             $tab_dossiers = ["large""medium""originals""small""thumbnails"];
  2112.                             for ($t 0$t count($tab_dossiers); $t++) {
  2113.                                 $chemin_src  "uploads/articles/images/".$ref_article_precedent_obj->getDate()->format("Y")."/".$ref_article_precedent_obj->getDate()->format(
  2114.                                         "m"
  2115.                                     )."/".$ref_article_precedent_obj->getDate()->format("d")."/".$ref_article_precedent_obj->getId()."/".$tab_dossiers[$t]."/".$image_parent->getUrl();
  2116.                                 $chemin_dest "uploads/articles/images/".$articleMarketPlace->getArticle()->getDate()->format("Y")."/".$articleMarketPlace->getArticle()->getDate()->format(
  2117.                                         "m"
  2118.                                     )."/".$articleMarketPlace->getArticle()->getDate()->format("d")."/".$articleMarketPlace->getArticle()->getId()."/".$tab_dossiers[$t]."/";
  2119.                                 if ( ! is_dir($chemin_dest)) {
  2120.                                     //echo "<div>CREATION</div>";
  2121.                                     mkdir($chemin_dest0755true);
  2122.                                     chown($chemin_dest"www-data");
  2123.                                     chgrp($chemin_dest"www-data");
  2124.                                     chmod($chemin_dest0755);
  2125.                                 }
  2126.                                 exec("cp ".$chemin_src." ".$chemin_dest);
  2127.                             }
  2128.                             $em->remove($imageAnnonce);
  2129.                         }
  2130.                         $em->flush();
  2131.                     }
  2132.                 } else {
  2133.                     //echo "ON DEPLACE PAS";
  2134.                 }
  2135.                 $service_article_market_place->creerHistorique($articleMarketPlace9, ["article_precedent_obj" => $ref_article_precedent_obj]);
  2136.                 $this->addFlash('notice''Offre déplacée avec succès !');
  2137.                 $url "";
  2138.                 //$url = $this->generateUrl('dtc_article_modifier', array('id' => $articleMarketPlace->getArticle()->getId(),'tab'=>'m'.$market));
  2139.                 return new JsonResponse(['rendu' => '''valide' => '1''url' => '']);
  2140.             } else {
  2141.                 $repo_article              $em->getRepository(Article::class);
  2142.                 $ref_article_precedent_obj $repo_article->find($form->get('precedent')->getData());
  2143.                 $articleMarketPlace->setArticle($ref_article_precedent_obj);
  2144.                 $errors $validator->validate($articleMarketPlace);
  2145.                 $rendu  $this->renderView(
  2146.                     'MarketPlace/ArticleMarketPlace/deplacer.html.twig',
  2147.                     ['articleMarketPlace' => $articleMarketPlace'form' => $form->createView(), 'errors' => $errors'errorsSup' => $errorsSup]
  2148.                 );
  2149.                 return new Response(json_encode(['rendu' => $rendu'valide' => '0''url' => '''titre' => $titre_modal]), 200, ['Content-Type' => 'application/json']);
  2150.             }
  2151.         }
  2152.         $rendu $this->renderView(
  2153.             'MarketPlace/ArticleMarketPlace/deplacer.html.twig',
  2154.             ['articleMarketPlace' => $articleMarketPlace'form' => $form->createView(), 'errors' => $errors'errorsSup' => $errorsSup]
  2155.         );
  2156.         return new Response(json_encode(['rendu' => $rendu'valide' => '0''url' => '''titre' => $titre_modal]), 200, ['Content-Type' => 'application/json']);
  2157.     }
  2158.     /**
  2159.      * @Route("/application-annonces/charger-tableau/{id}/", name="dtc_application_article_market_place_charger_tableau")
  2160.      */
  2161.     public function chargerTableauApplicationAction(Request $requestArticleMarketPlace $articleMarketPlace)
  2162.     {
  2163.         $rendu $this->renderView('MarketPlace/ArticleMarketPlace/charger_application_tableau.html.twig', ["articleMarketPlace" => $articleMarketPlace]);
  2164.         return new JsonResponse(['rendu' => $rendu]);
  2165.     }
  2166.     /**
  2167.      * @Route("/annonce/{id}/marque/{marque}/statut/{statut}", name="dtc_article_associer_marque_vehicule_ajax")
  2168.      */
  2169.     public function associerArticleMarqueVehiculeAction(Request $requestArticleMarketPlace $articleMarketPlaceMarque $marque$statutEntityManagerInterface $em
  2170.     ) {
  2171.         //$repo_articlesCategories = $em->getRepository('DTCArticlesBundle:ArticleCategorie');
  2172.         //$articleCategorie = $repo_articlesCategories->findOneBy(array('article'=>$article, 'categorie'=>$categorie));
  2173.         $repo_applications $em->getRepository(Application::class);
  2174.         $application       $repo_applications->findOneBy(['articleMarketPlace' => $articleMarketPlace'marque' => $marque'modele' => null'type' => null]);
  2175.         if ($statut == 'add') {
  2176.             if ( ! is_object($application)) {
  2177.                 $application = new Application();
  2178.                 $application->setArticleMarketPlace($articleMarketPlace);
  2179.                 $application->setMarque($marque);
  2180.             }
  2181.             $em->persist($application);
  2182.         } else {
  2183.             if (is_object($application)) {
  2184.                 $em->remove($application);
  2185.             }
  2186.         }
  2187.         $em->flush();
  2188.         $response = new JsonResponse;
  2189.         $response->setData([
  2190.                                'articleMarketPlace' => $articleMarketPlace->getId(),
  2191.                                'marque'             => $marque->getId(),
  2192.                                'statut'             => $statut,
  2193.                            ]);
  2194.         return $response;
  2195.     }
  2196.     /**
  2197.      * @Route("/annonce/{id}/modele/{modele}/statut/{statut}", name="dtc_article_associer_modele_vehicule_ajax")
  2198.      */
  2199.     public function associerArticleModeleVehiculeAction(Request             $requestArticleMarketPlace $articleMarketPlaceModele $modele$statutEntityManagerInterface $em,
  2200.                                                         TranslatorInterface $translatorValidatorInterface $validator
  2201.     ) {
  2202.         //$repo_articlesCategories = $em->getRepository('DTCArticlesBundle:ArticleCategorie');
  2203.         //$articleCategorie = $repo_articlesCategories->findOneBy(array('article'=>$article, 'categorie'=>$categorie));
  2204.         $repo_applications $em->getRepository(Application::class);
  2205.         $application       $repo_applications->findOneBy(['articleMarketPlace' => $articleMarketPlace'marque' => $modele->getMarque(), 'modele' => $modele'type' => null]);
  2206.         if ($statut == 'add') {
  2207.             if ( ! is_object($application)) {
  2208.                 $application = new Application;
  2209.                 $application->setArticleMarketPlace($articleMarketPlace);
  2210.                 $application->setModele($modele);
  2211.                 $application->setMarque($modele->getMarque());
  2212.             }
  2213.             $em->persist($application);
  2214.         } else {
  2215.             if (is_object($application)) {
  2216.                 $em->remove($application);
  2217.             }
  2218.         }
  2219.         $em->flush();
  2220.         $response = new JsonResponse;
  2221.         $response->setData([
  2222.                                'articleMarketPlace' => $articleMarketPlace->getId(),
  2223.                                'modele'             => $modele->getId(),
  2224.                                'statut'             => $statut,
  2225.                            ]);
  2226.         return $response;
  2227.     }
  2228.     /**
  2229.      * @Route("/annonce/{id}/type/{type}/statut/{statut}", name="dtc_article_associer_type_vehicule_ajax")
  2230.      */
  2231.     public function associerArticleTypeVehiculeAction(Request             $requestArticleMarketPlace $articleMarketPlaceType $type$statutEntityManagerInterface $em,
  2232.                                                       TranslatorInterface $translatorValidatorInterface $validator
  2233.     ) {
  2234.         //$repo_articlesCategories = $em->getRepository('DTCArticlesBundle:ArticleCategorie');
  2235.         //$articleCategorie = $repo_articlesCategories->findOneBy(array('article'=>$article, 'categorie'=>$categorie));
  2236.         $repo_applications $em->getRepository(Application::class);
  2237.         $application       $repo_applications->findOneBy(
  2238.             ['articleMarketPlace' => $articleMarketPlace'marque' => $type->getModele()->getMarque(), 'modele' => $type->getModele(), 'type' => $type]
  2239.         );
  2240.         if ($statut == 'add') {
  2241.             if ( ! is_object($application)) {
  2242.                 $application = new Application;
  2243.                 $application->setArticleMarketPlace($articleMarketPlace);
  2244.                 $application->setType($type);
  2245.                 $application->setModele($type->getModele());
  2246.                 $application->setMarque($type->getModele()->getMarque());
  2247.             }
  2248.             $em->persist($application);
  2249.         } else {
  2250.             if (is_object($application)) {
  2251.                 $em->remove($application);
  2252.             }
  2253.         }
  2254.         $em->flush();
  2255.         $response = new JsonResponse;
  2256.         $response->setData([
  2257.                                'articleMarketPlace' => $articleMarketPlace->getId(),
  2258.                                'type'               => $type->getId(),
  2259.                                'statut'             => $statut,
  2260.                            ]);
  2261.         return $response;
  2262.     }
  2263. }