Browse Source

Merge branch 'develop'

master
Fabien Normand 3 years ago
parent
commit
568b1e2267
8 changed files with 171 additions and 40 deletions
  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. +6
    -2
      Factory/Order/OrderShopFactory.php
  6. +3
    -2
      Factory/Ticket/TicketFactory.php
  7. +1
    -1
      Repository/Product/ProductFamilyRepositoryQuery.php
  8. +25
    -0
      Solver/Product/ProductCategorySolver.php

+ 57
- 0
Builder/Product/ProductCategoryBuilder.php View File

@@ -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 View File

@@ -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 View File

@@ -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 View File

@@ -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

}

}

+ 6
- 2
Factory/Order/OrderShopFactory.php View File

@@ -23,7 +23,6 @@ class OrderShopFactory extends AbstractFactory
VisitorInterface $visitor = null
): OrderShopInterface
{

$orderShop = $this->createBase($section);
$orderShopBelongTo = false;

@@ -38,7 +37,12 @@ class OrderShopFactory extends AbstractFactory
}

if (!$orderShopBelongTo) {
throw new \ErrorException('La commande doit être liée à un utilisateur ou à un visiteur.');
/*
* @TODO : lors de la première visite, le cookie visitor n'étant pas encore sur le navigateur du visiteur,
* visitor et user sont à null. Du coup, on ne peut pas déclencher cette exception. Voir s'il n'est pas
* possible d'avoir directement un visitor lors de la première visite.
*/
// throw new \ErrorException('La commande doit être liée à un utilisateur ou à un visiteur.');
}

return $orderShop;

+ 3
- 2
Factory/Ticket/TicketFactory.php View File

@@ -16,13 +16,14 @@ class TicketFactory extends SovTicketFactory
{
$ticket = parent::create();

if(!is_null($this->section)) {
if(isset($this->section) && !is_null($this->section)) {
$ticket->setSection($this->section);
}

if(!is_null($this->merchant)) {
if(isset($this->merchant) && !is_null($this->merchant)) {
$ticket->setMerchant($this->merchant);
}

return $ticket;
}
}

+ 1
- 1
Repository/Product/ProductFamilyRepositoryQuery.php View File

@@ -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 View File

@@ -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;
}

}



Loading…
Cancel
Save