Parcourir la source

Divers

develop
Guillaume Bourgeois il y a 1 an
Parent
révision
04dab44e41
4 fichiers modifiés avec 58 ajouts et 30 suppressions
  1. +42
    -0
      Builder/Product/ProductFamilyBuilder.php
  2. +4
    -30
      Controller/AdminControllerTrait.php
  3. +5
    -0
      Repository/Product/ProductCategoryRepositoryQuery.php
  4. +7
    -0
      Repository/Product/ProductCategoryStore.php

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



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

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

$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($merchant);
}
else { else {
$newEntity->setMerchant($merchant); $newEntity->setMerchant($merchant);
} }
//
//

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



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



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 Voir le fichier

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

Chargement…
Annuler
Enregistrer