0

How can I build this module for our Magento 2 for cache warmer to crawl both desktop and mobile version pages?

We would like to create a plugin with the method afterGetData. On the class Magento\Framework\App\Http\Context

In this method of the plugin, I would like to add a condition by which an additional parameter "device-type" is added to that data.

The afterGetData method may look like this one:

public function afterGetData($subject, $data)
{
    if ([mobile-user-agent-condition]) {
        $data['device-type'] = 'mobile';
    } else {
        $data['device-type'] = 'desktop';
    }

    return $data;
}

Where [mobile-user-agent-condition] is the condition that should return 'true' if the user agent is a mobile user-agent.

0
2
  1. To create any plugin, you need to put this code into di.xml file :

app\code\Vendor\Extension\etc\di.xml

<config>
    <type name="{ObservedType}">
        <plugin name="{pluginName}" type="{PluginClassName}" sortOrder="1" disabled="false"/>
    </type>
</config>

Where :

type name. A class or interface which the plugin observes.

plugin name. An arbitrary plugin name that identifies a plugin. Also used to merge the configurations for the plugin.

plugin type. The name of a plugin’s class or its virtual type. Use the following naming convention when you specify this element: \Vendor\Extension\Plugin<ClassName>.

  1. Then you need to create plugin type file like this one:

    <?php
    namespace Vendor\Extension\Plugin;
    
    class Yourpluginclassname
    {
        public function afterGetData($subject, $result)
        {
            return '|' . $result . '|';
        }
    }
    

For More information you can read here : https://devdocs.magento.com/guides/v2.4/extension-dev-guide/plugins.html

3
  • can I order such a plugin from you? Nov 2 '21 at 7:24
  • Someone, who can help me a little more, how to build a module like this? Please :-) Nov 9 '21 at 11:38
  • Kindly check the devdoc link, which give you more and clear idea. Nov 9 '21 at 11:39

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.