Explorar el Código

Finalisation edition produit

packProduct
Fab hace 3 años
padre
commit
ef968b2503
Se han modificado 8 ficheros con 180 adiciones y 47 borrados
  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 Ver fichero

@@ -21,6 +21,7 @@ use Lc\CaracoleBundle\Doctrine\Extension\FilterSectionInterface;
use Lc\CaracoleBundle\Factory\User\UserMerchantFactory;
use Lc\CaracoleBundle\Form\Merchant\DuplicateToOtherMerchantFormType;
use Lc\CaracoleBundle\Form\Section\DuplicateToOtherSectionFormType;
use Lc\CaracoleBundle\Repository\Reduction\ReductionCatalogStore;
use Lc\CaracoleBundle\Resolver\MerchantResolver;
use Lc\CaracoleBundle\Resolver\SectionResolver;
use EasyCorp\Bundle\EasyAdminBundle\Dto\EntityDto;
@@ -43,6 +44,7 @@ trait AdminControllerTrait
'section_resolver' => SectionResolver::class,
'user_factory' => UserFactory::class,
'user_merchant_factory' => UserMerchantFactory::class,
ReductionCatalogStore::class => ReductionCatalogStore::class,
]
);
}

+ 1
- 3
Controller/User/UserMerchantAdminController.php Ver fichero

@@ -209,7 +209,7 @@ abstract class UserMerchantAdminController extends AbstractAdminController
}

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


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

+ 0
- 17
Doctrine/Extension/ReductionPropertyTrait.php Ver fichero

@@ -22,11 +22,6 @@ trait ReductionPropertyTrait
*/
protected $groupUsers;

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

/**
* @ORM\Column(type="datetime", nullable=true)
@@ -50,18 +45,6 @@ trait ReductionPropertyTrait
$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[]
*/

EventSubscriber/Product/DuplicateProductEventSubscriber.php → EventSubscriber/Product/DuplicateProductfamilyEventSubscriber.php Ver fichero

@@ -16,7 +16,7 @@ use Lc\SovBundle\Event\EntityManager\EntityManagerEvent;
use Lc\SovBundle\Repository\AbstractRepositoryInterface;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;

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

+ 144
- 0
EventSubscriber/Product/UpdateProductfamilyEventSubscriber.php Ver fichero

@@ -0,0 +1,144 @@
<?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 Ver fichero

@@ -6,6 +6,7 @@ use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Lc\CaracoleBundle\Doctrine\Extension\FilterMerchantInterface;
use Lc\CaracoleBundle\Doctrine\Extension\FilterSectionInterface;
use Lc\CaracoleBundle\Doctrine\Extension\OrderAmountMinInterface;
use Lc\CaracoleBundle\Doctrine\Extension\OrderAmountMinTrait;
use Lc\CaracoleBundle\Doctrine\Extension\ReductionCartPropertyInterface;
@@ -16,6 +17,7 @@ use Lc\CaracoleBundle\Doctrine\Extension\ReductionTrait;
use Lc\CaracoleBundle\Doctrine\Extension\ReductionPropertyInterface;
use Lc\CaracoleBundle\Model\Merchant\MerchantInterface;
use Lc\CaracoleBundle\Model\PointSale\PointSaleInterface;
use Lc\CaracoleBundle\Model\Section\SectionInterface;
use Lc\SovBundle\Doctrine\Extension\StatusInterface;
use Lc\SovBundle\Doctrine\Extension\StatusTrait;
use Lc\SovBundle\Doctrine\Pattern\AbstractLightEntity;
@@ -26,7 +28,7 @@ use Lc\SovBundle\Model\User\UserInterface;
*/
abstract class ReductionCartModel extends AbstractLightEntity implements ReductionPropertyInterface, ReductionInterface,
ReductionCartPropertyInterface,
FilterMerchantInterface,
FilterSectionInterface,
OrderAmountMinInterface, StatusInterface
{

@@ -47,11 +49,12 @@ abstract class ReductionCartModel extends AbstractLightEntity implements Reducti
*/
protected $title;


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

/**
* @ORM\Column(type="array", nullable=true)
@@ -148,14 +151,14 @@ abstract class ReductionCartModel extends AbstractLightEntity implements Reducti
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;
}

+ 13
- 11
Model/Reduction/ReductionCatalogModel.php Ver fichero

@@ -5,13 +5,14 @@ namespace Lc\CaracoleBundle\Model\Reduction;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
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\ReductionTrait;
use Lc\CaracoleBundle\Doctrine\Extension\ReductionPropertyInterface;
use Lc\CaracoleBundle\Model\Merchant\MerchantInterface;
use Lc\CaracoleBundle\Model\Product\ProductCategoryInterface;
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\StatusTrait;
use Lc\SovBundle\Doctrine\Pattern\AbstractLightEntity;
@@ -21,7 +22,7 @@ use Lc\SovBundle\Doctrine\Pattern\AbstractLightEntity;
*/
abstract class ReductionCatalogModel extends AbstractLightEntity implements ReductionCatalogInterface,
ReductionPropertyInterface,
FilterMerchantInterface, StatusInterface
FilterSectionInterface, StatusInterface
{
use StatusTrait;
use ReductionTrait;
@@ -34,11 +35,12 @@ abstract class ReductionCatalogModel extends AbstractLightEntity implements Redu
*/
protected $title;


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

/**
* @ORM\ManyToMany(targetEntity="Lc\CaracoleBundle\Model\Product\ProductFamilyInterface")
@@ -76,14 +78,14 @@ abstract class ReductionCatalogModel extends AbstractLightEntity implements Redu
}


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;
}
@@ -116,12 +118,12 @@ abstract class ReductionCatalogModel extends AbstractLightEntity implements Redu
}


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

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


+ 9
- 8
Model/Reduction/ReductionCreditModel.php Ver fichero

@@ -6,9 +6,11 @@ use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Lc\CaracoleBundle\Doctrine\Extension\FilterMerchantInterface;
use Lc\CaracoleBundle\Doctrine\Extension\FilterSectionInterface;
use Lc\CaracoleBundle\Doctrine\Extension\ReductionInterface;
use Lc\CaracoleBundle\Doctrine\Extension\ReductionTrait;
use Lc\CaracoleBundle\Model\Merchant\MerchantInterface;
use Lc\CaracoleBundle\Model\Section\SectionInterface;
use Lc\SovBundle\Doctrine\Extension\StatusInterface;
use Lc\SovBundle\Doctrine\Extension\StatusTrait;
use Lc\SovBundle\Doctrine\Pattern\AbstractLightEntity;
@@ -17,7 +19,7 @@ use Lc\SovBundle\Model\User\UserInterface;
/**
* @ORM\MappedSuperclass()
*/
abstract class ReductionCreditModel extends AbstractLightEntity implements ReductionInterface, FilterMerchantInterface,
abstract class ReductionCreditModel extends AbstractLightEntity implements ReductionInterface, FilterSectionInterface,
StatusInterface
{
const TYPE_CREDIT = 'credit';
@@ -38,12 +40,11 @@ abstract class ReductionCreditModel extends AbstractLightEntity implements Reduc
*/
protected $users;


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

/**
* @ORM\Column(type="string", length=255)
@@ -84,14 +85,14 @@ abstract class ReductionCreditModel extends AbstractLightEntity implements Reduc
}


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

Cargando…
Cancelar
Guardar