I am new to magento 2 and i would like to add extra field to newsletter so i created a module with plugin to call aroundsubscribe method to save the new field data while subscription but i am unable to do so.
Plugin class is
namespace Microwebby\Micro\Module\Plugin\Newsletter;
use Magento\Framework\App\Request\Http;
class Subscriber {
protected $request;
public function __construct(
Http $request
) {
$this->request = $request;
}
public function aroundSubscribe($subject, \Closure $proceed, $email) {
$result = $proceed($email);
if ($this->request->isPost()) {
$subscriber_country = $this->request->getPost('subscriber_country');
$subject->setCSubscriber_country($subscriber_country);
try {
$subject->save();
}catch (\Exception $e) {
throw new \Exception($e->getMessage());
}
}
return $result;
}
}
In system.log i can see the trace
Microwebby\Micro\Module\Plugin\Newsletter\Subscriber->aroundSubscribe(Object(Magento\Newsletter\Model\Subscriber\Interceptor), Object(Closure), 'rashidtahir05@g...')
Anything else needed to help please mention so that i can provide you.
I want to add extra field to newsletter subscription form.
thanks