@@ -48,4 +48,6 @@ class ProductContainer | |||
return $this->store; | |||
} | |||
} |
@@ -79,13 +79,7 @@ class UpdateProductfamilyEventSubscriber implements EventSubscriberInterface | |||
{ | |||
//Récupère le product origin | |||
$originProducts = $this->em->getRepository(ProductInterface::class) | |||
->findBy( | |||
array( | |||
'productFamily' => $entity->getId(), | |||
'originProduct' => true, | |||
) | |||
); | |||
$originProducts = $this->productContainer->getStore()->getOriginByProductFamily($entity); | |||
if (count($originProducts) > 1) { | |||
throw new \ErrorException('Plusieurs OriginProduct pour un même produit... Contacter fab'); |
@@ -95,6 +95,19 @@ class ProductRepositoryQuery extends AbstractRepositoryQuery | |||
} | |||
public function filterIsOriginProduct():self | |||
{ | |||
$this->andWhere('.originProduct = 1'); | |||
return $this; | |||
} | |||
public function filterByProductFamily(ProductFamilyInterface $productFamily): self | |||
{ | |||
return $this->andWhereEqual('productFamily', $productFamily); | |||
} | |||
public function filterAvailableQuantityNegative() :self | |||
{ | |||
@@ -2,6 +2,7 @@ | |||
namespace Lc\CaracoleBundle\Repository\Product; | |||
use App\Entity\Product\ProductFamily; | |||
use App\Solver\Product\ProductFamilySectionPropertySolver; | |||
use Lc\CaracoleBundle\Repository\MerchantStoreTrait; | |||
use Lc\CaracoleBundle\Repository\SectionStoreTrait; | |||
@@ -77,4 +78,13 @@ class ProductStore extends AbstractStore | |||
} | |||
public function getOriginByProductFamily(ProductFamily $productFamily, ProductRepositoryQuery $query = null): array | |||
{ | |||
$query = $this->createQuery(); | |||
$query->filterByProductFamily($productFamily); | |||
$query->filterIsOriginProduct(); | |||
$query->filterIsOnlineAndOffline(); | |||
return $query->find(); | |||
} | |||
} |