|
- <?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);
- }
- }
- }
-
- }
|