Browse Source

Finalisation edition produit

packProduct
Fab 3 years ago
parent
commit
ef968b2503
8 changed files with 180 additions and 47 deletions
  1. +2
    -0
      Controller/AdminControllerTrait.php
  2. +1
    -3
      Controller/User/UserMerchantAdminController.php
  3. +0
    -17
      Doctrine/Extension/ReductionPropertyTrait.php
  4. +1
    -1
      EventSubscriber/Product/DuplicateProductfamilyEventSubscriber.php
  5. +144
    -0
      EventSubscriber/Product/UpdateProductfamilyEventSubscriber.php
  6. +10
    -7
      Model/Reduction/ReductionCartModel.php
  7. +13
    -11
      Model/Reduction/ReductionCatalogModel.php
  8. +9
    -8
      Model/Reduction/ReductionCreditModel.php

+ 2
- 0
Controller/AdminControllerTrait.php View File

use Lc\CaracoleBundle\Factory\User\UserMerchantFactory; use Lc\CaracoleBundle\Factory\User\UserMerchantFactory;
use Lc\CaracoleBundle\Form\Merchant\DuplicateToOtherMerchantFormType; use Lc\CaracoleBundle\Form\Merchant\DuplicateToOtherMerchantFormType;
use Lc\CaracoleBundle\Form\Section\DuplicateToOtherSectionFormType; use Lc\CaracoleBundle\Form\Section\DuplicateToOtherSectionFormType;
use Lc\CaracoleBundle\Repository\Reduction\ReductionCatalogStore;
use Lc\CaracoleBundle\Resolver\MerchantResolver; use Lc\CaracoleBundle\Resolver\MerchantResolver;
use Lc\CaracoleBundle\Resolver\SectionResolver; use Lc\CaracoleBundle\Resolver\SectionResolver;
use EasyCorp\Bundle\EasyAdminBundle\Dto\EntityDto; use EasyCorp\Bundle\EasyAdminBundle\Dto\EntityDto;
'section_resolver' => SectionResolver::class, 'section_resolver' => SectionResolver::class,
'user_factory' => UserFactory::class, 'user_factory' => UserFactory::class,
'user_merchant_factory' => UserMerchantFactory::class, 'user_merchant_factory' => UserMerchantFactory::class,
ReductionCatalogStore::class => ReductionCatalogStore::class,
] ]
); );
} }

+ 1
- 3
Controller/User/UserMerchantAdminController.php View File

} }


return $this->render( return $this->render(
'@LcCaracole/admin/user/usermerchant_edit.html.twig',
'@LcCaracole/admin/user/edit_usermerchant.html.twig',
[ [
'form' => $form->createView(), 'form' => $form->createView(),
] ]
if (!$context->getEntity()->isAccessible()) { if (!$context->getEntity()->isAccessible()) {
throw new InsufficientEntityPermissionException($context); throw new InsufficientEntityPermissionException($context);
} }
dump($context->getCrud()->getControllerFqcn());



$options['action'] = $adminUrlGenerator $options['action'] = $adminUrlGenerator
->setController($context->getCrud()->getControllerFqcn()) ->setController($context->getCrud()->getControllerFqcn())

+ 0
- 17
Doctrine/Extension/ReductionPropertyTrait.php View File

*/ */
protected $groupUsers; protected $groupUsers;


/**
* @ORM\ManyToOne(targetEntity="Lc\CaracoleBundle\Model\Merchant\MerchantInterface", inversedBy="productFamilies")
* @ORM\JoinColumn(nullable=false)
*/
protected $merchant;


/** /**
* @ORM\Column(type="datetime", nullable=true) * @ORM\Column(type="datetime", nullable=true)
$this->groupUsers = new ArrayCollection(); $this->groupUsers = new ArrayCollection();
} }


public function getMerchant(): ?MerchantInterface
{
return $this->merchant;
}

public function setMerchant(?MerchantInterface $merchant): self
{
$this->merchant = $merchant;

return $this;
}

/** /**
* @return Collection|UserInterface[] * @return Collection|UserInterface[]
*/ */

EventSubscriber/Product/DuplicateProductEventSubscriber.php → EventSubscriber/Product/DuplicateProductfamilyEventSubscriber.php View File

use Lc\SovBundle\Repository\AbstractRepositoryInterface; use Lc\SovBundle\Repository\AbstractRepositoryInterface;
use Symfony\Component\EventDispatcher\EventSubscriberInterface; use Symfony\Component\EventDispatcher\EventSubscriberInterface;


class DuplicateProductEventSubscriber implements EventSubscriberInterface
class DuplicateProductfamilyEventSubscriber implements EventSubscriberInterface
{ {
protected $em; protected $em;
protected $adminUrlGenerator; protected $adminUrlGenerator;

+ 144
- 0
EventSubscriber/Product/UpdateProductfamilyEventSubscriber.php View File

<?php

namespace Lc\CaracoleBundle\EventSubscriber\Product;

use Doctrine\ORM\EntityManagerInterface;

use Lc\CaracoleBundle\Model\Product\ProductFamilyInterface;
use Lc\CaracoleBundle\Model\Product\ProductInterface;
use Lc\CaracoleBundle\Model\Reduction\ReductionCatalogInterface;
use Lc\SovBundle\Event\EntityManager\EntityManagerEvent;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;

class UpdateProductfamilyEventSubscriber implements EventSubscriberInterface
{
protected $em;
protected $adminUrlGenerator;

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

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

public function processBeforePersistProductFamily(EntityManagerEvent $event)
{
$entity = $event->getEntity();
if($entity instanceof ProductFamilyInterface) {
$this->processProducts($entity);
$this->processPrice($entity);
$this->processReductionCatalog($entity);
}
//TODO updatePriceByProductFamily
}


protected function processReductionCatalog($entity)
{
$reductionCatalog = $entity->getReductionCatalog();

if ($reductionCatalog instanceof ReductionCatalogInterface) {
if ($reductionCatalog->getValue() && $reductionCatalog->getBehaviorTaxRate() && $reductionCatalog->getUnit()) {
//$reductionCatalog->setSection($entity->getSection());
$reductionCatalog->setProductFamily($entity);
if(is_null($reductionCatalog->getId())) {
$this->em->create($reductionCatalog);
}else {
$this->em->update($reductionCatalog);
}
}
}
}

protected function processPrice($entity)
{
if ($entity->getBehaviorPrice() == 'by-piece') {
$entity->setPriceByRefUnit(null);
$entity->setBuyingPriceByRefUnit(null);
} else {
if ($entity->getBehaviorPrice() == 'by-reference-unit') {
$entity->setPrice(null);
$entity->setBuyingPrice(null);
}
}
}

protected function processProducts($entity)
{

//Récupère le product origin
$originProducts = $this->em->getRepository(ProductInterface::class)
->findBy(
array(
'productFamily' => $entity->getId(),
'originProduct' => true,
)
);

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 {
$originProduct->setStatus(1);
}

//Enregistrement
$entity->addProduct($originProduct);

foreach ($entity->getProducts() as $product) {
$product->setProductFamily($entity);

if ($entity->getProductsQuantityAsTitle() && $product->getStatus() >= 1) {
$product->setTitle(
str_replace('.', ',', $product->getQuantityInherited()).$product->getUnitInherited(
)->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);
}
}
}*/
}

+ 10
- 7
Model/Reduction/ReductionCartModel.php View File

use Doctrine\Common\Collections\Collection; use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM; use Doctrine\ORM\Mapping as ORM;
use Lc\CaracoleBundle\Doctrine\Extension\FilterMerchantInterface; use Lc\CaracoleBundle\Doctrine\Extension\FilterMerchantInterface;
use Lc\CaracoleBundle\Doctrine\Extension\FilterSectionInterface;
use Lc\CaracoleBundle\Doctrine\Extension\OrderAmountMinInterface; use Lc\CaracoleBundle\Doctrine\Extension\OrderAmountMinInterface;
use Lc\CaracoleBundle\Doctrine\Extension\OrderAmountMinTrait; use Lc\CaracoleBundle\Doctrine\Extension\OrderAmountMinTrait;
use Lc\CaracoleBundle\Doctrine\Extension\ReductionCartPropertyInterface; use Lc\CaracoleBundle\Doctrine\Extension\ReductionCartPropertyInterface;
use Lc\CaracoleBundle\Doctrine\Extension\ReductionPropertyInterface; use Lc\CaracoleBundle\Doctrine\Extension\ReductionPropertyInterface;
use Lc\CaracoleBundle\Model\Merchant\MerchantInterface; use Lc\CaracoleBundle\Model\Merchant\MerchantInterface;
use Lc\CaracoleBundle\Model\PointSale\PointSaleInterface; use Lc\CaracoleBundle\Model\PointSale\PointSaleInterface;
use Lc\CaracoleBundle\Model\Section\SectionInterface;
use Lc\SovBundle\Doctrine\Extension\StatusInterface; use Lc\SovBundle\Doctrine\Extension\StatusInterface;
use Lc\SovBundle\Doctrine\Extension\StatusTrait; use Lc\SovBundle\Doctrine\Extension\StatusTrait;
use Lc\SovBundle\Doctrine\Pattern\AbstractLightEntity; use Lc\SovBundle\Doctrine\Pattern\AbstractLightEntity;
*/ */
abstract class ReductionCartModel extends AbstractLightEntity implements ReductionPropertyInterface, ReductionInterface, abstract class ReductionCartModel extends AbstractLightEntity implements ReductionPropertyInterface, ReductionInterface,
ReductionCartPropertyInterface, ReductionCartPropertyInterface,
FilterMerchantInterface,
FilterSectionInterface,
OrderAmountMinInterface, StatusInterface OrderAmountMinInterface, StatusInterface
{ {


*/ */
protected $title; protected $title;



/** /**
* @ORM\ManyToOne(targetEntity="Lc\CaracoleBundle\Model\Merchant\MerchantInterface")
* @ORM\ManyToOne(targetEntity="Lc\CaracoleBundle\Model\Section\SectionInterface")
* @ORM\JoinColumn(nullable=false) * @ORM\JoinColumn(nullable=false)
*/ */
protected $merchant;
protected $section;


/** /**
* @ORM\Column(type="array", nullable=true) * @ORM\Column(type="array", nullable=true)
return $this; return $this;
} }


public function getMerchant(): ?MerchantInterface
public function getSection(): SectionInterface
{ {
return $this->merchant;
return $this->section;
} }


public function setMerchant(?MerchantInterface $merchant): self
public function setSection(SectionInterface $section): self
{ {
$this->merchant = $merchant;
$this->section = $section;


return $this; return $this;
} }

+ 13
- 11
Model/Reduction/ReductionCatalogModel.php View File

use Doctrine\Common\Collections\ArrayCollection; use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection; use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM; use Doctrine\ORM\Mapping as ORM;
use Lc\CaracoleBundle\Doctrine\Extension\FilterMerchantInterface;
use Lc\CaracoleBundle\Doctrine\Extension\FilterSectionInterface;
use Lc\CaracoleBundle\Doctrine\Extension\ReductionPropertyTrait; use Lc\CaracoleBundle\Doctrine\Extension\ReductionPropertyTrait;
use Lc\CaracoleBundle\Doctrine\Extension\ReductionTrait; use Lc\CaracoleBundle\Doctrine\Extension\ReductionTrait;
use Lc\CaracoleBundle\Doctrine\Extension\ReductionPropertyInterface; use Lc\CaracoleBundle\Doctrine\Extension\ReductionPropertyInterface;
use Lc\CaracoleBundle\Model\Merchant\MerchantInterface;
use Lc\CaracoleBundle\Model\Product\ProductCategoryInterface; use Lc\CaracoleBundle\Model\Product\ProductCategoryInterface;
use Lc\CaracoleBundle\Model\Product\ProductFamilyInterface; use Lc\CaracoleBundle\Model\Product\ProductFamilyInterface;
use Lc\CaracoleBundle\Model\Product\ProductFamilyModel;
use Lc\CaracoleBundle\Model\Section\SectionInterface;
use Lc\SovBundle\Doctrine\Extension\StatusInterface; use Lc\SovBundle\Doctrine\Extension\StatusInterface;
use Lc\SovBundle\Doctrine\Extension\StatusTrait; use Lc\SovBundle\Doctrine\Extension\StatusTrait;
use Lc\SovBundle\Doctrine\Pattern\AbstractLightEntity; use Lc\SovBundle\Doctrine\Pattern\AbstractLightEntity;
*/ */
abstract class ReductionCatalogModel extends AbstractLightEntity implements ReductionCatalogInterface, abstract class ReductionCatalogModel extends AbstractLightEntity implements ReductionCatalogInterface,
ReductionPropertyInterface, ReductionPropertyInterface,
FilterMerchantInterface, StatusInterface
FilterSectionInterface, StatusInterface
{ {
use StatusTrait; use StatusTrait;
use ReductionTrait; use ReductionTrait;
*/ */
protected $title; protected $title;



/** /**
* @ORM\ManyToOne(targetEntity="Lc\CaracoleBundle\Model\Merchant\MerchantInterface")
* @ORM\ManyToOne(targetEntity="Lc\CaracoleBundle\Model\Section\SectionInterface")
* @ORM\JoinColumn(nullable=false) * @ORM\JoinColumn(nullable=false)
*/ */
protected $merchant;
protected $section;


/** /**
* @ORM\ManyToMany(targetEntity="Lc\CaracoleBundle\Model\Product\ProductFamilyInterface") * @ORM\ManyToMany(targetEntity="Lc\CaracoleBundle\Model\Product\ProductFamilyInterface")
} }




public function getMerchant(): ?MerchantInterface
public function getSection(): SectionInterface
{ {
return $this->merchant;
return $this->section;
} }


public function setMerchant(?MerchantInterface $merchant): self
public function setSection(SectionInterface $section): self
{ {
$this->merchant = $merchant;
$this->section = $section;


return $this; return $this;
} }
} }




public function getProductFamily(): ?ProductFamily
public function getProductFamily(): ?ProductFamilyModel
{ {
return $this->productFamily; return $this->productFamily;
} }


public function setProductFamily(?ProductFamily $productFamily): self
public function setProductFamily(?ProductFamilyModel $productFamily): self
{ {
$this->productFamily = $productFamily; $this->productFamily = $productFamily;



+ 9
- 8
Model/Reduction/ReductionCreditModel.php View File

use Doctrine\Common\Collections\Collection; use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM; use Doctrine\ORM\Mapping as ORM;
use Lc\CaracoleBundle\Doctrine\Extension\FilterMerchantInterface; use Lc\CaracoleBundle\Doctrine\Extension\FilterMerchantInterface;
use Lc\CaracoleBundle\Doctrine\Extension\FilterSectionInterface;
use Lc\CaracoleBundle\Doctrine\Extension\ReductionInterface; use Lc\CaracoleBundle\Doctrine\Extension\ReductionInterface;
use Lc\CaracoleBundle\Doctrine\Extension\ReductionTrait; use Lc\CaracoleBundle\Doctrine\Extension\ReductionTrait;
use Lc\CaracoleBundle\Model\Merchant\MerchantInterface; use Lc\CaracoleBundle\Model\Merchant\MerchantInterface;
use Lc\CaracoleBundle\Model\Section\SectionInterface;
use Lc\SovBundle\Doctrine\Extension\StatusInterface; use Lc\SovBundle\Doctrine\Extension\StatusInterface;
use Lc\SovBundle\Doctrine\Extension\StatusTrait; use Lc\SovBundle\Doctrine\Extension\StatusTrait;
use Lc\SovBundle\Doctrine\Pattern\AbstractLightEntity; use Lc\SovBundle\Doctrine\Pattern\AbstractLightEntity;
/** /**
* @ORM\MappedSuperclass() * @ORM\MappedSuperclass()
*/ */
abstract class ReductionCreditModel extends AbstractLightEntity implements ReductionInterface, FilterMerchantInterface,
abstract class ReductionCreditModel extends AbstractLightEntity implements ReductionInterface, FilterSectionInterface,
StatusInterface StatusInterface
{ {
const TYPE_CREDIT = 'credit'; const TYPE_CREDIT = 'credit';
*/ */
protected $users; protected $users;



/** /**
* @ORM\ManyToOne(targetEntity="Lc\CaracoleBundle\Model\Merchant\MerchantInterface")
* @ORM\ManyToOne(targetEntity="Lc\CaracoleBundle\Model\Section\SectionInterface")
* @ORM\JoinColumn(nullable=false) * @ORM\JoinColumn(nullable=false)
*/ */
protected $merchant;
protected $section;


/** /**
* @ORM\Column(type="string", length=255) * @ORM\Column(type="string", length=255)
} }




public function getMerchant(): ?MerchantInterface
public function getSection(): SectionInterface
{ {
return $this->merchant;
return $this->section;
} }


public function setMerchant(?MerchantInterface $merchant): self
public function setSection(SectionInterface $section): self
{ {
$this->merchant = $merchant;
$this->section = $section;


return $this; return $this;
} }

Loading…
Cancel
Save