Browse Source

Merge branch 'develop'

master
Guillaume Bourgeois 1 year ago
parent
commit
7d3ebbd346
9 changed files with 86 additions and 36 deletions
  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 View File



namespace Lc\CaracoleBundle\Builder\Product; 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; use Lc\CaracoleBundle\Model\Product\ProductFamilyInterface;


class ProductFamilyBuilder 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 View File

$this->userMerchantStore = $userMerchantStore; $this->userMerchantStore = $userMerchantStore;
} }


public function createIfNotExist(UserInterface $user, MerchantInterface $merchant): UserMerchantInterface
public function createIfNotExist(UserInterface $user, MerchantInterface $merchant, $flush = true): UserMerchantInterface
{ {
$userMerchant = $this->userMerchantStore $userMerchant = $this->userMerchantStore
->setMerchant($merchant) ->setMerchant($merchant)
if (!$userMerchant) { if (!$userMerchant) {
$userMerchantFactory = new UserMerchantFactory(); $userMerchantFactory = new UserMerchantFactory();
$userMerchant = $userMerchantFactory->create($merchant, $user); $userMerchant = $userMerchantFactory->create($merchant, $user);

$this->entityManager->create($userMerchant); $this->entityManager->create($userMerchant);
$this->entityManager->flush();
if($flush) {
$this->entityManager->flush();
}
}elseif(!$userMerchant->getActive()){ }elseif(!$userMerchant->getActive()){
$userMerchant->setActive(true); $userMerchant->setActive(true);
$this->entityManager->update($userMerchant); $this->entityManager->update($userMerchant);
$this->entityManager->flush();
if($flush) {
$this->entityManager->flush();
}
} }


return $userMerchant; return $userMerchant;

+ 4
- 30
Controller/AdminControllerTrait.php View File

$newEntity = $entityComponent->duplicateEntity($context->getEntity()->getInstance()); $newEntity = $entityComponent->duplicateEntity($context->getEntity()->getInstance());


$merchant = $duplicateOtherMerchantForm->get('merchants')->getData(); $merchant = $duplicateOtherMerchantForm->get('merchants')->getData();
//
if($this->isInstanceOf(ProductFamilyInterface::class)) { 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 { else {
$newEntity->setMerchant($merchant); $newEntity->setMerchant($merchant);
} }
//
//

$entityManager->create($newEntity, false); $entityManager->create($newEntity, false);
$entityManager->flush(); $entityManager->flush();



+ 6
- 1
Model/Product/ProductFamilyModel.php View File

public function __construct() public function __construct()
{ {
$this->productCategories = new ArrayCollection(); $this->productCategories = new ArrayCollection();
$this->products = new ArrayCollection();
$this->qualityLabels = new ArrayCollection(); $this->qualityLabels = new ArrayCollection();
$this->initProducts();
}

public function initProducts()
{
$this->products = new ArrayCollection();
} }


public function __toString() public function __toString()

+ 5
- 0
Repository/Product/ProductCategoryRepositoryQuery.php View File



return $this->andWhere('productFamilies.status = 1'); 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 View File

$query->filterByDevAlias($devAlias); $query->filterByDevAlias($devAlias);
return $query->find(); return $query->find();
} }

public function getOneByTitle(string $title): ?ProductCategoryInterface
{
$query = $this->createDefaultQuery();
$query->filterByTitle($title);
return $query->findOne();
}
} }

+ 4
- 0
Repository/Product/ProductFamilyRepositoryQuery.php View File

return $this; return $this;
} }


public function filterByTitle(string $title): self
{
return $this->andWhere('.title LIKE :title')->setParameter('title', $title);
}
} }

+ 6
- 0
Repository/Product/ProductFamilyStore.php View File

return $productFamiliesToReturn; return $productFamiliesToReturn;
} }


public function getOneByTitle(string $title): ?ProductFamilyInterface
{
$query = $this->createDefaultQuery();
$query->filterByTitle($title);
return $query->findOne();
}
} }

+ 5
- 1
Resolver/MerchantResolver.php View File

use Lc\CaracoleBundle\Repository\Merchant\MerchantRepository; use Lc\CaracoleBundle\Repository\Merchant\MerchantRepository;
use Lc\CaracoleBundle\Repository\Merchant\MerchantStore; use Lc\CaracoleBundle\Repository\Merchant\MerchantStore;
use Lc\CaracoleBundle\Repository\User\UserMerchantRepository; use Lc\CaracoleBundle\Repository\User\UserMerchantRepository;
use Lc\CaracoleBundle\Solver\Merchant\MerchantSolver;
use Lc\SovBundle\Model\User\UserInterface; use Lc\SovBundle\Model\User\UserInterface;
use Lc\SovBundle\Resolver\UrlResolver; use Lc\SovBundle\Resolver\UrlResolver;
use Lc\SovBundle\Solver\Setting\SettingSolver; use Lc\SovBundle\Solver\Setting\SettingSolver;
protected MerchantStore $merchantStore; protected MerchantStore $merchantStore;
protected ParameterBagInterface $parameterBag; protected ParameterBagInterface $parameterBag;
protected SettingSolver $settingSolver; protected SettingSolver $settingSolver;
protected MerchantSolver $merchantSolver;


public function __construct( public function __construct(
EntityManagerInterface $entityManager, EntityManagerInterface $entityManager,
UrlGeneratorInterface $router, UrlGeneratorInterface $router,
MerchantStore $merchantStore, MerchantStore $merchantStore,
ParameterBagInterface $parameterBag, ParameterBagInterface $parameterBag,
SettingSolver $settingSolver
SettingSolver $settingSolver,
MerchantSolver $merchantSolver
) { ) {
$this->requestStack = $requestStack; $this->requestStack = $requestStack;
$this->em = $entityManager; $this->em = $entityManager;
$this->router = $router; $this->router = $router;
$this->parameterBag = $parameterBag; $this->parameterBag = $parameterBag;
$this->settingSolver = $settingSolver; $this->settingSolver = $settingSolver;
$this->merchantSolver = $merchantSolver;
} }


public function isOutOfMerchant() public function isOutOfMerchant()

Loading…
Cancel
Save