25 private $attributeRepository;
30 private $metadataPool;
35 private $searchCriteriaBuilder;
40 private $attributePersistor;
45 private $readSnapshot;
50 private $scopeResolver;
60 private $attributeLoader;
82 $this->metadataPool = $metadataPool;
84 $this->attributePersistor = $attributePersistor;
85 $this->readSnapshot = $readSnapshot;
86 $this->scopeResolver = $scopeResolver;
114 $metadata = $this->metadataPool->getMetadata(
$entityType);
115 if ($metadata->getEavEntityType()) {
116 $context = $this->scopeResolver->getEntityContext(
$entityType, $entityData);
117 $entityDataForSnapshot = [$metadata->getLinkField() => $entityData[$metadata->getLinkField()]];
118 foreach ($context as $scope) {
119 if (isset($entityData[$scope->getIdentifier()])) {
120 $entityDataForSnapshot[$scope->getIdentifier()] = $entityData[$scope->getIdentifier()];
126 if (!isset($entityDataForSnapshot[
'attribute_set_id'])) {
129 $snapshot = $this->readSnapshot->execute(
$entityType, $entityDataForSnapshot);
132 $isAllowedValueType = array_key_exists(
$code, $entityData)
133 && (is_scalar($entityData[
$code]) || $entityData[
$code] ===
null);
135 if (
$attribute->isStatic() || !$isAllowedValueType) {
139 $newValue = $entityData[
$code];
140 $isValueEmpty =
$attribute->isValueEmpty($newValue);
141 $isAllowedEmptyStringValue =
$attribute->isAllowedEmptyTextValue($newValue);
143 if (array_key_exists(
$code, $snapshot)) {
144 $snapshotValue = $snapshot[
$code];
148 if ($snapshotValue ===
false) {
152 if (!$isValueEmpty || $isAllowedEmptyStringValue) {
156 if ($snapshotValue === $newValue) {
160 $this->attributePersistor->registerUpdate(
162 $entityData[$metadata->getLinkField()],
167 $this->attributePersistor->registerDelete(
169 $entityData[$metadata->getLinkField()],
177 if (!$isValueEmpty || $isAllowedEmptyStringValue) {
178 $this->attributePersistor->registerInsert(
180 $entityData[$metadata->getLinkField()],
187 $this->attributePersistor->flush(
$entityType, $context);
202 if (!$this->readHandler) {
206 return $this->readHandler;
execute($entityType, $entityData, $arguments=[])
__construct(AttributeRepository $attributeRepository, MetadataPool $metadataPool, SearchCriteriaBuilder $searchCriteriaBuilder, AttributePersistor $attributePersistor, ReadSnapshot $readSnapshot, ScopeResolver $scopeResolver, AttributeLoader $attributeLoader=null)
getAttributes($entityType, $attributeSetId=null)