Browse Source

Correctif dupplication produit

packProduct
Fabien Normand 3 years ago
parent
commit
e6c492fcda
2 changed files with 33 additions and 31 deletions
  1. +32
    -30
      EventSubscriber/Product/UpdateProductfamilyEventSubscriber.php
  2. +1
    -1
      Model/Site/PageModel.php

+ 32
- 30
EventSubscriber/Product/UpdateProductfamilyEventSubscriber.php View File

@@ -78,44 +78,46 @@ class UpdateProductfamilyEventSubscriber implements EventSubscriberInterface
protected function processProducts($entity)
{

//Récupère le product origin
$originProducts = $this->productContainer->getStore()->getOriginByProductFamily($entity);
if($entity->getId()) {
//Récupère le product origin
$originProducts = $this->productContainer->getStore()->getOriginByProductFamily($entity);

if (count($originProducts) > 1) {
throw new \ErrorException('Plusieurs OriginProduct pour un même produit... Contacter fab');
// Case Nouveau product family
} else {
if (count($originProducts) == 0) {
$entityClassName = $this->em->getEntityName(ProductInterface::class);
$originProduct = new $entityClassName();
$originProduct->setProductFamily($entity);
$originProduct->setOriginProduct(true);
$entity->addProduct($originProduct);
if (count($originProducts) > 1) {
throw new \ErrorException('Plusieurs OriginProduct pour un même produit... Contacter fab');
// Case Nouveau product family
} else {
$originProduct = $originProducts[0];
if (count($originProducts) == 0) {
$entityClassName = $this->em->getEntityName(ProductInterface::class);
$originProduct = new $entityClassName();
$originProduct->setProductFamily($entity);
$originProduct->setOriginProduct(true);
$entity->addProduct($originProduct);
} else {
$originProduct = $originProducts[0];
}
}
}

if ($entity->getActiveProducts()) {
$originProduct->setStatus(-1);
} else {
$originProduct->setStatus(1);
}
if ($entity->getActiveProducts()) {
$originProduct->setStatus(-1);
} else {
$originProduct->setStatus(1);
}

//Enregistrement
$entity->addProduct($originProduct);
//Enregistrement
$entity->addProduct($originProduct);

foreach ($entity->getProducts() as $product) {
$product->setProductFamily($entity);
foreach ($entity->getProducts() as $product) {
$product->setProductFamily($entity);

if ($entity->getProductsQuantityAsTitle() && $product->getStatus() >= 1) {
$product->setTitle(
str_replace('.', ',', $this->productContainer->getSolver()->getQuantityInherited($product)) . $this->productContainer->getSolver()->getUnitInherited($product)->getWording()
);
}
if ($entity->getProductsQuantityAsTitle() && $product->getStatus() >= 1) {
$product->setTitle(
str_replace('.', ',', $this->productContainer->getSolver()->getQuantityInherited($product)) . $this->productContainer->getSolver()->getUnitInherited($product)->getWording()
);
}

$this->em->persist($product);
$entity->addProduct($product);
$this->em->persist($product);
$entity->addProduct($product);
}
}
}


+ 1
- 1
Model/Site/PageModel.php View File

@@ -43,7 +43,7 @@ abstract class PageModel extends SovPageModel implements FilterMerchantInterface
return $this->section;
}

public function setSection(SectionInterface $section): self
public function setSection(?SectionInterface $section): self
{
$this->section = $section;


Loading…
Cancel
Save