This repository has been archived by the owner on Feb 13, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
bugfix(multimedia) - Relation strategy added for attributes added as …
…bindings (#1732)
- Loading branch information
Showing
5 changed files
with
90 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
module/product/src/Domain/Query/ProductWithVariantsQueryInterface.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<?php | ||
|
||
/** | ||
* Copyright © Bold Brand Commerce Sp. z o.o. All rights reserved. | ||
* See LICENSE.txt for license details. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Ergonode\Product\Domain\Query; | ||
|
||
use Ergonode\SharedKernel\Domain\AggregateId; | ||
|
||
interface ProductWithVariantsQueryInterface | ||
{ | ||
/** | ||
* @return array | ||
*/ | ||
public function findProductIdsWithBoundAttributeByAttributeId(AggregateId $id): array; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
...Infrastructure/Strategy/Relationship/ProductWithVariantsAttributeRelationshipStrategy.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
<?php | ||
|
||
/** | ||
* Copyright © Bold Brand Commerce Sp. z o.o. All rights reserved. | ||
* See LICENSE.txt for license details. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Ergonode\Product\Infrastructure\Strategy\Relationship; | ||
|
||
use Ergonode\Core\Infrastructure\Model\RelationshipGroup; | ||
use Ergonode\Core\Infrastructure\Strategy\RelationshipStrategyInterface; | ||
use Ergonode\Product\Domain\Query\ProductWithVariantsQueryInterface; | ||
use Ergonode\SharedKernel\Domain\Aggregate\AttributeId; | ||
use Ergonode\SharedKernel\Domain\AggregateId; | ||
use Webmozart\Assert\Assert; | ||
|
||
class ProductWithVariantsAttributeRelationshipStrategy implements RelationshipStrategyInterface | ||
{ | ||
private const ONE_MESSAGE = 'This attribute is a binding attribute in product.'; | ||
private const MULTIPLE_MESSAGE = 'This attribute is a binding attribute in %count% products.'; | ||
|
||
private ProductWithVariantsQueryInterface $query; | ||
|
||
public function __construct(ProductWithVariantsQueryInterface $query) | ||
{ | ||
$this->query = $query; | ||
} | ||
|
||
public function supports(AggregateId $id): bool | ||
{ | ||
return $id instanceof AttributeId; | ||
} | ||
|
||
public function getRelationshipGroup(AggregateId $id): RelationshipGroup | ||
{ | ||
Assert::isInstanceOf($id, AttributeId::class); | ||
|
||
$relations = $this->query->findProductIdsWithBoundAttributeByAttributeId($id); | ||
$message = count($relations) === 1 ? self::ONE_MESSAGE : self::MULTIPLE_MESSAGE; | ||
|
||
return new RelationshipGroup($message, $relations); | ||
} | ||
} |