0
<?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('subscriber_name')) {
      $firstname = $this->getRequest->getPost('subscriber_name');
      print_r($firstname);
      $subject->setCFirstname($firstname);
      $result = $proceed($email);

      try {
        $subject->save();
      }catch (\Exception $e) {
        throw new \Exception($e->getMessage());
      }
    }

    return $result;
  }
}
6
  • Are you trying to save a customer attribute? And can you show the code in the di.xml for the plugin too? Aug 19, 2021 at 15:42
  • Is Custom newsletter field in Custom table or in product table ? Please elaborate.
    – BornCoder
    Aug 19, 2021 at 17:12
  • @BornCoder Custom newsletter field
    – Mark
    Aug 20, 2021 at 4:04
  • @AlanZavagli di.xml <?xml version="1.0"?> <config xmlns:xsi="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"/> </type> </config>
    – Mark
    Aug 20, 2021 at 4:05
  • Please check answer here - magento.stackexchange.com/questions/344887/…
    – ZealousWeb
    Aug 23, 2021 at 14:09

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.