1. app/code/Test/Customers/registration.php
Код: Выделить всё
\Magento\Framework\Component\ComponentRegistrar::register(
\Magento\Framework\Component\ComponentRegistrar::MODULE,
'Test_Customers',
__DIR__
);
Код: Выделить всё
Код: Выделить всё
Код: Выделить всё
Код: Выделить всё
namespace Test\Customers\Api;
/**
* Account interface.
* @api
*/
interface AccountInterface
{
/**
* Check if given email is associated with a customer account in given website.
* @api
* @param string $customerEmail
* @return \Test\Customers\Api\AccountInterface
* @throws \Magento\Framework\Exception\LocalizedException
*/
public function isEmailExist($customerEmail);
}
Код: Выделить всё
namespace Test\Customers\Model;
use Test\Customers\Api\AccountInterface;
use Magento\Customer\Api\CustomerRepositoryInterface;
use Magento\Framework\Exception\NoSuchEntityException;
class Account implements AccountInterface
{
/**
* @var CustomerRepositoryInterface
*/
private $customerRepository;
/** @var \Magento\Framework\Controller\Result\JsonFactory */
protected $resultJsonFactory;
/**
* @param CustomerRepositoryInterface $customerRepository
* @param \Magento\Framework\Controller\Result\JsonFactory $resultJsonFactory
*/
public function __construct(
CustomerRepositoryInterface $customerRepository,
\Magento\Framework\Controller\Result\JsonFactory $resultJsonFactory
)
{
$this->customerRepository = $customerRepository;
$this->resultJsonFactory = $resultJsonFactory;
}
/**
* {@inheritdoc}
*/
public
function isEmailExist($customerEmail)
{
/** @var \Magento\Framework\Controller\Result\JsonFactory */
$result = $this->resultJsonFactory->create();
try {
$this->customerRepository->get($customerEmail);
} catch (NoSuchEntityException $e) {
}
return $result->setData(['success' => true]);
}
}
http://127.0.0.1/PATH_TO_MAGENTO_DIRECTORY/index. php/rest/V1/customers/isEmailExist
Тело POST:
Код: Выделить всё
{
"customerEmail": "sa@example.com"
}
Подробнее здесь: https://stackoverflow.com/questions/422 ... lank-array