Selaa lähdekoodia

Correctif dupplication produit

packProduct
Fabien Normand 3 vuotta sitten
vanhempi
commit
e6c492fcda
2 muutettua tiedostoa jossa 33 lisäystä ja 31 poistoa
  1. +32
    -30
      EventSubscriber/Product/UpdateProductfamilyEventSubscriber.php
  2. +1
    -1
      Model/Site/PageModel.php

+ 32
- 30
EventSubscriber/Product/UpdateProductfamilyEventSubscriber.php Näytä tiedosto

@@ -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 Näytä tiedosto

@@ -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…
Peruuta
Tallenna