本文整理汇总了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;
}
示例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;
}
示例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;
}
示例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;
}
示例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);
}
示例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'));
}
示例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'));
}
}
示例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;
}
示例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);
}
示例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);
}