Extending Shop classes

I am not sure if extending a class should be done with the full namsespace

class XController extends \OxidEsales\Eshop\Application\Controller\FrontendController

``
or it should be extanded as

class XController extends FrontendController_parent

what i am sure about is that I get an Error whenever i use the _parent syntaxe
Is the documentation outdated or am i doing something work?
of course i am using this in metadata:

'extend' => [
		// Component Widgets
		\OxidEsales\Eshop\Application\Controller\FrontendController::class => \CMP\WEB\Controllers\XController::class 
]

Try class XController extends XController_parent

If you want to build your own class which acts just like some existing oxid classes, you extend your class the same way as the oxid classes do, so you would use:

class XController extends \OxidEsales\Eshop\Application\Controller\FrontendController

And you do NOT need an entry in “extends” for that, because no oxid class is changed, you just made your own controller. Your own classes used to be in the “files” array in Oxid 4.x, but with namespaces, this is no longer needed. But, in order to use your new frontend controller in a browser, you have to give it a key in the “controllers” array:

'controllers'  => [
    'xcontroller' =>  \CMP\WEB\Controllers\XController::class,
],

This key has to be unique and lowercase, and with this key you can call your controller like:

index.php?cl=xcontroller
1 Like

The “parent” syntax is used when you want to change the behaviour of an existing class, like if you want to add some functionality to articles or categories. Then you would use:

'extend'      => array(
    \OxidEsales\Eshop\Core\Config::class => \My\Namespace\Config::class,
),

and in the file:

class Config extends Config_parent

(No need to rename the class because it is namespaced).

So, if your goal is to change the behaviour of FrontendController for all existing controllers, this would seem the way to go, but unfortunately this is not possible, you can only change classes that are not extended by other classes, and are directly instantiated with “oxnew”.

Oxid Team, should work on the documentation, how could such an information not included in docs

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.