@@ -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; | |||
} |
@@ -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); | |||
} | |||
} |
@@ -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; | |||
} | |||
} |
@@ -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,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) | |||
{ |
@@ -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); | |||
} | |||
} |
@@ -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; | |||
} | |||
} |