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; | ||||
} | } |
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); | |||||
} | } | ||||
} | } |
<?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; | |||||
} | |||||
} |
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(); | |||||
} | } | ||||
} | } |
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) | ||||
{ | { |
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); | |||||
} | } | ||||
} | } |
<?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; | |||||
} | |||||
} |