This commit is contained in:
2026-09-15 10:26:34 +08:00
commit ecf36afa56
10493 changed files with 1404888 additions and 0 deletions
@@ -0,0 +1,42 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\TestModuleDefaultHydrator\Model\Address;
use Magento\Framework\EntityManager\MapperInterface;
/**
* Class Mapper
*/
class Mapper implements MapperInterface
{
/**
* {@inheritdoc}
*/
public function entityToDatabase($entityType, $data)
{
$data['street'] = implode("\n", $data['street']);
$data['region_id'] = $data['region']['region_id'];
$data['region_code'] = $data['region']['region_code'];
$data['region'] = $data['region']['region'];
return $data;
}
/**
* {@inheritdoc}
*/
public function databaseToEntity($entityType, $data)
{
$data['street'] = explode("\n", $data['street']);
$region = [
'region' => $data['region'],
'region_code' => $data['region_code'],
'region_id' => $data['region_id']
];
$data['region'] = $region;
unset($data['region_id'], $data['region_code']);
return $data;
}
}
@@ -0,0 +1,73 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\TestModuleDefaultHydrator\Model;
use Magento\TestModuleDefaultHydrator\Api\CustomerPersistenceInterface;
use Magento\Framework\EntityManager\EntityManager;
use Magento\Customer\Api\Data\CustomerInterfaceFactory;
class CustomerPersistence implements CustomerPersistenceInterface
{
/**
* @var EntityManager
*/
private $entityManager;
/**
* @var CustomerInterfaceFactory
*/
private $customerDataFactory;
public function __construct(
EntityManager $entityManager,
CustomerInterfaceFactory $customerDataFactory
) {
$this->entityManager = $entityManager;
$this->customerDataFactory = $customerDataFactory;
}
/**
* {@inheritdoc}
*/
public function save(\Magento\Customer\Api\Data\CustomerInterface $customer)
{
return $this->entityManager->save($customer);
}
/**
* {@inheritdoc}
*/
public function get($email, $websiteId = null)
{
}
/**
* {@inheritdoc}
*/
public function getById($id, $websiteId = null)
{
/** @var \Magento\Customer\Api\Data\CustomerInterface $customer */
$customer = $this->customerDataFactory->create();
$entity = $this->entityManager->load($customer, $id);
return $entity;
}
/**
* {@inheritdoc}
*/
public function delete($id)
{
/** @var \Magento\Customer\Api\Data\CustomerInterface $customer */
$customer = $this->customerDataFactory->create();
$customer = $this->entityManager->load($customer, $id);
try {
$this->entityManager->delete($customer);
} catch (\Exception $e) {
return false;
}
return true;
}
}
@@ -0,0 +1,73 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\TestModuleDefaultHydrator\Model\Data;
class ExtensionAttribute extends \Magento\Framework\Api\AbstractSimpleObject implements
\Magento\TestModuleDefaultHydrator\Api\Data\ExtensionAttributeInterface
{
/**
* Get id
*
* @return int|null
*/
public function getId()
{
return $this->_get(self::ID);
}
/**
* Get customer id
*
* @return string
*/
public function getCustomerId()
{
return $this->_get(self::CUSTOMER_ID);
}
/**
* Get value
*
* @return string
*/
public function getValue()
{
return $this->_get(self::VALUE);
}
/**
* Set id
*
* @param int $id
* @return $this
*/
public function setId($id)
{
return $this->setData(self::ID, $id);
}
/**
* Set customer id
*
* @param int $customerId
* @return $this
*/
public function setCustomerId($customerId)
{
return $this->setData(self::CUSTOMER_ID, $customerId);
}
/**
* Set value
*
* @param int $value
* @return $this
*/
public function setValue($value)
{
return $this->setData(self::VALUE, $value);
}
}
@@ -0,0 +1,52 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\TestModuleDefaultHydrator\Model\ResourceModel\Address;
use Magento\Framework\EntityManager\Operation\ExtensionInterface;
use Magento\Customer\Api\AddressRepositoryInterface;
use Magento\Framework\Api\SearchCriteriaBuilder;
use Magento\Customer\Api\Data\CustomerInterface;
use Magento\Framework\EntityManager\EntityManager;
class ReadHandler implements ExtensionInterface
{
/**
* @var EntityManager
*/
private $addressRepository;
/**
* @var SearchCriteriaBuilder
*/
private $searchCriteriaBuilder;
/**
* @param AddressRepositoryInterface $addressRepositoryInterface
* @param SearchCriteriaBuilder $SearchCriteriaBuilder
*/
public function __construct(
\Magento\Customer\Api\AddressRepositoryInterface $addressRepository,
\Magento\Framework\Api\SearchCriteriaBuilder $searchCriteriaBuilder
) {
$this->addressRepository = $addressRepository;
$this->searchCriteriaBuilder = $searchCriteriaBuilder;
}
/**
* @param CustomerInterface $entity
* @return CustomerInterface
* @throws \Exception
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/
public function execute($entity, $arguments = [])
{
$searchCriteria = $this->searchCriteriaBuilder->addFilter('parent_id', $entity->getId())
->create();
$addressesResult = $this->addressRepository->getList($searchCriteria);
$entity->setAddresses($addressesResult->getItems());
return $entity;
}
}
@@ -0,0 +1,46 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\TestModuleDefaultHydrator\Model\ResourceModel\Address;
use Magento\Framework\EntityManager\Operation\ExtensionInterface;
use Magento\Framework\EntityManager\MetadataPool;
use Magento\Framework\EntityManager\EntityManager;
use Magento\Customer\Api\Data\CustomerInterface;
class SaveHandler implements ExtensionInterface
{
/**
* @var EntityManager
*/
private $entityManager;
/**
* @param EntityManager $entityManager
*/
public function __construct(
EntityManager $entityManager
) {
$this->entityManager = $entityManager;
}
/**
* @param CustomerInterface $entity
* @param array $arguments
* @return CustomerInterface
* @throws \Exception
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/
public function execute($entity, $arguments = [])
{
$newAddresses = [];
foreach ($entity->getAddresses() as $address) {
$address->setCustomerId($entity->getId());
$newAddresses[] = $this->entityManager->save($address);
}
$entity->setAddresses($newAddresses);
return $entity;
}
}
@@ -0,0 +1,94 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\TestModuleDefaultHydrator\Model\ResourceModel;
use Magento\Framework\EntityManager\Operation\ExtensionInterface;
use Magento\Framework\EntityManager\MetadataPool;
use Magento\Framework\EntityManager\EntityManager;
use Magento\Framework\App\ResourceConnection;
use Magento\Customer\Api\Data\CustomerInterface;
use Magento\Customer\Api\Data\CustomerExtensionFactory;
use Magento\TestModuleDefaultHydrator\Api\Data\ExtensionAttributeInterface;
use Magento\TestModuleDefaultHydrator\Api\Data\ExtensionAttributeInterfaceFactory as ExtensionAttributeFactory;
class ReadHandler implements ExtensionInterface
{
/**
* @var EntityManager
*/
private $entityManager;
/**
* @var ExtensionAttributeFactory
*/
private $extensionAttributeFactory;
/**
* @var CustomerExtensionFactory
*/
private $customerExtensionFactory;
/**
* @var MetadataPool
*/
private $metadataPool;
/**
* @var ResourceConnection
*/
private $resourceConnection;
/**
* @param EntityManager $entityManager
* @param ExtensionAttributeFactory $extensionAttributeFactory
* @param CustomerExtensionFactory $customerExtensionFactory
* @param MetadataPool $metadataPool
* @param ResourceConnection $resourceConnection
*/
public function __construct(
EntityManager $entityManager,
ExtensionAttributeFactory $extensionAttributeFactory,
CustomerExtensionFactory $customerExtensionFactory,
MetadataPool $metadataPool,
ResourceConnection $resourceConnection
) {
$this->entityManager = $entityManager;
$this->extensionAttributeFactory = $extensionAttributeFactory;
$this->customerExtensionFactory = $customerExtensionFactory;
$this->metadataPool = $metadataPool;
$this->resourceConnection = $resourceConnection;
}
/**
* @param CustomerInterface $entity
* @param array $arguments
* @return CustomerInterface
* @throws \Exception
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/
public function execute($entity, $arguments = [])
{
$metadata = $this->metadataPool->getMetadata(ExtensionAttributeInterface::class);
$connection = $this->resourceConnection->getConnectionByName(
$metadata->getEntityConnectionName()
);
$id = $connection->fetchOne(
$connection->select()
->from($metadata->getEntityTable(), [$metadata->getIdentifierField()])
->where('customer_id = ?', $entity->getId())
->limit(1)
);
$extensionAttribute = $this->extensionAttributeFactory->create();
$extensionAttribute = $this->entityManager->load($extensionAttribute, $id);
$customerExtension = $this->customerExtensionFactory->create(
[
'data' => ['extension_attribute' => $extensionAttribute]
]
);
$entity->setExtensionAttributes($customerExtension);
return $entity;
}
}
@@ -0,0 +1,44 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\TestModuleDefaultHydrator\Model\ResourceModel;
use Magento\Framework\EntityManager\Operation\ExtensionInterface;
use Magento\TestModuleDefaultHydrator\Api\Data\ExtensionAttributeInterface;
use Magento\Customer\Api\Data\CustomerInterface;
use Magento\Framework\EntityManager\EntityManager;
class SaveHandler implements ExtensionInterface
{
/**
* @var EntityManager
*/
private $entityManager;
/**
* @param EntityManager $entityManager
*/
public function __construct(
EntityManager $entityManager
) {
$this->entityManager = $entityManager;
}
/**
* @param CustomerInterface $entity
* @param array $arguments
* @return CustomerInterface
* @throws \Exception
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/
public function execute($entity, $arguments = [])
{
$extensionAttribute = $entity->getExtensionAttributes()->getExtensionAttribute();
$extensionAttribute->setCustomerId($entity->getId());
$extensionAttribute = $this->entityManager->save($extensionAttribute);
$entity->getExtensionAttributes()->setExtensionAttribute($extensionAttribute);
return $entity;
}
}