浏览代码

[Backend] Form produit : pas de Product à la première sauvegarde #108

packProduct
Fabien Normand 2 年前
父节点
当前提交
d0cec2cc63
共有 1 个文件被更改,包括 34 次插入52 次删除
  1. +34
    -52
      EventSubscriber/Product/UpdateProductfamilyEventSubscriber.php

+ 34
- 52
EventSubscriber/Product/UpdateProductfamilyEventSubscriber.php 查看文件

@@ -80,67 +80,49 @@ class UpdateProductfamilyEventSubscriber implements EventSubscriberInterface
protected function processProducts($entity)
{

if($entity->getId()) {
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);
} else {
$originProduct = $originProducts[0];
}
}

if ($entity->getActiveProducts()) {
$originProduct->setStatus(-1);
} else {
//CAse de création d'un produit
$originProducts = array();
}
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);
} else {
$originProduct->setStatus(1);
$originProduct = $originProducts[0];
}
}

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

foreach ($entity->getProducts() as $product) {
$product->setProductFamily($entity);
//Enregistrement
$entity->addProduct($originProduct);

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

$this->em->persist($product);
$entity->addProduct($product);
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);
}
}

/* protected function processCategories(ProductFamilyInterface $entity)
{
$productCategoryRepository = $this->em->getRepository(ProductCategoryInterface::class);
$productCategories = $entity->getProductCategories();

$entity->initProductCategories();

foreach ($productCategories as $key => $bool) {
if (is_bool($bool) && $bool) {
if (strpos($key, 'category_children_') !== false) {
$idCategory = (int)str_replace('category_children_', '', $key);
} else {
$idCategory = (int)str_replace('category_', '', $key);
}

$category = $productCategoryRepository->find($idCategory);
$entity->addProductCategory($category);
}
}
}*/
}
}

正在加载...
取消
保存