Problem adding a client using API v2.x

PeterSGT

New Member
I installed the API using composer.
I can't add the client and I get this message.


EmsApi\Params Object
(
[_data:EmsApi\Params:private] => Array
(
[status] => error
[error] => Customer creation is disabled.
)

[_readOnly:EmsApi\Params:private] =>
)


In file:
/apps/common/models/Customer.php

I found such an entry:
// unsafe
['group_id, parent_id, status, email_details, inactiveAt', 'unsafe', 'on' => 'update-profile, register'],

I modified it by removing the group_id and parent _id, like this:
// unsafe
['status', 'unsafe', 'on' => 'update-profile, register'],


I add the client using code like this (I add it from the same server, but from a different website):
<?php

// require the setup which has registered the autoloader
require_once __DIR__ . '/setup.php';

// CREATE THE ENDPOINT
$endpoint = new EmsApi\Endpoint\Customers();
/*===================================================================================*/

// CREATE CUSTOMER
$response = $endpoint->create([
'customer' => [
'first_name' => 'John',
'last_name' => 'Doe',
'email' => 'john.doe@doe.com',
'password' => '12324pass',
'timezone' => 'Europe/Warsaw',
'birthDate' => '2000-01-01',
'group_id' => '4',
],
// company is optional, unless required from app settings
'company' => [
'name' => 'Company',
'country' => 'Country', // see the countries endpoint for available countries and their zones
'city' => 'City',
'zip_code' => '00000',
'address_1'=> 'Some Address',
],
]);

// DISPLAY RESPONSE
echo '<hr /><pre>';
print_r($response->body);
echo '</pre>';

Is there anything else I can check why I can't add a client, using the API?
 
I found the registration option to enable and it worked, thanks for the hint - super!

But how can I now disable the registration button that appeared on the login page?

I want to add a customer only through the API.
 
I would like to prevent in php from submitting the registration form.

How can I edit this on the script side in php?
 
I would like to prevent in php from submitting the registration form.
Then you will need to handle the submission using javascript. Something like:
1. First register your js file, by creating a file named init-custom.php with the following content:

Code:
<?php

hooks()->addAction('customer_controller_before_action', function (CAction $action)
{
$allowedRoutes = ['guest/register'];
if (in_array(controller()->getRoute(), $allowedRoutes)) {
clientScript()->registerScriptFile(apps()->getBaseUrl('assets/js/custom-registration.js'));
    }
});

2. You need to create the file named custom-registration.js in the web/assets/js folder.
Its content should be something like:

Code:
jQuery(document).ready(function($){
$(document).on('submit', '#yw0', function(){
const $form = $(this);
const customerData = $form.serialize();
$.post([YOUR_PHP_SCRIPT_URL], customerData, function(json){
// HANDLE THE RESPONSE
}, 'json');
 return false;
    });
});
 
Thank you so much for your willingness to help !!!
Unfortunately it does not work, this code,
but I think it can be circumvented if it is on the frontend side. (But I may be thinking wrong...)

I found actions as below, but unfortunately I don't understand how Yii works....
Can someone suggest how to eliminate from the backend the registration button using one of the actions below?



Action Hooks (1 files, 4 hooks)​

Open all Close all


backend/views/settings/customer-registration.php
  • Tag: 'before_view_file_content'
  • Signature:Yii::app()->hooks->doAction('before_view_file_content', $viewCollection = new CAttributeCollection(array(
    'controller' => $this,
    'renderContent' => true,
    )));
  • Line: 23
  • Description: This hook gives a chance to prepend content or to replace the default view content with a custom content. Please note that from inside the action callback you can access all the controller view.

  • Tag: 'before_active_form'
  • Signature:Yii::app()->hooks->doAction('before_active_form', $collection = new CAttributeCollection(array(
    'controller' => $this,
    'renderForm' => true,
    )));
  • Line: 39
  • Description: This hook gives a chance to prepend content before the active form or to replace the default active form entirely.

  • Tag: 'after_active_form'
  • Signature:Yii::app()->hooks->doAction('after_active_form', new CAttributeCollection(array(
    'controller' => $this,
    'renderedForm' => $collection->renderForm,
    )));
  • Line: 339
  • Description: This hook gives a chance to append content after the active form.

  • Tag: 'after_view_file_content'
  • Signature:Yii::app()->hooks->doAction('after_view_file_content', new CAttributeCollection(array(
    'controller' => $this,
    'renderedContent' => $viewCollection->renderContent,
    )));
  • Line: 350
  • Description: This hook gives a chance to append content after the view file default content.
 
Unfortunately, I don't know how to do it with the backend,
so for the moment I blocked the possibility of entering
the registration page
with the help of a .htaccess entry
Maybe someone else will find such a solution useful.

Meanwhile, I'm waiting, maybe someone will suggest how to do it from the backend.

Greetings

# CUSTOMER REGISTRATION REDIRECT
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !.*\.(ico|gif|jpg|jpeg|png|js|css)
RewriteCond %{REQUEST_URI} ^/customer/guest/register
RewriteRule ^customer/guest/register$ https://mailwizz-site/ [L,R=301]
 
Hello,
The registration form is appearing in the customer area only. Only a customer can register. That is why I targeted the customer Guest controller.

Cosmin
 
Back
Top