Пример #1
0
 /**
  * @param string $entityType
  * @param array $data
  * @return array
  * @throws \Exception
  * @SuppressWarnings(PHPMD.CyclomaticComplexity)
  * @SuppressWarnings(PHPMD.NPathComplexity)
  */
 public function execute($entityType, $data)
 {
     /** @var \Magento\Eav\Model\Entity\Attribute\AbstractAttribute $attribute */
     $metadata = $this->metadataPool->getMetadata($entityType);
     if ($metadata->getEavEntityType()) {
         $context = $this->getActionContext($entityType, $data);
         $snapshot = $this->readSnapshot->execute($entityType, $data);
         $processed = [];
         foreach ($this->getAttributes($entityType) as $attribute) {
             if ($attribute->isStatic()) {
                 continue;
             }
             if (isset($snapshot[$attribute->getAttributeCode()]) && $snapshot[$attribute->getAttributeCode()] !== false && (array_key_exists($attribute->getAttributeCode(), $data) && $attribute->isValueEmpty($data[$attribute->getAttributeCode()]))) {
                 $this->attributePersistor->registerDelete($entityType, $data[$metadata->getLinkField()], $attribute->getAttributeCode());
             }
             if ((!array_key_exists($attribute->getAttributeCode(), $snapshot) || $snapshot[$attribute->getAttributeCode()] === false) && !empty($data[$attribute->getAttributeCode()]) && !$attribute->isValueEmpty($data[$attribute->getAttributeCode()])) {
                 $this->attributePersistor->registerInsert($entityType, $data[$metadata->getLinkField()], $attribute->getAttributeCode(), $data[$attribute->getAttributeCode()]);
                 $processed[$attribute->getAttributeCode()] = $data[$attribute->getAttributeCode()];
             }
             if (array_key_exists($attribute->getAttributeCode(), $snapshot) && $snapshot[$attribute->getAttributeCode()] !== false && !empty($data[$attribute->getAttributeCode()]) && $snapshot[$attribute->getAttributeCode()] != $data[$attribute->getAttributeCode()] && !$attribute->isValueEmpty($data[$attribute->getAttributeCode()])) {
                 $this->attributePersistor->registerUpdate($entityType, $data[$metadata->getLinkField()], $attribute->getAttributeCode(), $data[$attribute->getAttributeCode()]);
                 $processed[$attribute->getAttributeCode()] = $data[$attribute->getAttributeCode()];
             }
         }
         $this->attributePersistor->flush($entityType, $context);
     }
     return $data;
 }
 /**
  * @param string $entityType
  * @param array $data
  * @return array
  * @throws \Exception
  */
 public function execute($entityType, $data)
 {
     /** @var \Magento\Eav\Model\Entity\Attribute\AbstractAttribute $attribute */
     $metadata = $this->metadataPool->getMetadata($entityType);
     if ($metadata->getEavEntityType()) {
         $context = $this->getActionContext($entityType, $data);
         $processed = [];
         foreach ($this->getAttributes($entityType) as $attribute) {
             if ($attribute->isStatic()) {
                 continue;
             }
             if (isset($data[$attribute->getAttributeCode()]) && !$attribute->isValueEmpty($data[$attribute->getAttributeCode()])) {
                 $this->attributePersistor->registerInsert($entityType, $data[$metadata->getLinkField()], $attribute->getAttributeCode(), $data[$attribute->getAttributeCode()]);
                 $processed[$attribute->getAttributeCode()] = $data[$attribute->getAttributeCode()];
             }
         }
         $this->attributePersistor->flush($entityType, $context);
     }
     return $data;
 }
Пример #3
0
 /**
  * @param string $entityType
  * @param array $entityData
  * @param array $arguments
  * @return array
  * @throws \Exception
  * @throws \Magento\Framework\Exception\ConfigurationMismatchException
  * @SuppressWarnings(PHPMD.UnusedFormalParameter)
  */
 public function execute($entityType, $entityData, $arguments = [])
 {
     $metadata = $this->metadataPool->getMetadata($entityType);
     if ($metadata->getEavEntityType()) {
         $processed = [];
         /** @var \Magento\Eav\Model\Entity\Attribute\AbstractAttribute $attribute */
         foreach ($this->getAttributes($entityType) as $attribute) {
             if ($attribute->isStatic()) {
                 continue;
             }
             if (isset($entityData[$attribute->getAttributeCode()]) && !is_array($entityData[$attribute->getAttributeCode()]) && !$attribute->isValueEmpty($entityData[$attribute->getAttributeCode()])) {
                 $entityLinkField = $metadata->getLinkField();
                 $this->attributePersistor->registerInsert($entityType, $entityData[$entityLinkField], $attribute->getAttributeCode(), $entityData[$attribute->getAttributeCode()]);
                 $processed[$attribute->getAttributeCode()] = $entityData[$attribute->getAttributeCode()];
             }
         }
         $context = $this->scopeResolver->getEntityContext($entityType, $entityData);
         $this->attributePersistor->flush($entityType, $context);
     }
     return $entityData;
 }
Пример #4
0
 /**
  * @param string $entityType
  * @param array $entityData
  * @param array $arguments
  * @return array
  * @throws \Exception
  * @throws \Magento\Framework\Exception\ConfigurationMismatchException
  * @SuppressWarnings(PHPMD.CyclomaticComplexity)
  * @SuppressWarnings(PHPMD.NPathComplexity)
  * @SuppressWarnings(PHPMD.UnusedFormalParameter)
  */
 public function execute($entityType, $entityData, $arguments = [])
 {
     /** @var \Magento\Eav\Model\Entity\Attribute\AbstractAttribute $attribute */
     $metadata = $this->metadataPool->getMetadata($entityType);
     if ($metadata->getEavEntityType()) {
         $context = $this->scopeResolver->getEntityContext($entityType, $entityData);
         $entityDataForSnapshot = [$metadata->getLinkField() => $entityData[$metadata->getLinkField()]];
         foreach ($context as $scope) {
             if (isset($entityData[$scope->getIdentifier()])) {
                 $entityDataForSnapshot[$scope->getIdentifier()] = $entityData[$scope->getIdentifier()];
             }
         }
         $snapshot = $this->readSnapshot->execute($entityType, $entityDataForSnapshot);
         foreach ($this->getAttributes($entityType) as $attribute) {
             if ($attribute->isStatic()) {
                 continue;
             }
             /**
              * Only scalar values can be stored in generic tables
              */
             if (isset($entityData[$attribute->getAttributeCode()]) && !is_scalar($entityData[$attribute->getAttributeCode()])) {
                 continue;
             }
             if (isset($snapshot[$attribute->getAttributeCode()]) && $snapshot[$attribute->getAttributeCode()] !== false && (array_key_exists($attribute->getAttributeCode(), $entityData) && $attribute->isValueEmpty($entityData[$attribute->getAttributeCode()]))) {
                 $this->attributePersistor->registerDelete($entityType, $entityData[$metadata->getLinkField()], $attribute->getAttributeCode());
             }
             if ((!array_key_exists($attribute->getAttributeCode(), $snapshot) || $snapshot[$attribute->getAttributeCode()] === false) && array_key_exists($attribute->getAttributeCode(), $entityData) && !$attribute->isValueEmpty($entityData[$attribute->getAttributeCode()])) {
                 $this->attributePersistor->registerInsert($entityType, $entityData[$metadata->getLinkField()], $attribute->getAttributeCode(), $entityData[$attribute->getAttributeCode()]);
             }
             if (array_key_exists($attribute->getAttributeCode(), $snapshot) && $snapshot[$attribute->getAttributeCode()] !== false && array_key_exists($attribute->getAttributeCode(), $entityData) && $snapshot[$attribute->getAttributeCode()] != $entityData[$attribute->getAttributeCode()] && !$attribute->isValueEmpty($entityData[$attribute->getAttributeCode()])) {
                 $this->attributePersistor->registerUpdate($entityType, $entityData[$metadata->getLinkField()], $attribute->getAttributeCode(), $entityData[$attribute->getAttributeCode()]);
             }
         }
         $this->attributePersistor->flush($entityType, $context);
     }
     return $this->getReadHandler()->execute($entityType, $entityData, $arguments);
 }