{"id":62589,"date":"2016-10-22T15:37:23","date_gmt":"2016-10-22T15:37:23","guid":{"rendered":"http:\/\/webkul.com\/blog\/?p=62589"},"modified":"2026-04-24T12:03:26","modified_gmt":"2026-04-24T12:03:26","slug":"magento2-interceptor-pattern-code-generation","status":"publish","type":"post","link":"https:\/\/webkul.com\/blog\/magento2-interceptor-pattern-code-generation\/","title":{"rendered":"Magento 2 Interceptor pattern and Code Generation"},"content":{"rendered":"\n<p>In my previous blog, we tried to understand the concept of code generation and why it is needed, along with the concept of factory code generation. In this blog, we will understand the interceptor pattern and code generation.<\/p>\n\n\n\n<p>As we know design patterns are used to solve specific problems and interceptor design pattern also used in Magento 2 to solve the problem of customization. <\/p>\n\n\n\n<p>Since in a system like Magento, many <a href=\"https:\/\/webkul.com\/hire-magento-developers\/\">Magento developers<\/a> work on creating extensions and may try to customize Magento core functions for specific requirements.<\/p>\n\n\n\n<p>It is very important to have a better system. It is also important to follow a proper approach for customization in Magento.<\/p>\n\n\n\n<p><strong>Problem:<\/strong><\/p>\n\n\n\n<p>In Magento 1, there was a rewrite system for customization. You could easily override the core class in your module, and Magento would start using your class instead of the core class.<\/p>\n\n\n\n<p>However, the problem occurs when two or more modules override the same core class. In this case, only one module works correctly. The other modules\u2019 customizations in the core class do not work.<\/p>\n\n\n\n<p><strong>Solution:<\/strong><\/p>\n\n\n\n<p>for the solution of the above problem Magento 2 now uses interceptor design patter or plugin system.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">What is Interceptor design pattern ?<\/h2>\n\n\n\n<p>In the field of <a href=\"https:\/\/webkul.com\/services\/\">software development<\/a>, an interceptor pattern is a software design pattern that is used when software systems or frameworks want to offer a way to change, or augment, their usual processing cycle<\/p>\n\n\n\n<p><a href=\"https:\/\/en.wikipedia.org\/wiki\/Interceptor_pattern\">&#8211;Source<\/a><\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Magento2 Interceptor code generation:<\/h3>\n\n\n\n<p>Now we will see how interceptor code generation works. Unlike factory you don&#8217;t use interceptor classes directly, they are used without the knowledge of the user.<\/p>\n\n\n\n<p>An interceptor class is generated when it encounters a plugin declaration in the di.xml file. Lets see how plugins are defined in di.xml:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\">&lt;type name=&quot;Magento\\Customer\\Model\\ResourceModel\\Visitor&quot;&gt;\n\n&lt;plugin name=&quot;catalogLog&quot; type=&quot;Magento\\Catalog\\Model\\Plugin\\Log&quot; \/&gt;\n\n&lt;\/type&gt;<\/pre>\n\n\n\n<p>if the object manager encounters the above type declaration in the di.xml then it automatically generate interceptor class in the generated\/code folder .<\/p>\n\n\n\n<p>In the type declaration :<\/p>\n\n\n\n<p>type attribute \u201cname\u201d: defines the class that need to be intercepted.<\/p>\n\n\n\n<p><strong>\u201cplugin\u201d tag:<\/strong> defines plugin declaration<\/p>\n\n\n\n<p><strong>plugin \u201cname\u201d attribute :<\/strong> plugin identifier<\/p>\n\n\n\n<p><strong>plugin \u201ctype\u201d attribute :<\/strong>&nbsp; your class in which you will define the method need to be customized.<\/p>\n\n\n\n<p>For more details about plugins and how to use them you can go through this blog :<\/p>\n\n\n\n<p><a href=\"http:\/\/webkul.com\/blog\/magento2-use-plugins\/\">create and use plugins<\/a><\/p>\n\n\n\n<p>or simply view this video:<\/p>\n\n\n\n<p><a href=\"https:\/\/www.youtube.com\/watch?v=PWDS2j-M2wU\">Magento 2 Plugins<\/a><\/p>\n\n\n\n<p><strong>Plugin class created to work after clean method of&nbsp;<\/strong><br><strong>Magento\\Customer\\Model\\ResourceModel\\Visitor class<\/strong><\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\">&lt;?php\n\/**\n * Plugin for \\Magento\\Customer\\Model\\ResourceModel\\Visitor model\n *\n * Copyright \u00a9 2016 Magento. All rights reserved.\n * See COPYING.txt for license details.\n *\/\nnamespace Magento\\Catalog\\Model\\Plugin;\n\nclass Log\n{\n    \/**\n     * @var \\Magento\\Catalog\\Model\\Product\\Compare\\Item\n     *\/\n    protected $_productCompareItem;\n\n    \/**\n     * @param \\Magento\\Catalog\\Model\\Product\\Compare\\Item $productCompareItem\n     *\/\n    public function __construct(\\Magento\\Catalog\\Model\\Product\\Compare\\Item $productCompareItem)\n    {\n        $this-&gt;_productCompareItem = $productCompareItem;\n    }\n\n    \/**\n     * Catalog Product Compare Items Clean\n     * after plugin for clean method\n     *\n     * @param \\Magento\\Customer\\Model\\ResourceModel\\Visitor $subject\n     * @param \\Magento\\Customer\\Model\\ResourceModel\\Visitor $logResourceModel\n     *\n     * @return \\Magento\\Customer\\Model\\ResourceModel\\Visitor\n     * @SuppressWarnings(PHPMD.UnusedFormalParameter)\n     *\/\n    public function afterClean(\\Magento\\Customer\\Model\\ResourceModel\\Visitor $subject, $logResourceModel)\n    {\n        $this-&gt;_productCompareItem-&gt;clean();\n        return $logResourceModel;\n    }\n}<\/pre>\n\n\n\n<p>in the above class a plugin is created to work after the clean method of \\Magento\\Customer\\Model\\ResourceModel\\Visitor<\/p>\n\n\n\n<p><strong>afterClean:&nbsp;<\/strong> plugin method to work after clean method to modify its return data, or to do something before returning some data.<br><strong>\\Magento\\Customer\\Model\\ResourceModel\\Visitor $subject<\/strong><br>: original class passed as argument so that you can use any of its public methods.<br><strong>$logResourceModel<\/strong><br>: this is the original response from the clean method so that user it can be modified and returned .<\/p>\n\n\n\n<p><strong>Now we will see the structure of the interceptor class that is generated automatically in generated\/code folder:<\/strong><\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"php\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">&lt;?php\nnamespace Magento\\Customer\\Model\\ResourceModel\\Visitor;\n\n\/**\n * Interceptor class for @see \\Magento\\Customer\\Model\\ResourceModel\\Visitor\n *\/\nclass Interceptor extends \\Magento\\Customer\\Model\\ResourceModel\\Visitor implements \\Magento\\Framework\\Interception\\InterceptorInterface\n{\n    use \\Magento\\Framework\\Interception\\Interceptor;\n\n    public function __construct(\\Magento\\Framework\\Model\\ResourceModel\\Db\\Context $context, \\Magento\\Framework\\Stdlib\\DateTime\\DateTime $date, \\Magento\\Framework\\Stdlib\\DateTime $dateTime, $connectionName = null)\n    {\n        $this->___init();\n        parent::__construct($context, $date, $dateTime, $connectionName);\n    }\n\n    \/**\n     * {@inheritdoc}\n     *\/\n    public function clean(\\Magento\\Customer\\Model\\Visitor $object)\n    {\n        $pluginInfo = $this->pluginList->getNext($this->subjectType, 'clean');\n        return $pluginInfo ? $this->___callPlugins('clean', func_get_args(), $pluginInfo) : parent::clean($object);\n    }\n}\n<\/pre>\n\n\n\n<p>In the above interceptor class you can see in has extended the original class so that it can override the function that plugin is needed, you can also see that it has implemented<br><strong>\\Magento\\Framework\\Interception\\InterceptorInterface&nbsp;<\/strong><\/p>\n\n\n\n<p>and inside, it uses its concrete class, this class has a method .<\/p>\n\n\n\n<p>Lets see some of the methods used in this interceptor class and its usage:<\/p>\n\n\n\n<p><code class=\"php plain\"><code class=\"php plain\"><\/code><\/code><strong>___init():<\/strong><code class=\"php plain\"> this method is called in the constructor it is simply loading all the plugin that are defined for the class in pluginList property.<\/code><\/p>\n\n\n\n<p><strong>clean(<code class=\"php plain\">\\Magento\\Customer\\Model\\Visitor <\/code><code class=\"php variable\">$object<\/code>):<\/strong> this method in overridden in this interceptor class, since we needed to change its behavior.<\/p>\n\n\n\n<p><strong><code class=\"php variable\">$pluginInfo<\/code> <code class=\"php plain\">= <\/code><code class=\"php variable\">$this<\/code><code class=\"php plain\">-&gt;pluginList-&gt;getNext(<\/code><code class=\"php variable\">$this<\/code><code class=\"php plain\">-&gt;subjectType, <\/code><code class=\"php string\">'clean'<\/code><code class=\"php plain\">); :<\/code><\/strong><\/p>\n\n\n\n<p>in this line inside clean method we are loading all the plugin for the class method clean(), and you can see that &#8220;pluginList&#8221; property used which was initialized &nbsp;by calling the ___init() method inside the constructor,&nbsp;<strong><code class=\"php variable\">$pluginInfo <\/code><\/strong> will have the information about the plugin like when plugin need to be called around, after or before.<\/p>\n\n\n\n<p>then it check if there is any plugin configured or not, if not it calls the original parent method<\/p>\n\n\n\n<p><strong><code class=\"php plain\">parent::clean(<\/code><code class=\"php variable\">$object<\/code><code class=\"php plain\">);<\/code><\/strong><\/p>\n\n\n\n<p>otherwise your parent method will be called.<\/p>\n\n\n\n<p><strong><code class=\"php variable\">$this<\/code><\/strong><code class=\"php plain\"><code class=\"php plain\"><\/code><\/code><strong>-&gt;___callPlugins:<\/strong> this will call the plugin method according to around, after or before listeners.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Why interceptors need to be generated automatically :<\/h3>\n\n\n\n<p>As we can see there is uncertainty that which class interceptor is needed, there can be any class which need to be customized according to the requirement, so it is best to generate the class automatically when a plugin is found in the di.xml file.<\/p>\n\n\n\n<p>That&#8217;s all for now, I&#8217;ll discuss proxy design pattern in my next article, till then if you have any doubt in this blog you can ask me in the comments below.<\/p>\n\n\n\n<p>Thanks \ud83d\ude42<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In my previous blog, we tried to understand the concept of code generation and why it is needed, along with the concept of factory code generation. In this blog, we will understand the interceptor pattern and code generation. As we know design patterns are used to solve specific problems and interceptor design pattern also used <a href=\"https:\/\/webkul.com\/blog\/magento2-interceptor-pattern-code-generation\/\">[&#8230;]<\/a><\/p>\n","protected":false},"author":33,"featured_media":60192,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[302],"tags":[3672,3830,3831,3832,42],"class_list":["post-62589","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-magento2","tag-code-generation","tag-magento2-interceptor","tag-magento2-plugin","tag-pattern","tag-plugin"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v24.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Magento 2 Interceptor pattern and Code Generation<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/webkul.com\/blog\/magento2-interceptor-pattern-code-generation\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Magento 2 Interceptor pattern and Code Generation\" \/>\n<meta property=\"og:description\" content=\"In my previous blog, we tried to understand the concept of code generation and why it is needed, along with the concept of factory code generation. In this blog, we will understand the interceptor pattern and code generation. As we know design patterns are used to solve specific problems and interceptor design pattern also used [...]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/webkul.com\/blog\/magento2-interceptor-pattern-code-generation\/\" \/>\n<meta property=\"og:site_name\" content=\"Webkul Blog\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/webkul\/\" \/>\n<meta property=\"article:published_time\" content=\"2016-10-22T15:37:23+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2026-04-24T12:03:26+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2016\/09\/Magneto-Code-Snippet-1.png\" \/>\n\t<meta property=\"og:image:width\" content=\"825\" \/>\n\t<meta property=\"og:image:height\" content=\"260\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Ashutosh Srivastava\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@webkul\" \/>\n<meta name=\"twitter:site\" content=\"@webkul\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Ashutosh Srivastava\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"4 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/webkul.com\/blog\/magento2-interceptor-pattern-code-generation\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/webkul.com\/blog\/magento2-interceptor-pattern-code-generation\/\"},\"author\":{\"name\":\"Ashutosh Srivastava\",\"@id\":\"https:\/\/webkul.com\/blog\/#\/schema\/person\/5555025750ec4e4df34fadc78b083970\"},\"headline\":\"Magento 2 Interceptor pattern and Code Generation\",\"datePublished\":\"2016-10-22T15:37:23+00:00\",\"dateModified\":\"2026-04-24T12:03:26+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/webkul.com\/blog\/magento2-interceptor-pattern-code-generation\/\"},\"wordCount\":766,\"commentCount\":2,\"publisher\":{\"@id\":\"https:\/\/webkul.com\/blog\/#organization\"},\"image\":{\"@id\":\"https:\/\/webkul.com\/blog\/magento2-interceptor-pattern-code-generation\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2016\/09\/Magneto-Code-Snippet-1.png\",\"keywords\":[\"code generation\",\"magento2 interceptor\",\"magento2 plugin\",\"pattern\",\"plugin\"],\"articleSection\":[\"Magento2\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/webkul.com\/blog\/magento2-interceptor-pattern-code-generation\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/webkul.com\/blog\/magento2-interceptor-pattern-code-generation\/\",\"url\":\"https:\/\/webkul.com\/blog\/magento2-interceptor-pattern-code-generation\/\",\"name\":\"Magento 2 Interceptor pattern and Code Generation\",\"isPartOf\":{\"@id\":\"https:\/\/webkul.com\/blog\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/webkul.com\/blog\/magento2-interceptor-pattern-code-generation\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/webkul.com\/blog\/magento2-interceptor-pattern-code-generation\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2016\/09\/Magneto-Code-Snippet-1.png\",\"datePublished\":\"2016-10-22T15:37:23+00:00\",\"dateModified\":\"2026-04-24T12:03:26+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/webkul.com\/blog\/magento2-interceptor-pattern-code-generation\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/webkul.com\/blog\/magento2-interceptor-pattern-code-generation\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/webkul.com\/blog\/magento2-interceptor-pattern-code-generation\/#primaryimage\",\"url\":\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2016\/09\/Magneto-Code-Snippet-1.png\",\"contentUrl\":\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2016\/09\/Magneto-Code-Snippet-1.png\",\"width\":825,\"height\":260},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/webkul.com\/blog\/magento2-interceptor-pattern-code-generation\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/webkul.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Magento 2 Interceptor pattern and Code Generation\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/webkul.com\/blog\/#website\",\"url\":\"https:\/\/webkul.com\/blog\/\",\"name\":\"Webkul Blog\",\"description\":\"\",\"publisher\":{\"@id\":\"https:\/\/webkul.com\/blog\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/webkul.com\/blog\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/webkul.com\/blog\/#organization\",\"name\":\"WebKul Software Private Limited\",\"url\":\"https:\/\/webkul.com\/blog\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/webkul.com\/blog\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2021\/08\/webkul-logo-accent-sq.png\",\"contentUrl\":\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2021\/08\/webkul-logo-accent-sq.png\",\"width\":380,\"height\":380,\"caption\":\"WebKul Software Private Limited\"},\"image\":{\"@id\":\"https:\/\/webkul.com\/blog\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/webkul\/\",\"https:\/\/x.com\/webkul\",\"https:\/\/www.instagram.com\/webkul\/\",\"https:\/\/www.linkedin.com\/company\/webkul\",\"https:\/\/www.youtube.com\/user\/webkul\/\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/webkul.com\/blog\/#\/schema\/person\/5555025750ec4e4df34fadc78b083970\",\"name\":\"Ashutosh Srivastava\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/webkul.com\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/2f5312e6903909ffeb33aa5eb38e1c0bed8f498f92144f5f84065adf7e8708a6?s=96&d=https%3A%2F%2Fcdnblog.webkul.com%2Fblog%2Fwp-content%2Fuploads%2F2019%2F10%2Fmike.png&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/2f5312e6903909ffeb33aa5eb38e1c0bed8f498f92144f5f84065adf7e8708a6?s=96&d=https%3A%2F%2Fcdnblog.webkul.com%2Fblog%2Fwp-content%2Fuploads%2F2019%2F10%2Fmike.png&r=g\",\"caption\":\"Ashutosh Srivastava\"},\"sameAs\":[\"http:\/\/webkul.com\"],\"url\":\"https:\/\/webkul.com\/blog\/author\/ashutosh\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Magento 2 Interceptor pattern and Code Generation","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/webkul.com\/blog\/magento2-interceptor-pattern-code-generation\/","og_locale":"en_US","og_type":"article","og_title":"Magento 2 Interceptor pattern and Code Generation","og_description":"In my previous blog, we tried to understand the concept of code generation and why it is needed, along with the concept of factory code generation. In this blog, we will understand the interceptor pattern and code generation. As we know design patterns are used to solve specific problems and interceptor design pattern also used [...]","og_url":"https:\/\/webkul.com\/blog\/magento2-interceptor-pattern-code-generation\/","og_site_name":"Webkul Blog","article_publisher":"https:\/\/www.facebook.com\/webkul\/","article_published_time":"2016-10-22T15:37:23+00:00","article_modified_time":"2026-04-24T12:03:26+00:00","og_image":[{"width":825,"height":260,"url":"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2016\/09\/Magneto-Code-Snippet-1.png","type":"image\/png"}],"author":"Ashutosh Srivastava","twitter_card":"summary_large_image","twitter_creator":"@webkul","twitter_site":"@webkul","twitter_misc":{"Written by":"Ashutosh Srivastava","Est. reading time":"4 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/webkul.com\/blog\/magento2-interceptor-pattern-code-generation\/#article","isPartOf":{"@id":"https:\/\/webkul.com\/blog\/magento2-interceptor-pattern-code-generation\/"},"author":{"name":"Ashutosh Srivastava","@id":"https:\/\/webkul.com\/blog\/#\/schema\/person\/5555025750ec4e4df34fadc78b083970"},"headline":"Magento 2 Interceptor pattern and Code Generation","datePublished":"2016-10-22T15:37:23+00:00","dateModified":"2026-04-24T12:03:26+00:00","mainEntityOfPage":{"@id":"https:\/\/webkul.com\/blog\/magento2-interceptor-pattern-code-generation\/"},"wordCount":766,"commentCount":2,"publisher":{"@id":"https:\/\/webkul.com\/blog\/#organization"},"image":{"@id":"https:\/\/webkul.com\/blog\/magento2-interceptor-pattern-code-generation\/#primaryimage"},"thumbnailUrl":"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2016\/09\/Magneto-Code-Snippet-1.png","keywords":["code generation","magento2 interceptor","magento2 plugin","pattern","plugin"],"articleSection":["Magento2"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/webkul.com\/blog\/magento2-interceptor-pattern-code-generation\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/webkul.com\/blog\/magento2-interceptor-pattern-code-generation\/","url":"https:\/\/webkul.com\/blog\/magento2-interceptor-pattern-code-generation\/","name":"Magento 2 Interceptor pattern and Code Generation","isPartOf":{"@id":"https:\/\/webkul.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/webkul.com\/blog\/magento2-interceptor-pattern-code-generation\/#primaryimage"},"image":{"@id":"https:\/\/webkul.com\/blog\/magento2-interceptor-pattern-code-generation\/#primaryimage"},"thumbnailUrl":"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2016\/09\/Magneto-Code-Snippet-1.png","datePublished":"2016-10-22T15:37:23+00:00","dateModified":"2026-04-24T12:03:26+00:00","breadcrumb":{"@id":"https:\/\/webkul.com\/blog\/magento2-interceptor-pattern-code-generation\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/webkul.com\/blog\/magento2-interceptor-pattern-code-generation\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/webkul.com\/blog\/magento2-interceptor-pattern-code-generation\/#primaryimage","url":"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2016\/09\/Magneto-Code-Snippet-1.png","contentUrl":"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2016\/09\/Magneto-Code-Snippet-1.png","width":825,"height":260},{"@type":"BreadcrumbList","@id":"https:\/\/webkul.com\/blog\/magento2-interceptor-pattern-code-generation\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/webkul.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Magento 2 Interceptor pattern and Code Generation"}]},{"@type":"WebSite","@id":"https:\/\/webkul.com\/blog\/#website","url":"https:\/\/webkul.com\/blog\/","name":"Webkul Blog","description":"","publisher":{"@id":"https:\/\/webkul.com\/blog\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/webkul.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/webkul.com\/blog\/#organization","name":"WebKul Software Private Limited","url":"https:\/\/webkul.com\/blog\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/webkul.com\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2021\/08\/webkul-logo-accent-sq.png","contentUrl":"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2021\/08\/webkul-logo-accent-sq.png","width":380,"height":380,"caption":"WebKul Software Private Limited"},"image":{"@id":"https:\/\/webkul.com\/blog\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/webkul\/","https:\/\/x.com\/webkul","https:\/\/www.instagram.com\/webkul\/","https:\/\/www.linkedin.com\/company\/webkul","https:\/\/www.youtube.com\/user\/webkul\/"]},{"@type":"Person","@id":"https:\/\/webkul.com\/blog\/#\/schema\/person\/5555025750ec4e4df34fadc78b083970","name":"Ashutosh Srivastava","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/webkul.com\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/2f5312e6903909ffeb33aa5eb38e1c0bed8f498f92144f5f84065adf7e8708a6?s=96&d=https%3A%2F%2Fcdnblog.webkul.com%2Fblog%2Fwp-content%2Fuploads%2F2019%2F10%2Fmike.png&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/2f5312e6903909ffeb33aa5eb38e1c0bed8f498f92144f5f84065adf7e8708a6?s=96&d=https%3A%2F%2Fcdnblog.webkul.com%2Fblog%2Fwp-content%2Fuploads%2F2019%2F10%2Fmike.png&r=g","caption":"Ashutosh Srivastava"},"sameAs":["http:\/\/webkul.com"],"url":"https:\/\/webkul.com\/blog\/author\/ashutosh\/"}]}},"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/posts\/62589","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/users\/33"}],"replies":[{"embeddable":true,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/comments?post=62589"}],"version-history":[{"count":18,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/posts\/62589\/revisions"}],"predecessor-version":[{"id":536386,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/posts\/62589\/revisions\/536386"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/media\/60192"}],"wp:attachment":[{"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/media?parent=62589"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/categories?post=62589"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/tags?post=62589"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}