display all customers using console command magento2.2.3
up vote
2
down vote
favorite
How to display registered customers in terminal using custom console command?Can anyone please help me out.
magento2.2.3
add a comment |
up vote
2
down vote
favorite
How to display registered customers in terminal using custom console command?Can anyone please help me out.
magento2.2.3
add a comment |
up vote
2
down vote
favorite
up vote
2
down vote
favorite
How to display registered customers in terminal using custom console command?Can anyone please help me out.
magento2.2.3
How to display registered customers in terminal using custom console command?Can anyone please help me out.
magento2.2.3
magento2.2.3
asked 2 hours ago
Vishali Mariappan
10411
10411
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
up vote
4
down vote
accepted
First, you need to create di.xml
in your customer module(I am assuming that you already know how to create a module)
app/code/VENDOR/MODULE/etc/di.xml
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<type name="MagentoFrameworkConsoleCommandList">
<arguments>
<argument name="commands" xsi:type="array">
<item name="registered_customer_list" xsi:type="object">VENDORMODULEConsoleCommandGetRegisteredCustomerList</item>
</argument>
</arguments>
</type>
</config>
Now you need to create GetRegisteredCustomerList.php
app/code/VENDOR/MODULE/Console/Command/GetRegisteredCustomerList.php
<?php
namespace VendorMODULEConsoleCommand;
use SymfonyComponentConsoleCommandCommand;
use SymfonyComponentConsoleInputInputInterface;
use SymfonyComponentConsoleOutputOutputInterface;
use MagentoCustomerModelResourceModelCustomerCollectionFactory;
class GetRegisteredCustomerList extends Command
{
const COMMAND = 'customer:list';
private $customerCollectionFactory;
public function __construct(
CollectionFactory $customerCollectionFactory
)
{
parent::__construct();
$this->customerCollectionFactory = $customerCollectionFactory;
}
/**
* @inheritdoc
*/
protected function configure()
{
$this->setName(self::COMMAND);
$desc = 'Registered customers list';
$this->setDescription($desc);
}
protected function execute(InputInterface $input, OutputInterface $output)
{
try {
$table = $this->getHelperSet()->get('table');
$table->setHeaders(['ID', 'Website ID', 'Group ID', 'First Name', 'Last Name', 'Email']);
$customerCollection = $this->customerCollectionFactory->create();
foreach ($customerCollection as $customer) {
$table->addRow([
$customer->getData('entity_id'),
$customer->getData('website_id'),
$customer->getData('group_id'),
$customer->getData('firstname'),
$customer->getData('lastname'),
$customer->getData('email'),
]);
}
$table->render($output);
} catch (Exception $e) {
$output->writeln("<error>Error executing command: {$e->getMessage()}</error>");
}
}
}
Now you need to execute the php bin/magento setup:di:compile
command from the magento root directory
and php bin/magento cache:clean
And now you can get your registered customer list by executing below command,
php bin/magento customer:list
it will print something like this,
$ php bin/magento customer:list
+----+------------+----------+------------+-----------+------------------------------+
| ID | Website ID | Group ID | First Name | Last Name | Email |
+----+------------+----------+------------+-----------+------------------------------+
| 1 | 1 | 1 | Keyur | Shah1 | keyurtest@gmail.com |
| 2 | 1 | 1 | Keyur | Shah | keyur@gmail.com |
| 3 | 1 | 1 | Keyur | Shah | keyurdemo@gmail.com |
| 4 | 1 | 1 | Keyur | Shah | demo@gmail.com |
| 5 | 1 | 1 | Keyur | Shah | test@gmail.com |
+----+------------+----------+------------+-----------+------------------------------+
Thanks @Keyur Shah.It works
– Vishali Mariappan
11 mins ago
add a comment |
up vote
3
down vote
You can add your own commands for listing customers:
add your command class through di.
<type name="MagentoFrameworkConsoleCommandListInterface">
<arguments>
<argument name="commands" xsi:type="array">
<item name="customersList" xsi:type="object">ComapanyModuleNameConsoleCommandCustomersList</item>
</argument>
</arguments>
</type>
Create your class. Take help from magento created command classes. Here i create class from MagentoCatalogConsoleCommandProductAttributesCleanUp
<?php
namespace ComapanyModuleNameConsoleCommand;
use SymfonyComponentConsoleInputInputInterface;
use SymfonyComponentConsoleOutputOutputInterface;
/**
* Class ProductAttributesCleanUp
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
*/
class CustomersList extends SymfonyComponentConsoleCommandCommand
{
/**
* @var MagentoFrameworkAppState
*/
protected $appState;
/**
* @var MagentoCustomerModelResourceModelCustomerCollectionFactory
*/
protected $customerCollectionFactory;
/**
* @param MagentoFrameworkAppState $appState
* @param MagentoCustomerModelResourceModelCustomerCollectionFactory
*/
public function __construct(
MagentoFrameworkAppState $appState,
MagentoCustomerModelResourceModelCustomerCollectionFactory $customerCollectionFactory
) {
$this->appState = $appState;
$this->customerCollectionFactory = $customerCollectionFactory;
parent::__construct();
}
/**
* {@inheritdoc}
*/
protected function configure()
{
$this->setName('customers:list');
$this->setDescription('List All Customers.');
}
/**
* {@inheritdoc}
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$output->setDecorated(true);
$this->appState->setAreaCode(MagentoFrameworkAppArea::AREA_GLOBAL);
$output->writeln("");
$collection =$this->customerCollectionFactory->create();
$output->writeln("<info>Customers:</info>");
foreach ($collection as $customer) {
$output->writeln("<comment> ".$customer->getEmail()." </comment>");
}
return MagentoFrameworkConsoleCli::RETURN_SUCCESS;
}
}
[SymfonyComponentConsoleExceptionCommandNotFoundException] There are no commands defined in the "customers" namespace. Did you mean one of these? customer customer:hash
– Vishali Mariappan
1 hour ago
missed to update the name of command ,now updated my post name="customersList" . after making changes run setup:upgrade and cache:flush command
– satya prakash patel
1 hour ago
yes, check the updated post, it will display the email of all customers . you can update it according to your need.
– satya prakash patel
59 mins ago
Argument 2 passed to CodemTimeslotConsoleCommandCustomersList::__construct() must be an instance of MagentoCustomerModelResourceModelCustomerCollectionFactory, none given, called in /Library/WebServer/Documents/magento/vendor/magento/framework/ObjectManager/Factory/AbstractFactory.php on line 111 and defined in /Library/WebServer/Documents/magento/app/code/Codem/Timeslot/Console/Command/CustomersList.php on line 30...This error appears
– Vishali Mariappan
53 mins ago
clean your generated directory and try cache flush
– satya prakash patel
51 mins ago
|
show 5 more comments
Your Answer
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "479"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f254839%2fdisplay-all-customers-using-console-command-magento2-2-3%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
4
down vote
accepted
First, you need to create di.xml
in your customer module(I am assuming that you already know how to create a module)
app/code/VENDOR/MODULE/etc/di.xml
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<type name="MagentoFrameworkConsoleCommandList">
<arguments>
<argument name="commands" xsi:type="array">
<item name="registered_customer_list" xsi:type="object">VENDORMODULEConsoleCommandGetRegisteredCustomerList</item>
</argument>
</arguments>
</type>
</config>
Now you need to create GetRegisteredCustomerList.php
app/code/VENDOR/MODULE/Console/Command/GetRegisteredCustomerList.php
<?php
namespace VendorMODULEConsoleCommand;
use SymfonyComponentConsoleCommandCommand;
use SymfonyComponentConsoleInputInputInterface;
use SymfonyComponentConsoleOutputOutputInterface;
use MagentoCustomerModelResourceModelCustomerCollectionFactory;
class GetRegisteredCustomerList extends Command
{
const COMMAND = 'customer:list';
private $customerCollectionFactory;
public function __construct(
CollectionFactory $customerCollectionFactory
)
{
parent::__construct();
$this->customerCollectionFactory = $customerCollectionFactory;
}
/**
* @inheritdoc
*/
protected function configure()
{
$this->setName(self::COMMAND);
$desc = 'Registered customers list';
$this->setDescription($desc);
}
protected function execute(InputInterface $input, OutputInterface $output)
{
try {
$table = $this->getHelperSet()->get('table');
$table->setHeaders(['ID', 'Website ID', 'Group ID', 'First Name', 'Last Name', 'Email']);
$customerCollection = $this->customerCollectionFactory->create();
foreach ($customerCollection as $customer) {
$table->addRow([
$customer->getData('entity_id'),
$customer->getData('website_id'),
$customer->getData('group_id'),
$customer->getData('firstname'),
$customer->getData('lastname'),
$customer->getData('email'),
]);
}
$table->render($output);
} catch (Exception $e) {
$output->writeln("<error>Error executing command: {$e->getMessage()}</error>");
}
}
}
Now you need to execute the php bin/magento setup:di:compile
command from the magento root directory
and php bin/magento cache:clean
And now you can get your registered customer list by executing below command,
php bin/magento customer:list
it will print something like this,
$ php bin/magento customer:list
+----+------------+----------+------------+-----------+------------------------------+
| ID | Website ID | Group ID | First Name | Last Name | Email |
+----+------------+----------+------------+-----------+------------------------------+
| 1 | 1 | 1 | Keyur | Shah1 | keyurtest@gmail.com |
| 2 | 1 | 1 | Keyur | Shah | keyur@gmail.com |
| 3 | 1 | 1 | Keyur | Shah | keyurdemo@gmail.com |
| 4 | 1 | 1 | Keyur | Shah | demo@gmail.com |
| 5 | 1 | 1 | Keyur | Shah | test@gmail.com |
+----+------------+----------+------------+-----------+------------------------------+
Thanks @Keyur Shah.It works
– Vishali Mariappan
11 mins ago
add a comment |
up vote
4
down vote
accepted
First, you need to create di.xml
in your customer module(I am assuming that you already know how to create a module)
app/code/VENDOR/MODULE/etc/di.xml
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<type name="MagentoFrameworkConsoleCommandList">
<arguments>
<argument name="commands" xsi:type="array">
<item name="registered_customer_list" xsi:type="object">VENDORMODULEConsoleCommandGetRegisteredCustomerList</item>
</argument>
</arguments>
</type>
</config>
Now you need to create GetRegisteredCustomerList.php
app/code/VENDOR/MODULE/Console/Command/GetRegisteredCustomerList.php
<?php
namespace VendorMODULEConsoleCommand;
use SymfonyComponentConsoleCommandCommand;
use SymfonyComponentConsoleInputInputInterface;
use SymfonyComponentConsoleOutputOutputInterface;
use MagentoCustomerModelResourceModelCustomerCollectionFactory;
class GetRegisteredCustomerList extends Command
{
const COMMAND = 'customer:list';
private $customerCollectionFactory;
public function __construct(
CollectionFactory $customerCollectionFactory
)
{
parent::__construct();
$this->customerCollectionFactory = $customerCollectionFactory;
}
/**
* @inheritdoc
*/
protected function configure()
{
$this->setName(self::COMMAND);
$desc = 'Registered customers list';
$this->setDescription($desc);
}
protected function execute(InputInterface $input, OutputInterface $output)
{
try {
$table = $this->getHelperSet()->get('table');
$table->setHeaders(['ID', 'Website ID', 'Group ID', 'First Name', 'Last Name', 'Email']);
$customerCollection = $this->customerCollectionFactory->create();
foreach ($customerCollection as $customer) {
$table->addRow([
$customer->getData('entity_id'),
$customer->getData('website_id'),
$customer->getData('group_id'),
$customer->getData('firstname'),
$customer->getData('lastname'),
$customer->getData('email'),
]);
}
$table->render($output);
} catch (Exception $e) {
$output->writeln("<error>Error executing command: {$e->getMessage()}</error>");
}
}
}
Now you need to execute the php bin/magento setup:di:compile
command from the magento root directory
and php bin/magento cache:clean
And now you can get your registered customer list by executing below command,
php bin/magento customer:list
it will print something like this,
$ php bin/magento customer:list
+----+------------+----------+------------+-----------+------------------------------+
| ID | Website ID | Group ID | First Name | Last Name | Email |
+----+------------+----------+------------+-----------+------------------------------+
| 1 | 1 | 1 | Keyur | Shah1 | keyurtest@gmail.com |
| 2 | 1 | 1 | Keyur | Shah | keyur@gmail.com |
| 3 | 1 | 1 | Keyur | Shah | keyurdemo@gmail.com |
| 4 | 1 | 1 | Keyur | Shah | demo@gmail.com |
| 5 | 1 | 1 | Keyur | Shah | test@gmail.com |
+----+------------+----------+------------+-----------+------------------------------+
Thanks @Keyur Shah.It works
– Vishali Mariappan
11 mins ago
add a comment |
up vote
4
down vote
accepted
up vote
4
down vote
accepted
First, you need to create di.xml
in your customer module(I am assuming that you already know how to create a module)
app/code/VENDOR/MODULE/etc/di.xml
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<type name="MagentoFrameworkConsoleCommandList">
<arguments>
<argument name="commands" xsi:type="array">
<item name="registered_customer_list" xsi:type="object">VENDORMODULEConsoleCommandGetRegisteredCustomerList</item>
</argument>
</arguments>
</type>
</config>
Now you need to create GetRegisteredCustomerList.php
app/code/VENDOR/MODULE/Console/Command/GetRegisteredCustomerList.php
<?php
namespace VendorMODULEConsoleCommand;
use SymfonyComponentConsoleCommandCommand;
use SymfonyComponentConsoleInputInputInterface;
use SymfonyComponentConsoleOutputOutputInterface;
use MagentoCustomerModelResourceModelCustomerCollectionFactory;
class GetRegisteredCustomerList extends Command
{
const COMMAND = 'customer:list';
private $customerCollectionFactory;
public function __construct(
CollectionFactory $customerCollectionFactory
)
{
parent::__construct();
$this->customerCollectionFactory = $customerCollectionFactory;
}
/**
* @inheritdoc
*/
protected function configure()
{
$this->setName(self::COMMAND);
$desc = 'Registered customers list';
$this->setDescription($desc);
}
protected function execute(InputInterface $input, OutputInterface $output)
{
try {
$table = $this->getHelperSet()->get('table');
$table->setHeaders(['ID', 'Website ID', 'Group ID', 'First Name', 'Last Name', 'Email']);
$customerCollection = $this->customerCollectionFactory->create();
foreach ($customerCollection as $customer) {
$table->addRow([
$customer->getData('entity_id'),
$customer->getData('website_id'),
$customer->getData('group_id'),
$customer->getData('firstname'),
$customer->getData('lastname'),
$customer->getData('email'),
]);
}
$table->render($output);
} catch (Exception $e) {
$output->writeln("<error>Error executing command: {$e->getMessage()}</error>");
}
}
}
Now you need to execute the php bin/magento setup:di:compile
command from the magento root directory
and php bin/magento cache:clean
And now you can get your registered customer list by executing below command,
php bin/magento customer:list
it will print something like this,
$ php bin/magento customer:list
+----+------------+----------+------------+-----------+------------------------------+
| ID | Website ID | Group ID | First Name | Last Name | Email |
+----+------------+----------+------------+-----------+------------------------------+
| 1 | 1 | 1 | Keyur | Shah1 | keyurtest@gmail.com |
| 2 | 1 | 1 | Keyur | Shah | keyur@gmail.com |
| 3 | 1 | 1 | Keyur | Shah | keyurdemo@gmail.com |
| 4 | 1 | 1 | Keyur | Shah | demo@gmail.com |
| 5 | 1 | 1 | Keyur | Shah | test@gmail.com |
+----+------------+----------+------------+-----------+------------------------------+
First, you need to create di.xml
in your customer module(I am assuming that you already know how to create a module)
app/code/VENDOR/MODULE/etc/di.xml
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<type name="MagentoFrameworkConsoleCommandList">
<arguments>
<argument name="commands" xsi:type="array">
<item name="registered_customer_list" xsi:type="object">VENDORMODULEConsoleCommandGetRegisteredCustomerList</item>
</argument>
</arguments>
</type>
</config>
Now you need to create GetRegisteredCustomerList.php
app/code/VENDOR/MODULE/Console/Command/GetRegisteredCustomerList.php
<?php
namespace VendorMODULEConsoleCommand;
use SymfonyComponentConsoleCommandCommand;
use SymfonyComponentConsoleInputInputInterface;
use SymfonyComponentConsoleOutputOutputInterface;
use MagentoCustomerModelResourceModelCustomerCollectionFactory;
class GetRegisteredCustomerList extends Command
{
const COMMAND = 'customer:list';
private $customerCollectionFactory;
public function __construct(
CollectionFactory $customerCollectionFactory
)
{
parent::__construct();
$this->customerCollectionFactory = $customerCollectionFactory;
}
/**
* @inheritdoc
*/
protected function configure()
{
$this->setName(self::COMMAND);
$desc = 'Registered customers list';
$this->setDescription($desc);
}
protected function execute(InputInterface $input, OutputInterface $output)
{
try {
$table = $this->getHelperSet()->get('table');
$table->setHeaders(['ID', 'Website ID', 'Group ID', 'First Name', 'Last Name', 'Email']);
$customerCollection = $this->customerCollectionFactory->create();
foreach ($customerCollection as $customer) {
$table->addRow([
$customer->getData('entity_id'),
$customer->getData('website_id'),
$customer->getData('group_id'),
$customer->getData('firstname'),
$customer->getData('lastname'),
$customer->getData('email'),
]);
}
$table->render($output);
} catch (Exception $e) {
$output->writeln("<error>Error executing command: {$e->getMessage()}</error>");
}
}
}
Now you need to execute the php bin/magento setup:di:compile
command from the magento root directory
and php bin/magento cache:clean
And now you can get your registered customer list by executing below command,
php bin/magento customer:list
it will print something like this,
$ php bin/magento customer:list
+----+------------+----------+------------+-----------+------------------------------+
| ID | Website ID | Group ID | First Name | Last Name | Email |
+----+------------+----------+------------+-----------+------------------------------+
| 1 | 1 | 1 | Keyur | Shah1 | keyurtest@gmail.com |
| 2 | 1 | 1 | Keyur | Shah | keyur@gmail.com |
| 3 | 1 | 1 | Keyur | Shah | keyurdemo@gmail.com |
| 4 | 1 | 1 | Keyur | Shah | demo@gmail.com |
| 5 | 1 | 1 | Keyur | Shah | test@gmail.com |
+----+------------+----------+------------+-----------+------------------------------+
answered 31 mins ago
Keyur Shah
12.6k23764
12.6k23764
Thanks @Keyur Shah.It works
– Vishali Mariappan
11 mins ago
add a comment |
Thanks @Keyur Shah.It works
– Vishali Mariappan
11 mins ago
Thanks @Keyur Shah.It works
– Vishali Mariappan
11 mins ago
Thanks @Keyur Shah.It works
– Vishali Mariappan
11 mins ago
add a comment |
up vote
3
down vote
You can add your own commands for listing customers:
add your command class through di.
<type name="MagentoFrameworkConsoleCommandListInterface">
<arguments>
<argument name="commands" xsi:type="array">
<item name="customersList" xsi:type="object">ComapanyModuleNameConsoleCommandCustomersList</item>
</argument>
</arguments>
</type>
Create your class. Take help from magento created command classes. Here i create class from MagentoCatalogConsoleCommandProductAttributesCleanUp
<?php
namespace ComapanyModuleNameConsoleCommand;
use SymfonyComponentConsoleInputInputInterface;
use SymfonyComponentConsoleOutputOutputInterface;
/**
* Class ProductAttributesCleanUp
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
*/
class CustomersList extends SymfonyComponentConsoleCommandCommand
{
/**
* @var MagentoFrameworkAppState
*/
protected $appState;
/**
* @var MagentoCustomerModelResourceModelCustomerCollectionFactory
*/
protected $customerCollectionFactory;
/**
* @param MagentoFrameworkAppState $appState
* @param MagentoCustomerModelResourceModelCustomerCollectionFactory
*/
public function __construct(
MagentoFrameworkAppState $appState,
MagentoCustomerModelResourceModelCustomerCollectionFactory $customerCollectionFactory
) {
$this->appState = $appState;
$this->customerCollectionFactory = $customerCollectionFactory;
parent::__construct();
}
/**
* {@inheritdoc}
*/
protected function configure()
{
$this->setName('customers:list');
$this->setDescription('List All Customers.');
}
/**
* {@inheritdoc}
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$output->setDecorated(true);
$this->appState->setAreaCode(MagentoFrameworkAppArea::AREA_GLOBAL);
$output->writeln("");
$collection =$this->customerCollectionFactory->create();
$output->writeln("<info>Customers:</info>");
foreach ($collection as $customer) {
$output->writeln("<comment> ".$customer->getEmail()." </comment>");
}
return MagentoFrameworkConsoleCli::RETURN_SUCCESS;
}
}
[SymfonyComponentConsoleExceptionCommandNotFoundException] There are no commands defined in the "customers" namespace. Did you mean one of these? customer customer:hash
– Vishali Mariappan
1 hour ago
missed to update the name of command ,now updated my post name="customersList" . after making changes run setup:upgrade and cache:flush command
– satya prakash patel
1 hour ago
yes, check the updated post, it will display the email of all customers . you can update it according to your need.
– satya prakash patel
59 mins ago
Argument 2 passed to CodemTimeslotConsoleCommandCustomersList::__construct() must be an instance of MagentoCustomerModelResourceModelCustomerCollectionFactory, none given, called in /Library/WebServer/Documents/magento/vendor/magento/framework/ObjectManager/Factory/AbstractFactory.php on line 111 and defined in /Library/WebServer/Documents/magento/app/code/Codem/Timeslot/Console/Command/CustomersList.php on line 30...This error appears
– Vishali Mariappan
53 mins ago
clean your generated directory and try cache flush
– satya prakash patel
51 mins ago
|
show 5 more comments
up vote
3
down vote
You can add your own commands for listing customers:
add your command class through di.
<type name="MagentoFrameworkConsoleCommandListInterface">
<arguments>
<argument name="commands" xsi:type="array">
<item name="customersList" xsi:type="object">ComapanyModuleNameConsoleCommandCustomersList</item>
</argument>
</arguments>
</type>
Create your class. Take help from magento created command classes. Here i create class from MagentoCatalogConsoleCommandProductAttributesCleanUp
<?php
namespace ComapanyModuleNameConsoleCommand;
use SymfonyComponentConsoleInputInputInterface;
use SymfonyComponentConsoleOutputOutputInterface;
/**
* Class ProductAttributesCleanUp
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
*/
class CustomersList extends SymfonyComponentConsoleCommandCommand
{
/**
* @var MagentoFrameworkAppState
*/
protected $appState;
/**
* @var MagentoCustomerModelResourceModelCustomerCollectionFactory
*/
protected $customerCollectionFactory;
/**
* @param MagentoFrameworkAppState $appState
* @param MagentoCustomerModelResourceModelCustomerCollectionFactory
*/
public function __construct(
MagentoFrameworkAppState $appState,
MagentoCustomerModelResourceModelCustomerCollectionFactory $customerCollectionFactory
) {
$this->appState = $appState;
$this->customerCollectionFactory = $customerCollectionFactory;
parent::__construct();
}
/**
* {@inheritdoc}
*/
protected function configure()
{
$this->setName('customers:list');
$this->setDescription('List All Customers.');
}
/**
* {@inheritdoc}
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$output->setDecorated(true);
$this->appState->setAreaCode(MagentoFrameworkAppArea::AREA_GLOBAL);
$output->writeln("");
$collection =$this->customerCollectionFactory->create();
$output->writeln("<info>Customers:</info>");
foreach ($collection as $customer) {
$output->writeln("<comment> ".$customer->getEmail()." </comment>");
}
return MagentoFrameworkConsoleCli::RETURN_SUCCESS;
}
}
[SymfonyComponentConsoleExceptionCommandNotFoundException] There are no commands defined in the "customers" namespace. Did you mean one of these? customer customer:hash
– Vishali Mariappan
1 hour ago
missed to update the name of command ,now updated my post name="customersList" . after making changes run setup:upgrade and cache:flush command
– satya prakash patel
1 hour ago
yes, check the updated post, it will display the email of all customers . you can update it according to your need.
– satya prakash patel
59 mins ago
Argument 2 passed to CodemTimeslotConsoleCommandCustomersList::__construct() must be an instance of MagentoCustomerModelResourceModelCustomerCollectionFactory, none given, called in /Library/WebServer/Documents/magento/vendor/magento/framework/ObjectManager/Factory/AbstractFactory.php on line 111 and defined in /Library/WebServer/Documents/magento/app/code/Codem/Timeslot/Console/Command/CustomersList.php on line 30...This error appears
– Vishali Mariappan
53 mins ago
clean your generated directory and try cache flush
– satya prakash patel
51 mins ago
|
show 5 more comments
up vote
3
down vote
up vote
3
down vote
You can add your own commands for listing customers:
add your command class through di.
<type name="MagentoFrameworkConsoleCommandListInterface">
<arguments>
<argument name="commands" xsi:type="array">
<item name="customersList" xsi:type="object">ComapanyModuleNameConsoleCommandCustomersList</item>
</argument>
</arguments>
</type>
Create your class. Take help from magento created command classes. Here i create class from MagentoCatalogConsoleCommandProductAttributesCleanUp
<?php
namespace ComapanyModuleNameConsoleCommand;
use SymfonyComponentConsoleInputInputInterface;
use SymfonyComponentConsoleOutputOutputInterface;
/**
* Class ProductAttributesCleanUp
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
*/
class CustomersList extends SymfonyComponentConsoleCommandCommand
{
/**
* @var MagentoFrameworkAppState
*/
protected $appState;
/**
* @var MagentoCustomerModelResourceModelCustomerCollectionFactory
*/
protected $customerCollectionFactory;
/**
* @param MagentoFrameworkAppState $appState
* @param MagentoCustomerModelResourceModelCustomerCollectionFactory
*/
public function __construct(
MagentoFrameworkAppState $appState,
MagentoCustomerModelResourceModelCustomerCollectionFactory $customerCollectionFactory
) {
$this->appState = $appState;
$this->customerCollectionFactory = $customerCollectionFactory;
parent::__construct();
}
/**
* {@inheritdoc}
*/
protected function configure()
{
$this->setName('customers:list');
$this->setDescription('List All Customers.');
}
/**
* {@inheritdoc}
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$output->setDecorated(true);
$this->appState->setAreaCode(MagentoFrameworkAppArea::AREA_GLOBAL);
$output->writeln("");
$collection =$this->customerCollectionFactory->create();
$output->writeln("<info>Customers:</info>");
foreach ($collection as $customer) {
$output->writeln("<comment> ".$customer->getEmail()." </comment>");
}
return MagentoFrameworkConsoleCli::RETURN_SUCCESS;
}
}
You can add your own commands for listing customers:
add your command class through di.
<type name="MagentoFrameworkConsoleCommandListInterface">
<arguments>
<argument name="commands" xsi:type="array">
<item name="customersList" xsi:type="object">ComapanyModuleNameConsoleCommandCustomersList</item>
</argument>
</arguments>
</type>
Create your class. Take help from magento created command classes. Here i create class from MagentoCatalogConsoleCommandProductAttributesCleanUp
<?php
namespace ComapanyModuleNameConsoleCommand;
use SymfonyComponentConsoleInputInputInterface;
use SymfonyComponentConsoleOutputOutputInterface;
/**
* Class ProductAttributesCleanUp
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
*/
class CustomersList extends SymfonyComponentConsoleCommandCommand
{
/**
* @var MagentoFrameworkAppState
*/
protected $appState;
/**
* @var MagentoCustomerModelResourceModelCustomerCollectionFactory
*/
protected $customerCollectionFactory;
/**
* @param MagentoFrameworkAppState $appState
* @param MagentoCustomerModelResourceModelCustomerCollectionFactory
*/
public function __construct(
MagentoFrameworkAppState $appState,
MagentoCustomerModelResourceModelCustomerCollectionFactory $customerCollectionFactory
) {
$this->appState = $appState;
$this->customerCollectionFactory = $customerCollectionFactory;
parent::__construct();
}
/**
* {@inheritdoc}
*/
protected function configure()
{
$this->setName('customers:list');
$this->setDescription('List All Customers.');
}
/**
* {@inheritdoc}
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$output->setDecorated(true);
$this->appState->setAreaCode(MagentoFrameworkAppArea::AREA_GLOBAL);
$output->writeln("");
$collection =$this->customerCollectionFactory->create();
$output->writeln("<info>Customers:</info>");
foreach ($collection as $customer) {
$output->writeln("<comment> ".$customer->getEmail()." </comment>");
}
return MagentoFrameworkConsoleCli::RETURN_SUCCESS;
}
}
edited 1 hour ago
answered 2 hours ago
satya prakash patel
30416
30416
[SymfonyComponentConsoleExceptionCommandNotFoundException] There are no commands defined in the "customers" namespace. Did you mean one of these? customer customer:hash
– Vishali Mariappan
1 hour ago
missed to update the name of command ,now updated my post name="customersList" . after making changes run setup:upgrade and cache:flush command
– satya prakash patel
1 hour ago
yes, check the updated post, it will display the email of all customers . you can update it according to your need.
– satya prakash patel
59 mins ago
Argument 2 passed to CodemTimeslotConsoleCommandCustomersList::__construct() must be an instance of MagentoCustomerModelResourceModelCustomerCollectionFactory, none given, called in /Library/WebServer/Documents/magento/vendor/magento/framework/ObjectManager/Factory/AbstractFactory.php on line 111 and defined in /Library/WebServer/Documents/magento/app/code/Codem/Timeslot/Console/Command/CustomersList.php on line 30...This error appears
– Vishali Mariappan
53 mins ago
clean your generated directory and try cache flush
– satya prakash patel
51 mins ago
|
show 5 more comments
[SymfonyComponentConsoleExceptionCommandNotFoundException] There are no commands defined in the "customers" namespace. Did you mean one of these? customer customer:hash
– Vishali Mariappan
1 hour ago
missed to update the name of command ,now updated my post name="customersList" . after making changes run setup:upgrade and cache:flush command
– satya prakash patel
1 hour ago
yes, check the updated post, it will display the email of all customers . you can update it according to your need.
– satya prakash patel
59 mins ago
Argument 2 passed to CodemTimeslotConsoleCommandCustomersList::__construct() must be an instance of MagentoCustomerModelResourceModelCustomerCollectionFactory, none given, called in /Library/WebServer/Documents/magento/vendor/magento/framework/ObjectManager/Factory/AbstractFactory.php on line 111 and defined in /Library/WebServer/Documents/magento/app/code/Codem/Timeslot/Console/Command/CustomersList.php on line 30...This error appears
– Vishali Mariappan
53 mins ago
clean your generated directory and try cache flush
– satya prakash patel
51 mins ago
[SymfonyComponentConsoleExceptionCommandNotFoundException] There are no commands defined in the "customers" namespace. Did you mean one of these? customer customer:hash
– Vishali Mariappan
1 hour ago
[SymfonyComponentConsoleExceptionCommandNotFoundException] There are no commands defined in the "customers" namespace. Did you mean one of these? customer customer:hash
– Vishali Mariappan
1 hour ago
missed to update the name of command ,now updated my post name="customersList" . after making changes run setup:upgrade and cache:flush command
– satya prakash patel
1 hour ago
missed to update the name of command ,now updated my post name="customersList" . after making changes run setup:upgrade and cache:flush command
– satya prakash patel
1 hour ago
yes, check the updated post, it will display the email of all customers . you can update it according to your need.
– satya prakash patel
59 mins ago
yes, check the updated post, it will display the email of all customers . you can update it according to your need.
– satya prakash patel
59 mins ago
Argument 2 passed to CodemTimeslotConsoleCommandCustomersList::__construct() must be an instance of MagentoCustomerModelResourceModelCustomerCollectionFactory, none given, called in /Library/WebServer/Documents/magento/vendor/magento/framework/ObjectManager/Factory/AbstractFactory.php on line 111 and defined in /Library/WebServer/Documents/magento/app/code/Codem/Timeslot/Console/Command/CustomersList.php on line 30...This error appears
– Vishali Mariappan
53 mins ago
Argument 2 passed to CodemTimeslotConsoleCommandCustomersList::__construct() must be an instance of MagentoCustomerModelResourceModelCustomerCollectionFactory, none given, called in /Library/WebServer/Documents/magento/vendor/magento/framework/ObjectManager/Factory/AbstractFactory.php on line 111 and defined in /Library/WebServer/Documents/magento/app/code/Codem/Timeslot/Console/Command/CustomersList.php on line 30...This error appears
– Vishali Mariappan
53 mins ago
clean your generated directory and try cache flush
– satya prakash patel
51 mins ago
clean your generated directory and try cache flush
– satya prakash patel
51 mins ago
|
show 5 more comments
Thanks for contributing an answer to Magento Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f254839%2fdisplay-all-customers-using-console-command-magento2-2-3%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown