<?php
namespace App\Controller\MarketPlace;
use App\Entity\Articles\Article;
use App\Entity\Articles\ArticleCategorie;
use App\Entity\Articles\Ean;
use App\Entity\MarketPlace\ArticleMarketPlace;
use App\Entity\MarketPlace\ArticleMarketPlaceCaracteristique;
use App\Entity\MarketPlace\ArticleMarketPlaceImage;
use App\Entity\MarketPlace\Caracteristiques;
use App\Entity\MarketPlace\CategorieErpCategorieMarketPlace;
use App\Entity\MarketPlace\CompteMarketPlace;
use App\Entity\MarketPlace\HistoriqueArticleMarketPlace;
use App\Entity\MarketPlace\MarketPlace;
use App\Entity\MarketPlace\StatutArticle;
use App\Entity\Taxes\RegleTaxe;
use App\Entity\Traductions\Langue;
use App\Entity\Traductions\Traduction;
use App\Entity\Vehicules\Application;
use App\Entity\Vehicules\Marque;
use App\Entity\Vehicules\Modele;
use App\Entity\Vehicules\Type;
use App\Form\Articles\StockArticleAnnonceType;
use App\Form\MarketPlace\ArticleMarketPlaceType;
use App\Form\MarketPlace\DeplacerArticleMarketPlaceType;
use App\Form\MarketPlace\DupliquerArticleMarketPlaceType;
use App\Form\MarketPlace\MarketPlaceType;
use App\Form\MarketPlace\SupprimerArticleMarketPlaceType;
use App\Library\Datatable\Util\Datatable;
use App\Security\Voter\EntityVoter;
use App\Service\Articles\ArticleService;
use App\Service\MarketPlace\ArticleMarketPlaceService;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\Form\FormError;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\Validator\Validator\ValidatorInterface;
use Symfony\Contracts\Translation\TranslatorInterface;
class ArticleMarketPlaceController extends AbstractController
{
/**
* @Route("/mp/charger-tableau/{id}/{idmarket}", name="dtc_mp_article_charger_tableau")
*/
public function chargerTableauAction(Request $request, Article $article, CompteMarketPlace $idmarket, $parametres = [], EntityManagerInterface $em,
TranslatorInterface $translator, ValidatorInterface $validator
) {
$rendu = $this->renderView('MarketPlace/ArticleMarketPlace/charger_tableau.html.twig', ['article' => $article, 'market' => $idmarket, 'parametres' => $parametres]);
return new JsonResponse(['rendu' => $rendu], 200, ['Content-Type' => 'application/json']);
}
/**
* @Route("/article/marketplace/statut-en-ligne/{id}", name="dtc_article_market_place_changer_statut_en_ligne")
*/
public function changeStatutEnLigneAction(Request $request, ArticleMarketPlace $articleMarketPlace, EntityManagerInterface $em)
{
$repo_statut_article_market_place = $em->getRepository(StatutArticle::class);
if ( ! is_object($articleMarketPlace->getStatutArticleMarketPlace())) {
$statutAPublierAnnonce = $repo_statut_article_market_place->find(1);
//echo "toto ".$articleMarketPlace->getId()." ".$statutAPublierAnnonce->getLibelle();
$articleMarketPlace->setStatutArticleMarketPlace($statutAPublierAnnonce);
$articleMarketPlace->setDateDemandePublicationMarketPlace(new \Datetime());
$articleMarketPlace->setEnvoyerUniquementStock(0);
//$em->persist($articleMarketPlace);
//$em->flush();
//exit;
} else {
if ($articleMarketPlace->getStatutArticleMarketPlace()->getId() == 1) {
$articleMarketPlace->setStatutArticleMarketPlace(null);
$articleMarketPlace->setEnvoyerImageAmazon(false);
//$em->persist($articleMarketPlace);
//$em->flush();
} elseif ($articleMarketPlace->getStatutArticleMarketPlace()->getId() == 2) {
$statutAPublierAnnonce = $repo_statut_article_market_place->find(1);
$articleMarketPlace->setStatutArticleMarketPlace($statutAPublierAnnonce);
//$em->persist($articleMarketPlace);
//$em->flush();
}
}
if ($articleMarketPlace->getStatut() == 1) {
$articleMarketPlace->setStatut(0);
} else {
$articleMarketPlace->setStatut(1);
}
$em->persist($articleMarketPlace);
$em->flush();
$headers = [
'Content-Type' => 'application/json',
'Access-Control-Allow-Origin' => '*',
'Access-Control-Allow-Methods' => 'POST',
];
return new JsonResponse(['data' => '1', 'statut_annonce' => $articleMarketPlace->getId()]);
}
/**
* @Route("/article/marketplace/statut/{id}", name="dtc_article_market_place_changer_statut")
*/
public function changeStatutAction(Request $request, ArticleMarketPlace $articleMarketPlace, EntityManagerInterface $em, ArticleMarketPlaceService $service_article_market_place)
{
$repo_statut_article_market_place = $em->getRepository(StatutArticle::class);
if ( ! is_object($articleMarketPlace->getStatutArticleMarketPlace())) {
$statutAPublierAnnonce = $repo_statut_article_market_place->find(1);
$articleMarketPlace->setStatutArticleMarketPlace($statutAPublierAnnonce);
$articleMarketPlace->setDateDemandePublicationMarketPlace(new \Datetime());
$articleMarketPlace->setEnvoyerUniquementStock(0);
$em->persist($articleMarketPlace);
$em->flush();
//exit;
$service_article_market_place->creerHistorique($articleMarketPlace, 3);
} else {
if ($articleMarketPlace->getStatutArticleMarketPlace()->getId() == 1) {
$articleMarketPlace->setStatutArticleMarketPlace(null);
$articleMarketPlace->setEnvoyerImageAmazon(false);
$em->persist($articleMarketPlace);
$em->flush();
$service_article_market_place->creerHistorique($articleMarketPlace, 4);
} elseif ($articleMarketPlace->getStatutArticleMarketPlace()->getId() == 2) {
$statutAPublierAnnonce = $repo_statut_article_market_place->find(1);
$articleMarketPlace->setStatutArticleMarketPlace($statutAPublierAnnonce);
$em->persist($articleMarketPlace);
$em->flush();
$service_article_market_place->creerHistorique($articleMarketPlace, 3);
}
}
$headers = [
'Content-Type' => 'application/json',
'Access-Control-Allow-Origin' => '*',
'Access-Control-Allow-Methods' => 'POST',
];
return new JsonResponse(['data' => '1'], 200, $headers);
}
public function slugify($text)
{
// replace non letter or digits by -
$text = preg_replace('~[^\pL\d]+~u', '-', $text);
// transliterate
$text = iconv('utf-8', 'us-ascii//TRANSLIT', $text);
// remove unwanted characters
$text = preg_replace('~[^-\w]+~', '', $text);
// trim
$text = trim($text, '-');
// remove duplicate -
$text = preg_replace('~-+~', '-', $text);
// lowercase
$text = strtolower($text);
if (empty($text)) {
return 'n-a';
}
return $text;
}
/**
* @Route("/article/marketplace/{article}/{compteMarketPlace}/nouveau", name="dtc_article_market_place_ajouter_modal")
*/
public function ajouterModalAction(Request $request, Article $article, CompteMarketPlace $compteMarketPlace, $parametres = [], EntityManagerInterface $em,
TranslatorInterface $translator, ValidatorInterface $validator
) {
$titre_modal = "Nouvelle offre ";
$user = $this->getUser();
$repo_regle_taxe = $em->getRepository(RegleTaxe::class);
$regle_taxe = $repo_regle_taxe->find(1);
$articleMarketPlace = new ArticleMarketPlace;
$articleMarketPlace->setCompteMarketPlace($compteMarketPlace);
$articleMarketPlace->setArticle($article);
$articleMarketPlace->setLibelle($article->getLibelle());
$articleMarketPlace->setStock($article->getStock());
//$articleMarketPlace->setTitreSeo($article->getLibelle());
$articleMarketPlace->setPrixvente($article->getPrixvente());
$articleMarketPlace->setResume($article->getDescriptionCourte());
if ($article->getDescription() != "") {
$articleMarketPlace->setDescription($article->getDescription());
} else {
$articleMarketPlace->setDescription($article->getDescriptionCourte());
}
//$articleMarketPlace->setUrlRewriting($this->slugify($article->getLibelle()));
$articleMarketPlace->setRegleTaxe($regle_taxe);
$articleMarketPlace->setVisible(false);
$repo_article_categorie = $em->getRepository(ArticleCategorie::class);
$repo_article_market_place_image = $em->getRepository(ArticleMarketPlaceImage::class);
$repo_traduction = $em->getRepository(Traduction::class);
$repo_langue = $em->getRepository(Langue::class);
$repo_article_market_place = $em->getRepository(ArticleMarketPlace::class);
$em->persist($articleMarketPlace);
$em->flush();
$em->refresh($articleMarketPlace);
if (count($article->getImages()) > 0) {
foreach ($article->getImages() as $img) {
$articleMarketPlaceImage = new ArticleMarketPlaceImage();
$articleMarketPlaceImage->setArticleMArketPlace($articleMarketPlace);
$articleMarketPlaceImage->setImage($img);
$em->persist($articleMarketPlaceImage);
}
$em->flush();
}
$categorieMarket = $repo_article_categorie->findBy(["article" => $article, "marketPlace" => $compteMarketPlace->getMarketPlace()]);
//echo "TOTO".count($categorieMarket);
if (count($categorieMarket) > 0) {
foreach ($categorieMarket as $cm) {
$articleCategorie = new ArticleCategorie();
$articleCategorie->setArticleMarketPlace($articleMarketPlace);
$articleCategorie->setCategorie($cm->getCategorie());
$em->persist($articleCategorie);
}
$em->flush();
} else {
if (is_object($articleMarketPlace->getCompteMarketPlace()) && is_object($articleMarketPlace->getCompteMarketPlace()->getMarketPlace())) {
$catErp = $repo_article_categorie->getCategorieErpArticle($article);
$continuer_recherche_cat = true;
if (count($catErp) > 0) {
foreach ($catErp as $ce) {
if ($continuer_recherche_cat) {
if (is_object($ce->getCategorie())) {
//echo "<div>CAT ".$ce->getCategorie()."</div>";
$repo_CategorieErpCategorieMarketPlace = $em->getRepository(CategorieErpCategorieMarketPlace::class);
$cateCorrespondance = $repo_CategorieErpCategorieMarketPlace->findOneBy(
["categorieErp" => $ce->getCategorie(), "compteMarketPlace" => $articleMarketPlace->getCompteMarketPlace()]
);
if (is_object($cateCorrespondance) && is_object($cateCorrespondance->getCategorieMarketPlace())) {
$articleCategorie = new ArticleCategorie();
$articleCategorie->setArticleMarketPlace($articleMarketPlace);
$articleCategorie->setCategorie($cateCorrespondance->getCategorieMarketPlace());
$em->persist($articleCategorie);
$continuer_recherche_cat = false;
}
/*
if($articleMarketPlace->getCompteMarketPlace()->getMarketPlace()->getId() == "8") {
//Wordpress
if(is_object($ce->getCategorie()->getCategorieWordpress())) {
$articleCategorie = new ArticleCategorie;
$articleCategorie->setArticleMarketPlace($articleMarketPlace);
$articleCategorie->setCategorie($ce->getCategorie()->getCategorieWordpress());
$em->persist($articleCategorie);
}
}
else if($articleMarketPlace->getCompteMarketPlace()->getMarketPlace()->getId() == "5") {
// Prestashop
if(is_object($ce->getCategorie()->getCategoriePrestahop())) {
$articleCategorie = new ArticleCategorie;
$articleCategorie->setArticleMarketPlace($articleMarketPlace);
$articleCategorie->setCategorie($ce->getCategorie()->getCategoriePrestahop());
$em->persist($articleCategorie);
}
}
*/
}
//echo $ce->getCategorie()->getLibelle();
}
}
$em->flush();
}
}
}
$form = $this->createForm(ArticleMarketPlaceType::class, $articleMarketPlace);
$get = $request->query->all();
$langues = $repo_langue->findAll();
$repo_caracteristique = $em->getRepository(Caracteristiques::class);
$errors = "";
$form->handleRequest($request);
if ( ! $form->isSubmitted()) {
}
if ($form->isSubmitted()) {
if ($form->isValid()) {
$erreur_image = false;
$erreur_categorie_priceminister = false;
$erreur_image_annonce = false;
$erreur_sku_priceminister = false;
$erreur_sku_priceminister_existe = false;
$erreur_sku_ean = false;
$erreur_sku_ean_existe = false;
$temp_sku = "";
$post = $request->request->all();
$caracteristiques_ps = $repo_caracteristique->findBy(["marketPlace" => $articleMarketPlace->getCompteMarketPlace()->getMarketPlace()]);
if (count($caracteristiques_ps) > 0) {
foreach ($caracteristiques_ps as $carac) {
//caracteristique_17860
if (array_key_exists('caracteristique_'.$carac->getId(), $post)) {
if (is_array($post['caracteristique_'.$carac->getId()])) {
foreach ($post['caracteristique_'.$carac->getId()] as $key => $value) {
$articleMarketPlaceCaracteristique = new ArticleMarketPlaceCaracteristique();
$articleMarketPlaceCaracteristique->setArticleMarketPlace($articleMarketPlace);
$articleMarketPlaceCaracteristique->setCaracteristique($carac);
$articleMarketPlaceCaracteristique->setValeur($value);
$em->persist($articleMarketPlaceCaracteristique);
}
}
$em->flush();
}
}
}
if (is_object($articleMarketPlace->getArticle()) && count($articleMarketPlace->getArticle()->getImages()) == 0) {
$erreur_image = true;
}
//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")) {
if (is_object($articleMarketPlace->getCompteMarketPlace()) and is_object($articleMarketPlace->getCompteMarketPlace()->getMarketPlace())) {
$imagesAnnonce = $repo_article_market_place_image->findBy(["articleMarketPlace" => $articleMarketPlace]);
if (count($imagesAnnonce) == 0) {
//$erreur_image_annonce = true;
}
if (count($articleMarketPlace->getArticleCategorie()) == 0 and ($articleMarketPlace->getIdImport() == null or $articleMarketPlace->getIdImport() == "")) {
$erreur_categorie_priceminister = true;
}
if (($articleMarketPlace->getSku() == "" or $articleMarketPlace->getSku() == null) and ($articleMarketPlace->getIdImport() == "" or $articleMarketPlace->getIdImport(
) == null)) {
$erreur_sku_priceminister = true;
}
if ($articleMarketPlace->getSku() != "") {
$articleMarketPlaceSku = $repo_article_market_place->findBy(
["compteMarketPlace" => $articleMarketPlace->getCompteMarketPlace(), "sku" => $articleMarketPlace->getSku()]
);
if (count($articleMarketPlaceSku) > 1) {
$erreur_sku_priceminister_existe = true;
$temp_sku = $articleMarketPlace->getSku();
$articleMarketPlace->setSku("");
} else {
foreach ($articleMarketPlaceSku as $ampsku) {
if ($ampsku->getId() != $articleMarketPlace->getId()) {
$erreur_sku_priceminister_existe = true;
$temp_sku = $articleMarketPlace->getSku();
$articleMarketPlace->setSku("");
}
}
}
}
// echo "<div>EAN ".$articleMarketPlace->getEan()."</div>";
if ($articleMarketPlace->getEan() != "") {
$articleMarketPlaceSku = $repo_article_market_place->findBy(
["ean" => $articleMarketPlace->getEan(), "compteMarketPlace" => $articleMarketPlace->getCompteMarketPlace()]
);
//echo "<div><COUNT ".count($articleMarketPlaceSku)."</div>";
if (count($articleMarketPlaceSku) > 1) {
$erreur_sku_ean_existe = true;
$temp_sku = $articleMarketPlace->getSku();
$articleMarketPlace->setEan("");
$articleMarketPlace->setEanObjet(null);
} else {
foreach ($articleMarketPlaceSku as $ampsku) {
if ($ampsku->getId() != $articleMarketPlace->getId()) {
$erreur_sku_ean_existe = true;
//$temp_sku = $articleMarketPlace->getSku();
$articleMarketPlace->setEan("");
$articleMarketPlace->setEanObjet(null);
}
}
}
}
if (($articleMarketPlace->getIdImport() == "" or $articleMarketPlace->getIdImport() == null) and ($articleMarketPlace->getEan() == null or $articleMarketPlace->getEan(
) == "")) {
//if(($articleMarketPlace->getIdImport() == "" or $articleMarketPlace->getIdImport() == NULL) and ($articleMarketPlace->getArticle()->getCodeProduit() == NULL or $articleMarketPlace->getArticle()->getCodeProduit() == "")) {
//$erreur_sku_ean = true;
}
}
$postForm = $request->request->all();
//print_r($postForm);
$postForm = $request->request->all();
//print_r($postForm);
if (count($langues) > 0) {
foreach ($langues as $l) {
$trad = $repo_traduction->findOneBy(["articleMarketPlace" => $articleMarketPlace, "langue" => $l]);
if ( ! is_object($trad)) {
$trad = new Traduction();
$trad->setArticleMarketPlace($articleMarketPlace);
$trad->setlangue($l);
}
if (array_key_exists('libelle_'.$l->getId(), $postForm)) {
$trad->setLibelle($postForm['libelle_'.$l->getId()]);
}
if (array_key_exists('descriptionCourte_'.$l->getId(), $postForm)) {
$trad->setDescriptionCourte($postForm['descriptionCourte_'.$l->getId()]);
}
if (array_key_exists('altImg_'.$l->getId(), $postForm)) {
$trad->setaltImg($postForm['altImg_'.$l->getId()]);
}
if (array_key_exists('titreSeo_'.$l->getId(), $postForm)) {
$trad->setTitreSeo($postForm['titreSeo_'.$l->getId()]);
}
if (array_key_exists('description_'.$l->getId(), $postForm)) {
$trad->setDescription($postForm['description_'.$l->getId()]);
}
if (array_key_exists('urlRewriting_'.$l->getId(), $postForm)) {
$trad->setUrlRewriting($postForm['urlRewriting_'.$l->getId()]);
}
if (array_key_exists('metaDescription_'.$l->getId(), $postForm)) {
$trad->setMetaDescription($postForm['metaDescription_'.$l->getId()]);
}
$em->persist($trad);
}
}
$statutArticleMarketPlace = $em->getRepository(StatutArticle::class)->find(1);
if ((count($article->getArticleCategorie()) > 0 || $articleMarketPlace->getCompteMarketPlace()->getMarketPlace()->getId() == 1) && $articleMarketPlace->getLibelle(
) != "" && $articleMarketPlace->getDescription(
) != "" && ! $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(
) > 0 and ($articleMarketPlace->getAnnonceSupprime() == null or $articleMarketPlace->getAnnonceSupprime() == 0)) {
$articleMarketPlace->setDateDemandePublicationMarketPlace(new \Datetime());
$articleMarketPlace->setStatutArticleMarketPlace($statutArticleMarketPlace);
$articleMarketPlace->setEnvoyerUniquementStock(0);
if (array_key_exists('supprimer', $postForm) and $postForm["supprimer"] == "1" and is_object($articleMarketPlace->getCompteMarketPlace()) and is_object(
$articleMarketPlace->getCompteMarketPlace(
)->getMarketPlace()
) and $articleMarketPlace->getCompteMarketPlace(
)->getMarketPlace()->getId() == "4") {
$articleMarketPlace->setAnnonceSupprime(1);
}
if ($articleMarketPlace->getArret() == true) {
$articleMarketPlace->setStatut(false);
}
} else {
$articleMarketPlace->setDateDemandePublicationMarketPlace(null);
$articleMarketPlace->setStatutArticleMarketPlace(null);
}
$em->persist($articleMarketPlace);
$em->flush();
$conn = $em->getConnection();
$em->flush();
$erreur_construit = "";
if ($erreur_image_annonce) {
$erreur_construit .= "<br/>Merci de choisir une image !";
}
if ($erreur_categorie_priceminister and 1 != 1) {
$erreur_construit .= "<br/>Merci de choisir une catégorie market place !";
}
if (trim($articleMarketPlace->getPrixVente()) == "" or is_null(trim($articleMarketPlace->getPrixVente()))) {
$erreur_construit .= "<br/>Merci de définir un prix de vente !";
}
if ($erreur_sku_priceminister) {
$erreur_construit .= "<br/>Merci de définir un SKU !";
}
if ($erreur_sku_priceminister_existe) {
$erreur_construit .= "<br/>SKU (".$temp_sku.") non disponible, il déja attribué à une autre offre ".$articleMarketPlace->getCompteMarketPlace()->getMarketPlace(
)->getLibelle()." !";
}
if ($erreur_sku_ean) {
$erreur_construit .= "<br/>Merci de définir un code EAN !";
}
if ($erreur_sku_ean_existe) {
$erreur_construit .= "<br/>Code EAN déja utilisé !";
}
if ($erreur_image) {
$erreur_construit .= "<br/>Merci d'uploader au moins une image !";
}
if (count($article->getArticleCategorie()) == 0 and 1 != 1) {
$erreur_construit .= "<br/>Merci de choisir une catégorie pour la fiche produit";
}
if ($articleMarketPlace->getLibelle() == "") {
$erreur_construit .= "<br/>Merci de définir un libellé";
}
if ($articleMarketPlace->getDescription() == "" and 1 != 1) {
$erreur_construit .= "<br/>Merci de définir une description";
}
if ($erreur_construit == "") {
if ($articleMarketPlace->getAnnonceSupprime() == null or $articleMarketPlace->getAnnonceSupprime() == 0) {
$articleMarketPlace->setVisible(true);
$em->persist($articleMarketPlace);
$em->flush();
$em->refresh($articleMarketPlace);
$this->addFlash('notice', 'Offre modifiée avec succès !');
//'Annonce modifiée avec succès ! Elle sera publiée dans un délai moyen de 15 minutes'
}
} else {
$this->addFlash(
'warning',
$erreur_construit
);
$rendu = $this->renderView(
'MarketPlace/ArticleMarketPlace/ajouter_modal.html.twig',
['article' => $article, 'articleMarketPlace' => $articleMarketPlace, 'errors' => $errors, 'form' => $form->createView()]
);
return new JsonResponse(['rendu' => $rendu, 'valide' => '0', 'url' => '', 'titre' => $titre_modal]);
}
$url = $this->generateUrl('dtc_article_modifier', ['id' => $article->getId(), 'tab' => 'm'.$articleMarketPlace->getCompteMarketPlace()->getId()]);
return new JsonResponse(['rendu' => "", 'valide' => '1', 'url' => $url, 'titre' => $titre_modal]);
//return $this->redirectToRoute('dtc_article_modifier',array("id"=>$article->getId(),'amp'=>$articleMarketPlace->getId() ,'tab'=>"m".$articleMarketPlace->getCompteMarketPlace()->getId()));
} else {
$errors = $validator->validate($articleMarketPlace);
$this->addFlash(
'warning',
'formulaire non valide !'
);
foreach ($errors as $error) {
$this->addFlash(
'warning',
$error
);
}
}
}
$action_form = $this->generateUrl(
'dtc_article_market_place_modifier',
['article' => $article->getId(), 'id' => $articleMarketPlace->getId(), 'tab' => 'm'.$articleMarketPlace->getCompteMarketPlace()->getId()]
);
$rendu = $this->renderView(
'MarketPlace/ArticleMarketPlace/ajouter_modal.html.twig',
['nouveau' => '1', 'article' => $article, 'articleMarketPlace' => $articleMarketPlace, 'errors' => $errors, 'form' => $form->createView()]
);
return new JsonResponse(
['link' => $action_form, 'rendu' => $rendu, 'valide' => '0', 'url' => '', 'titre' => $titre_modal]
);
}
/**
* @Route("/article/marketplace/{article}/annonce/{id}", name="dtc_article_market_place_modifier")
*/
public function modifierModalAction(Request $request, Article $article, ArticleMarketPlace $articleMarketPlace, $parametres = [], EntityManagerInterface $em,
ValidatorInterface $validator, ArticleMarketPlaceService $articleMarketPlaceService
) {
$titre_modal = "Modifier offre ";
$user = $this->getUser();
if ( ! is_object($articleMarketPlace)) {
$articleMarketPlace = new ArticleMarketPlace;
}
$repo_statut_article_market_place = $em->getRepository(StatutArticle::class);
$statutAPublierAnnonce = $repo_statut_article_market_place->find(1);
$repo_langue = $em->getRepository(Langue::class);
$langues = $repo_langue->findAll();
$repo_article_market_place = $em->getRepository(ArticleMarketPlace::class);
$repo_article_market_place_image = $em->getRepository(ArticleMarketPlaceImage::class);
$repo_caracteristique = $em->getRepository(Caracteristiques::class);
if (is_array($request->query->get('parametres'))) {
$parametres = $request->query->get('parametres');
}
$form = $this->createForm(ArticleMarketPlaceType::class, $articleMarketPlace);
$errors = "";
$renouvelable = true;
$termine = false;
$date = new \Datetime;
$nouveau = "";
$form->handleRequest($request);
if ($form->isSubmitted()) {
if ($form->isValid()) {
$post = $request->request->all();
$postForm = $request->request->all();
if (array_key_exists('nouveau', $postForm) && $postForm["nouveau"] == "1") {
$nouveau = 1;
}
$caracteristiques_ps = $repo_caracteristique->findBy(["marketPlace" => $articleMarketPlace->getCompteMarketPlace()->getMarketPlace()]);
//echo "ttc :".count($caracteristiques_ps);
//print_r($post);
$compteur_carac = 0;
if (count($caracteristiques_ps) > 0) {
foreach ($caracteristiques_ps as $carac) {
//caracteristique_17860
if (array_key_exists('carac_'.$carac->getId(), $post)) {
if ($compteur_carac == 0) {
$conn = $em->getConnection();
$sql = "DELETE FROM market_place__article_market_place_caracteristique where article_market_place_id = ".$articleMarketPlace->getId();;
//echo "<div>".$sql."</div>";
$stmt = $conn->executeQuery($sql);
//exit;
}
$compteur_carac++;
}
if (array_key_exists('carac_'.$carac->getId(), $post) && $post['carac_'.$carac->getId()] != "") {
$articleMarketPlaceCaracteristique = new ArticleMarketPlaceCaracteristique();
$articleMarketPlaceCaracteristique->setArticleMarketPlace($articleMarketPlace);
$articleMarketPlaceCaracteristique->setCaracteristique($carac);
$articleMarketPlaceCaracteristique->setValeur($post['carac_'.$carac->getId()]);
$em->persist($articleMarketPlaceCaracteristique);
}
}
}
$em->flush();
$erreur_image = false;
$erreur_categorie_priceminister = false;
$erreur_image_annonce = false;
$erreur_sku_priceminister = false;
$erreur_sku_priceminister_existe = false;
$erreur_sku_ean = false;
$erreur_sku_ean_existe = false;
$temp_sku = "";
if (is_object($articleMarketPlace->getArticle()) && count($articleMarketPlace->getArticle()->getImages()) == 0) {
$erreur_image = true;
}
//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")) {
if (is_object($articleMarketPlace->getCompteMarketPlace()) and is_object($articleMarketPlace->getCompteMarketPlace()->getMarketPlace())) {
$imagesAnnonce = $repo_article_market_place_image->findBy(["articleMarketPlace" => $articleMarketPlace]);
if (count($imagesAnnonce) == 0) {
//$erreur_image_annonce = true;
}
if (count($articleMarketPlace->getArticleCategorie()) == 0 and ($articleMarketPlace->getIdImport() == null or $articleMarketPlace->getIdImport() == "")) {
$erreur_categorie_priceminister = true;
}
if (($articleMarketPlace->getSku() == "" or $articleMarketPlace->getSku() == null) and ($articleMarketPlace->getIdImport() == "" or $articleMarketPlace->getIdImport(
) == null)) {
$erreur_sku_priceminister = true;
}
if ($articleMarketPlace->getSku() != "") {
$articleMarketPlaceSku = $repo_article_market_place->findBy(
["compteMarketPlace" => $articleMarketPlace->getCompteMarketPlace(), "sku" => $articleMarketPlace->getSku()]
);
if (count($articleMarketPlaceSku) > 1) {
$erreur_sku_priceminister_existe = true;
$temp_sku = $articleMarketPlace->getSku();
$articleMarketPlace->setSku("");
} else {
foreach ($articleMarketPlaceSku as $ampsku) {
if ($ampsku->getId() != $articleMarketPlace->getId()) {
$erreur_sku_priceminister_existe = true;
$temp_sku = $articleMarketPlace->getSku();
$articleMarketPlace->setSku("");
}
}
}
}
// echo "<div>EAN ".$articleMarketPlace->getEan()."</div>";
if ($articleMarketPlace->getEan() != "") {
$articleMarketPlaceSku = $repo_article_market_place->findBy(
["ean" => $articleMarketPlace->getEan(), "compteMarketPlace" => $articleMarketPlace->getCompteMarketPlace()]
);
//echo "<div><COUNT ".count($articleMarketPlaceSku)."</div>";
if (count($articleMarketPlaceSku) > 1) {
$erreur_sku_ean_existe = true;
$temp_sku = $articleMarketPlace->getSku();
$articleMarketPlace->setEan("");
$articleMarketPlace->setEanObjet(null);
} else {
foreach ($articleMarketPlaceSku as $ampsku) {
if ($ampsku->getId() != $articleMarketPlace->getId()) {
$erreur_sku_ean_existe = true;
//$temp_sku = $articleMarketPlace->getSku();
$articleMarketPlace->setEan("");
$articleMarketPlace->setEanObjet(null);
}
}
}
}
if (($articleMarketPlace->getIdImport() == "" or $articleMarketPlace->getIdImport() == null) and ($articleMarketPlace->getEan() == null or $articleMarketPlace->getEan(
) == "")) {
//if(($articleMarketPlace->getIdImport() == "" or $articleMarketPlace->getIdImport() == NULL) and ($articleMarketPlace->getArticle()->getCodeProduit() == NULL or $articleMarketPlace->getArticle()->getCodeProduit() == "")) {
//$erreur_sku_ean = true;
}
}
$statutArticleMarketPlace = $em->getRepository(StatutArticle::class)->find(1);
if ((count($article->getArticleCategorie()) > 0 || $articleMarketPlace->getCompteMarketPlace()->getMarketPlace()->getId() == 1) && $articleMarketPlace->getLibelle(
) != "" && $articleMarketPlace->getDescription(
) != "" && ! $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(
) > 0 and ($articleMarketPlace->getAnnonceSupprime() == null or $articleMarketPlace->getAnnonceSupprime() == 0)) {
//$articleMarketPlace->setDateDemandePublicationMarketPlace(new \Datetime());
//$articleMarketPlace->setStatutArticleMarketPlace($statutArticleMarketPlace);
//$articleMarketPlace->setEnvoyerUniquementStock(0);
if (array_key_exists('supprimer', $postForm) and $postForm["supprimer"] == "1" and is_object($articleMarketPlace->getCompteMarketPlace()) and is_object(
$articleMarketPlace->getCompteMarketPlace(
)->getMarketPlace()
) and $articleMarketPlace->getCompteMarketPlace(
)->getMarketPlace()->getId() == "4") {
$articleMarketPlace->setAnnonceSupprime(1);
}
if ($articleMarketPlace->getArret() == true) {
$articleMarketPlace->setStatut(false);
}
} else {
//$articleMarketPlace->setDateDemandePublicationMarketPlace(NULL);
//$articleMarketPlace->setStatutArticleMarketPlace(NULL);
}
$em->persist($articleMarketPlace);
$em->flush();
$conn = $em->getConnection();
$em->flush();
$erreur_construit = "";
if ($erreur_image_annonce) {
$erreur_construit .= "<br/>Merci de choisir une image !";
}
if ($erreur_categorie_priceminister and 1 != 1) {
$erreur_construit .= "<br/>Merci de choisir une catégorie market place !";
}
if (trim($articleMarketPlace->getPrixVente()) == "" or trim($articleMarketPlace->getPrixVente()) == "0" or is_null(trim($articleMarketPlace->getPrixVente()))) {
$erreur_construit .= "<br/>Merci de définir un prix de vente ! ";
}
if ($erreur_sku_priceminister) {
$erreur_construit .= "<br/>Merci de définir un SKU !";
}
if ($erreur_sku_priceminister_existe) {
$erreur_construit .= "<br/>SKU (".$temp_sku.") non disponible, il déja attribué à une autre offre ".$articleMarketPlace->getCompteMarketPlace()->getMarketPlace(
)->getLibelle()." !";
}
if ($erreur_sku_ean) {
$erreur_construit .= "<br/>Merci de définir un code EAN !";
}
if ($erreur_sku_ean_existe) {
$erreur_construit .= "<br/>Code EAN déja utilisé !";
}
if ($erreur_image && ($articleMarketPlace->getIdImport() == "" or is_null($articleMarketPlace->getIdImport()))) {
$erreur_construit .= "<br/>Merci d'uploader au moins une image !";
}
if (count($article->getArticleCategorie()) == 0 and 1 != 1) {
$erreur_construit .= "<br/>Merci de choisir une catégorie pour la fiche produit";
}
if ($articleMarketPlace->getLibelle() == "") {
$erreur_construit .= "<br/>Merci de définir un libellé";
}
if ($articleMarketPlace->getDescription() == "" and 1 != 1) {
$erreur_construit .= "<br/>Merci de définir une description";
}
if ($erreur_construit == "") {
if ($articleMarketPlace->getAnnonceSupprime() == null or $articleMarketPlace->getAnnonceSupprime() == 0) {
$articleMarketPlace->setVisible(true);
$em->persist($articleMarketPlace);
$em->flush();
$em->refresh($articleMarketPlace);
$annonce_en_cours_de_publication = false;
if (($articleMarketPlace->getVisible() or is_null($articleMarketPlace->getVisible()))) {
//$articleMarketPlace->setDateDemandePublicationMarketPlace(new \Datetime());
//$articleMarketPlace->setStatutArticleMarketPlace($statutAPublierAnnonce);
$em->persist($articleMarketPlace);
$em->flush();
$message_maj = $articleMarketPlaceService->majStockAnnonce($articleMarketPlace->getArticle()->getId(), $articleMarketPlace->getId());
if (is_array($message_maj)) {
if (array_key_exists('notice', $message_maj) && $message_maj["notice"] != "") {
$annonce_en_cours_de_publication = true;
$this->addFlash('notice', $message_maj["notice"]);
}
if (array_key_exists('warning', $message_maj) && $message_maj["warning"] != "") {
$this->addFlash('warning', $message_maj["warning"]);
}
}
}
$nouveau = "";
if (array_key_exists('nouveau', $postForm) && $postForm["nouveau"] == "1") {
$this->addFlash('notice', 'Offre créée avec succès !');
$message = [];
$message["message"] = "";
$message["en_cours_publication"] = $annonce_en_cours_de_publication;
$articleMarketPlaceService->creerHistorique($articleMarketPlace, 12, $message);
} else {
$this->addFlash('notice', 'Offre modifiée avec succès !');
$message = [];
$message["message"] = "Modification manuelle de l'offre";
$message["en_cours_publication"] = $annonce_en_cours_de_publication;
$articleMarketPlaceService->creerHistorique($articleMarketPlace, 3, $message);
}
}
} else {
$this->addFlash('warning', $erreur_construit);
$rendu = $this->renderView(
'MarketPlace/ArticleMarketPlace/ajouter_modal.html.twig',
[
'nouveau' => $nouveau,
'article' => $article,
'articleMarketPlace' => $articleMarketPlace,
'errors' => $errors,
'form' => $form->createView(),
]
);
return new JsonResponse(['rendu' => $rendu, 'valide' => '0', 'url' => '', 'titre' => $titre_modal]);
}
$url = $this->generateUrl('dtc_article_modifier', ['id' => $article->getId(), 'tab' => 'm'.$articleMarketPlace->getCompteMarketPlace()->getId()]);
return new JsonResponse(['rendu' => "", 'valide' => '1', 'url' => '', 'titre' => $titre_modal]);
//return $this->redirectToRoute('dtc_article_modifier',array("id"=>$article->getId(),'amp'=>$articleMarketPlace->getId() ,'tab'=>"m".$articleMarketPlace->getCompteMarketPlace()->getId()));
} else {
$errors = $validator->validate($articleMarketPlace);
$this->addFlash('warning', 'formulaire non valide!!!');
foreach ($errors as $error) {
$this->addFlash('warning', $error);
}
}
}
$rendu = $this->renderView(
'MarketPlace/ArticleMarketPlace/ajouter_modal.html.twig',
['nouveau' => $nouveau, 'article' => $article, 'articleMarketPlace' => $articleMarketPlace, 'errors' => $errors, 'form' => $form->createView()]
);
return new JsonResponse(['rendu' => $rendu, 'valide' => '0', 'url' => '', 'titre' => $titre_modal]);
}
/**
* @Route("", name="")
*/
public function listerAction(Request $request, Article $article, CompteMarketPlace $compteMarketPlace, $parametres = [], Datatable $datatable)
{
$articleMarketPlace = new ArticleMarketPlace();
$articleMarketPlace->setCompteMarketPlace($compteMarketPlace);
$this->datatableEnfants($datatable, $compteMarketPlace, $article);
return $this->render(
'MarketPlace/ArticleMarketPlace/lister.html.twig',
[
"articleMarketPlace" => $articleMarketPlace,
"compteMarketPlace" => $compteMarketPlace,
"article" => $article,
]
);
}
/**
* @Route("/article/marketplace/{article}/{compteMarketPlace}", name="dtc_article_market_place_ajouter")
*/
public function ajouterAction(Request $request, Article $article, CompteMarketPlace $compteMarketPlace, $parametres = [], EntityManagerInterface $em,
ValidatorInterface $validator, ArticleMarketPlaceService $service_article_market_place, Datatable $datatable
) {
$repo_article_market_place = $em->getRepository(ArticleMarketPlace::class);
$repo_article_market_place_image = $em->getRepository(ArticleMarketPlaceImage::class);
if (is_array($request->query->get('parametres'))) {
$parametres = $request->query->get('parametres');
}
if (array_key_exists('mp', $parametres) && $parametres["mp"] == $compteMarketPlace->getId()) {
if ($request->isMethod('POST')) {
$articleMarketPlace = $repo_article_market_place->find($request->request->get('articleMarketPlaceId'));
} elseif ( ! $request->isMethod('POST') && array_key_exists('amp', $parametres) && $parametres["amp"] == "new") {
//echo "erreurerreurerreurerreurerreurerreur";
$articleMarketPlaceParent = $repo_article_market_place->findOneBy(["article" => $article, "compteMarketPlace" => $compteMarketPlace, "articleMarketPlaceParent" => null]
);
$articleMarketPlaceSource = "";
if (array_key_exists('source', $parametres) && $parametres["source"] != "") {
$articleMarketPlaceSource = $repo_article_market_place->find($parametres["source"]);
}
if ( ! is_object($articleMarketPlaceSource)) {
$articleMarketPlaceSource = $repo_article_market_place->findOneBy(["article" => $article, "compteMarketPlace" => $compteMarketPlace], ["id" => "desc"]);
}
$articleMarketPlace = new ArticleMarketPlace;
$articleMarketPlace->setArticle($article);
if (is_object($articleMarketPlaceSource)) {
$articleMarketPlace->setLibelle($articleMarketPlaceSource->getLibelle());
$articleMarketPlace->setPrixVente($articleMarketPlaceSource->getPrixVente());
$articleMarketPlace->setTitreDescription($articleMarketPlaceSource->getTitreDescription());
$articleMarketPlace->setRenouvellementAuto(true);
} else {
$articleMarketPlace->setLibelle($article->getLibelle());
}
if (is_object($articleMarketPlaceSource)) {
$articleMarketPlace->setDescription($articleMarketPlaceSource->getDescription());
} else {
$articleMarketPlace->setDescription("");
}
if (is_object($articleMarketPlaceSource) and count($articleMarketPlaceSource->getArticleCategorie()) > 0) {
foreach ($articleMarketPlaceSource->getArticleCategorie() as $c) {
$ArticleCategorie = new ArticleCategorie;
$ArticleCategorie->setCategorie($c->getCategorie());
$ArticleCategorie->setArticleMarketPlace($articleMarketPlace);
$em->persist($ArticleCategorie);
}
}
if (is_object($articleMarketPlaceSource)) {
$imagesAnnonceSource = $repo_article_market_place_image->findBy(["articleMarketPlace" => $articleMarketPlaceSource]);
if (count($imagesAnnonceSource) > 0) {
foreach ($imagesAnnonceSource as $imgSource) {
$articleMarketPlaceImage = new ArticleMarketPlaceImage();
$articleMarketPlaceImage->setArticleMarketPlace($articleMarketPlace);
$articleMarketPlaceImage->setImage($imgSource->getImage());
$em->persist($articleMarketPlaceImage);
}
}
}
$articleMarketPlace->setStock(100);
$articleMarketPlace->setCompteMarketPlace($compteMarketPlace);
$repo_ean = $em->getRepository(Ean::class);
$ean = $repo_ean->findOneBy(['libre' => true]);
if (is_object($ean)) {
$articleMarketPlace->setEan($ean->getCode());
$articleMarketPlace->setEanObjet($ean);
$ean->setLibre(false);
$em->persist($ean);
}
if (is_object($articleMarketPlaceParent)) {
$articleMarketPlace->setArticleMarketPlaceParent($articleMarketPlaceParent);
}
$em->persist($articleMarketPlace);
$em->flush();
$em->refresh($articleMarketPlace);
if ($article->getCodeProduit() != "") {
//echo "AAAA";
$skuGen = "AMA".$compteMarketPlace->getId().str_replace(" ", "", $article->getCodeProduit());
$testAnnonceSku = $repo_article_market_place->findOneBy(["article" => $article, "compteMarketPlace" => $compteMarketPlace, "sku" => $skuGen]);
if ( ! is_object($testAnnonceSku)) {
$articleMarketPlace->setSku($skuGen);
} else {
for ($l = 1; $l <= 100; $l++) {
$skuGen = "AMA".$compteMarketPlace->getId().str_replace(" ", "", $article->getCodeProduit());
$skuGen .= "/".$l;
$testAnnonceSku = $repo_article_market_place->findOneBy(["article" => $article, "compteMarketPlace" => $compteMarketPlace, "sku" => $skuGen]);
if ( ! is_object($testAnnonceSku)) {
$articleMarketPlace->setSku($skuGen);
break;
}
}
}
}
} elseif (array_key_exists('amp', $parametres)) {
//echo "okokokok";
$articleMarketPlace = $repo_article_market_place->find($parametres["amp"]);
}
} else {
//$articleMarketPlace = $repo_article_market_place->findOneBy(array("article"=>$article,"compteMarketPlace"=>$compteMarketPlace, 'visible'=>true));
$articleMarketPlace = $repo_article_market_place->listerAnnonnceArticle($article, $compteMarketPlace);
}
if (array_key_exists('amp', $parametres) && $parametres["amp"] != "new") {
//echo "TESTETS".$parametres["amp"];
$articleMarketPlaceTemp = $repo_article_market_place->find($parametres["amp"]);
if (is_object($articleMarketPlaceTemp) && $articleMarketPlaceTemp->getCompteMarketPlace()->getId() == $compteMarketPlace->getId()) {
$articleMarketPlace = $articleMarketPlaceTemp;
}
}
//print_r($parametres);
if ( ! is_object($articleMarketPlace)) {
//echo "NOUVEAU";
$repo_regle_taxe = $em->getRepository(RegleTaxe::class);
$regle_taxe = $repo_regle_taxe->find(1);
$articleMarketPlace = new ArticleMarketPlace;
$articleMarketPlace->setArticle($article);
$articleMarketPlace->setStatut(false);
$articleMarketPlace->setCompteMarketPlace($compteMarketPlace);
$articleMarketPlace->setVisible(false);
$articleMarketPlace->setLibelle($article->getLibelle());
$articleMarketPlace->setStock($article->getStock());
$articleMarketPlace->setTitreSeo($article->getLibelle());
$articleMarketPlace->setPrixvente($article->getPrixvente());
$articleMarketPlace->setResume($article->getDescriptionCourte());
$articleMarketPlace->setUrlRewriting($this->slugify($article->getLibelle()));
$articleMarketPlace->setRegleTaxe($regle_taxe);
$em->persist($articleMarketPlace);
$em->flush();
$em->refresh($articleMarketPlace);
if ($article->getCodeProduit() != "") {
$skuGen = "AMA".$compteMarketPlace->getId().str_replace(" ", "", $article->getCodeProduit()).$articleMarketPlace->getId();
if (array_key_exists('amp', $parametres) && $parametres["amp"] == "new") {
//$annonceEan = $repo_article_market_place->findOneBy(array("article"=>$article->getCodeProduit(),"compteMarketPlace"=>$compteMarketPlace));
}
$articleMarketPlace->setSku($skuGen);
$annonceEan = $repo_article_market_place->findOneBy(["ean" => $article->getCodeProduit(), "compteMarketPlace" => $compteMarketPlace]);
if ( ! is_object($annonceEan)) {
$articleMarketPlace->setEan($article->getCodeProduit());
// TODO FIX THIS
if (is_object($article->getEan())) {
$articleMarketPlace->setEanObjet($article->getEan());
}
}
}
$articleMarketPlace->setLibelle($article->getLibelle());
$articleMarketPlace->setStatut(false);
$articleMarketPlace->setDescription($article->getDescription());
} else {
//echo "ANCIEN";
if ($articleMarketPlace->getLibelle() == "") {
$articleMarketPlace->setLibelle($article->getLibelle());
}
if ($articleMarketPlace->getDescription() == "") {
$articleMarketPlace->setDescription($article->getDescription());
}
if ($articleMarketPlace->getSku() == "" and $article->getCodeProduit() != "") {
//$skuGen = "AMA".$compteMarketPlace->getId().str_replace(" ","",$article->getCodeProduit());
//$articleMarketPlace->setSku($skuGen);
}
if ($articleMarketPlace->getEan() == "" and $article->getCodeProduit() != "" and $articleMarketPlace->getIdImport() == "") {
/*
$annonceEan = $repo_article_market_place->findOneBy(array("ean"=>$article->getCodeProduit(),"compteMarketPlace"=>$compteMarketPlace));
if(!is_object($annonceEan)) {
$articleMarketPlace->setEan($article->getCodeProduit());
if(is_object($article->getEan())) {
$articleMarketPlace->setEanObjet($article->getEan());
}
}
*/
}
}
//exit;
//$conn = $em->getConnection();
//$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();
//echo "<div>".$sql."</div>";
//$stmt = $conn->query($sql);
//$stmt->execute();
$form = $this->createForm(ArticleMarketPlaceType::class, $articleMarketPlace);
$errors = "";
$renouvelable = true;
$termine = false;
$date = new \Datetime;
$endTime = $articleMarketPlace->getEndTime();
if (is_object($endTime) && $date > $endTime) {
$termine = true;
$diff = $date->diff($endTime);
if ($diff->format('%a') > 90) {
$renouvelable = false;
}
}
$form->handleRequest($request);
if ($form->isSubmitted()) {
if ($form->isValid()) {
/*
if($articleMarketPlace->getEan() != "") {
$repo_ean = $em->getRepository('DTCArticlesBundle:Ean');
$ean_obj = $repo_ean->findOneBy(array('code'=>$articleMarketPlace->getEan()));
if(is_object($ean_obj) && $ean_obj->getLibre() == true) {
$ean_obj->setLibre(false);
$em->persist($ean_obj);
$articleMarketPlace->setEanObjet($ean_obj);
}
else {
$repo_ean = $em->getRepository('DTCArticlesBundle:Ean');
$ean = $repo_ean->findOneBy(array('libre'=>true));
$articleMarketPlace->setEan("");
if(is_object($ean)) {
$ean->setLibre(false);
$em->persist($ean);
$articleMarketPlace->setEan($ean->getCode());
$articleMarketPlace->setEanObjet($ean);
}
}
}
*/
$erreur_image = false;
$erreur_categorie_priceminister = false;
$erreur_image_annonce = false;
$erreur_sku_priceminister = false;
$erreur_sku_priceminister_existe = false;
$erreur_sku_ean = false;
$erreur_sku_ean_existe = false;
$temp_sku = "";
if (is_object($articleMarketPlace->getArticle()) && count($articleMarketPlace->getArticle()->getImages()) == 0) {
$erreur_image = true;
}
//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")) {
if (is_object($articleMarketPlace->getCompteMarketPlace()) and is_object($articleMarketPlace->getCompteMarketPlace()->getMarketPlace())) {
$imagesAnnonce = $repo_article_market_place_image->findBy(["articleMarketPlace" => $articleMarketPlace]);
if (count($imagesAnnonce) == 0) {
//$erreur_image_annonce = true;
}
if (count($articleMarketPlace->getArticleCategorie()) == 0 and ($articleMarketPlace->getIdImport() == null or $articleMarketPlace->getIdImport() == "")) {
$erreur_categorie_priceminister = true;
}
if (($articleMarketPlace->getSku() == "" or $articleMarketPlace->getSku() == null) and ($articleMarketPlace->getIdImport() == "" or $articleMarketPlace->getIdImport(
) == null)) {
$erreur_sku_priceminister = true;
}
if ($articleMarketPlace->getSku() != "") {
$articleMarketPlaceSku = $repo_article_market_place->findBy(
["compteMarketPlace" => $articleMarketPlace->getCompteMarketPlace(), "sku" => $articleMarketPlace->getSku()]
);
if (count($articleMarketPlaceSku) > 1) {
$erreur_sku_priceminister_existe = true;
$temp_sku = $articleMarketPlace->getSku();
$articleMarketPlace->setSku("");
} else {
foreach ($articleMarketPlaceSku as $ampsku) {
if ($ampsku->getId() != $articleMarketPlace->getId()) {
$erreur_sku_priceminister_existe = true;
$temp_sku = $articleMarketPlace->getSku();
$articleMarketPlace->setSku("");
}
}
}
}
// echo "<div>EAN ".$articleMarketPlace->getEan()."</div>";
if ($articleMarketPlace->getEan() != "" and 1 != 1) {
$articleMarketPlaceSku = $repo_article_market_place->findBy(
["ean" => $articleMarketPlace->getEan(), "compteMarketPlace" => $articleMarketPlace->getCompteMarketPlace()]
);
//echo "<div><COUNT ".count($articleMarketPlaceSku)."</div>";
if (count($articleMarketPlaceSku) > 1) {
$erreur_sku_ean_existe = true;
$temp_sku = $articleMarketPlace->getSku();
$articleMarketPlace->setEan("");
$articleMarketPlace->setEanObjet(null);
} else {
foreach ($articleMarketPlaceSku as $ampsku) {
if ($ampsku->getId() != $articleMarketPlace->getId()) {
$erreur_sku_ean_existe = true;
//$temp_sku = $articleMarketPlace->getSku();
$articleMarketPlace->setEan("");
$articleMarketPlace->setEanObjet(null);
}
}
}
}
if (($articleMarketPlace->getIdImport() == "" or $articleMarketPlace->getIdImport() == null) and ($articleMarketPlace->getEan() == null or $articleMarketPlace->getEan(
) == "")) {
//if(($articleMarketPlace->getIdImport() == "" or $articleMarketPlace->getIdImport() == NULL) and ($articleMarketPlace->getArticle()->getCodeProduit() == NULL or $articleMarketPlace->getArticle()->getCodeProduit() == "")) {
//$erreur_sku_ean = true;
}
}
$postForm = $request->request->all();
//print_r($postForm);
$statutArticleMarketPlace = $em->getRepository(StatutArticle::class)->find(1);
if ((count($article->getArticleCategorie()) > 0 || $articleMarketPlace->getCompteMarketPlace()->getMarketPlace()->getId() == 1) && $articleMarketPlace->getLibelle(
) != "" && $articleMarketPlace->getDescription(
) != "" && ! $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(
) > 0 and ($articleMarketPlace->getAnnonceSupprime() == null or $articleMarketPlace->getAnnonceSupprime() == 0)) {
$articleMarketPlace->setDateDemandePublicationMarketPlace(new \Datetime());
$articleMarketPlace->setStatutArticleMarketPlace($statutArticleMarketPlace);
$articleMarketPlace->setEnvoyerUniquementStock(0);
if (array_key_exists('supprimer', $postForm) and $postForm["supprimer"] == "1" and is_object($articleMarketPlace->getCompteMarketPlace()) and is_object(
$articleMarketPlace->getCompteMarketPlace(
)->getMarketPlace()
) and $articleMarketPlace->getCompteMarketPlace(
)->getMarketPlace()->getId() == "4") {
$articleMarketPlace->setAnnonceSupprime(1);
}
if ($articleMarketPlace->getArret() == true) {
$articleMarketPlace->setStatut(false);
}
} else {
$articleMarketPlace->setDateDemandePublicationMarketPlace(null);
$articleMarketPlace->setStatutArticleMarketPlace(null);
}
//recuperer le texte brut
$soumission = $request->request->get('soumission');
if ($soumission == "recuperer") {
if (is_object($articleMarketPlace)) {
$idImport = $articleMarketPlace->getIdImport();
if ($idImport != '') {
$response = $service_article_market_place->getItem($idImport);
if ($response->Ack !== 'Failure') {
$description = $service_article_market_place->nettoyer($response->Item->Description);
$titreDescription = $articleMarketPlace->getLibelle();
$articleMarketPlace->setDescription($description);
$articleMarketPlace->setTitreDescription($titreDescription);
$this->addFlash('notice', 'Récupération du texte brut');
} else {
$message = '';
if (isset($response->Errors)) {
foreach ($response->Errors as $error) {
/*
printf(
"%s: %s\n%s\n\n",
$error->SeverityCode === Enums\SeverityCodeType::C_ERROR ? 'Error' : 'Warning',
$error->ShortMessage,
$error->LongMessage
);
*
*/
$message .= '<br>'.$error->SeverityCode;
$message .= '<br>'.$error->ShortMessage;
$message .= '<br>'.$error->LongMessage;
}
}
$this->addFlash('warning', 'Problème de récupération du texte brut.'.$message);
}
}
}
}
$em->persist($articleMarketPlace);
$em->flush();
$conn = $em->getConnection();
/*
$sql = 'DELETE FROM market_place__article_market_place_caracteristique WHERE article_market_place_id="'.$articleMarketPlace->getId().'"';
$stmt = $conn->query($sql);
$stmt->execute();
*/
/*
if(count($articleMarketPlace->getArticleCategorie())>0) {
foreach($articleMarketPlace->getArticleCategorie() as $articleCategorie) {
$caracteristiques = $serviceCategories->getCaracteristiqueCategorie($articleCategorie->getCategorie());
foreach($caracteristiques as $car) {
if (array_key_exists('carac_'.$car->getId(), $postForm)) {
//echo "<div>okokokok ".$car->getLibelle()."==> ".$postForm['carac_'.$car->getId()]."</div>";
//carac_{{carac.id}}_libre
$valeur = $postForm['carac_'.$car->getId()];
if (array_key_exists('carac_'.$car->getId().'_libre', $postForm) && $postForm['carac_'.$car->getId().'_libre'] != "") {
$valeur = $postForm['carac_'.$car->getId().'_libre'];
}
$articleMarketPlaceCaracteristique = new ArticleMarketPlaceCaracteristique();
$articleMarketPlaceCaracteristique->setValeur($valeur);
$articleMarketPlaceCaracteristique->setCaracteristique($car);
$articleMarketPlaceCaracteristique->setArticleMarketPlace($articleMarketPlace);
$em->persist($articleMarketPlaceCaracteristique);
}
}
}
}
*/
$em->flush();
//Mise à jour de la couleur de ligne
//$article = $articleMarketPlace->getArticle();
//$couleur = $articleService->couleurLigne($article->getId());
//$article->setCouleurLigne($couleur);
//$em->persist($article);
$em->flush();
$erreur_construit = "";
if ($erreur_image_annonce) {
$erreur_construit .= "<br/>Merci de choisir une image !";
}
if ($erreur_categorie_priceminister and 1 != 1) {
$erreur_construit .= "<br/>Merci de choisir une catégorie market place !";
}
if (trim($articleMarketPlace->getPrixVente()) == "" or is_null(trim($articleMarketPlace->getPrixVente()))) {
$erreur_construit .= "<br/>Merci de définir un prix de vente !";
}
if ($erreur_sku_priceminister) {
$erreur_construit .= "<br/>Merci de définir un SKU !";
}
if ($erreur_sku_priceminister_existe) {
$erreur_construit .= "<br/>SKU (".$temp_sku.") non disponible, il déjà attribué à une autre offre ".$articleMarketPlace->getCompteMarketPlace()->getMarketPlace(
)->getLibelle()." !";
}
if ($erreur_sku_ean) {
$erreur_construit .= "<br/>Merci de définir un code EAN !";
}
if ($erreur_sku_ean_existe) {
$erreur_construit .= "<br/>Code EAN déja utilisé !";
}
if ($erreur_image) {
$erreur_construit .= "<br/>Merci d'uploader au moins une image !";
}
if (count($article->getArticleCategorie()) == 0 and 1 != 1) {
$erreur_construit .= "<br/>Merci de choisir une catégorie pour la fiche produit";
}
if ($articleMarketPlace->getLibelle() == "") {
$erreur_construit .= "<br/>Merci de définir un libellé";
}
if ($articleMarketPlace->getDescription() == "" and 1 != 1) {
$erreur_construit .= "<br/>Merci de définir une description";
}
if ($erreur_construit == "") {
if ($articleMarketPlace->getAnnonceSupprime() == null or $articleMarketPlace->getAnnonceSupprime() == 0) {
$this->addFlash('notice', 'Offre modifiée avec succès !!');
}
} else {
$this->addFlash('warning', $erreur_construit);
}
//echo "amp==>".$articleMarketPlace->getId();
//exit;
//Mofifier les prix des autres annonces
$annoncesAmodifier = $repo_article_market_place->findBy([
'article' => $articleMarketPlace->getArticle(),
'prixVente' => null,
'statutArticleMarketPlace' => null,
'idImport' => null,
]);
if (count($annoncesAmodifier)) {
$prixVente = $articleMarketPlace->getPrixVente();
foreach ($annoncesAmodifier as $annonceAmodifier) {
$annonceAmodifier->setPrixVente($prixVente);
$em->persist($annonceAmodifier);
}
$em->flush();
}
return $this->redirectToRoute(
'dtc_article_modifier',
["id" => $article->getId(), 'amp' => $articleMarketPlace->getId(), 'tab' => "m".$articleMarketPlace->getCompteMarketPlace()->getId()]
);
} else {
$errors = $validator->validate($articleMarketPlace);
$this->addFlash('warning', 'formulaire non valide !');
foreach ($errors as $error) {
$this->addFlash('warning', $error);
}
//echo "HHHHH";
//\Doctrine\Common\Util\Debug::dump($errors);
//return $this->redirectToRoute('dtc_article_modifier',array("id"=>$article->getId(),'amp'=>$articleMarketPlace->getId() ,'tab'=>"m".$articleMarketPlace->getCompteMarketPlace()->getId()));
}
}
if (array_key_exists('mp', $parametres) && $parametres["mp"] == $compteMarketPlace->getId() && is_object($articleMarketPlace->getArticleMarketPlaceParent())) {
$this->datatableEnfants($datatable, $articleMarketPlace, $article);
} else {
$this->datatableEnfants($datatable, $articleMarketPlace, $article);
}
return $this->render('MarketPlace/ArticleMarketPlace/ajouter.html.twig', [
'form' => $form->createView(),
"articleMarketPlace" => $articleMarketPlace,
"article" => $article,
"compteMarketPlace" => $compteMarketPlace,
"parametres" => $parametres,
'renouvelable' => $renouvelable,
'termine' => $termine,
]);
}
/**
* @Route("/article/marketplace/enfants/grid/{id}/{article}", name="dtc_article_market_place_enfants_grid")
*/
public function gridEnfantsAction(Request $request, CompteMarketPlace $compteMarketPlace, Article $article, Datatable $datatable)
{
return $this->datatableEnfants($datatable, $compteMarketPlace, $article)->execute();
}
public function datatableEnfants(Datatable $datatable, $compteMarketPlace, $article)
{
$datatable->setDatatableId('dta-enfants-'.$compteMarketPlace->getId())
->setEntity(ArticleMarketPlace::class, "x")
->setFields(
[
"ID" => 'x.id',
"Sku" => 'x.sku',
"EAN" => 'x.ean',
"Id Import" => 'x.idImport',
"Libellé" => 'x.libelle',
"Prix" => 'x.prixVente',
"Stock" => 'x.stock',
"En ligne" => 'x.statut',
"En publication" => 'x.id',
"Langue" => 'x.siteMarketPlace',
"Actions" => 'x.id',
"_identifier_" => 'x.id',
]
)
->addJoin('x.compteMarketPlace', 'cmp', \Doctrine\ORM\Query\Expr\Join::LEFT_JOIN)
->addJoin('x.article', 'a', \Doctrine\ORM\Query\Expr\Join::LEFT_JOIN)
//->addJoin('x.contact', 'c', \Doctrine\ORM\Query\Expr\Join::LEFT_JOIN)
->setWhere(
'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'
, [
'compteMarketPlace' => $compteMarketPlace->getId(),
'article' => $article->getId(),
]
)
/*
->setWhere(
'(x.articleMarketPlaceParent = :articleMarketPlaceParent or x.id = :articleMarketPlaceParent)'
,array('articleMarketPlaceParent'=>$articleMarketPlaceParent)
)
*/
->setGroupBy('x.id')
->setRenderers(
[
5 => [
'view' => 'FO/DataTable/prix.html.twig',
'params' => [
'edit_route' => 'dtc_article_market_place_changer_statut_en_ligne',
'afficher_total' => false,
],
],
7 => [
'view' => 'FO/DataTable/statut_id_import.html.twig',
'params' => [
'edit_route' => 'dtc_article_market_place_changer_statut_en_ligne',
],
],
8 => [
'view' => 'FO/DataTable/statut_publication_article_market_place.html.twig',
'params' => [
//'edit_route' => 'dtc_erreur_article_market_place_changer_statut',
'edit_route' => 'dtc_article_market_place_changer_statut',
//'compteMarketPlaceId' => 5
],
],
9 => ['view' => 'FO/DataTable/siteMarketPlace.html.twig'],
10 => [
'view' => 'FO/DataTable/actions_article_market_place.html.twig',
'params' => [
// 'edit_route' => 'dtc_market_place_modifier_modal',
'supprimer_route' => 'dtc_article_market_place_supprimer',
'historique_route' => 'dtc_article_market_place_historique',
'deplacer_route' => 'dtc_article_market_place_historique',
'table' => 'dta-enfants-'.$compteMarketPlace->getId(),
// 'id' => $objet->getId(),
// 'type' => $type,
// 'entite' => 'adresse',
// 'objet' => "DTCMarketPlaceBundle:ArticleMarketPlace"
],
],
/*
1 => array(
'view' => 'FO/DataTable/actions_modal.html.twig',
'params' => array(
'edit_route' => 'dtc_note_modifier',
'supprimer_route' => 'dtc_note_supprimer',
'id' => $client->getId(),
'type' => "client",
'objet' => "DTCClientsBundle:Note",
'width_modal' => 900,
),
),
*/
]
)
//->setOrder("x.dateSaisie", "desc")
->setSearch(true)
->setSearchFields([1, 2])/*
->setMultiple(
array(
'delete' => array(
'title' => 'Dupliquer',
'route' => 'dtc_article_market_place_dupliquer'
),
)
)
*/
;
//$where = "x.client = :client AND (x.prive = :prive OR x.prive IS NULL or x.utilisateur = :utilisateur)";
//$parameters = array("prive"=>0,"utilisateur"=>$user,'client'=>$client);
//$datatable->setWhere($where, $parameters);
return $datatable;
}
/**
* @Route("/article/marketplace/actiondupliquer", name="dtc_article_market_place_action_dupliquer")
*/
public function dupliquerAction(Request $request)
{
return new JsonResponse(['type' => 'dupliquer', 'valide' => '1']);
}
/**
* @Route("/article/marketplace/dupliquer", name="dtc_article_market_place_dupliquer")
*/
public function dupliquerModalAction(Request $request, EntityManagerInterface $em, ValidatorInterface $validator, ArticleMarketPlaceService $service_article_market_place)
{
$titre_modal = "Duplication d'annonces";
$user = $this->getUser();
$articleMarketPlace = new ArticleMarketPlace;
$get = $request->query->all();
$repo_article_market_place = $em->getRepository(ArticleMarketPlace::class);
$repo_article_market_place_image = $em->getRepository(ArticleMarketPlaceImage::class);
$repo_statut_article_market_place = $em->getRepository(StatutArticle::class);
$repo_compte_market_place = $em->getRepository(CompteMarketPlace::class);
$repo_article_categorie = $em->getRepository(ArticleCategorie::class);
$repo_article_market_place_caracteristique = $em->getRepository(ArticleMarketPlaceCaracteristique::class);
$nb_en_publications = "0";
$annonces_a_dupliquer = $repo_article_market_place->getAnnoncesIn($get["ids"]);
$comptes_market_place = $repo_compte_market_place->findAll();
$nbAnnoncesCrees = 0;
$marketCourant = "";
$article = "";
foreach ($annonces_a_dupliquer as $a) {
$article = $a->getArticle();
$marketCourant = $a->getCompteMarketPlace();
break;
}
//print_r($get["ids"]);
$form = $this->createForm(DupliquerArticleMarketPlaceType::class, $articleMarketPlace);
$errors = "";
$form->handleRequest($request);
if ($form->isSubmitted()) {
$post = $request->request->all();
$dateAnnonce = new \Datetime();
$listeCompteMarketPlaceId = $post["compteMarketPlace"];
if ($form->isValid()) {
$repo_ean = $em->getRepository(Ean::class);
$construction_erreur = [];
$creation_erreur = [];
$statutAPublierAnnonce = $repo_statut_article_market_place->find(1);
for ($o = 0; $o < count($listeCompteMarketPlaceId); $o++) {
$compteMarketPlaceDestination = $repo_compte_market_place->find($listeCompteMarketPlaceId[$o]);
foreach ($annonces_a_dupliquer as $a) {
$erreur_categorie = true;
$erreur_image = true;
$erreur_libelle = false;
$erreur_description = false;
$erreur_prix = false;
$erreur_ean = false;
$erreur_stock = false;
if ($a->getLibelle() == "") {
$erreur_libelle = true;
}
if ($a->getDescription() == "") {
$erreur_description = true;
}
if ($a->getPrixVente() == "") {
$erreur_prix = true;
}
if ($a->getStock() == "") {
$erreur_stock = true;
}
$images = $repo_article_market_place_image->findBy(["articleMarketPlace" => $a]);
if (count($images) > 0) {
foreach ($images as $i) {
$erreur_image = false;
}
}
$categorie_annonce = $repo_article_categorie->findBy(["article" => $article, "marketPlace" => $compteMarketPlaceDestination->getMarketPlace()]);
if (count($categorie_annonce) > 0) {
foreach ($categorie_annonce as $categ) {
$erreur_categorie = false;
}
}
if ($erreur_categorie) {
$annonce_du_compte_destination = $repo_article_market_place->findBy(["article" => $article, "compteMarketPlace" => $compteMarketPlaceDestination]);
if (count($annonce_du_compte_destination) > 0) {
foreach ($annonce_du_compte_destination as $andc) {
if (count($andc->getArticleCategorie()) > 0) {
$erreur_categorie = false;
break;
}
}
}
}
if ( ! $erreur_categorie && ! $erreur_image && ! $erreur_libelle && ! $erreur_description && ! $erreur_prix && ! $erreur_stock) {
$a_au_moins_une_image = false;
$a_au_moins_une_categorie = false;
$article = $a->getArticle();
$articleMarketPlaceDuplique = new ArticleMarketPlace;
if ($article->getCodeProduit() != "") {
$skuGen = "AMA".$compteMarketPlaceDestination->getId().str_replace(" ", "", $article->getCodeProduit());
$testAnnonceSku = $repo_article_market_place->findOneBy(["article" => $article, "compteMarketPlace" => $compteMarketPlaceDestination, "sku" => $skuGen]);
if ( ! is_object($testAnnonceSku)) {
$articleMarketPlaceDuplique->setSku($skuGen);
} else {
for ($l = 1; $l <= 100; $l++) {
$skuGen = "AMA".$compteMarketPlaceDestination->getId().str_replace(" ", "", $article->getCodeProduit());
$skuGen .= "/".$l;
$testAnnonceSku = $repo_article_market_place->findOneBy(
["article" => $article, "compteMarketPlace" => $compteMarketPlaceDestination, "sku" => $skuGen]
);
if ( ! is_object($testAnnonceSku)) {
$articleMarketPlaceDuplique->setSku($skuGen);
break;
}
}
}
}
$articleMarketPlaceDuplique->setLibelle($a->getLibelle());
$description = $a->getDescription();
if ($compteMarketPlaceDestination->getId() == "1") {
$description = $service_article_market_place->formatTexteAnnonceEbay($description);
$articleMarketPlaceDuplique->setRenouvellementAuto(1);
}
$articleMarketPlaceDuplique->setDescription($description);
$articleMarketPlaceDuplique->setPrixVente($a->getPrixVente());
$articleMarketPlaceDuplique->setPrixVente($a->getPrixVente());
$articleMarketPlaceDuplique->setStock(100);
$articleMarketPlaceDuplique->setDate($dateAnnonce);
$articleMarketPlaceDuplique->setStatut($a->getStatut());
$articleMarketPlaceDuplique->setVisible($a->getVisible());
$articleMarketPlaceDuplique->setEnvoyerImageAmazon(0);
$articleMarketPlaceDuplique->setArticle($article);
$articleMarketPlaceDuplique->setCompteMarketPlace($compteMarketPlaceDestination);
$ean = $repo_ean->findOneBy(['libre' => true]);
if (is_object($ean)) {
$articleMarketPlaceDuplique->setEan($ean->getCode());
$articleMarketPlaceDuplique->setEanObjet($ean);
$ean->setLibre(false);
$em->persist($ean);
}
$nbAnnoncesCrees++;
$em->persist($articleMarketPlaceDuplique);
$em->flush();
$em->refresh($articleMarketPlaceDuplique);
$images = $repo_article_market_place_image->findBy(["articleMarketPlace" => $a]);
if (count($images) > 0) {
foreach ($images as $i) {
$a_au_moins_une_image = true;
$articleMarketPlaceImage = new ArticleMarketPlaceImage();
$articleMarketPlaceImage->setImage($i->getImage());
$articleMarketPlaceImage->setOrdre($i->getOrdre());
$articleMarketPlaceImage->setArticleMarketPlace($articleMarketPlaceDuplique);
$articleMarketPlaceImage->setDate($dateAnnonce);
$em->persist($articleMarketPlaceImage);
}
}
$em->flush();
$categorie_annonce = $repo_article_categorie->findBy(["article" => $article, "marketPlace" => $compteMarketPlaceDestination->getMarketPlace()]);
if (count($categorie_annonce) > 0) {
foreach ($categorie_annonce as $categ) {
$a_au_moins_une_categorie = true;
$articleCategorie = new ArticleCategorie();
$articleCategorie->setArticleMarketPlace($articleMarketPlaceDuplique);
$articleCategorie->setCategorie($categ->getCategorie());
$em->persist($articleCategorie);
}
}
if ( ! $a_au_moins_une_categorie) {
$annonce_du_compte_destination = $repo_article_market_place->findBy(["article" => $article, "compteMarketPlace" => $compteMarketPlaceDestination]);
if (count($annonce_du_compte_destination) > 0) {
foreach ($annonce_du_compte_destination as $andc) {
if (count($andc->getArticleCategorie()) > 0) {
$a_au_moins_une_categorie = true;
foreach ($andc->getArticleCategorie() as $categ) {
$a_au_moins_une_categorie = true;
$articleCategorie = new ArticleCategorie();
$articleCategorie->setArticleMarketPlace($articleMarketPlaceDuplique);
$articleCategorie->setCategorie($categ->getCategorie());
$em->persist($articleCategorie);
}
break;
}
}
}
}
$caracteristiques = $repo_article_market_place_caracteristique->findBy(["article" => $article]);
if (count($caracteristiques) > 0) {
foreach ($caracteristiques as $cara) {
$articleMarketPlaceCaracteristique = new ArticleMarketPlaceCaracteristique();
$articleMarketPlaceCaracteristique->setCaracteristique($cara->getCaracteristique());
$articleMarketPlaceCaracteristique->setValeur($cara->getValeur());
$articleMarketPlaceCaracteristique->setArticleMarketPlace($articleMarketPlaceDuplique);
$em->persist($articleMarketPlaceCaracteristique);
}
}
$em->flush();
$sans_erreur = true;
$construction_erreur_temp = "";
if ( ! $a_au_moins_une_categorie) {
$sans_erreur = false;
$construction_erreur_temp .= "<div>Catégorie manquante</div>";
}
if ( ! $a_au_moins_une_image) {
$sans_erreur = false;
$construction_erreur_temp .= "<div>Image manquante</div>";
}
if ($articleMarketPlaceDuplique->getLibelle() == "") {
$sans_erreur = false;
$construction_erreur_temp .= "<div>Libellé manquant</div>";
}
if ($articleMarketPlaceDuplique->getDescription() == "") {
$sans_erreur = false;
$construction_erreur_temp .= "<div>Description manquante</div>";
}
if ($articleMarketPlaceDuplique->getPrixVente() == "") {
$sans_erreur = false;
$construction_erreur_temp .= "<div>Prix de vente manquant</div>";
}
if ($articleMarketPlaceDuplique->getEan() == "") {
$sans_erreur = false;
$construction_erreur_temp .= "<div>Ean manquant</div>";
}
if ($articleMarketPlaceDuplique->getStock() == "") {
$sans_erreur = false;
$construction_erreur_temp .= "<div>Stock manquant</div>";
}
if ($construction_erreur_temp != "") {
$construction_erreur[$articleMarketPlaceDuplique->getId()] = $construction_erreur_temp;
}
if ($sans_erreur && ($articleMarketPlaceDuplique->getVisible() or is_null($articleMarketPlaceDuplique->getVisible()))) {
$articleMarketPlaceDuplique->setDateDemandePublicationMarketPlace($dateAnnonce);
$articleMarketPlaceDuplique->setStatutArticleMarketPlace($statutAPublierAnnonce);
$em->persist($articleMarketPlaceDuplique);
$nb_en_publications++;
}
$em->flush();
} else {
$construction_erreur_temp = "";
if ($erreur_categorie) {
$sans_erreur = false;
$construction_erreur_temp .= "<div>Catégorie manquante</div>";
}
if ($erreur_image) {
$sans_erreur = false;
$construction_erreur_temp .= "<div>Image manquante</div>";
}
if ($erreur_libelle) {
$sans_erreur = false;
$construction_erreur_temp .= "<div>Libellé manquant</div>";
}
if ($erreur_description) {
$sans_erreur = false;
$construction_erreur_temp .= "<div>Description manquante</div>";
}
if ($erreur_prix) {
$sans_erreur = false;
$construction_erreur_temp .= "<div>Prix de vente manquant</div>";
}
if ($erreur_stock) {
$sans_erreur = false;
$construction_erreur_temp .= "<div>Stock manquant</div>";
}
if ($construction_erreur_temp != "") {
if (array_key_exists($a->getId(), $creation_erreur)) {
$creation_erreur[$a->getId()] .= "Impossible de dupliquer l'offre ".$a->getSku()." pour le market place ".$compteMarketPlaceDestination->getLibelle(
)." ".$construction_erreur_temp;
} else {
$creation_erreur[$a->getId()] = "Impossible de dupliquer l'offre ".$a->getSku()." pour le market place ".$compteMarketPlaceDestination->getLibelle(
)." ".$construction_erreur_temp;
}
}
}
}
}
//echo "<div>NEW ANNONCE ID ".$articleMarketPlaceDuplique->getId()."</div>";
$messageErreur = "";
if (count($construction_erreur) > 0) {
$messageErreur = "";
foreach ($construction_erreur as $key => $value) {
$messageErreur .= "<div>Impossible de lancer la publication de la nouvelle offre id : ".$key."</div>";
$messageErreur .= $value;
}
}
if (count($creation_erreur) > 0) {
$messageErreur = "";
foreach ($creation_erreur as $key => $value) {
//$messageErreur .= "<div>Impossible de lancer la publication de la nouvelle annonce id : ".$key."</div>";
$messageErreur .= $value;
}
}
if ($messageErreur != "") {
$this->addFlash(
'warning',
$messageErreur
);
}
$this->addFlash(
'notice',
$nbAnnoncesCrees.' offre(s) créées avec succès ! '.$nb_en_publications.' sont en cours de publication'
);
$url = $this->generateUrl('dtc_article_modifier', ['id' => $article->getId()]);
return new JsonResponse(['rendu' => '', 'valide' => '1', 'url' => $url]);
} else {
$errors = $validator->validate($articleMarketPlace);
$rendu = $this->renderView(
'MarketPlace/ArticleMarketPlace/dupliquer.html.twig',
[
'marketCourant' => $marketCourant,
'comptes_market_place' => $comptes_market_place,
'annonces_a_dupliquer' => $annonces_a_dupliquer,
'form' => $form->createView(),
'errors' => $errors,
'type' => '',
'objet' => '',
]
);
return new JsonResponse(['rendu' => $rendu, 'valide' => '0', 'url' => '', 'titre' => $titre_modal]);
}
}
$rendu = $this->renderView(
'MarketPlace/ArticleMarketPlace/dupliquer.html.twig',
[
'marketCourant' => $marketCourant,
'comptes_market_place' => $comptes_market_place,
'annonces_a_dupliquer' => $annonces_a_dupliquer,
'form' => $form->createView(),
'errors' => $errors,
'type' => '',
'objet' => '',
]
);
return new JsonResponse(['rendu' => $rendu, 'valide' => '0', 'url' => '', 'titre' => $titre_modal]);
}
/**
* @Route("", name="")
*/
public function modifierAction(Request $request, MarketPlace $marketPlace, EntityManagerInterface $em, ValidatorInterface $validator)
{
$user = $this->getUser();
$marketPlace->setUtilisateur($user);
$form = $this->createForm(MarketPlaceType::class, $marketPlace);
$errors = "";
$form->handleRequest($request);
if ($form->isSubmitted()) {
$droit = $this->isGranted(EntityVoter::UPDATE, MarketPlace::class);
if ( ! $droit) {
return $this->redirectToRoute('dtc_market_place_modifier', ["id" => $marketPlace->getId()]);
}
if ($form->isValid()) {
$em->persist($marketPlace);
$em->flush();
$em->flush();
$this->addFlash(
'notice',
'Market Place modifié avec succès !'
);
return $this->redirectToRoute('dtc_market_place_modifier', ["id" => $marketPlace->getId()]);
} else {
$errors = $validator->validate($marketPlace);
}
}
return $this->render('MarketPlace/MarketPlace/ajouter.html.twig', ['form' => $form->createView(), 'errors' => $errors, 'marketPlace' => $marketPlace]);
}
/**
* @Route("/marketplace/description", name="dtc_market_place_supprimer_description")
*/
public function SupprimerDescriptionAction(Request $request, EntityManagerInterface $em)
{
$repo_article_market_place = $em->getRepository(ArticleMarketPlace::class);
$repoArticle = $em->getRepository(Article::class);
$Articles = $repoArticle->findBy(['mouvemente' => 1]);
//$MKArticles = $repoArticle->findAll();
$compte = 0;
$String = "MODES DE PAIEMENTS PAYPAL Nous acceptons les paiements par PAYPAL.Le paiement doit être effectué dans 7 jours après l'enchère soit finie. CHEQUE BANCAIRE Nous acceptons les paiements par CHEQUE BANCAIRE.Nos coordonnées sont visible sur le récapitulatif de la vente. VIREMENT BANCAIRE Nous acceptons les paiements par VIREMENT BANCAIRE. Nos coordonnées bancaires vous seront envoyés sur simple demande. AUTRES, NOUS CONSULTER Tous nos produits sont neuf dans leurs emballages d'origine Expédition en colissimo suivi 48 /72 Heures dès réception de votre paiement. Nous fournissons facture et documents de garantie (si l'objet est garantie) Créé par eBay Turbo Lister L'outil de mise en vente gratuit. Mettez vos objets en vente rapidement et en toute simplicité, et gérez vos annonces en cours.";
foreach ($Articles as $Article) {
$description = null;
$description = str_replace($String, "", $Article->getDescription());
$Article->setDescription($description);
if ($description != null) {
$compte += 1;
$em->persist($Article);
}
}
$em->flush();
return new Response($compte);
}
/**
* @Route("/marketplace/commentaire/scan", name="dtc_market_scan_commentaire")
*/
public function ScanCommentaireAction(Request $request, EntityManagerInterface $em)
{
$idAnnonce = trim($request->query->get('annonce'));
//$repoMK_Article = $em->getRepository('DTCMarketPlaceBundle:ArticleMarketPlace');
//$repoArticle = $em->getRepository('DTCArticlesBundle:Article');
$repoMK_Article = $em->getRepository(ArticleMarketPlace::class);
if ($request->isMethod('POST')) {
if ($idAnnonce != "") {
$commentaire = $request->get('texte');
$commentaire = str_replace(" ", " ", $commentaire);
$articleMK = $repoMK_Article->find($idAnnonce);
if (is_object($articleMK) and is_object($articleMK->getArticle())) {
$articleMK->setCommentaire(nl2br($commentaire));
$em->persist($articleMK);
$em->flush();
}
$em->flush();
$this->addFlash(
'notice',
'Commentaire enregistré'
);
return $this->redirectToRoute('dtc_market_scan_commentaire', []);
} else {
$article = trim($request->get('articlescan'));
$commentaire = $request->get('commentaire');
$nbArticleMK = $repoMK_Article->findBy(['idImport' => $article]);
if (count($nbArticleMK) > 1) {
$message_erreur = "Plusieurs annonces correspondent à cette référence : ".$article;
return $this->render('GestionComerciale/Annonce/ScanCommentaire.html.twig', ['erreur' => $message_erreur]);
}
$articleMK = $repoMK_Article->findOneBy(['idImport' => $article]);
if ($article == "") {
return $this->render('GestionComerciale/Annonce/ScanCommentaire.html.twig', ['erreur' => "Id import non reconnu"]);
}
if ($articleMK == null) {
$articleMK = $repoMK_Article->findOneBy(['idImport' => $article]);
if ($articleMK == null) {
return $this->render('GestionComerciale/Annonce/ScanCommentaire.html.twig', ['erreur' => "Annonce inconnue"]);
}
}
$commentaire = $articleMK->getCommentaire();
$commentaire = str_replace(" ", " ", $commentaire);
return $this->redirectToRoute('dtc_market_scan_commentaire', ["annonceObj" => $articleMK, "annonce" => $articleMK->getId(), "commentaire" => $commentaire]);
}
//$articleMK->setPointageAmazon(1);
//$articleMK->setDatePointage(new \Datetime());
//$em->persist($articleMK);
/*
$em->flush();
$this->addFlash(
'notice',
'Article pointé'
);
*/
return $this->render('GestionComerciale/Annonce/ScanCommentaire.html.twig', ['erreur' => ""]);
} else {
if ($idAnnonce != "") {
$articleMK = $repoMK_Article->find($idAnnonce);
if (is_object($articleMK)) {
return $this->render(
'GestionComerciale/Annonce/ScanCommentaire.html.twig',
["annonceObj" => $articleMK, 'erreur' => "", "annonce" => $articleMK->getId(), "commentaire" => $articleMK->getCommentaire()]
);
//return $this->redirectToRoute('dtc_market_scan_commentaire',array("annonce"=>$articleMK->getId(),"commentaire"=>$articleMK->getArticle()->getCommentairePonctuel()));
} else {
//return $this->redirectToRoute('dtc_market_scan_commentaire',array());
}
} else {
return $this->render('GestionComerciale/Annonce/ScanCommentaire.html.twig', ['erreur' => ""]);
}
}
}
/**
* @Route("/marketplace/amazon/scan", name="dtc_market_scan_amazon")
*/
public function ScanAmazonAction(Request $request, EntityManagerInterface $em)
{
//$repoMK_Article = $em->getRepository('DTCMarketPlaceBundle:ArticleMarketPlace');
//$repoArticle = $em->getRepository('DTCArticlesBundle:Article');
if ($request->isMethod('POST')) {
$article = $request->get('articlescan');
$repoMK_Article = $em->getRepository(ArticleMarketPlace::class);
$repoArticle = $em->getRepository(Article::class);
$repoCompteMK = $em->getRepository(CompteMarketPlace::class);
$Amazon = $repoCompteMK->findOneBy(['id' => 3]);
$articleMK = $repoMK_Article->findOneBy(['idImport' => $article, 'compteMarketPlace' => $Amazon]);
if ($article == "") {
return $this->render('GestionComerciale/Annonce/ScanAmazon.html.twig', ['erreur' => "Id import non reconnu"]);
}
if ($articleMK == null) {
$articleMK = $repoMK_Article->findOneBy(['idImport' => $article]);
if ($articleMK == null) {
return $this->render('GestionComerciale/Annonce/ScanAmazon.html.twig', ['erreur' => "Annonce inconnue"]);
}
if ($articleMK->getCompteMarketPlace()->getId() != 3) {
return $this->render('GestionComerciale/Annonce/ScanAmazon.html.twig', ['erreur' => "Cette annonce n'est pas un produit Amazon"]);
}
}
if ($articleMK->getPointageAmazon() == 1) {
return $this->render(
'GestionComerciale/Annonce/ScanAmazon.html.twig',
[
'erreur' => "Cette annonce a été pointée le ".date_format($articleMK->getDatePointage(), 'd-m-Y')." à ".date_format(
$articleMK->getDatePointage(),
'H:i'
),
]
);
}
$articleMK->setPointageAmazon(1);
$articleMK->setDatePointage(new \Datetime());
$em->persist($articleMK);
$em->flush();
$this->addFlash(
'notice',
'Produit pointé'
);
return $this->render('GestionComerciale/Annonce/ScanAmazon.html.twig', ['erreur' => ""]);
} else {
return $this->render('GestionComerciale/Annonce/ScanAmazon.html.twig', ['erreur' => ""]);
}
}
/**
* @Route("/marketplace/annuler/{id}", name="dtc_depointage")
*/
public function DepointageAction(Request $request, EntityManagerInterface $em)
{
$articleMK = $request->get('id');
$repoMK_Article = $em->getRepository(ArticleMarketPlace::class);
$annonce = $repoMK_Article->findOneBy(['id' => $articleMK]);
$annonce->setPointageAmazon(null);
$em->persist($annonce);
$em->flush();
$this->addFlash(
'notice',
"l'article Amazon est dépointé"
);
return $this->redirecttoRoute('dtc_article_modifier', ['id' => $annonce->getArticle()->getId()]);
}
/**
* @Route("/annonce/supprimer/{id}/{market}", name="dtc_article_market_place_supprimer")
*/
public function supprimerAction(Request $request, ArticleMarketPlace $articleMarketPlace, $market, EntityManagerInterface $em, ValidatorInterface $validator,
ArticleMarketPlaceService $service_article_market_place
) {
$titre_modal = "Demande de confirmation ";
$user = $this->getUser();
$get = $request->query->all();
$form = $this->createForm(SupprimerArticleMarketPlaceType::class, $articleMarketPlace);
$errors = "";
$form->handleRequest($request);
$messageModal = "Attention : Cette suppression n'entraine pas la suppression de l'offre auprès du market place ! <br/><br/>Confirmez la suppression ?";
if ($form->isSubmitted()) {
if ($form->isValid()) {
$articleMarketPlace->setAnnonceSupprime(true);
$articleMarketPlace->setStatutArticleMarketPlace(null);
$articleMarketPlace->setDateSuppression(new \Datetime());
$em->persist($articleMarketPlace);
$em->flush();
$service_article_market_place->creerHistorique($articleMarketPlace, 13, $message = []);
$url = $this->generateUrl('dtc_article_modifier', ['id' => $articleMarketPlace->getArticle()->getId(), 'tab' => 'm'.$market]);
if (array_key_exists('table', $get) && $get["table"] != "") {
$url = "";
return new JsonResponse(['rendu' => '', 'valide' => '1', 'url' => $url, 'type' => 'recharger_datatable', 'id_datatable' => $get["table"]]);
} else {
$this->addFlash('notice', 'Offre supprimée avec succès !');
return new JsonResponse(['rendu' => '', 'valide' => '1', 'url' => ''], 200, ['Content-Type' => 'application/json']);
}
} else {
$errors = $validator->validate($articleMarketPlace);
$rendu = $this->renderView(
'FO/Supprimer/supprimer.html.twig',
[
'messageModal' => $messageModal,
'form' => $form->createView(),
'errors' => $errors,
'id' => $articleMarketPlace->getArticle()->getId(),
'type' => '',
'objet' => '',
]
);
return new JsonResponse(['rendu' => $rendu, 'valide' => '0', 'url' => '', 'titre' => $titre_modal]);
}
}
$rendu = $this->renderView(
'FO/Supprimer/supprimer.html.twig',
[
'messageModal' => $messageModal,
'form' => $form->createView(),
'errors' => $errors,
'id' => $articleMarketPlace->getArticle()->getId(),
'type' => '',
'objet' => '',
]
);
return new JsonResponse(['rendu' => $rendu, 'valide' => '0', 'url' => '', 'titre' => $titre_modal]);
}
/**
* @Route("/article/marketplace/stock/{id}", name="dtc_article_market_place_stock")
*/
public function stockAction(Request $request, Article $article, EntityManagerInterface $em, ValidatorInterface $validator, ArticleService $articleService)
{
$titre_modal = "Changer le stock des offres";
$user = $this->getUser();
$form = $this->createForm(StockArticleAnnonceType::class, $article);
$errors = "";
$form->handleRequest($request);
$repo_article_market_place = $em->getRepository(ArticleMarketPlace::class);
$errorsSup = [];
$annonces_a_modifier = $repo_article_market_place->getAnnoncePourMajStock($article);
$dateAnnonceStock = new \Datetime();
$nb_en_publications = 0;
$message_erreur = "";
if ($form->isSubmitted()) {
$post = $request->request->all();
if ($post["stock"] == "" or $post["stock"] < 0 or ! is_numeric($post["stock"])) {
$errorsSup[] = "Merci de définir un stock";
$error = new FormError("Merci de définir un stock valide");
$form->get('accept')->addError($error);
}
if ( ! array_key_exists('annonces', $post)) {
$errorsSup[] = "Merci de sélectionner au moins une offre";
$error = new FormError("Merci de sélectionner au moins une offre");
$form->get('accept')->addError($error);
}
if ($form->isValid()) {
//print_r($post);
$repo_statut_article_market_place = $em->getRepository(StatutArticle::class);
$statutAPublierAnnonce = $repo_statut_article_market_place->find(1);
//echo "<div>COUNT ".count($post['annonces'])."</div>";
if (array_key_exists('annonces', $post)) {
for ($i = 0; $i < count($post['annonces']); $i++) {
//echo "<div>".$post['annonces'][$i]."</div>";
$articleMarketPlaceStock = $repo_article_market_place->find($post['annonces'][$i]);
if (is_object($articleMarketPlaceStock)) {
if ($articleMarketPlaceStock->getCompteMarketPlace()->getId() == 2 and $articleMarketPlaceStock->getSku() == "") {
$message_erreur .= "<div>Impossible de changer le stock de l'offre Priceminister id : ".$articleMarketPlaceStock->getId(
)." idImport : ".$articleMarketPlaceStock->getIdImport()." car le sku est vide</div>";
} else {
$articleMarketPlaceStock->setStock(trim($post['stock']));
$articleMarketPlaceStock->setDateDemandePublicationMarketPlace($dateAnnonceStock);
$articleMarketPlaceStock->setStatutArticleMarketPlace($statutAPublierAnnonce);
$articleMarketPlaceStock->setEnvoyerUniquementStock(1);
if (trim($post['stock']) == "0") {
$articleMarketPlaceStock->setStatut(0);
} elseif (trim($post['stock']) > "0") {
$articleMarketPlaceStock->setStatut(1);
}
$em->persist($articleMarketPlaceStock);
$nb_en_publications++;
}
}
}
if ($nb_en_publications > 0) {
$couleur = $articleService->couleurLigne($article->getId());
$article->setCouleurLigne($couleur);
$em->persist($article);
$em->flush();
}
}
//print_r($post);
//$articleMarketPlace->setVisible(false);
//$articleMarketPlace->setDateSuppression(new \Datetime());
//$em->persist($articleMarketPlace);
//$em->flush();
if ($message_erreur) {
$this->addFlash(
'warning',
$message_erreur
);
}
$this->addFlash(
'notice',
'Stock des offres modifiées avec succès !'
);
$url = $this->generateUrl('dtc_article_modifier', ['id' => $article->getId()]);
return new JsonResponse(['rendu' => '', 'valide' => '1', 'url' => $url]);
} else {
$errors = $validator->validate($article);
$rendu = $this->renderView(
'MarketPlace/ArticleMarketPlace/stock.html.twig',
[
'errorsSup' => $errorsSup,
'annonces_a_modifier' => $annonces_a_modifier,
'form' => $form->createView(),
'errors' => $errors,
'article' => $article->getId(),
]
);
return new JsonResponse(['rendu' => $rendu, 'valide' => '0', 'url' => '', 'titre' => $titre_modal]);
}
}
$rendu = $this->renderView(
'MarketPlace/ArticleMarketPlace/stock.html.twig',
[
'errorsSup' => $errorsSup,
'annonces_a_modifier' => $annonces_a_modifier,
'form' => $form->createView(),
'errors' => $errors,
'article' => $article->getId(),
]
);
return new JsonResponse(['rendu' => $rendu, 'valide' => '0', 'url' => '', 'titre' => $titre_modal]);
}
/**
* @Route("/article-marketplace/historique/{id}", name="dtc_article_market_place_historique")
*/
public function historiqueAction(Request $request, ArticleMarketPlace $articleMarketPlace, EntityManagerInterface $em, TranslatorInterface $translator)
{
$titre_modal = $translator->trans("Historique de l'offre");
$historiques = $em->getRepository(HistoriqueArticleMarketPlace::class)->findBy([
'articleMarketPlace' => $articleMarketPlace,
], ['date' => 'DESC']);
$rendu = $this->renderView('MarketPlace/ArticleMarketPlace/historique.html.twig', [
'historiques' => $historiques,
]);
return new JsonResponse(['rendu' => $rendu, 'valide' => '0', 'url' => '', 'titre' => $titre_modal, 'width' => 900]);
}
/**
* @Route("/article-marketplace/deplacer/{id}", name="dtc_article_market_place_deplacer")
*/
public function deplacerAction(Request $request, ArticleMarketPlace $articleMarketPlace, EntityManagerInterface $em, ArticleMarketPlaceService $service_article_market_place,
ValidatorInterface $validator
) {
$titre_modal = "Déplacement de l'offre vers un autre produit";
$user = $this->getUser();
//$articleMarketPlace->setArticle(NULL);
$form = $this->createForm(DeplacerArticleMarketPlaceType::class, $articleMarketPlace);
$form->get('precedent')->setData($articleMarketPlace->getArticle()->getId());
$form->get('article')->setData(null);
$errors = "";
$errorsSup = [];
$form->handleRequest($request);
if ($form->isSubmitted()) {
if ( ! is_object($articleMarketPlace->getArticle())) {
$error = new FormError("Merci de choisir un produit de destination");
$form->get('article')->addError($error);
$errorsSup[] = "Merci de choisir un produit de destination";
}
if ($form->isValid()) {
$repo_article = $em->getRepository(Article::class);
$ref_article_precedent_obj = $repo_article->find($form->get('precedent')->getData());
$deplace_img = $form->get('deplacerimages')->getData();
//echo "<div>deplace_img ".$deplace_img."</div>";
if ($deplace_img == 1) {
//echo "ON DEPLACE";
$repo_article_market_place_image = $em->getRepository(ArticleMarketPlaceImage::class);
$images_annonces = $repo_article_market_place_image->findBy(["articleMarketPlace" => $articleMarketPlace]);
//echo "<div>TOTALIMG = ".count($images_annonces)."</div>";
if (count($images_annonces) > 0) {
foreach ($images_annonces as $imageAnnonce) {
$image = $imageAnnonce->getImage();
$image_parent = clone $image;
$image_parent->setArticle($articleMarketPlace->getArticle());
$image_parent->setDate(new \Datetime());
$em->persist($image_parent);
$em->flush();
$liaison = $repo_article_market_place_image->findOneBy(["articleMarketPlace" => $articleMarketPlace, "image" => $image_parent]);
if ( ! is_object($liaison)) {
$ArticleMarketPlaceImage = new ArticleMarketPlaceImage();
$ArticleMarketPlaceImage->setImage($image_parent);
$ArticleMarketPlaceImage->setArticleMarketPlace($articleMarketPlace);
$em->persist($ArticleMarketPlaceImage);
}
$tab_dossiers = ["large", "medium", "originals", "small", "thumbnails"];
for ($t = 0; $t < count($tab_dossiers); $t++) {
$chemin_src = "uploads/articles/images/".$ref_article_precedent_obj->getDate()->format("Y")."/".$ref_article_precedent_obj->getDate()->format(
"m"
)."/".$ref_article_precedent_obj->getDate()->format("d")."/".$ref_article_precedent_obj->getId()."/".$tab_dossiers[$t]."/".$image_parent->getUrl();
$chemin_dest = "uploads/articles/images/".$articleMarketPlace->getArticle()->getDate()->format("Y")."/".$articleMarketPlace->getArticle()->getDate()->format(
"m"
)."/".$articleMarketPlace->getArticle()->getDate()->format("d")."/".$articleMarketPlace->getArticle()->getId()."/".$tab_dossiers[$t]."/";
if ( ! is_dir($chemin_dest)) {
//echo "<div>CREATION</div>";
mkdir($chemin_dest, 0755, true);
chown($chemin_dest, "www-data");
chgrp($chemin_dest, "www-data");
chmod($chemin_dest, 0755);
}
exec("cp ".$chemin_src." ".$chemin_dest);
}
$em->remove($imageAnnonce);
}
$em->flush();
}
} else {
//echo "ON DEPLACE PAS";
}
$service_article_market_place->creerHistorique($articleMarketPlace, 9, ["article_precedent_obj" => $ref_article_precedent_obj]);
$this->addFlash('notice', 'Offre déplacée avec succès !');
$url = "";
//$url = $this->generateUrl('dtc_article_modifier', array('id' => $articleMarketPlace->getArticle()->getId(),'tab'=>'m'.$market));
return new JsonResponse(['rendu' => '', 'valide' => '1', 'url' => '']);
} else {
$repo_article = $em->getRepository(Article::class);
$ref_article_precedent_obj = $repo_article->find($form->get('precedent')->getData());
$articleMarketPlace->setArticle($ref_article_precedent_obj);
$errors = $validator->validate($articleMarketPlace);
$rendu = $this->renderView(
'MarketPlace/ArticleMarketPlace/deplacer.html.twig',
['articleMarketPlace' => $articleMarketPlace, 'form' => $form->createView(), 'errors' => $errors, 'errorsSup' => $errorsSup]
);
return new Response(json_encode(['rendu' => $rendu, 'valide' => '0', 'url' => '', 'titre' => $titre_modal]), 200, ['Content-Type' => 'application/json']);
}
}
$rendu = $this->renderView(
'MarketPlace/ArticleMarketPlace/deplacer.html.twig',
['articleMarketPlace' => $articleMarketPlace, 'form' => $form->createView(), 'errors' => $errors, 'errorsSup' => $errorsSup]
);
return new Response(json_encode(['rendu' => $rendu, 'valide' => '0', 'url' => '', 'titre' => $titre_modal]), 200, ['Content-Type' => 'application/json']);
}
/**
* @Route("/application-annonces/charger-tableau/{id}/", name="dtc_application_article_market_place_charger_tableau")
*/
public function chargerTableauApplicationAction(Request $request, ArticleMarketPlace $articleMarketPlace)
{
$rendu = $this->renderView('MarketPlace/ArticleMarketPlace/charger_application_tableau.html.twig', ["articleMarketPlace" => $articleMarketPlace]);
return new JsonResponse(['rendu' => $rendu]);
}
/**
* @Route("/annonce/{id}/marque/{marque}/statut/{statut}", name="dtc_article_associer_marque_vehicule_ajax")
*/
public function associerArticleMarqueVehiculeAction(Request $request, ArticleMarketPlace $articleMarketPlace, Marque $marque, $statut, EntityManagerInterface $em
) {
//$repo_articlesCategories = $em->getRepository('DTCArticlesBundle:ArticleCategorie');
//$articleCategorie = $repo_articlesCategories->findOneBy(array('article'=>$article, 'categorie'=>$categorie));
$repo_applications = $em->getRepository(Application::class);
$application = $repo_applications->findOneBy(['articleMarketPlace' => $articleMarketPlace, 'marque' => $marque, 'modele' => null, 'type' => null]);
if ($statut == 'add') {
if ( ! is_object($application)) {
$application = new Application();
$application->setArticleMarketPlace($articleMarketPlace);
$application->setMarque($marque);
}
$em->persist($application);
} else {
if (is_object($application)) {
$em->remove($application);
}
}
$em->flush();
$response = new JsonResponse;
$response->setData([
'articleMarketPlace' => $articleMarketPlace->getId(),
'marque' => $marque->getId(),
'statut' => $statut,
]);
return $response;
}
/**
* @Route("/annonce/{id}/modele/{modele}/statut/{statut}", name="dtc_article_associer_modele_vehicule_ajax")
*/
public function associerArticleModeleVehiculeAction(Request $request, ArticleMarketPlace $articleMarketPlace, Modele $modele, $statut, EntityManagerInterface $em,
TranslatorInterface $translator, ValidatorInterface $validator
) {
//$repo_articlesCategories = $em->getRepository('DTCArticlesBundle:ArticleCategorie');
//$articleCategorie = $repo_articlesCategories->findOneBy(array('article'=>$article, 'categorie'=>$categorie));
$repo_applications = $em->getRepository(Application::class);
$application = $repo_applications->findOneBy(['articleMarketPlace' => $articleMarketPlace, 'marque' => $modele->getMarque(), 'modele' => $modele, 'type' => null]);
if ($statut == 'add') {
if ( ! is_object($application)) {
$application = new Application;
$application->setArticleMarketPlace($articleMarketPlace);
$application->setModele($modele);
$application->setMarque($modele->getMarque());
}
$em->persist($application);
} else {
if (is_object($application)) {
$em->remove($application);
}
}
$em->flush();
$response = new JsonResponse;
$response->setData([
'articleMarketPlace' => $articleMarketPlace->getId(),
'modele' => $modele->getId(),
'statut' => $statut,
]);
return $response;
}
/**
* @Route("/annonce/{id}/type/{type}/statut/{statut}", name="dtc_article_associer_type_vehicule_ajax")
*/
public function associerArticleTypeVehiculeAction(Request $request, ArticleMarketPlace $articleMarketPlace, Type $type, $statut, EntityManagerInterface $em,
TranslatorInterface $translator, ValidatorInterface $validator
) {
//$repo_articlesCategories = $em->getRepository('DTCArticlesBundle:ArticleCategorie');
//$articleCategorie = $repo_articlesCategories->findOneBy(array('article'=>$article, 'categorie'=>$categorie));
$repo_applications = $em->getRepository(Application::class);
$application = $repo_applications->findOneBy(
['articleMarketPlace' => $articleMarketPlace, 'marque' => $type->getModele()->getMarque(), 'modele' => $type->getModele(), 'type' => $type]
);
if ($statut == 'add') {
if ( ! is_object($application)) {
$application = new Application;
$application->setArticleMarketPlace($articleMarketPlace);
$application->setType($type);
$application->setModele($type->getModele());
$application->setMarque($type->getModele()->getMarque());
}
$em->persist($application);
} else {
if (is_object($application)) {
$em->remove($application);
}
}
$em->flush();
$response = new JsonResponse;
$response->setData([
'articleMarketPlace' => $articleMarketPlace->getId(),
'type' => $type->getId(),
'statut' => $statut,
]);
return $response;
}
}