Bläddra i källkod

Correctif mineur

packProduct
Fabien Normand 2 år sedan
förälder
incheckning
95e3491e38
6 ändrade filer med 162 tillägg och 36 borttagningar
  1. +57
    -0
      Builder/Product/ProductCategoryBuilder.php
  2. +9
    -0
      Container/Product/ProductCategoryContainer.php
  3. +70
    -0
      EventSubscriber/Product/OnlineOrOfflineProductCategoryAfterProductFamilyEventSubscriber.php
  4. +0
    -35
      EventSubscriber/Product/UpdateProductFamilySectionPropertyEventSubscriber.php
  5. +1
    -1
      Repository/Product/ProductFamilyRepositoryQuery.php
  6. +25
    -0
      Solver/Product/ProductCategorySolver.php

+ 57
- 0
Builder/Product/ProductCategoryBuilder.php Visa fil

@@ -0,0 +1,57 @@
<?php

namespace Lc\CaracoleBundle\Builder\Product;

use Doctrine\ORM\EntityManagerInterface;
use Lc\CaracoleBundle\Model\Product\ProductCategoryInterface;
use Lc\CaracoleBundle\Solver\Product\ProductCategorySolver;
use Lc\SovBundle\Translation\FlashBagTranslator;

class ProductCategoryBuilder
{
protected EntityManagerInterface $entityManager;
protected ProductCategorySolver $productCategorySolver;
protected FlashBagTranslator $flashBagTranslator;

public function __construct(EntityManagerInterface $entityManager, ProductCategorySolver $productCategorySolver, FlashBagTranslator $flashBagTranslator)
{
$this->entityManager = $entityManager;
$this->productCategorySolver = $productCategorySolver;
$this->flashBagTranslator = $flashBagTranslator;
}

public function setOnlineIfOnlineProductfamily(ProductCategoryInterface $productCategory)
{
if ($this->productCategorySolver->hasOnlineProductFamily($productCategory)) {
$productCategory->setStatus(1);
$this->entityManager->update($productCategory);

$this->flashBagTranslator->add('success', 'setOnline','ProductCategory', array('%category%'=> $productCategory, '%section%'=> $productCategory->getSection()));
// mise à jour du statut du parent
$productCategoryParent = $productCategory->getParent();
if ($productCategoryParent) {
$productCategoryParent->setStatus(1);
$this->entityManager->update($productCategoryParent);

}
}
}


public function setOfflineIfOfflineProductfamily(ProductCategoryInterface $productCategory)
{
if (!$this->productCategorySolver->hasOnlineProductFamily($productCategory)) {
$productCategory->setStatus(0);
$this->entityManager->update($productCategory);
$this->flashBagTranslator->add('info', 'setOffline','ProductCategory', array('%category%'=> $productCategory, '%section%'=> $productCategory->getSection()));

// mise à jour du statut du parent
$productCategoryParent = $productCategory->getParent();
if ($productCategoryParent && !$this->productCategorySolver->hasOnlineProductFamily($productCategoryParent)) {
$productCategoryParent->setStatus(0);
$this->entityManager->update($productCategoryParent);
}
}
}

}

+ 9
- 0
Container/Product/ProductCategoryContainer.php Visa fil

@@ -2,6 +2,7 @@

namespace Lc\CaracoleBundle\Container\Product;

use Lc\CaracoleBundle\Builder\Product\ProductCategoryBuilder;
use Lc\CaracoleBundle\Definition\Field\Product\ProductCategoryFieldDefinition;
use Lc\CaracoleBundle\Factory\Product\ProductCategoryFactory;
use Lc\CaracoleBundle\Repository\Product\ProductCategoryRepositoryQuery;
@@ -11,6 +12,7 @@ use Lc\CaracoleBundle\Solver\Product\ProductCategorySolver;
class ProductCategoryContainer
{
protected ProductCategoryFactory $factory;
protected ProductCategoryBuilder $builder;
protected ProductCategorySolver $solver;
protected ProductCategoryRepositoryQuery $repositoryQuery;
protected ProductCategoryStore $store;
@@ -18,12 +20,14 @@ class ProductCategoryContainer

public function __construct(
ProductCategoryFactory $factory,
ProductCategoryBuilder $builder,
ProductCategorySolver $solver,
ProductCategoryRepositoryQuery $repositoryQuery,
ProductCategoryStore $store,
ProductCategoryFieldDefinition $fieldDefinition
) {
$this->factory = $factory;
$this->builder = $builder;
$this->solver = $solver;
$this->repositoryQuery = $repositoryQuery;
$this->store = $store;
@@ -35,6 +39,11 @@ class ProductCategoryContainer
return $this->factory;
}

public function getBuilder(): ProductCategoryBuilder
{
return $this->builder;
}

public function getSolver(): ProductCategorySolver
{
return $this->solver;

+ 70
- 0
EventSubscriber/Product/OnlineOrOfflineProductCategoryAfterProductFamilyEventSubscriber.php Visa fil

@@ -0,0 +1,70 @@
<?php

namespace Lc\CaracoleBundle\EventSubscriber\Product;

use Doctrine\ORM\EntityManagerInterface;

use Lc\CaracoleBundle\Container\Product\ProductCategoryContainer;
use Lc\CaracoleBundle\Model\Product\ProductFamilyInterface;
use Lc\CaracoleBundle\Model\Product\ProductFamilySectionPropertyInterface;
use Lc\CaracoleBundle\Solver\Product\ProductCategorySolver;
use Lc\SovBundle\Event\EntityManager\EntityManagerEvent;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;

class OnlineOrOfflineProductCategoryAfterProductFamilyEventSubscriber implements EventSubscriberInterface
{
protected EntityManagerInterface $entityManager;
protected ProductCategoryContainer $productCategoryContainer;

public function __construct(EntityManagerInterface $entityManager, ProductCategoryContainer $productCategoryContainer)
{
$this->entityManager = $entityManager;
$this->productCategoryContainer = $productCategoryContainer;
}

public static function getSubscribedEvents()
{
return [
EntityManagerEvent::PRE_CREATE_EVENT => ['processBeforePersistProductFamilySectionInterface'],
EntityManagerEvent::PRE_UPDATE_EVENT => ['processBeforePersistProductFamilySectionInterface'],
];
}

public function processBeforePersistProductFamilySectionInterface(EntityManagerEvent $event)
{
if ($event->getEntity() instanceof ProductFamilySectionPropertyInterface) {
$this->setProductCategoryByProductFamilySectionProperty($event->getEntity());
} else if ($event->getEntity() instanceof ProductFamilyInterface) {

foreach ($event->getEntity()->getProductFamilySectionProperties() as $productFamilySectionProperty) {
$this->setProductCategoryByProductFamilySectionProperty($productFamilySectionProperty);
}


}
}

protected function setProductCategoryByProductFamilySectionProperty($productFamilySectionProperty)
{
$productFamily = $productFamilySectionProperty->getProductFamily();

if ($productFamilySectionProperty->getStatus() == 1 && $productFamily->getStatus() == 1) {
$section = $productFamilySectionProperty->getSection();
$productCategoryArray = $productFamilySectionProperty->getProductFamily()->getProductCategories();
foreach ($productCategoryArray as $productCategory) {
if ($productCategory->getSection() === $section) {
$this->productCategoryContainer->getBuilder()->setOnlineIfOnlineProductfamily($productCategory);
}
}
} else if ($productFamilySectionProperty->getStatus() == 0 || $productFamily->getStatus() == 0) {
$section = $productFamilySectionProperty->getSection();
$productCategoryArray = $productFamilySectionProperty->getProductFamily()->getProductCategories();
foreach ($productCategoryArray as $productCategory) {
if ($productCategory->getSection() === $section) {
$this->productCategoryContainer->getBuilder()->setOfflineIfOfflineProductfamily($productCategory);
}
}

}
}
}

+ 0
- 35
EventSubscriber/Product/UpdateProductFamilySectionPropertyEventSubscriber.php Visa fil

@@ -1,35 +0,0 @@
<?php

namespace Lc\CaracoleBundle\EventSubscriber\Product;

use Doctrine\ORM\EntityManagerInterface;

use Lc\CaracoleBundle\Model\Product\ProductFamilySectionPropertyInterface;
use Lc\SovBundle\Event\EntityManager\EntityManagerEvent;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;

class UpdateProductFamilySectionPropertyEventSubscriber implements EventSubscriberInterface
{
protected EntityManagerInterface $entityManager;

public function __construct(EntityManagerInterface $entityManager)
{
$this->entityManager = $entityManager;
}

public static function getSubscribedEvents()
{
return [
EntityManagerEvent::PRE_CREATE_EVENT => ['processBeforePersistProductFamilySectionInterface'],
EntityManagerEvent::PRE_UPDATE_EVENT => ['processBeforePersistProductFamilySectionInterface'],
];
}

public function processBeforePersistProductFamilySectionInterface(EntityManagerEvent $event)
{

//TODO à supprimer déplacer dans le script d'import, à remplacer par une alerte à l'édition d'un produit

}

}

+ 1
- 1
Repository/Product/ProductFamilyRepositoryQuery.php Visa fil

@@ -86,7 +86,7 @@ class ProductFamilyRepositoryQuery extends AbstractRepositoryQuery
$this->joinProductFamilySectionProperties(false);
$this->joinSections(false);
$this->andWhereMerchant('section', $merchant);
$this->andWhere('productFamilySectionProperties.status = 1');
//$this->andWhere('productFamilySectionProperties.status = 1');
}



+ 25
- 0
Solver/Product/ProductCategorySolver.php Visa fil

@@ -7,6 +7,11 @@ use Lc\CaracoleBundle\Model\Product\ProductCategoryInterface;
class ProductCategorySolver
{

protected ProductFamilySectionPropertySolver $productFamilySectionPropertySolver;
public function __construct(ProductFamilySectionPropertySolver $productFamilySectionPropertySolver){
$this->productFamilySectionPropertySolver = $productFamilySectionPropertySolver;
}

public function isOnline(ProductCategoryInterface $productCategory)
{
if ($productCategory->getParent()) {
@@ -19,6 +24,26 @@ class ProductCategorySolver
return false;
}

public function hasOnlineProductFamily(ProductCategoryInterface $productCategory){
if($productCategory->getProductFamilies()) {
foreach ($productCategory->getProductFamilies() as $productFamily) {
$productFamilySectionProperty = $this->productFamilySectionPropertySolver->getProductFamilySectionProperty($productFamily, $productCategory->getSection());
//vérifie que le produit est en ligne et qu'il est actif sur cette section
if ($productFamily->getStatus() == 1 && $productFamilySectionProperty && $productFamilySectionProperty->getStatus() == 1) {
return true;
}
}
}

foreach($productCategory->getChildrens() as $productCategoryChildren){
if($this->hasOnlineProductFamily($productCategoryChildren) && $productCategoryChildren->getStatus()==1){
return true;
}
}

return false;
}

}



Laddar…
Avbryt
Spara