<?php
namespace App\Controller\Articles;
use App\Entity\Articles\Article;
use App\Entity\Clients\ClientMarque;
use App\Entity\Articles\ArticleComplementOption;
use App\Entity\Articles\ArticleComposant;
use App\Entity\Articles\ArticleCategorie;
use App\Entity\Articles\Categorie;
use App\Entity\Articles\ConditionAchat;
use App\Entity\Articles\FamilleCompta;
use App\Entity\Articles\HistoriqueArticle;
use App\Entity\Articles\Image;
use App\Entity\Articles\Marque;
use App\Entity\Articles\MouvementStock;
use App\Entity\Articles\RaisonMouvementStock;
use App\Entity\Articles\RefsEquivalentes;
use App\Entity\Articles\Type;
use App\Entity\FO\FoDocument;
use App\Entity\FO\Societe;
use App\Entity\FO\FoDocumentArticle;
use App\Entity\Fournisseurs\Fournisseur;
use App\Entity\Ged\Fichier;
use App\Entity\GestionComerciale\Commande;
use App\Model\GestionCommerciale\TypeDocumentCommercial;
use App\Entity\GestionComerciale\ArticleCommande;
use App\Entity\GestionComerciale\StatutCommande;
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\ErreurPublicationArticleMarketPlace;
use App\Entity\MarketPlace\MarketPlace;
use App\Entity\MarketPlace\Profil;
use App\Entity\MarketPlace\StatutArticle;
use App\Entity\MarketPlace\TarifModeLivraison;
use App\Entity\Vehicules\Application;
use App\Entity\Vehicules\Modele;
use App\Entity\Vehicules\Type as VehiculesType;
use App\Form\Articles\ArticleDiversType;
use App\Form\Articles\ArticleRechercheType;
use App\Form\Articles\ArticleType;
use App\Library\Datatable\Util\Datatable;
use App\Library\Uploader\Services\FileUploader;
use App\Security\Voter\EntityVoter;
use App\Service\Articles\ArticleCategorieService;
use App\Service\Articles\ArticleService;
use App\Service\Articles\DocumentArticle;
use App\Service\Articles\ImageArticleService;
use App\Service\MarketPlace\ArticleMarketPlaceService;
use App\Service\Utilisateur\ColonneTableauService;
use Doctrine\ORM\EntityManagerInterface;
use DTS\eBaySDK\FileTransfer\Types\Data;
use JMS\Serializer\SerializerBuilder;
use Knp\Component\Pager\PaginatorInterface;
use Knp\Snappy\Pdf;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\Security\Core\Exception\AccessDeniedException;
use Symfony\Component\Validator\Validator\ValidatorInterface;
use Symfony\Contracts\Translation\TranslatorInterface;
use Symfony\Component\Serializer\Normalizer\AbstractNormalizer;
use JMS\Serializer\SerializationContext;
use Liip\ImagineBundle\Imagine\Cache\CacheManager;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
class ArticleController extends AbstractController
{
/**
* @Route("/catalogue", name="dtc_article_liste")
*/
public function listerAction(Request $request, EntityManagerInterface $em, ColonneTableauService $serviceColonneTableau, Datatable $datatable,TranslatorInterface $translator,$parent = null)
{
$categorie_enfants = [];
$categorie_enfants_enfants = [];
$repo_categorie_article = $em->getRepository(Categorie::class);
$categorie_article_racine = $repo_categorie_article->findBy(["categorieParent" => 1]);
$encartCatalogue = $em->getRepository(FoDocument::class)->getEncartCatalogue(false);
$encartCatalogueMobile = $em->getRepository(FoDocument::class)->getEncartCatalogue(true);
$repo_marque_article = $em->getRepository(Marque::class);
$marque_article = $repo_marque_article->findBy([], ['libelle' => 'ASC']);
$repo_type_article = $em->getRepository(Type::class);
$type_article = $repo_type_article->findBy([], ['libelle' => 'ASC']);
$param = $request->query->all();
//if(count($param) == 0) $param['mouvemente'] = '0';
if (array_key_exists('categorie_article', $param) and $param["categorie_article"] > 0) {
$parent = $repo_categorie_article->find($param["categorie_article"]);
if (is_object($parent)) {
$categorie_enfants = $repo_categorie_article->findBy(["categorieParent" => $parent]);
}
}
//\Doctrine\Common\Util\Debug::dump($param);
// $param["mouvemente"]=1;
$this->datatable($datatable, $request, $em, $translator);
$tableau_class_cellule = array();
$tableau_class_cellule[] = ["searchable" => true,"className" => "","targets"=> [0],"visible"=> false,];
$tableau_class_cellule[] = [
"searchable" => true,
"className" => "",
"targets" => [1],
"visible" => false,
];
$tableau_class_cellule[] = [
"searchable" => true,
"className" => "",
"targets" => [2],
"visible" => false,
];
$tableau_class_cellule[] = [
"searchable" => true,
"className" => "",
"targets" => [4],
"visible" => false,
];
if (array_key_exists('mc', $param) or array_key_exists('p', $param) or array_key_exists('c', $param) or array_key_exists('m', $param)) {
return $this->render('Articles/Article/lister.html.twig', [
'name' => 'article',
'tableauClassColonne' => $tableau_class_cellule,
'parametres' => $param,
"categorie_article" => $categorie_article_racine,
"sous_categorie_article" => $categorie_enfants,
"sous_sous_categorie_article" => $categorie_enfants_enfants,
"marque" => $marque_article,
"type" => $type_article,
"parent" => $parent,
"encartCatalogueMobile" => $encartCatalogueMobile,
"encartCatalogue" => $encartCatalogue,
//'mouvemente' => $mouvemente
]);
} else {
return $this->render('Articles/Article/recherche.html.twig', [
'name' => 'article',
'tableauClassColonne' => $tableau_class_cellule,
'parametres' => $param,
"categorie_article" => $categorie_article_racine,
"sous_categorie_article" => $categorie_enfants,
"sous_sous_categorie_article" => $categorie_enfants_enfants,
"marque" => $marque_article,
"type" => $type_article,
"parent" => $parent,
"encartCatalogueMobile" => $encartCatalogueMobile,
"encartCatalogue" => $encartCatalogue,
]);
}
}
/**
* set datatable configs
*
* @return \App\Library\Datatable\Util\Datatable
*/
private function datatable(Datatable $datatable, Request $request, EntityManagerInterface $em, TranslatorInterface $translator)
{
$clientId = 0;
if($this->getUser() && $this->getUser()->getClient()) $clientId = $this->getUser()->getClient()->getId();
$param = $request->query->all();
$parametres = [];
$parent = $request->query->get('parent');
if ($parent == '') {
$where = " AND x.parent is null";
} else {
$where = " AND x.parent = :parent";
$parametres['parent'] = $parent;
}
if ( ! array_key_exists('parametres', $param)) {
$param["parametres"] = $param;
}
$conn = $em->getConnection();
$conn->getConfiguration()->setSQLLogger(null);
$qb = $em->createQueryBuilder();
$qb->select(
"
x.id as x_id,
x.dateProchaineDispo as x_dateProchaineDispo,
x.libelle as x_libelle,
x.reference as x_reference,
x.descriptionCourte as x_descriptionCourte,
x.description as x_description,
x.libelleSecondaire as x_libelleSecondaire,
x.prixVente as x_prixVente,
x.prixBase as x_prixBase,
x.tauxMarge as x_tauxMarge,"
//."x.cpump as x_cpump,"
."x.pump as x_pump,"
."x.stock as x_stock,
x.dispo as x_dispo,
x.statut as x_statut,
m.libelle as m_libelle,
m.logo as m_logo,
m.id as m_id,
r.id as r_id,
r.tauxDefaut as r_tauxDefaut,
x.referenceAppel10 as x_referenceAppel10
"
)
->orderBy('x.id', 'DESC')
->from(Article::class, "x")
->leftJoin('x.marque', 'm')
->leftJoin('App\Entity\Clients\ClientMarque','ccm',\Doctrine\ORM\Query\Expr\Join::WITH, 'ccm.marque = x.marque AND ccm.client = :clientId')
->leftJoin('x.regleTaxe', 'r', \Doctrine\ORM\Query\Expr\Join::LEFT_JOIN);
$parametres['clientId']=$clientId;
$where .= " AND (m.statut = 1)";
$where .= " AND ccm.id IS NULL";
if (array_key_exists('p', $param['parametres']) and count($param['parametres']['p'])>0) {
$where .= " AND x.id IN (:produits)";
$parametres['produits'] = $param['parametres']['p'];
}
if (array_key_exists('st', $param['parametres']) and $param['parametres']['st'] == "1") {
$where .= " AND (x.dispo > 0)";
}
if (array_key_exists('mc', $param['parametres']) and $param['parametres']['mc'] != "" and $param['parametres']['mc'] != "" and $param['parametres']['mc'] != "0") {
//$cond = "%".trim($param['parametres']['mc'])."%";
//$where .= " AND (x.reference LIKE :recherche or x.libelle LIKE :recherche)";
//$parametres['recherche'] = $cond;
$search = trim($param['parametres']['mc']);
$words = preg_split('/\s+/', $search);
$conditions = [];
foreach ($words as $index => $word) {
$key = 'recherche_' . $index;
$conditions[] = "(x.reference LIKE :$key OR x.libelle LIKE :$key)";
$parametres[$key] = '%' . $word . '%';
}
if (!empty($conditions)) {
$where .= " AND (" . implode(' AND ', $conditions) . ")";
}
}
if (array_key_exists('cn3', $param['parametres']) and $param['parametres']['cn3'] != "" and $param['parametres']['cn3'] != "0") {
$qb->join('x.articleCategorie', 'ac3', \Doctrine\ORM\Query\Expr\Join::LEFT_JOIN);
$qb->join('ac3.categorie', 'cat3', \Doctrine\ORM\Query\Expr\Join::LEFT_JOIN);
$where .= " AND cat3.id = :categorie3";
$parametres['categorie3'] = $param['parametres']['cn3'];
}
else if (array_key_exists('cn2', $param['parametres']) and $param['parametres']['cn2'] != "" and $param['parametres']['cn2'] != "0") {
$qb->join('x.articleCategorie', 'ac2', \Doctrine\ORM\Query\Expr\Join::LEFT_JOIN);
$qb->join('ac2.categorie', 'cat2', \Doctrine\ORM\Query\Expr\Join::LEFT_JOIN);
$where .= " AND cat2.id = :categorie2";
$parametres['categorie2'] = $param['parametres']['cn2'];
}
else if (array_key_exists('c', $param['parametres']) and $param['parametres']['c'] != "" and $param['parametres']['c'] != "0") {
$qb->join('x.articleCategorie', 'ac', \Doctrine\ORM\Query\Expr\Join::LEFT_JOIN);
$qb->join('ac.categorie', 'cat', \Doctrine\ORM\Query\Expr\Join::LEFT_JOIN);
$where .= " AND cat.id = :categorie";
$parametres['categorie'] = $param['parametres']['c'];
}
if (array_key_exists('m', $param['parametres']) and $param['parametres']['m'] != "" and $param['parametres']['m'] != "0") {
//$qb->join('x.marque', 'm', \Doctrine\ORM\Query\Expr\Join::LEFT_JOIN);
$where .= " AND x.marque = :marque";
$parametres['marque'] = $param['parametres']['m'];
}
if (array_key_exists('tv', $param['parametres']) and $param['parametres']['tv'] != "" and $param['parametres']['tv'] != "0") {
$qb->leftJoin('x.articleApplication', 'aa', \Doctrine\ORM\Query\Expr\Join::LEFT_JOIN);
//$where .= " AND (x.universel = 1)";
$where .= " AND (aa.type = :typeVehicule or x.universel = 1)";
$parametres['typeVehicule'] = $param['parametres']['tv'];
}
else if (array_key_exists('mov', $param['parametres']) and $param['parametres']['mov'] != "" and $param['parametres']['mov'] != "0") {
$qb->leftJoin('x.articleApplication', 'aa', \Doctrine\ORM\Query\Expr\Join::LEFT_JOIN);
$where .= " AND (aa.modele = :modeleVehicule or x.universel = 1)";
$parametres['modeleVehicule'] = $param['parametres']['mov'];
}
else if (array_key_exists('mv', $param['parametres']) and $param['parametres']['mv'] != "" and $param['parametres']['mv'] != "0") {
$qb->leftJoin('x.articleApplication', 'aa', \Doctrine\ORM\Query\Expr\Join::LEFT_JOIN);
$where .= " AND ( aa.marque = :marqueVehicule OR x.universel = 1 )";
//$where .= " AND (aa.marque = :marqueVehicule or (aa.id is null and x.universel = 1))";
$parametres['marqueVehicule'] = $param['parametres']['mv'];
}
//echo $where;
//print_r($parametres);
//$qb->where('x.temporaire is null and (x.archive = 0 or x.archive is null)'.$where);
$where .= " AND (
(x.virtuel != 1
)
OR NOT EXISTS (
SELECT ac_check.id
FROM App\Entity\Articles\ArticleComposant ac_check
JOIN ac_check.article a_child
WHERE ac_check.articleCompose = x
AND ((a_child.archive = 1) OR (a_child.arretGamme = 1))
)
)";
$qb->where('x.temporaire is null AND (x.statut is null or x.statut = 1) AND (x.arretGamme = 0 or x.arretGamme is null ) AND (x.archive = 0 or x.archive is null ) '.$where);
$qb->distinct();
if (count($parametres) > 0) {
$qb->setParameters($parametres);
}
$qb->orderBy("x.position", "desc");
$datatable = $datatable
->setFields(
[
$translator->trans("ID") => 'x.id',
$translator->trans("Img") => 'x.reference',
$translator->trans("Réf") => 'x.reference',
$translator->trans("Libelle") => 'x.libelle',
"_identifier_" => 'x.id'
]
)
->setRenderers(
[
0 => [
'view' => 'FO/DataTable/article_id.html.twig',
'params' => [
'edit_route' => 'dtc_article_liste',
],
],
1 => [
'view' => 'FO/DataTable/article_image.html.twig',
'params' => [
'edit_route' => 'dtc_article_liste',
],
],
2 => [
'view' => 'FO/DataTable/detail_produit.html.twig',
'params' => [
'edit_route' => 'dtc_article_liste',
],
],
]
)
->setSearch(true)
->setGlobalSearch(1)
//->setFilteringType([2 => 'e', 3 => 'e'])
//->setSearchFields([2, 3])
->setMultiple(
[
'delete' => [
'title' => 'Non disponible',
'route' => 'dtc_article_liste',
],
]
)
->setOrder("x.id", "desc")
;
$datatable->getQueryBuilder()->setDoctrineQueryBuilder($qb);
return $datatable;
}
/**
* @Route("/articles/grid", name="dtc_article_liste_grid")
*/
public function gridAction(Request $request, Datatable $datatable, EntityManagerInterface $entityManager, TranslatorInterface $translator)
{
return $this->datatable($datatable, $request, $entityManager, $translator)->execute();
}
/**
* @Route("/produits/{slug}-{id}", name="dtc_article_afficher", requirements={"id"="\d+", "slug"="[a-z0-9\-]+"})
*/
public function AfficherAction(Request $request, Article $article, EntityManagerInterface $em, ImageArticleService $imageArticleService,
ArticleCategorieService $articleCategorieService, ValidatorInterface $validator, DocumentArticle $documentArticle, ArticleService $articleService,
Datatable $datatable, TranslatorInterface $translator, FileUploader $fileUploader
) {
$user = $this->getUser();
$client_id = 0;
$marque_visible = true;
if($user && is_object($user->getClient())) {
$client_id = $user->getClient()->getId();
$marqueClient = $em->getRepository(ClientMarque::class)->findOneBy(["client"=>$user->getClient(),"marque"=>$article->getMarque()]);
if(is_object($marqueClient)) $marque_visible = false;
}
if (!$marque_visible or ($article->getArchive()) or ($article->getArretGamme()) or (!$article->getStatut() && !is_null($article->getStatut())) or (is_object($article->getMarque()) && !$article->getMarque()->getStatut()))
{
throw $this->createNotFoundException('La ressource demandée n’existe pas.');
}
//$articleOptions = $em->getRepository(ArticleComplementOption::class)->findBy(["parent"=>$article,'type'=>'option']);
$articleOptions = $em->getRepository(ArticleComplementOption::class)->findEnfantsByParentAndStatus($article->getid(), $status = 1,'option',$client_id);
$articleComplements = $em->getRepository(ArticleComplementOption::class)->findEnfantsByParentAndStatus($article->getid(), $status = 1,'complement',$client_id);
$catalogues = $em->getRepository(FoDocumentArticle::class)->findBy(["article"=>$article]);
$articleComposants = [];
if($article->getVirtuel()) {
$articleComposants = $em->getRepository(ArticleComposant::class)->findComposantsByParentAndStatus($article->getid(), $status = 1,$client_id);
if(count($articleComposants)>0) {
foreach($articleComposants as $ac) {
if(!$ac->getArticle()->getStatut() || ($ac->getArticle()->getArchive() && !is_null($ac->getArticle()->getArchive())) || $ac->getArticle()->getArretGamme()) {
$articleComposants = [];
throw $this->createNotFoundException('La ressource demandée n’existe pas.');
break;
}
}
}
}
return $this->render(
'Articles/Article/afficher.html.twig',
[
'article' => $article,
'articleOptions' => $articleOptions,
'articleComplements' => $articleComplements,
'articleComposants' => $articleComposants,
'catalogues' => $catalogues,
]
);
}
/**
* @Route("/article/recherche", name="dtc_article_recherche")
*/
public function rechercheAction(Request $request, EntityManagerInterface $em, PaginatorInterface $paginator, ArticleService $articleService, ImageArticleService $imageArticleService,CacheManager $cacheManager)
{
//exit;
$user = $this->getUser();
$tabMarqueExclure = [];
if($user && is_object($user->getClient())) {
$marqueClient = $em->getRepository(ClientMarque::class)->findBy(["client"=>$user->getClient()]);
if(count($marqueClient)>0) {
foreach($marqueClient as $mc) {
if(is_object($mc->getMarque())) {
$tabMarqueExclure[]=$mc->getMarque()->getId();
}
}
}
}
$q = $request->query->get('q');
$produitInterne = $request->query->get('interne');
$articleAExclure = $request->query->get('article');
$articlesAExclure = [];
if ($articleAExclure !== null && $articleAExclure != '') {
$article = $em->getRepository(Article::class)->find($articleAExclure);
$articlesAExclure[] = $articleAExclure;
if (is_object($article)) {
foreach ($article->getArticlesComposants() as $articleComposant) {
$articlesAExclure[] = $articleComposant->getArticle()->getId();
}
}
}
$page = $request->query->getInt('page', 1);
$repo = $em->getRepository(Article::class);
$tri_reference = $request->query->get('tri_reference');
$tri_libelle = $request->query->get('tri_libelle');
$tri_prix = $request->query->get('tri_prix');
$tri_stock = $request->query->get('tri_stock');
if(1==1) {
$results = $repo->getRechercheArticleSelectObi(
$q,
$produitInterne,
$request->query->get('fournisseur'),
$articlesAExclure,
$request->query->get('stock'),
$request->query->get('reference_search'),
$request->query->get('libelle_search'),
$request->query->get('prix_search'),
$tri_reference,
$tri_libelle,
$tri_prix,
$tri_stock,
$request->query->get('categorie'),
$request->query->get('mouvemente'),
$request->query->get('inventaire'),
$request->query->get('declinaisons')
);
}
$triRechercheArticle = "";
$ordreTriRechercheArticle = "";
$majTri = false;
if ($request->query->get('mouvemente') != "") {
if ($request->query->get('mouvemente') == "1" && ( ! $user->getMouvementeRechercheArticle() or is_null($user->getMouvementeRechercheArticle()))) {
$user->setMouvementeRechercheArticle(true);
$em->persist($user);
$em->flush();
} elseif ($request->query->get('mouvemente') == "0" && ($user->getMouvementeRechercheArticle() or is_null($user->getMouvementeRechercheArticle()))) {
$user->setMouvementeRechercheArticle(false);
$em->persist($user);
$em->flush();
}
}
if ($request->query->get('tri_reference') != "") {
$triRechercheArticle = "tri_reference";
$ordreTriRechercheArticle = $request->query->get('tri_reference');
$majTri = true;
} elseif ($request->query->get('tri_libelle') != "") {
$triRechercheArticle = "tri_libelle";
$ordreTriRechercheArticle = $request->query->get('tri_libelle');
$majTri = true;
} elseif ($request->query->get('tri_prix') != "") {
$triRechercheArticle = "tri_prix";
$ordreTriRechercheArticle = $request->query->get('tri_prix');
$majTri = true;
} elseif ($request->query->get('tri_stock') != "") {
$triRechercheArticle = "tri_stock";
$ordreTriRechercheArticle = $request->query->get('tri_stock');
$majTri = true;
}
//echo $user->getEmail();
if ($majTri) {
$user->setTriRechercheArticle($triRechercheArticle);
$user->setOrdreTriRechercheArticle($ordreTriRechercheArticle);
$em->persist($user);
$em->flush();
}
$pagination = $paginator->paginate(
$results, /* query NOT result */
$request->query->getInt('page', $page)/*page number*/,
20/*limit per page*/
);
$pagination_results = $pagination->getItems();
$tabPremiereLigne = [
"libelle_secondaire" => "",
"reference_appel_2" => "",
"reference_appel_3" => "",
"reference_appel_4" => "",
"reference_appel_5" => "",
"reference_appel_6" => "",
"reference_appel_7" => "",
"reference_appel_8" => "",
"reference_appel_9" => "",
"reference_appel_10" => "",
"reference_appel_11" => "",
"arret_gamme" => "",
"virtuel" => "",
"libelle" => "Sélectionnez",
"libelle_construit" => "Sélectionnez",
"id" => "",
"reference_fournisseur" => "",
"prixVente" => "",
"prixAchat" => "",
"poids" => "",
"stock" => 0,
"stock_reserve" => 0,
"cpump" => "",
"reference" => "",
"dispo" => "",
"image" => "",
"marque" => "",
"virtuel" => "",
"afficher_composant_pdf_externe" => "",
];
//$option_placeholde = array("libelle"=>"Sélectionnez","id"=>"","stock"=>"","stock_reserve"=>"");
$option_placeholde = $tabPremiereLigne;
if ($request->query->getInt('page', 1) == 1) {
array_unshift($pagination_results, $option_placeholde);
}
$pagination->setItems($pagination_results);
/*if($q == "" && $page < 2) {
$option_placeholde = array("libelle"=>"Recherche à partir du libellé ou de la référence article","id"=>"","reference"=>"Réf","prixVente"=>"Prix","stock"=>"Stock");
array_unshift($pagination_results, $option_placeholde);
$pagination->setItems($pagination_results);
}
*/
$option_placeholde = [
"libelle" => "Sélectionnez",
"id" => "",
"reference" => "",
"prixVente" => "",
"stock" => 0,
"prixAchat" => "",
"dispo" => "d",
"nbArticleInventaire" => "",
];
if ($request->query->getInt('page', 1) == 1) {
array_unshift($pagination_results, $option_placeholde);
}
//print_r($pagination_results);
$tabFinal = [];
//foreach($pagination as $p) {
for ($i = 1; $i < count($pagination_results); $i++) {
//print_r($pagination_results[$i]);
$tabTemp = [];
$continuer = true;
if ($request->query->get('declinaisons') == true) {
$enfants = $repo->findBy(["articleDeclinaisonParent" => $pagination_results[$i]["id"]]);
if (count($enfants) > 0) {
//echo "TEST ".$pagination_results[$i]["id"];
$continuer = false;
}
}
if ($continuer) {
$tabTemp = $pagination_results[$i];
$tabTemp["affichagePrix"] = "TTC";
$tabTemp["prixVenteTtc"] = 0;
if($user) {
$tabTemp["affichagePrix"] = "HT";
}
else {
if($pagination_results[$i]["id"]>0) $tabTemp["prixVenteTtc"] = $articleService->getPrixVenteTtc($pagination_results[$i]["id"]);
}
if ( ! array_key_exists('virtuel', $tabTemp) or $tabTemp["virtuel"] == "") {
$tabTemp["virtuel"] = 0;
}
$tabTemp["dateProchaineDispo"]=null;
if( $tabTemp["dispo"] <= 0) {
if(count($articleService->getDatesProchainesDispo($tabTemp["id"]))>0) $tabTemp["dateProchaineDispo"]="ok";
}
/*
$tabTemp["dispo"] = 0;
if ($tabTemp["virtuel"] === 0) {
$tabTemp["dispo"] = $tabTemp["stock"] - $tabTemp["stock_reserve"];
} else {
//echo "HHHH";
//{% set dispo = dtc_article.getStock(a.article) %}
$objArticle = $em->getRepository(Article::class)->find($tabTemp["id"]);
$tabTemp["dispo"] = $articleService->getStock($objArticle);
}
*/
if($pagination_results[$i]["id"]>0) $tabTemp["slug"] = $articleService->getslugifArticle($pagination_results[$i]["id"]);
$tabTemp["dispo"] = max(0, $tabTemp["dispo"]);
// {% set images = dtc_image_article.getImageDefaut(dt_obj.x_id) %}
$images = $imageArticleService->getImageDefaut($tabTemp["id"]);
$tabTemp["image"] = "";
$URL_IMAGE_DISTANT = $this->getParameter('URL_IMAGE_DISTANT');
if(count($images)>0) {
foreach($images as $img) {
//<img src="{{ asset(images[0].getUploadDir ~ '/' ~ dt_obj.x_id ~ '/' ~ images[0].url) | imagine_filter('400x300') }}" style="max-width:100%;">
//$tabTemp["image"] = "/".$img->getUploadDir()."/".$img->getArticle()->getId()."/".$img->getUrl();
//$tabTemp["image"] = $cacheManager->getBrowserPath($tabTemp["image"], "400x300");
$tabTemp["image"] = $URL_IMAGE_DISTANT."/image/400/300/".$img->getUlid();
break;
}
}
else {
$tabTemp["image"] ="/images/defaut-img-product.jpg";
}
if($pagination_results[$i]["id"]>0) {
$tabTemp["remiseId"] = NULL;
$tabTemp["valeurRemise"] = NULL;
$tabTemp["prixRemise"] = NULL;
if($user) {
$remise_article = $articleService->getRemisesPossibleArticleClient(['article'=>$pagination_results[$i]["id"]],$user->getClient());
$tabTemp["remiseId"] = $remise_article["remiseId"];
$tabTemp["valeurRemise"] = $remise_article["valeur"];
$tabTemp["prixRemise"] = $remise_article["prixRemise"];
}
}
if(array_key_exists('logo_marque', $tabTemp) && $tabTemp["logo_marque"] != "") {
$tabTemp["logo_marque"] = "/uploads/logos/marques/". $tabTemp["id_marque"]."/".$tabTemp["logo_marque"];
$tabTemp["logo_marque"] = $cacheManager->getBrowserPath($tabTemp["logo_marque"], "400x300");
}
if(!array_key_exists('id_marque', $tabTemp) or !in_array($tabTemp["id_marque"],$tabMarqueExclure)) {
$client_id = 0;
if($user && is_object($user->getClient())) {
$client_id = $user->getClient()->getId();
}
$ajouter_article = true;
if($pagination_results[$i]["virtuel"]==1) {
$articleComposants = $em->getRepository(ArticleComposant::class)->findComposantsByParentAndStatus($pagination_results[$i]["id"], $status = 1,$client_id);
if(count($articleComposants)>0) {
foreach($articleComposants as $ac) {
if(!$ac->getArticle()->getStatut() || ($ac->getArticle()->getArchive() && !is_null($ac->getArticle()->getArchive())) || $ac->getArticle()->getArretGamme()) {
$ajouter_article = false;
break;
}
}
}
}
if($ajouter_article) $tabFinal[] = $tabTemp;
}
}
}
//print_r($tabFinal);
//print_r($tabFinal);
//$pagination->setItems($pagination_results);
$pagination->setItems($tabFinal);
//print_r($pagination);
//$em->getConnection()->close();
$context = SerializationContext::create()->setSerializeNull(true);
$serializer = SerializerBuilder::create()->build();
return JsonResponse::fromJsonString($serializer->serialize($pagination, 'json',
$context));
}
/**
* @Route("/article/complement/{id}", name="dtc_article_complement_modal")
*/
public function ArticleComplementModalAction(Request$request, Article $article, EntityManagerInterface $em,TranslatorInterface $translator,ValidatorInterface $validator)
{
$titre_modal = "Optimisez votre commande : pensez aux essentiels qui vont avec !";
$articleComplements = $em->getRepository(ArticleComplementOption::class)->findEnfantsByParentAndStatus($article->getid(), $status = 1,'complement');
$rendu = $this->renderView('Articles/Article/complement_modal.html.twig',["articleComplements"=>$articleComplements]);
// $rendu = $this->renderView('FO/Supprimer/supprimer_impossible.html.twig', ['errors' => $erreur]);
return new JsonResponse(['rendu' => $rendu, 'valide' => '0', 'url' => '', 'titre' => $titre_modal]);
}
}