How I can add these fields in the table, display it on the form, save values in the table.
Vendor\Module\Plugin\Newsletter\Subscriber.php
<?php
namespace Vendor\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) {
if ($this->request->isPost() && $this->request->getPost('name')) {
$name = $this->request->getPost('name');
// $lastname = $this->request->getPost('lastname');
// $gender = $this->request->getPost('gender');
$subject->setName($name);
// $subject->setCLastname($lastname);
// $subject->setGender($gender);
$result = $proceed($email);
try {
$subject->save();
}catch (\Exception $e) {
throw new \Exception($e->getMessage());
}
}
return $result;
}
}
db_schema.xml
<schema xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Setup/Declaration/Schema/etc/schema.xsd">
<table name="newsletter_subscriber" resource="default" engine="innodb" comment="Newsletter Subscriber">
<column xsi:type="varchar" name="subscriber_name" nullable="true" comment="Name"/>
</table>
</schema>
di.xml
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../lib/internal/Magento/Framework/ObjectManager/etc/config.xsd">
<type name="Magento\Newsletter\Model\Subscriber">
<plugin name="vendor_module_newsletter_model_subscriber" type="Vendor\Module\Plugin\Newsletter\Subscriber" sortOrder="1"/>
</type>
</config>