Parcourir la source

Merge branch 'develop'

master
Guillaume Bourgeois il y a 1 an
Parent
révision
7d3ebbd346
9 fichiers modifiés avec 86 ajouts et 36 suppressions
  1. +42
    -0
      Builder/Product/ProductFamilyBuilder.php
  2. +7
    -4
      Builder/User/UserMerchantBuilder.php
  3. +4
    -30
      Controller/AdminControllerTrait.php
  4. +6
    -1
      Model/Product/ProductFamilyModel.php
  5. +5
    -0
      Repository/Product/ProductCategoryRepositoryQuery.php
  6. +7
    -0
      Repository/Product/ProductCategoryStore.php
  7. +4
    -0
      Repository/Product/ProductFamilyRepositoryQuery.php
  8. +6
    -0
      Repository/Product/ProductFamilyStore.php
  9. +5
    -1
      Resolver/MerchantResolver.php

+ 42
- 0
Builder/Product/ProductFamilyBuilder.php Voir le fichier

@@ -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();
}
}

+ 7
- 4
Builder/User/UserMerchantBuilder.php Voir le fichier

@@ -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;

+ 4
- 30
Controller/AdminControllerTrait.php Voir le fichier

@@ -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();


+ 6
- 1
Model/Product/ProductFamilyModel.php Voir le fichier

@@ -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()

+ 5
- 0
Repository/Product/ProductCategoryRepositoryQuery.php Voir le fichier

@@ -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);
}
}

+ 7
- 0
Repository/Product/ProductCategoryStore.php Voir le fichier

@@ -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();
}
}

+ 4
- 0
Repository/Product/ProductFamilyRepositoryQuery.php Voir le fichier

@@ -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);
}
}

+ 6
- 0
Repository/Product/ProductFamilyStore.php Voir le fichier

@@ -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();
}
}

+ 5
- 1
Resolver/MerchantResolver.php Voir le fichier

@@ -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()

Chargement…
Annuler
Enregistrer