Вопрос

I am trying to use a plugin to alter the contact form post data by using the afterExecute method:

    public function afterExecute(\Magento\Contact\Controller\Index\Post $subject, $result)
    {
        $comment =  $subject->getRequest()->getParam('comment', false);
        $subject->getRequest()->setParam('comment', 'testing: '.$comment); // <--- this is not working and not changing the comment post value
        return $result;
    }

I just want to append/prepend a string to the comment (message) that is posted. But the above does not work and the comment post value is not changed. Thanks

Это было полезно?

Решение

use before plugin instead of after plugin.

public function beforeExecute(\Magento\Contact\Controller\Index\Post $subject)
{
    $comment =  $subject->getRequest()->getParam('comment', false);
    $subject->getRequest()->setParam('comment', 'testing: '.$comment); 
}

try this.

Другие советы

Try before plugin with below code

<?php
declare(strict_types=1);

namespace Vendor\MyModule\Plugin\Frontend\Magento\Contact\Controller\Index;

class Post
{

    public function beforeExecute(
        \Magento\Contact\Controller\Index\Post $subject
    ) {
        $comment =  $subject->getRequest()->getParam('comment', false);
        $subject->getRequest()->setParam('comment', 'testing: '.$comment);
        return;
    }
}
Лицензировано под: CC-BY-SA с атрибуция
Не связан с magento.stackexchange
scroll top