@@ -28,23 +28,23 @@ class ProductDistributionRepository extends AbstractRepository | |||
public function findOneProductDistribution(Distribution $distribution, Product $product): ?ProductDistribution | |||
{ | |||
return ProductDistribution::searchOne([ | |||
'id_distribution' => $distribution->id, | |||
'id_product' => $product->id | |||
]); | |||
return $this->createDefaultQuery() | |||
->filterByDistribution($distribution) | |||
->filterByProduct($product) | |||
->findOne(); | |||
} | |||
public function findProductDistributionsByDistribution(Distribution $distribution): array | |||
{ | |||
return ProductDistribution::searchAll([ | |||
'id_distribution' => $distribution->id | |||
]) ; | |||
return $this->createDefaultQuery() | |||
->filterByDistribution($distribution) | |||
->find(); | |||
} | |||
public function countProductDistributionsByDistribution(Distribution $distribution): int | |||
{ | |||
return ProductDistribution::searchCount([ | |||
'id_distribution' => $distribution->id | |||
]); | |||
return $this->createDefaultQuery() | |||
->filterByDistribution($distribution) | |||
->count(); | |||
} | |||
} |
@@ -3,8 +3,10 @@ | |||
namespace common\logic\Distribution\ProductDistribution\Repository; | |||
use common\logic\AbstractRepositoryQuery; | |||
use common\logic\Distribution\Distribution\Model\Distribution; | |||
use common\logic\Distribution\ProductDistribution\Model\ProductDistribution; | |||
use common\logic\Distribution\ProductDistribution\Service\ProductDistributionDefinition; | |||
use common\logic\Product\Product\Model\Product; | |||
use yii\db\ActiveQuery; | |||
class ProductDistributionRepositoryQuery extends AbstractRepositoryQuery | |||
@@ -15,4 +17,18 @@ class ProductDistributionRepositoryQuery extends AbstractRepositoryQuery | |||
{ | |||
$this->loadDefinition(ProductDistributionDefinition::class); | |||
} | |||
public function filterByDistribution(Distribution $distribution): self | |||
{ | |||
$this->andWhere(['id_distribution' => $distribution->id]); | |||
return $this; | |||
} | |||
public function filterByProduct(Product $product): self | |||
{ | |||
$this->andWhere(['id_product' => $product->id]); | |||
return $this; | |||
} | |||
} |