# How can i override controller function inside custom plugins in shopware ?

**URL:** <https://forum.shopware.com/t/how-can-i-override-controller-function-inside-custom-plugins-in-shopware/56056>\
**Category:** International (English Only)\
**Tags:** programming, shopping-worlds\
**Created:** [29. Oktober 2018 um 10:53 UTC](https://forum.shopware.com/t/how-can-i-override-controller-function-inside-custom-plugins-in-shopware/56056 "2018-10-29T10:53:33Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![ansarhusain](https://avatars.discourse-cdn.com/v4/letter/a/cc9497/32.png) [@ansarhusain](https://forum.shopware.com/u/ansarhusain)\
**Post date:** [29. Oktober 2018 um 10:53 UTC](https://forum.shopware.com/t/how-can-i-override-controller-function-inside-custom-plugins-in-shopware/56056/1 "2018-10-29T10:53:33Z")

</div>

I am trying to override&nbsp;Enlight\_Controller\_Action\_Backend\_Article\_Save inside custom plugin like below .

public static function getSubscribedEvents()  
&nbsp; &nbsp; {  
&nbsp; &nbsp; &nbsp; &nbsp; return [  
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ‘Enlight\_Controller\_Action\_Backend\_Article\_Save’ =\> ‘onSave’  
&nbsp; &nbsp; &nbsp; &nbsp; ];  
&nbsp; &nbsp; }

public function onSave()  
&nbsp; &nbsp; {  
&nbsp; &nbsp; &nbsp; &nbsp; $data = $this-\>Request()-\>getParams();

&nbsp; &nbsp; &nbsp; &nbsp; if ($this-\>Request()-\>has(‘id’)) {  
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; /\*\* @var Article $article \*/  
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $article = $this-\>getRepository()-\>find((int) $this-\>Request()-\>getParam(‘id’));  
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // Check whether the article has been modified in the meantime  
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $lastChanged = new \DateTime($data[‘changed’]);

&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if ($article-\>getChanged()-\>getTimestamp() != $lastChanged-\>getTimestamp()) {

&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $namespace = Shopware()-\>Snippets()-\>getNamespace(‘backend/article/controller/main’);

&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $this-\>View()-\>assign([  
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ‘success’ =\> false,  
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ‘overwriteAble’ =\> true,  
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ‘data’ =\> $this-\>getArticle($article-\>getId()),  
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ‘message’ =\> $namespace-\>get(‘article\_has\_been\_changed’, ‘The article has been changed in the meantime. To prevent overwriting these changes, saving the article was aborted. Please close the article and re-open it.’),  
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ]);  
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;  
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return;  
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }  
&nbsp; &nbsp; &nbsp; &nbsp; } else {  
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $article = new Article();  
&nbsp; &nbsp; &nbsp; &nbsp; }

&nbsp; &nbsp; &nbsp; &nbsp; $this-\>saveArticle($data, $article);  
&nbsp; &nbsp; }

&nbsp;

**Now i am getting error&nbsp;Fatal error: &nbsp;Call to undefined method OrderSample\OrderSample::Request()**

&nbsp;

**Thanks**
