0

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?

2

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.phpfile 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 cron
  • app/code/{vendorname}/{Company}/Cron/Sendnewsletterlist.php Php class of cronjob which send the list of new subscriber to admin
  • Can we create this as plugin in my existing module??? – sam Oct 6 '17 at 4:14
  • can you please help me little bit, what will be code in Sendnewsletterlist.php – sam Oct 6 '17 at 4:48
  • will update Soon.... – Amit Bera Oct 6 '17 at 5:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.