Пользовательский модуль Magento 2 и веб-сервис возвращают пустой массивPhp

Кемеровские программисты php общаются здесь
Ответить
Anonymous
 Пользовательский модуль Magento 2 и веб-сервис возвращают пустой массив

Сообщение Anonymous »

Я новичок в Magento 2x. Однако я попытался создать собственный модуль и веб-сервис для проверки существования электронной почты клиента. Но в результате я получаю просто пустой массив. Вот что я сделал на данный момент:

1. app/code/Test/Customers/registration.php

Код: Выделить всё

\Magento\Framework\Component\ComponentRegistrar::register(
\Magento\Framework\Component\ComponentRegistrar::MODULE,
'Test_Customers',
__DIR__
);
2. app/code/Test/Customers/etc/module.xml
3. app/code/Test/Customers/etc/di.xml
4. app/code/Test/Customers/etc/webapi.xml
5. app/code/Test/Customers/Api/AccountInterface.php

Код: Выделить всё

    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);
}
6. app/code/Test/Customers/Model/Account.php

Код: Выделить всё

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]);

}
}
Я попробовал запрос POST от клиента REST

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
Ответить

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

Вернуться в «Php»