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.

Dhiren Vasoya
9,70914 gold badges37 silver badges61 bronze badges
asked Oct 31, 2021 at 15:10
0

1 Answer 1

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

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

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.