当前位置: 首页>>代码示例>>PHP>>正文


PHP MetadataPool::getHydrator方法代码示例

本文整理汇总了PHP中Magento\Framework\Model\Entity\MetadataPool::getHydrator方法的典型用法代码示例。如果您正苦于以下问题:PHP MetadataPool::getHydrator方法的具体用法?PHP MetadataPool::getHydrator怎么用?PHP MetadataPool::getHydrator使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Magento\Framework\Model\Entity\MetadataPool的用法示例。


在下文中一共展示了MetadataPool::getHydrator方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: execute

 /**
  * @param string $entityType
  * @param object $entity
  * @return object
  * @throws CouldNotSaveException
  * @SuppressWarnings(PHPMD.UnusedFormalParameter)
  */
 public function execute($entityType, $entity)
 {
     /**
      * @var $entity \Magento\Catalog\Api\Data\ProductLinkInterface
      */
     $linkedProduct = $this->productRepository->get($entity->getLinkedProductSku());
     $product = $this->productRepository->get($entity->getSku());
     $links = [];
     $extensions = $this->dataObjectProcessor->buildOutputDataArray($entity->getExtensionAttributes(), 'Magento\\Catalog\\Api\\Data\\ProductLinkExtensionInterface');
     $extensions = is_array($extensions) ? $extensions : [];
     $data = $entity->__toArray();
     foreach ($extensions as $attributeCode => $attribute) {
         $data[$attributeCode] = $attribute;
     }
     unset($data['extension_attributes']);
     $data['product_id'] = $linkedProduct->getId();
     $links[$linkedProduct->getId()] = $data;
     try {
         $linkTypesToId = $this->linkTypeProvider->getLinkTypes();
         $prodyctHydrator = $this->metadataPool->getHydrator(ProductInterface::class);
         $productData = $prodyctHydrator->extract($product);
         $this->linkResource->saveProductLinks($productData[$this->metadataPool->getMetadata(ProductInterface::class)->getLinkField()], $links, $linkTypesToId[$entity->getLinkType()]);
     } catch (\Exception $exception) {
         throw new CouldNotSaveException(__('Invalid data provided for linked products'));
     }
     return $entity;
 }
开发者ID:koliaGI,项目名称:magento2,代码行数:34,代码来源:SaveHandler.php

示例2: execute

 /**
  * @param string $entityType
  * @param object $entity
  * @param array $data
  * @return object
  */
 public function execute($entityType, $entity, $data = [])
 {
     $hydrator = $this->metadataPool->getHydrator($entityType);
     $entityData = $this->createEntityRow->execute($entityType, array_merge($hydrator->extract($entity), $data));
     $entity = $hydrator->hydrate($entity, $entityData);
     return $entity;
 }
开发者ID:koliaGI,项目名称:magento2,代码行数:13,代码来源:CreateMain.php

示例3: execute

 /**
  * @param string $entityType
  * @param object $entity
  * @param array $data
  * @return object
  * @throws \Exception
  */
 public function execute($entityType, $entity, $data = [])
 {
     $hydrator = $this->metadataPool->getHydrator($entityType);
     $entityData = array_merge($hydrator->extract($entity), $data);
     $actions = $this->extensionPool->getActions($entityType, 'create');
     foreach ($actions as $action) {
         $entityData = $action->execute($entityType, $entityData);
     }
     $entity = $hydrator->hydrate($entity, $entityData);
     return $entity;
 }
开发者ID:koliaGI,项目名称:magento2,代码行数:18,代码来源:CreateExtension.php

示例4: execute

 /**
  * @param string $entityType
  * @param object $entity
  * @return object
  * @throws \Exception
  */
 public function execute($entityType, $entity)
 {
     $hydrator = $this->metadataPool->getHydrator($entityType);
     $entityData = $hydrator->extract($entity);
     $actions = $this->extensionPool->getActions($entityType, 'read');
     foreach ($actions as $action) {
         $data = $action->execute($entityType, $entityData);
         $entity = $hydrator->hydrate($entity, $data);
     }
     return $entity;
 }
开发者ID:koliaGI,项目名称:magento2,代码行数:17,代码来源:ReadExtension.php

示例5: save

 /**
  * @param string $entityType
  * @param object $entity
  * @return bool|object
  * @throws \Exception
  */
 public function save($entityType, $entity)
 {
     $hydrator = $this->metadataPool->getHydrator($entityType);
     $metadata = $this->metadataPool->getMetadata($entityType);
     $entityData = $hydrator->extract($entity);
     if (!empty($entityData[$metadata->getIdentifierField()]) && $metadata->checkIsEntityExists($entityData[$metadata->getIdentifierField()])) {
         $operation = $this->orchestratorPool->getWriteOperation($entityType, 'update');
     } else {
         $operation = $this->orchestratorPool->getWriteOperation($entityType, 'create');
     }
     return $operation->execute($entityType, $entity);
 }
开发者ID:koliaGI,项目名称:magento2,代码行数:18,代码来源:EntityManager.php

示例6: testHydrator

 public function testHydrator()
 {
     $metadataPool = new MetadataPool($this->entityMetadataFactoryMock, $this->entityHydratorFactoryMock, []);
     $entityHydrator = $this->getMockBuilder(EntityHydrator::class)->disableOriginalConstructor()->getMock();
     $this->entityHydratorFactoryMock->expects($this->once())->method('create')->willReturn($entityHydrator);
     $this->assertEquals($entityHydrator, $metadataPool->getHydrator('testType'));
 }
开发者ID:hientruong90,项目名称:magento2_installer,代码行数:7,代码来源:MetadataPoolTest.php

示例7: execute

 /**
  * @param string $entityType
  * @param object $entity
  * @return object
  * @throws CouldNotDeleteException
  * @throws NoSuchEntityException
  * @SuppressWarnings(PHPMD.UnusedFormalParameter)
  */
 public function execute($entityType, $entity)
 {
     $linkedProduct = $this->productRepository->get($entity->getLinkedProductSku());
     $product = $this->productRepository->get($entity->getSku());
     $linkTypesToId = $this->linkTypeProvider->getLinkTypes();
     $prodyctHydrator = $this->metadataPool->getHydrator(ProductInterface::class);
     $productData = $prodyctHydrator->extract($product);
     $linkId = $this->linkResource->getProductLinkId($productData[$this->metadataPool->getMetadata(ProductInterface::class)->getLinkField()], $linkedProduct->getId(), $linkTypesToId[$entity->getLinkType()]);
     if (!$linkId) {
         throw new NoSuchEntityException(__('Product with SKU %1 is not linked to product with SKU %2', $entity->getLinkedProductSku(), $entity->getSku()));
     }
     try {
         $this->linkResource->deleteProductLink($linkId);
     } catch (\Exception $exception) {
         throw new CouldNotDeleteException(__('Invalid data provided for linked products'));
     }
 }
开发者ID:koliaGI,项目名称:magento2,代码行数:25,代码来源:DeleteHandler.php

示例8: isModified

 /**
  * Check is current entity has changes, by comparing current object state with stored snapshot
  *
  * @param string $entityType
  * @param object $entity
  * @return bool
  */
 public function isModified($entityType, $entity)
 {
     $metadata = $this->metadataPool->getMetadata($entityType);
     $hydrator = $this->metadataPool->getHydrator($entityType);
     $entityData = $hydrator->extract($entity);
     if (empty($entityData[$metadata->getIdentifierField()])) {
         return true;
     }
     $identifier = $entityData[$metadata->getIdentifierField()];
     if (!isset($this->snapshotData[$entityType][$identifier])) {
         return true;
     }
     foreach ($this->snapshotData[$entityType][$identifier] as $field => $value) {
         if (isset($entityData[$field]) && $entityData[$field] != $value) {
             return true;
         }
     }
     return false;
 }
开发者ID:hientruong90,项目名称:magento2_installer,代码行数:26,代码来源:EntitySnapshot.php

示例9: execute

 /**
  * @param string $entityType
  * @param object $entity
  * @return bool
  */
 public function execute($entityType, $entity)
 {
     $hydrator = $this->metadataPool->getHydrator($entityType);
     $entityData = $hydrator->extract($entity);
     return $this->deleteEntityRow->execute($entityType, $entityData);
 }
开发者ID:koliaGI,项目名称:magento2,代码行数:11,代码来源:DeleteMain.php

示例10: execute

 /**
  * @param string $entityType
  * @param object $entity
  * @param string $identifier
  * @return object
  */
 public function execute($entityType, $entity, $identifier)
 {
     $hydrator = $this->metadataPool->getHydrator($entityType);
     $data = $this->readEntityRow->execute($entityType, $identifier);
     return $hydrator->hydrate($entity, $data);
 }
开发者ID:hientruong90,项目名称:magento2_installer,代码行数:12,代码来源:ReadMain.php


注:本文中的Magento\Framework\Model\Entity\MetadataPool::getHydrator方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。