display all customers using console command magento2.2.3
How to display registered customers in terminal using custom console command?Can anyone please help me out.
magento2.2.3 cli
add a comment |
How to display registered customers in terminal using custom console command?Can anyone please help me out.
magento2.2.3 cli
add a comment |
How to display registered customers in terminal using custom console command?Can anyone please help me out.
magento2.2.3 cli
How to display registered customers in terminal using custom console command?Can anyone please help me out.
magento2.2.3 cli
magento2.2.3 cli
edited Dec 18 '18 at 5:45
Purushotam Sharma
8601527
8601527
asked Dec 17 '18 at 7:38
Vishali MariappanVishali Mariappan
10911
10911
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
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
Dec 17 '18 at 10:04
add a comment |
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
Dec 17 '18 at 8:17
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
Dec 17 '18 at 9:05
yes, check the updated post, it will display the email of all customers . you can update it according to your need.
– satya prakash patel
Dec 17 '18 at 9:16
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
Dec 17 '18 at 9:22
clean your generated directory and try cache flush
– satya prakash patel
Dec 17 '18 at 9:24
|
show 7 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',
autoActivateHeartbeat: false,
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
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
Dec 17 '18 at 10:04
add a comment |
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
Dec 17 '18 at 10:04
add a comment |
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 Dec 17 '18 at 9:43
Keyur ShahKeyur Shah
12.9k23864
12.9k23864
Thanks @Keyur Shah.It works
– Vishali Mariappan
Dec 17 '18 at 10:04
add a comment |
Thanks @Keyur Shah.It works
– Vishali Mariappan
Dec 17 '18 at 10:04
Thanks @Keyur Shah.It works
– Vishali Mariappan
Dec 17 '18 at 10:04
Thanks @Keyur Shah.It works
– Vishali Mariappan
Dec 17 '18 at 10:04
add a comment |
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
Dec 17 '18 at 8:17
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
Dec 17 '18 at 9:05
yes, check the updated post, it will display the email of all customers . you can update it according to your need.
– satya prakash patel
Dec 17 '18 at 9:16
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
Dec 17 '18 at 9:22
clean your generated directory and try cache flush
– satya prakash patel
Dec 17 '18 at 9:24
|
show 7 more comments
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
Dec 17 '18 at 8:17
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
Dec 17 '18 at 9:05
yes, check the updated post, it will display the email of all customers . you can update it according to your need.
– satya prakash patel
Dec 17 '18 at 9:16
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
Dec 17 '18 at 9:22
clean your generated directory and try cache flush
– satya prakash patel
Dec 17 '18 at 9:24
|
show 7 more comments
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 Dec 17 '18 at 9:10
answered Dec 17 '18 at 7:55
satya prakash patelsatya prakash patel
31416
31416
[SymfonyComponentConsoleExceptionCommandNotFoundException] There are no commands defined in the "customers" namespace. Did you mean one of these? customer customer:hash
– Vishali Mariappan
Dec 17 '18 at 8:17
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
Dec 17 '18 at 9:05
yes, check the updated post, it will display the email of all customers . you can update it according to your need.
– satya prakash patel
Dec 17 '18 at 9:16
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
Dec 17 '18 at 9:22
clean your generated directory and try cache flush
– satya prakash patel
Dec 17 '18 at 9:24
|
show 7 more comments
[SymfonyComponentConsoleExceptionCommandNotFoundException] There are no commands defined in the "customers" namespace. Did you mean one of these? customer customer:hash
– Vishali Mariappan
Dec 17 '18 at 8:17
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
Dec 17 '18 at 9:05
yes, check the updated post, it will display the email of all customers . you can update it according to your need.
– satya prakash patel
Dec 17 '18 at 9:16
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
Dec 17 '18 at 9:22
clean your generated directory and try cache flush
– satya prakash patel
Dec 17 '18 at 9:24
[SymfonyComponentConsoleExceptionCommandNotFoundException] There are no commands defined in the "customers" namespace. Did you mean one of these? customer customer:hash
– Vishali Mariappan
Dec 17 '18 at 8:17
[SymfonyComponentConsoleExceptionCommandNotFoundException] There are no commands defined in the "customers" namespace. Did you mean one of these? customer customer:hash
– Vishali Mariappan
Dec 17 '18 at 8:17
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
Dec 17 '18 at 9:05
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
Dec 17 '18 at 9:05
yes, check the updated post, it will display the email of all customers . you can update it according to your need.
– satya prakash patel
Dec 17 '18 at 9:16
yes, check the updated post, it will display the email of all customers . you can update it according to your need.
– satya prakash patel
Dec 17 '18 at 9:16
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
Dec 17 '18 at 9:22
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
Dec 17 '18 at 9:22
clean your generated directory and try cache flush
– satya prakash patel
Dec 17 '18 at 9:24
clean your generated directory and try cache flush
– satya prakash patel
Dec 17 '18 at 9:24
|
show 7 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.
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