@@ -2,9 +2,51 @@ | |||
namespace Lc\CaracoleBundle\Builder\Product; | |||
use Doctrine\ORM\EntityManagerInterface; | |||
use Lc\CaracoleBundle\Container\Section\SectionContainer; | |||
use Lc\CaracoleBundle\Model\Merchant\MerchantInterface; | |||
use Lc\CaracoleBundle\Model\Product\ProductFamilyInterface; | |||
class ProductFamilyBuilder | |||
{ | |||
protected EntityManagerInterface $entityManager; | |||
protected SectionContainer $sectionContainer; | |||
public function __construct( | |||
EntityManagerInterface $entityManager, | |||
SectionContainer $sectionContainer | |||
) | |||
{ | |||
$this->entityManager = $entityManager; | |||
$this->sectionContainer = $sectionContainer; | |||
} | |||
public function setMerchant(ProductFamilyInterface $productFamily, MerchantInterface $merchant): void | |||
{ | |||
$sectionStore = $this->sectionContainer->getStore()->setMerchant($merchant); | |||
// Les ProductFamilySectionProperty sont créées en double, on rectifie ici | |||
$productFamilySectionPropertyArray = []; | |||
foreach($productFamily->getProductFamilySectionProperties() as $productFamilySectionProperty) { | |||
$productFamilySectionPropertyArray[$productFamilySectionProperty->getId()] = $productFamilySectionProperty; | |||
$productFamily->removeProductFamilySectionProperty($productFamilySectionProperty); | |||
} | |||
foreach($productFamilySectionPropertyArray as $productFamilySectionProperty) { | |||
$oldSection = $productFamilySectionProperty->getSection(); | |||
$newSection = $sectionStore->getOneByDevAlias($oldSection->getDevAlias()); | |||
if($newSection) { | |||
$productFamilySectionProperty->setProductFamily($productFamily); | |||
$productFamilySectionProperty->setSection($newSection); | |||
$productFamily->addProductFamilySectionProperty($productFamilySectionProperty); | |||
} | |||
else { | |||
$this->entityManager->remove($productFamilySectionProperty); | |||
$productFamily->removeProductFamilySectionProperty($productFamilySectionProperty); | |||
} | |||
} | |||
$productFamily->initProductCategories(); | |||
} | |||
} |
@@ -23,7 +23,7 @@ class UserMerchantBuilder | |||
$this->userMerchantStore = $userMerchantStore; | |||
} | |||
public function createIfNotExist(UserInterface $user, MerchantInterface $merchant): UserMerchantInterface | |||
public function createIfNotExist(UserInterface $user, MerchantInterface $merchant, $flush = true): UserMerchantInterface | |||
{ | |||
$userMerchant = $this->userMerchantStore | |||
->setMerchant($merchant) | |||
@@ -32,13 +32,16 @@ class UserMerchantBuilder | |||
if (!$userMerchant) { | |||
$userMerchantFactory = new UserMerchantFactory(); | |||
$userMerchant = $userMerchantFactory->create($merchant, $user); | |||
$this->entityManager->create($userMerchant); | |||
$this->entityManager->flush(); | |||
if($flush) { | |||
$this->entityManager->flush(); | |||
} | |||
}elseif(!$userMerchant->getActive()){ | |||
$userMerchant->setActive(true); | |||
$this->entityManager->update($userMerchant); | |||
$this->entityManager->flush(); | |||
if($flush) { | |||
$this->entityManager->flush(); | |||
} | |||
} | |||
return $userMerchant; |
@@ -130,40 +130,14 @@ trait AdminControllerTrait | |||
$newEntity = $entityComponent->duplicateEntity($context->getEntity()->getInstance()); | |||
$merchant = $duplicateOtherMerchantForm->get('merchants')->getData(); | |||
// | |||
if($this->isInstanceOf(ProductFamilyInterface::class)) { | |||
$sectionStore = $this->getSectionContainer()->getStore()->setMerchant($merchant); | |||
// Les ProductFamilySectionproperty sont créées en double, on rectifie ici | |||
// @TODO : j'imagine qu'on peut faire mieux que ça. Résoudre le problème à la base par exemple. | |||
$productFamilySectionPropertyArray = []; | |||
foreach($newEntity->getProductFamilySectionProperties() as $productFamilySectionProperty) { | |||
$productFamilySectionPropertyArray[$productFamilySectionProperty->getId()] = $productFamilySectionProperty; | |||
$newEntity->removeProductFamilySectionProperty($productFamilySectionProperty); | |||
} | |||
foreach($productFamilySectionPropertyArray as $productFamilySectionProperty) { | |||
$oldSection = $productFamilySectionProperty->getSection(); | |||
$newSection = $sectionStore->getOneByDevAlias($oldSection->getDevAlias()); | |||
if($newSection) { | |||
$productFamilySectionProperty->setProductFamily($newEntity); | |||
$productFamilySectionProperty->setSection($newSection); | |||
$newEntity->addProductFamilySectionProperty($productFamilySectionProperty); | |||
} | |||
else { | |||
$entityManager->remove($productFamilySectionProperty); | |||
$newEntity->removeProductFamilySectionProperty($productFamilySectionProperty); | |||
} | |||
} | |||
$newEntity->initProductCategories(); | |||
} | |||
$this->getProductFamilyContainer()->getBuilder()->setMerchant($newEntity, $merchant); | |||
} | |||
else { | |||
$newEntity->setMerchant($merchant); | |||
} | |||
// | |||
// | |||
$entityManager->create($newEntity, false); | |||
$entityManager->flush(); | |||
@@ -263,8 +263,13 @@ abstract class ProductFamilyModel extends AbstractFullEntity implements ProductP | |||
public function __construct() | |||
{ | |||
$this->productCategories = new ArrayCollection(); | |||
$this->products = new ArrayCollection(); | |||
$this->qualityLabels = new ArrayCollection(); | |||
$this->initProducts(); | |||
} | |||
public function initProducts() | |||
{ | |||
$this->products = new ArrayCollection(); | |||
} | |||
public function __toString() |
@@ -39,4 +39,9 @@ class ProductCategoryRepositoryQuery extends AbstractRepositoryQuery | |||
return $this->andWhere('productFamilies.status = 1'); | |||
} | |||
public function filterByTitle(string $title): self | |||
{ | |||
return $this->andWhere('.title LIKE :title')->setParameter('title', $title); | |||
} | |||
} |
@@ -53,4 +53,11 @@ class ProductCategoryStore extends AbstractStore | |||
$query->filterByDevAlias($devAlias); | |||
return $query->find(); | |||
} | |||
public function getOneByTitle(string $title): ?ProductCategoryInterface | |||
{ | |||
$query = $this->createDefaultQuery(); | |||
$query->filterByTitle($title); | |||
return $query->findOne(); | |||
} | |||
} |
@@ -201,4 +201,8 @@ class ProductFamilyRepositoryQuery extends AbstractRepositoryQuery | |||
return $this; | |||
} | |||
public function filterByTitle(string $title): self | |||
{ | |||
return $this->andWhere('.title LIKE :title')->setParameter('title', $title); | |||
} | |||
} |
@@ -361,4 +361,10 @@ class ProductFamilyStore extends AbstractStore | |||
return $productFamiliesToReturn; | |||
} | |||
public function getOneByTitle(string $title): ?ProductFamilyInterface | |||
{ | |||
$query = $this->createDefaultQuery(); | |||
$query->filterByTitle($title); | |||
return $query->findOne(); | |||
} | |||
} |
@@ -15,6 +15,7 @@ use Lc\CaracoleBundle\Model\User\UserMerchantInterface; | |||
use Lc\CaracoleBundle\Repository\Merchant\MerchantRepository; | |||
use Lc\CaracoleBundle\Repository\Merchant\MerchantStore; | |||
use Lc\CaracoleBundle\Repository\User\UserMerchantRepository; | |||
use Lc\CaracoleBundle\Solver\Merchant\MerchantSolver; | |||
use Lc\SovBundle\Model\User\UserInterface; | |||
use Lc\SovBundle\Resolver\UrlResolver; | |||
use Lc\SovBundle\Solver\Setting\SettingSolver; | |||
@@ -37,6 +38,7 @@ class MerchantResolver | |||
protected MerchantStore $merchantStore; | |||
protected ParameterBagInterface $parameterBag; | |||
protected SettingSolver $settingSolver; | |||
protected MerchantSolver $merchantSolver; | |||
public function __construct( | |||
EntityManagerInterface $entityManager, | |||
@@ -48,7 +50,8 @@ class MerchantResolver | |||
UrlGeneratorInterface $router, | |||
MerchantStore $merchantStore, | |||
ParameterBagInterface $parameterBag, | |||
SettingSolver $settingSolver | |||
SettingSolver $settingSolver, | |||
MerchantSolver $merchantSolver | |||
) { | |||
$this->requestStack = $requestStack; | |||
$this->em = $entityManager; | |||
@@ -60,6 +63,7 @@ class MerchantResolver | |||
$this->router = $router; | |||
$this->parameterBag = $parameterBag; | |||
$this->settingSolver = $settingSolver; | |||
$this->merchantSolver = $merchantSolver; | |||
} | |||
public function isOutOfMerchant() |