Browse Source

Refactoring, suppression champ merchant si section existe, adaption des repository et des factory

packProduct
Fab 3 years ago
parent
commit
4a43a75105
16 changed files with 93 additions and 166 deletions
  1. +0
    -2
      Controller/Site/PageAdminController.php
  2. +7
    -5
      Controller/Ticket/TicketAdminController.php
  3. +0
    -2
      Factory/Site/PageFactory.php
  4. +1
    -17
      Model/Newsletter/NewsletterModel.php
  5. +2
    -21
      Model/Order/OrderShopModel.php
  6. +1
    -22
      Model/Product/ProductCategoryModel.php
  7. +19
    -50
      Model/Product/ProductFamilyModel.php
  8. +0
    -12
      Model/Reminder/ReminderModel.php
  9. +4
    -23
      Model/Site/PageModel.php
  10. +22
    -4
      Repository/MerchantRepositoryQueryTrait.php
  11. +0
    -1
      Repository/Order/OrderShopRepositoryQuery.php
  12. +5
    -1
      Repository/Product/ProductCategoryRepositoryQuery.php
  13. +12
    -0
      Repository/Product/ProductCategoryStore.php
  14. +0
    -1
      Repository/Product/ProductFamilyRepositoryQuery.php
  15. +20
    -4
      Repository/SectionRepositoryQueryTrait.php
  16. +0
    -1
      Repository/Site/PageRepositoryQuery.php

+ 0
- 2
Controller/Site/PageAdminController.php View File

public function createEntity(string $entityFqcn) public function createEntity(string $entityFqcn)
{ {
$factory = new PageFactory(); $factory = new PageFactory();
$currentMerchant = $this->get('merchant_resolver')->getCurrent();
$currentSection = $this->get('section_resolver')->getCurrent(); $currentSection = $this->get('section_resolver')->getCurrent();
$factory->setMerchant($currentMerchant);
$factory->setSection($currentSection); $factory->setSection($currentSection);
return $factory->create(); return $factory->create();
} }

+ 7
- 5
Controller/Ticket/TicketAdminController.php View File



namespace Lc\CaracoleBundle\Controller\Ticket; namespace Lc\CaracoleBundle\Controller\Ticket;


use EasyCorp\Bundle\EasyAdminBundle\Config\KeyValueStore;
use Lc\CaracoleBundle\Controller\AdminControllerTrait; use Lc\CaracoleBundle\Controller\AdminControllerTrait;
use Lc\SovBundle\Controller\Ticket\TicketAdminController as SovTicketAdminController; use Lc\SovBundle\Controller\Ticket\TicketAdminController as SovTicketAdminController;
use Lc\CaracoleBundle\Factory\Ticket\TicketFactory;


class TicketAdminController extends SovTicketAdminController class TicketAdminController extends SovTicketAdminController
{ {
use AdminControllerTrait; use AdminControllerTrait;


public function createEntityFromFactory()
public function createEntity(string $entityFqcn)
{ {
return $this->ticketFactory
->setMerchant($this->get('merchant_resolver')->getCurrent())
->create();
$merchantResolver = $this->get('merchant_resolver');
$factory = new TicketFactory();
$factory->setMerchant($merchantResolver->getCurrent());
return $factory->create();
} }

} }

+ 0
- 2
Factory/Site/PageFactory.php View File



class PageFactory extends SovPageFactory class PageFactory extends SovPageFactory
{ {
use MerchantFactoryTrait;
use SectionFactoryTrait; use SectionFactoryTrait;


public function create(): PageInterface public function create(): PageInterface
{ {
$page = parent::create(); $page = parent::create();


$page->setMerchant($this->merchant);
$page->setSection($this->section); $page->setSection($this->section);


return $page; return $page;

+ 1
- 17
Model/Newsletter/NewsletterModel.php View File

/** /**
* @ORM\MappedSuperclass() * @ORM\MappedSuperclass()
*/ */
abstract class NewsletterModel extends SovNewsletterModel implements FilterMerchantInterface, FilterSectionInterface
abstract class NewsletterModel extends SovNewsletterModel implements FilterSectionInterface
{ {
/**
* @ORM\ManyToOne(targetEntity="Lc\CaracoleBundle\Model\Merchant\MerchantInterface", inversedBy="newsletters")
*/
protected $merchant;

/** /**
* @ORM\ManyToOne(targetEntity="Lc\CaracoleBundle\Model\Section\SectionInterface", inversedBy="newsletters") * @ORM\ManyToOne(targetEntity="Lc\CaracoleBundle\Model\Section\SectionInterface", inversedBy="newsletters")
*/ */
protected $section; protected $section;


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

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

return $this;
}


public function getSection(): ?SectionInterface public function getSection(): ?SectionInterface
{ {

+ 2
- 21
Model/Order/OrderShopModel.php View File

use Doctrine\Common\Collections\Collection; use Doctrine\Common\Collections\Collection;
use Gedmo\Mapping\Annotation as Gedmo; use Gedmo\Mapping\Annotation as Gedmo;
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\Model\Address\AddressInterface; use Lc\CaracoleBundle\Model\Address\AddressInterface;
use Lc\CaracoleBundle\Model\Credit\CreditHistoryInterface; use Lc\CaracoleBundle\Model\Credit\CreditHistoryInterface;
use Lc\CaracoleBundle\Model\File\DocumentInterface; use Lc\CaracoleBundle\Model\File\DocumentInterface;
use Lc\CaracoleBundle\Model\File\DocumentModel; use Lc\CaracoleBundle\Model\File\DocumentModel;
use Lc\CaracoleBundle\Model\Merchant\MerchantInterface;
use Lc\CaracoleBundle\Model\Section\SectionInterface; use Lc\CaracoleBundle\Model\Section\SectionInterface;
use Lc\SovBundle\Model\Ticket\TicketInterface; use Lc\SovBundle\Model\Ticket\TicketInterface;
use Lc\CaracoleBundle\Model\User\VisitorInterface; use Lc\CaracoleBundle\Model\User\VisitorInterface;
/** /**
* @ORM\MappedSuperclass() * @ORM\MappedSuperclass()
*/ */
abstract class OrderShopModel extends AbstractLightEntity implements FilterMerchantInterface
abstract class OrderShopModel extends AbstractLightEntity implements FilterSectionInterface
{ {
/**
* @ORM\ManyToOne(targetEntity="Lc\CaracoleBundle\Model\Merchant\MerchantInterface", inversedBy="productFamilies")
* @ORM\JoinColumn(nullable=false)
*/
protected $merchant;

/** /**
* @ORM\ManyToOne(targetEntity="Lc\SovBundle\Model\User\UserInterface", inversedBy="orders", fetch="EAGER") * @ORM\ManyToOne(targetEntity="Lc\SovBundle\Model\User\UserInterface", inversedBy="orders", fetch="EAGER")
*/ */
return null; return null;
} }


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

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

return $this;
}

public function getUser(): ?UserInterface public function getUser(): ?UserInterface
{ {
return $this->user; return $this->user;

+ 1
- 22
Model/Product/ProductCategoryModel.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\FilterSectionInterface;
use Lc\CaracoleBundle\Model\Merchant\MerchantInterface;
use Lc\CaracoleBundle\Model\Section\SectionInterface; use Lc\CaracoleBundle\Model\Section\SectionInterface;
use Lc\SovBundle\Doctrine\Extension\TreeInterface; use Lc\SovBundle\Doctrine\Extension\TreeInterface;
use Lc\SovBundle\Doctrine\Pattern\AbstractFullEntity; use Lc\SovBundle\Doctrine\Pattern\AbstractFullEntity;
/** /**
* @ORM\MappedSuperclass() * @ORM\MappedSuperclass()
*/ */
abstract class ProductCategoryModel extends AbstractFullEntity implements TreeInterface, FilterMerchantInterface, FilterSectionInterface
abstract class ProductCategoryModel extends AbstractFullEntity implements TreeInterface, FilterSectionInterface
{ {


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

/** /**
* @ORM\ManyToOne(targetEntity="Lc\CaracoleBundle\Model\Section\SectionInterface") * @ORM\ManyToOne(targetEntity="Lc\CaracoleBundle\Model\Section\SectionInterface")
* @ORM\JoinColumn(nullable=false) * @ORM\JoinColumn(nullable=false)
return $title; return $title;
} }



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

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

return $this;
}

public function getSection(): SectionInterface public function getSection(): SectionInterface
{ {
return $this->section; return $this->section;

+ 19
- 50
Model/Product/ProductFamilyModel.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\PriceInterface; use Lc\CaracoleBundle\Doctrine\Extension\PriceInterface;
use Lc\CaracoleBundle\Doctrine\Extension\ProductPropertyTrait; use Lc\CaracoleBundle\Doctrine\Extension\ProductPropertyTrait;
use Lc\CaracoleBundle\Doctrine\Extension\ProductPropertyInterface; use Lc\CaracoleBundle\Doctrine\Extension\ProductPropertyInterface;
use Gedmo\Mapping\Annotation as Gedmo; use Gedmo\Mapping\Annotation as Gedmo;
use Lc\CaracoleBundle\Model\Merchant\MerchantInterface;
use Lc\CaracoleBundle\Model\Reduction\ReductionCatalogInterface; use Lc\CaracoleBundle\Model\Reduction\ReductionCatalogInterface;
use Lc\CaracoleBundle\Model\Section\SectionInterface; use Lc\CaracoleBundle\Model\Section\SectionInterface;
use Lc\SovBundle\Doctrine\Pattern\AbstractFullEntity; use Lc\SovBundle\Doctrine\Pattern\AbstractFullEntity;
* @ORM\MappedSuperclass() * @ORM\MappedSuperclass()
*/ */
abstract class ProductFamilyModel extends AbstractFullEntity implements ProductPropertyInterface, PriceInterface, abstract class ProductFamilyModel extends AbstractFullEntity implements ProductPropertyInterface, PriceInterface,
FilterMerchantInterface
FilterSectionInterface
{ {


use ProductPropertyTrait; use ProductPropertyTrait;
*/ */
protected $updatedBy; protected $updatedBy;


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

/** /**
* @ORM\ManyToMany(targetEntity="Lc\CaracoleBundle\Model\Product\ProductCategoryInterface", inversedBy="productFamilies") * @ORM\ManyToMany(targetEntity="Lc\CaracoleBundle\Model\Product\ProductCategoryInterface", inversedBy="productFamilies")
*/ */
*/ */
protected $saleStatus; protected $saleStatus;



/** /**
* @ORM\ManyToMany(targetEntity="Lc\CaracoleBundle\Model\Section\SectionInterface", inversedBy="productFamilies")
* @ORM\ManyToOne(targetEntity="Lc\CaracoleBundle\Model\Section\SectionInterface")
* @ORM\JoinColumn(nullable=false)
*/ */
protected $sections;
protected $section;


public function __construct() public function __construct()
{ {
return $this->getTitle(); return $this->getTitle();
} }


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

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

return $this;
}

public function getAvailableQuantityInherited() public function getAvailableQuantityInherited()
{ {
$availableQuantity = 0; $availableQuantity = 0;
if ($this->getTaxRate()) { if ($this->getTaxRate()) {
return $this->getTaxRate(); return $this->getTaxRate();
} else { } else {
return $this->getMerchant()->getTaxRate();
return $this->getSection()->getMerchant()->getTaxRate();
} }
} }

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

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

return $this;
}

public function getActiveProducts(): ?bool public function getActiveProducts(): ?bool
{ {
return $this->activeProducts; return $this->activeProducts;
return $this; return $this;
} }


/**
* @return Collection|SectionInterface[]
*/
public function getSections(): Collection
{
return $this->sections;
}

public function addSection(SectionInterface $section): self
{
if (!$this->sections->contains($section)) {
$this->sections[] = $section;
}

return $this;
}

public function removeSection(SectionInterface $section): self
{
if ($this->sections->contains($section)) {
$this->sections->removeElement($section);
}

return $this;
}


public function getFieldBuyingPrice() public function getFieldBuyingPrice()
{ {

+ 0
- 12
Model/Reminder/ReminderModel.php View File

*/ */
protected $section; protected $section;


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

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

return $this;
}

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

+ 4
- 23
Model/Site/PageModel.php View File

namespace Lc\CaracoleBundle\Model\Site; namespace Lc\CaracoleBundle\Model\Site;


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\FilterSectionInterface;
use Lc\CaracoleBundle\Model\Merchant\MerchantInterface;
use Lc\CaracoleBundle\Model\Section\SectionInterface; use Lc\CaracoleBundle\Model\Section\SectionInterface;
use Lc\SovBundle\Model\Site\PageModel as SovPageModel; use Lc\SovBundle\Model\Site\PageModel as SovPageModel;


/** /**
* @ORM\MappedSuperclass() * @ORM\MappedSuperclass()
*/ */
abstract class PageModel extends SovPageModel implements FilterMerchantInterface, FilterSectionInterface
abstract class PageModel extends SovPageModel implements FilterSectionInterface
{ {


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

/** /**
* @ORM\ManyToOne(targetEntity="Lc\CaracoleBundle\Model\Section\SectionInterface", inversedBy="pages") * @ORM\ManyToOne(targetEntity="Lc\CaracoleBundle\Model\Section\SectionInterface", inversedBy="pages")
* @ORM\JoinColumn(nullable=false)
*/ */
protected $section; protected $section;




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

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

return $this;
}

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


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



+ 22
- 4
Repository/MerchantRepositoryQueryTrait.php View File

namespace Lc\CaracoleBundle\Repository; namespace Lc\CaracoleBundle\Repository;


use Lc\CaracoleBundle\Model\Merchant\MerchantInterface; use Lc\CaracoleBundle\Model\Merchant\MerchantInterface;
use Lc\CaracoleBundle\Model\Section\SectionInterface;


trait MerchantRepositoryQueryTrait trait MerchantRepositoryQueryTrait
{ {
public function filterByMerchant(MerchantInterface $merchant)
protected MerchantInterface $merchant;

public function setMerchant(MerchantInterface $merchant)
{ {
return $this
->andWhere('.merchant = :merchant')
->setParameter(':merchant', $merchant);
$this->merchant = $merchant;

return $this;
}

public function filterByMerchant(MerchantInterface $merchant = null)
{
$this->andWhere('.merchant = :merchant');

if(is_null($merchant)) {
if(is_null($this->merchant)){
throw new \ErrorException('Aucun merchant défini');
}
return $this->setParameter(':merchant', $this->merchant);
}else{
return $this->setParameter(':merchant', $merchant);

}
} }
} }

+ 0
- 1
Repository/Order/OrderShopRepositoryQuery.php View File



class OrderShopRepositoryQuery extends AbstractRepositoryQuery class OrderShopRepositoryQuery extends AbstractRepositoryQuery
{ {
use MerchantRepositoryQueryTrait;
use SectionRepositoryQueryTrait; use SectionRepositoryQueryTrait;


public function __construct(OrderShopRepository $repository, PaginatorInterface $paginator) public function __construct(OrderShopRepository $repository, PaginatorInterface $paginator)

+ 5
- 1
Repository/Product/ProductCategoryRepositoryQuery.php View File



class ProductCategoryRepositoryQuery extends AbstractRepositoryQuery class ProductCategoryRepositoryQuery extends AbstractRepositoryQuery
{ {
use MerchantRepositoryQueryTrait;
use SectionRepositoryQueryTrait; use SectionRepositoryQueryTrait;


public function __construct(ProductCategoryRepository $repository, PaginatorInterface $paginator) public function __construct(ProductCategoryRepository $repository, PaginatorInterface $paginator)
{ {
parent::__construct($repository, 'r', $paginator); parent::__construct($repository, 'r', $paginator);
} }

public function filterIsParent(){
return $this->andWhere('.parent is NULL');

}
} }

+ 12
- 0
Repository/Product/ProductCategoryStore.php View File

{ {
$this->query = $query; $this->query = $query;
} }

public function getParents(){

$query = $this->query->create();
$query->filterByMerchant();

if($this->section) {
$query->filterBySection($this->section);
}
$query->filterIsParent();

}
} }

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



class ProductFamilyRepositoryQuery extends AbstractRepositoryQuery class ProductFamilyRepositoryQuery extends AbstractRepositoryQuery
{ {
use MerchantRepositoryQueryTrait;
use SectionRepositoryQueryTrait; use SectionRepositoryQueryTrait;


public function __construct(ProductFamilyRepository $repository, PaginatorInterface $paginator) public function __construct(ProductFamilyRepository $repository, PaginatorInterface $paginator)

+ 20
- 4
Repository/SectionRepositoryQueryTrait.php View File



trait SectionRepositoryQueryTrait trait SectionRepositoryQueryTrait
{ {
public function filterBySection(SectionInterface $section)
protected SectionInterface $section;

public function setSection(SectionInterface $section)
{
$this->section = $section;

return $this;
}

public function filterBySection(SectionInterface $section = null)
{ {
return $this
->andWhere('.section = :section')
->setParameter(':section', $section);
$this->andWhere('.section = :section');

if(is_null($section)) {
if(is_null($this->section)){
throw new \ErrorException('Aucun merchant défini');
}
return $this->setParameter(':section', $this->section);
}else{
return $this->setParameter(':section', $section);
}
} }
} }

+ 0
- 1
Repository/Site/PageRepositoryQuery.php View File



class PageRepositoryQuery extends SovPageRepositoryQuery class PageRepositoryQuery extends SovPageRepositoryQuery
{ {
use MerchantRepositoryQueryTrait;
use SectionRepositoryQueryTrait; use SectionRepositoryQueryTrait;


} }

Loading…
Cancel
Save