Skip to content

Commit 0f64bbf

Browse files
committed
fix AddUserAttributeValueHandler
1 parent 571bc4b commit 0f64bbf

1 file changed

Lines changed: 8 additions & 3 deletions

File tree

‎src/User/Command/Handler/AddUserAttributeValueHandler.php‎

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
use MsgPhp\Domain\Factory\EntityAwareFactoryInterface;
88
use MsgPhp\Domain\Message\{DomainMessageBusInterface, MessageDispatchingTrait};
9-
use MsgPhp\Eav\Entity\Attribute;
9+
use MsgPhp\Eav\Entity\{Attribute, AttributeValue};
1010
use MsgPhp\User\Command\AddUserAttributeValueCommand;
1111
use MsgPhp\User\Entity\{User, UserAttributeValue};
1212
use MsgPhp\User\Event\UserAttributeValueAddedEvent;
@@ -30,12 +30,17 @@ public function __construct(EntityAwareFactoryInterface $factory, DomainMessageB
3030

3131
public function __invoke(AddUserAttributeValueCommand $command): void
3232
{
33+
$attributeValueContext = $command->context['attributeValue'] ?? $command->context['attribute_value'] ?? [];
34+
if (!isset($attributeValueContext['id'])) {
35+
$attributeValueContext['id'] = $this->factory->nextIdentifier(AttributeValue::class);
36+
}
37+
3338
$userAttributeValue = $this->factory->create(UserAttributeValue::class, [
3439
'user' => $this->factory->reference(User::class, $this->factory->identify(User::class, $command->userId)),
3540
'attributeValue' => [
36-
'attribute' => $this->factory->reference(Attribute::class, $command->attributeId),
41+
'attribute' => $this->factory->reference(Attribute::class, $this->factory->identify(Attribute::class, $command->attributeId)),
3742
'value' => $command->value,
38-
],
43+
] + $attributeValueContext,
3944
] + $command->context);
4045

4146
$this->repository->save($userAttributeValue);

0 commit comments

Comments
 (0)