選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

53 行
2.1KB

  1. <?php
  2. namespace Lc\CaracoleBundle\Builder\Product;
  3. use Doctrine\ORM\EntityManagerInterface;
  4. use Lc\CaracoleBundle\Container\Section\SectionContainer;
  5. use Lc\CaracoleBundle\Model\Merchant\MerchantInterface;
  6. use Lc\CaracoleBundle\Model\Product\ProductFamilyInterface;
  7. class ProductFamilyBuilder
  8. {
  9. protected EntityManagerInterface $entityManager;
  10. protected SectionContainer $sectionContainer;
  11. public function __construct(
  12. EntityManagerInterface $entityManager,
  13. SectionContainer $sectionContainer
  14. )
  15. {
  16. $this->entityManager = $entityManager;
  17. $this->sectionContainer = $sectionContainer;
  18. }
  19. public function setMerchant(ProductFamilyInterface $productFamily, MerchantInterface $merchant): void
  20. {
  21. $sectionStore = $this->sectionContainer->getStore()->setMerchant($merchant);
  22. // Les ProductFamilySectionProperty sont créées en double, on rectifie ici
  23. $productFamilySectionPropertyArray = [];
  24. foreach($productFamily->getProductFamilySectionProperties() as $productFamilySectionProperty) {
  25. $productFamilySectionPropertyArray[$productFamilySectionProperty->getId()] = $productFamilySectionProperty;
  26. $productFamily->removeProductFamilySectionProperty($productFamilySectionProperty);
  27. }
  28. foreach($productFamilySectionPropertyArray as $productFamilySectionProperty) {
  29. $oldSection = $productFamilySectionProperty->getSection();
  30. $newSection = $sectionStore->getOneByDevAlias($oldSection->getDevAlias());
  31. if($newSection) {
  32. $productFamilySectionProperty->setProductFamily($productFamily);
  33. $productFamilySectionProperty->setSection($newSection);
  34. $productFamily->addProductFamilySectionProperty($productFamilySectionProperty);
  35. }
  36. else {
  37. $this->entityManager->remove($productFamilySectionProperty);
  38. $productFamily->removeProductFamilySectionProperty($productFamilySectionProperty);
  39. }
  40. }
  41. $productFamily->initProductCategories();
  42. }
  43. }