I am using Magento 2.1.5, and I need to send email to admin after every 15 days with the list of new subscribers.
How to do this?
In magento, you cannot get last 15days list of new subscribers list because of there are not created_at
column at database table newsletter_subscriber
. So you cannot filter collection by date.
To achieve this requirement, you need to create a custom module. Where You need create column using installer script
Module's basic files:
app/code/{vendorname}/{Company}/registration.php
app/code/{vendorname}/{Company}/composer.json
app/code/{vendorname}/{Company}/etc/module.xml
First create an UpgradeSchema.php
file at app/code/{vendorname}/{Company}/Setup
.
<?php
namespace {vendorname}\{Company}\Setup;
use Magento\Framework\Setup\UpgradeSchemaInterface;
use Magento\Framework\Setup\SchemaSetupInterface;
use Magento\Framework\Setup\ModuleContextInterface;
class UpgradeSchema implements UpgradeSchemaInterface
{
public function upgrade(SchemaSetupInterface $setup, ModuleContextInterface $context)
{
$installer = $setup;
$installer->startSetup();
$connection = $installer->getConnection();
$connection->addColumn(
$installer->getTable('newsletter_subscriber'),
'creation_time',
[
'type' => \Magento\Framework\DB\Ddl\Table::TYPE_TIMESTAMP,
'default' => \Magento\Framework\DB\Ddl\Table::TIMESTAMP_INIT,
'comment' => 'Creation Time'
]
);
}
}
In this module, create a cronjob which will send the list of new subscriber to admin
app/code/{vendorname}/{Company}/etc/crontab.xml
Used to define cronapp/code/{vendorname}/{Company}/Cron/Sendnewsletterlist.php
Php class of cronjob which send the list of new subscriber to admin