Browse Source

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

packProduct
Fab 3 years ago
parent
commit
067a0629b0
7 changed files with 55 additions and 63 deletions
  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 View File

namespace Lc\CaracoleBundle\Factory\Product; namespace Lc\CaracoleBundle\Factory\Product;


use App\Entity\Product\ProductFamily; use App\Entity\Product\ProductFamily;
use Lc\CaracoleBundle\Factory\SectionFactoryTrait;
use Lc\CaracoleBundle\Model\Merchant\MerchantInterface; use Lc\CaracoleBundle\Model\Merchant\MerchantInterface;
use Lc\CaracoleBundle\Model\Product\ProductFamilyInterface; use Lc\CaracoleBundle\Model\Product\ProductFamilyInterface;
use Lc\CaracoleBundle\Model\Section\SectionInterface; use Lc\CaracoleBundle\Model\Section\SectionInterface;
class ProductFamilyFactory extends 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 = new ProductFamily();


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


return $productFamily; return $productFamily;
} }

+ 2
- 21
Repository/MerchantRepositoryQueryTrait.php View File



trait MerchantRepositoryQueryTrait 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 View File

<?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 View File



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


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


class ProductCategoryStore extends AbstractStore class ProductCategoryStore extends AbstractStore
{ {
use SectionStoreTrait;

protected ProductCategoryRepositoryQuery $query; protected ProductCategoryRepositoryQuery $query;


public function __construct(ProductCategoryRepositoryQuery $query) public function __construct(ProductCategoryRepositoryQuery $query)
public function getParents(){ public function getParents(){


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

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

+ 4
- 16
Repository/Reminder/ReminderStore.php View File



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


class ReminderStore extends 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) public function get($params = [], $query = null)
{ {

+ 2
- 20
Repository/SectionRepositoryQueryTrait.php View File



trait SectionRepositoryQueryTrait 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 View File

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

Loading…
Cancel
Save