<?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); | |||||
} | |||||
} | |||||
} | |||||
} |
namespace Lc\CaracoleBundle\Container\Product; | namespace Lc\CaracoleBundle\Container\Product; | ||||
use Lc\CaracoleBundle\Builder\Product\ProductCategoryBuilder; | |||||
use Lc\CaracoleBundle\Definition\Field\Product\ProductCategoryFieldDefinition; | use Lc\CaracoleBundle\Definition\Field\Product\ProductCategoryFieldDefinition; | ||||
use Lc\CaracoleBundle\Factory\Product\ProductCategoryFactory; | use Lc\CaracoleBundle\Factory\Product\ProductCategoryFactory; | ||||
use Lc\CaracoleBundle\Repository\Product\ProductCategoryRepositoryQuery; | use Lc\CaracoleBundle\Repository\Product\ProductCategoryRepositoryQuery; | ||||
class ProductCategoryContainer | class ProductCategoryContainer | ||||
{ | { | ||||
protected ProductCategoryFactory $factory; | protected ProductCategoryFactory $factory; | ||||
protected ProductCategoryBuilder $builder; | |||||
protected ProductCategorySolver $solver; | protected ProductCategorySolver $solver; | ||||
protected ProductCategoryRepositoryQuery $repositoryQuery; | protected ProductCategoryRepositoryQuery $repositoryQuery; | ||||
protected ProductCategoryStore $store; | protected ProductCategoryStore $store; | ||||
public function __construct( | public function __construct( | ||||
ProductCategoryFactory $factory, | ProductCategoryFactory $factory, | ||||
ProductCategoryBuilder $builder, | |||||
ProductCategorySolver $solver, | ProductCategorySolver $solver, | ||||
ProductCategoryRepositoryQuery $repositoryQuery, | ProductCategoryRepositoryQuery $repositoryQuery, | ||||
ProductCategoryStore $store, | ProductCategoryStore $store, | ||||
ProductCategoryFieldDefinition $fieldDefinition | ProductCategoryFieldDefinition $fieldDefinition | ||||
) { | ) { | ||||
$this->factory = $factory; | $this->factory = $factory; | ||||
$this->builder = $builder; | |||||
$this->solver = $solver; | $this->solver = $solver; | ||||
$this->repositoryQuery = $repositoryQuery; | $this->repositoryQuery = $repositoryQuery; | ||||
$this->store = $store; | $this->store = $store; | ||||
return $this->factory; | return $this->factory; | ||||
} | } | ||||
public function getBuilder(): ProductCategoryBuilder | |||||
{ | |||||
return $this->builder; | |||||
} | |||||
public function getSolver(): ProductCategorySolver | public function getSolver(): ProductCategorySolver | ||||
{ | { | ||||
return $this->solver; | return $this->solver; |
<?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); | |||||
} | |||||
} | |||||
} | |||||
} | |||||
} |
<?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 | |||||
} | |||||
} |
VisitorInterface $visitor = null | VisitorInterface $visitor = null | ||||
): OrderShopInterface | ): OrderShopInterface | ||||
{ | { | ||||
$orderShop = $this->createBase($section); | $orderShop = $this->createBase($section); | ||||
$orderShopBelongTo = false; | $orderShopBelongTo = false; | ||||
} | } | ||||
if (!$orderShopBelongTo) { | 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; | return $orderShop; |
{ | { | ||||
$ticket = parent::create(); | $ticket = parent::create(); | ||||
if(!is_null($this->section)) { | |||||
if(isset($this->section) && !is_null($this->section)) { | |||||
$ticket->setSection($this->section); | $ticket->setSection($this->section); | ||||
} | } | ||||
if(!is_null($this->merchant)) { | |||||
if(isset($this->merchant) && !is_null($this->merchant)) { | |||||
$ticket->setMerchant($this->merchant); | $ticket->setMerchant($this->merchant); | ||||
} | } | ||||
return $ticket; | return $ticket; | ||||
} | } | ||||
} | } |
$this->joinProductFamilySectionProperties(false); | $this->joinProductFamilySectionProperties(false); | ||||
$this->joinSections(false); | $this->joinSections(false); | ||||
$this->andWhereMerchant('section', $merchant); | $this->andWhereMerchant('section', $merchant); | ||||
$this->andWhere('productFamilySectionProperties.status = 1'); | |||||
//$this->andWhere('productFamilySectionProperties.status = 1'); | |||||
} | } | ||||
class ProductCategorySolver | class ProductCategorySolver | ||||
{ | { | ||||
protected ProductFamilySectionPropertySolver $productFamilySectionPropertySolver; | |||||
public function __construct(ProductFamilySectionPropertySolver $productFamilySectionPropertySolver){ | |||||
$this->productFamilySectionPropertySolver = $productFamilySectionPropertySolver; | |||||
} | |||||
public function isOnline(ProductCategoryInterface $productCategory) | public function isOnline(ProductCategoryInterface $productCategory) | ||||
{ | { | ||||
if ($productCategory->getParent()) { | if ($productCategory->getParent()) { | ||||
return false; | 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; | |||||
} | |||||
} | } | ||||