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.
1 Answer 1
- To create any plugin, you need to put this code into
di.xmlfile :
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>.
Then you need to create
plugin typefile 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
-
can I order such a plugin from you?Jesper Brejning– Jesper Brejning2021年11月02日 07:24:10 +00:00Commented Nov 2, 2021 at 7:24
-
Someone, who can help me a little more, how to build a module like this? Please :-)Jesper Brejning– Jesper Brejning2021年11月09日 11:38:12 +00:00Commented Nov 9, 2021 at 11:38
-
Kindly check the devdoc link, which give you more and clear idea.Dhiren Vasoya– Dhiren Vasoya2021年11月09日 11:39:15 +00:00Commented Nov 9, 2021 at 11:39