Ver código fonte

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

packProduct
Fab 3 anos atrás
pai
commit
067a0629b0
7 arquivos alterados com 55 adições e 63 exclusões
  1. +9
    -3
      Factory/Product/ProductFamilyFactory.php
  2. +2
    -21
      Repository/MerchantRepositoryQueryTrait.php
  3. +17
    -0
      Repository/MerchantStoreTrait.php
  4. +4
    -3
      Repository/Product/ProductCategoryStore.php
  5. +4
    -16
      Repository/Reminder/ReminderStore.php
  6. +2
    -20
      Repository/SectionRepositoryQueryTrait.php
  7. +17
    -0
      Repository/SectionStoreTrait.php

+ 9
- 3
Factory/Product/ProductFamilyFactory.php Ver arquivo

@@ -3,6 +3,7 @@
namespace Lc\CaracoleBundle\Factory\Product;

use App\Entity\Product\ProductFamily;
use Lc\CaracoleBundle\Factory\SectionFactoryTrait;
use Lc\CaracoleBundle\Model\Merchant\MerchantInterface;
use Lc\CaracoleBundle\Model\Product\ProductFamilyInterface;
use Lc\CaracoleBundle\Model\Section\SectionInterface;
@@ -11,12 +12,17 @@ use Lc\SovBundle\Factory\AbstractFactory;
class ProductFamilyFactory extends AbstractFactory
{

public function create(MerchantInterface $merchant, SectionInterface $section): ProductFamilyInterface
use SectionFactoryTrait;

public function create(SectionInterface $section = null): ProductFamilyInterface
{
$productFamily = new ProductFamily();

$productFamily->setMerchant($merchant);
$productFamily->setSection($section);
if(is_null($section)) {
$productFamily->setSection($this->section);
}else{
$productFamily->setSection($section);
}

return $productFamily;
}

+ 2
- 21
Repository/MerchantRepositoryQueryTrait.php Ver arquivo

@@ -7,27 +7,8 @@ use Lc\CaracoleBundle\Model\Section\SectionInterface;

trait MerchantRepositoryQueryTrait
{
protected MerchantInterface $merchant;

public function setMerchant(MerchantInterface $merchant)
public function filterByMerchant(MerchantInterface $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);

}
return $this->andWhere('.merchant = :merchant')->setParameter(':merchant', $merchant);
}
}

+ 17
- 0
Repository/MerchantStoreTrait.php Ver arquivo

@@ -0,0 +1,17 @@
<?php

namespace Lc\CaracoleBundle\Repository;

use Lc\CaracoleBundle\Model\Merchant\MerchantInterface;

trait MerchantStoreTrait
{
protected MerchantInterface $merchant;

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

return $this;
}
}

+ 4
- 3
Repository/Product/ProductCategoryStore.php Ver arquivo

@@ -2,10 +2,13 @@

namespace Lc\CaracoleBundle\Repository\Product;

use Lc\CaracoleBundle\Repository\SectionStoreTrait;
use Lc\SovBundle\Repository\AbstractStore;

class ProductCategoryStore extends AbstractStore
{
use SectionStoreTrait;

protected ProductCategoryRepositoryQuery $query;

public function __construct(ProductCategoryRepositoryQuery $query)
@@ -16,12 +19,10 @@ class ProductCategoryStore extends AbstractStore
public function getParents(){

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

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

+ 4
- 16
Repository/Reminder/ReminderStore.php Ver arquivo

@@ -4,26 +4,14 @@ namespace Lc\CaracoleBundle\Repository\Reminder;

use Lc\CaracoleBundle\Model\Merchant\MerchantInterface;
use Lc\CaracoleBundle\Model\Section\SectionInterface;
use Lc\CaracoleBundle\Repository\MerchantStoreTrait;
use Lc\CaracoleBundle\Repository\SectionStoreTrait;
use Lc\SovBundle\Repository\Reminder\ReminderStore as SovReminderStore;

class ReminderStore extends SovReminderStore
{
protected MerchantInterface $merchant;
protected SectionInterface $section;

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

return $this;
}

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

return $this;
}
use SectionStoreTrait;
use MerchantStoreTrait;

public function get($params = [], $query = null)
{

+ 2
- 20
Repository/SectionRepositoryQueryTrait.php Ver arquivo

@@ -6,26 +6,8 @@ use Lc\CaracoleBundle\Model\Section\SectionInterface;

trait SectionRepositoryQueryTrait
{
protected SectionInterface $section;

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

return $this;
}

public function filterBySection(SectionInterface $section = null)
public function filterBySection(SectionInterface $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);
}
$this->andWhere('.section = :section')->setParameter(':section', $section);
}
}

+ 17
- 0
Repository/SectionStoreTrait.php Ver arquivo

@@ -0,0 +1,17 @@
<?php

namespace Lc\CaracoleBundle\Repository;

use Lc\CaracoleBundle\Model\Section\SectionInterface;

trait SectionStoreTrait
{
protected SectionInterface $section;

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

return $this;
}
}

Carregando…
Cancelar
Salvar