Creating a subcomponent
Forum rules
Always add your Aimeos and PHP version as well as your environment (Linux/Mac/Win)
Spam and unrelated posts will be removed immediately!
Always add your Aimeos and PHP version as well as your environment (Linux/Mac/Win)
Spam and unrelated posts will be removed immediately!
Re: Creating a subcomponent
You don't need to create a new class for removing a component.Luke wrote:are you able to give me an example directory structure and class name / filename
If you are using e.g. Laravel, add this to your "./config/shop.php" file:
Code: Select all
'client' => array(
'html' => array(
'catalog' => array(
'detail' => array(
'default' => array(
'subparts' => array('image', 'basic', 'actions', 'basket', 'bundle', 'additional', 'suggest', 'bought', 'seen'),
),
),
),
),
-
- Posts: 26
- Joined: 22 Jun 2015, 09:12
Re: Creating a subcomponent
So what if you do have to change some params in _setViewParams? You do have to change the name of your class, right?
Like this as Luke defined?
And how does the default subcomponent will use this? Do you need to add your own subcomponent in the shop.php config file?
Just so my brain understands lol
Like this as Luke defined?
Code: Select all
class Client_Html_Catalog_RotexDetail_Default
extends Client_Html_Catalog_Detail_Default
Just so my brain understands lol
Re: Creating a subcomponent
The best way would be to create a decorator, e.g. "Client_Html_Common_Decorator_Rotex" and add the required values in the getBody() and getHeader() methods. This is the preferable way over subclassing because you can add several independent decorators to the class via configuration:Bananamoon wrote:So what if you do have to change some params in _setViewParams? You do have to change the name of your class, right?
Code: Select all
class Client_Html_Common_Decorator_Rotex extends Client_Html_Common_Decorator_Abstract
{
public function getBody(...)
{
$view = $this->setView( $this->_setViewParams( $this->getView() ) );
return $this->_getClient()->getBody();
}
protected function _setViewParams( $view, ... )
{
// ...
}
}
In very special cases when only subclassing is an option, than you should create a class named like this:
Code: Select all
class Client_Html_Catalog_Detail_Rotex
extends Client_Html_Catalog_Detail_Default
To use the alternative "Rotex" implementation, you have to configure it's name in the config file. For the catalog detail class itself it's https://aimeos.org/docs/Configuration/C ... etail/nameBananamoon wrote:And how does the default subcomponent will use this? Do you need to add your own subcomponent in the shop.php config file?
-
- Posts: 26
- Joined: 22 Jun 2015, 09:12
Re: Creating a subcomponent
Alright! Makes sense Does this also count for, say, Basket?aimeos wrote:The best way would be to create a decorator, e.g. "Client_Html_Common_Decorator_Rotex" and add the required values in the getBody() and getHeader() methods. This is the preferable way over subclassing because you can add several independent decorators to the class via configuration:Bananamoon wrote:So what if you do have to change some params in _setViewParams? You do have to change the name of your class, right?Add this and other decorators to the catalog detail client only with https://aimeos.org/docs/Configuration/C ... tors/localCode: Select all
class Client_Html_Common_Decorator_Rotex extends Client_Html_Common_Decorator_Abstract { public function getBody(...) { $view = $this->setView( $this->_setViewParams( $this->getView() ) ); return $this->_getClient()->getBody(); } protected function _setViewParams( $view, ... ) { // ... } }
In very special cases when only subclassing is an option, than you should create a class named like this:Code: Select all
class Client_Html_Catalog_Detail_Rotex extends Client_Html_Catalog_Detail_Default
To use the alternative "Rotex" implementation, you have to configure it's name in the config file. For the catalog detail class itself it's https://aimeos.org/docs/Configuration/C ... etail/nameBananamoon wrote:And how does the default subcomponent will use this? Do you need to add your own subcomponent in the shop.php config file?
So you add a decorator in "client/html/basket/decorators/local"?
Thanks for your help, really appreciate it
Re: Creating a subcomponent
Like for every code in Aimeos: If it works for one thing, it works for all others which are similar as wellBananamoon wrote: Alright! Makes sense Does this also count for, say, Basket?
So you add a decorator in "client/html/basket/decorators/local"?
For the standard basket, the configuration would be: https://aimeos.org/docs/Configuration/C ... tors/local
Simply wait for the minor release of the core tomorrow. Then everything will work as described
Re: Creating a subcomponent
Soo, the new Aimeos core release is out (2015.07.4 for the Aimeos Laravel and Symfony 1.1 packages) and we've added an article about decorators for HTML clients as well: https://aimeos.org/docs/Developers/Html ... components
Have fun!
Have fun!
-
- Posts: 26
- Joined: 22 Jun 2015, 09:12
Re: Creating a subcomponent
Hello! First of all, thanks for the update!aimeos wrote:Soo, the new Aimeos core release is out (2015.07.4 for the Aimeos Laravel and Symfony 1.1 packages) and we've added an article about decorators for HTML clients as well: https://aimeos.org/docs/Developers/Html ... components
Have fun!
I've been trying to actually implement this, for the mini basket but fail to complete it so far.
Here's what I got:
Code: Select all
class Client_Html_Common_Decorator_Optiphar
extends Client_Html_Common_Decorator_Abstract
implements Client_Html_Common_Decorator_Interface
{
protected function _setViewParams( MW_View_Interface $view, array &$tags = array(), &$expire = null )
{
//
}
}
In the shop config file I have this decorator declared in:
client/html/basket/mini/decorators/global/mydecorator
I get the following error:
Code: Select all
Client_Html_Exception in Abstract.php line 62:
Class "Client_Html_Common_Decorator_Optiphar" not found
Thanks for the help!
Re: Creating a subcomponent
For a local decorator, your file name is wrong and it's stored in the wrong directory.Bananamoon wrote: I've been trying to actually implement this, for the mini basket but fail to complete it so far.
Here's what I got:This decorator is stored in: ai-project/client/html/basket/mini/decorators/local/Medecorator.phpCode: Select all
class Client_Html_Common_Decorator_Optiphar extends Client_Html_Common_Decorator_Abstract implements Client_Html_Common_Decorator_Interface { }
In the shop config file I have this decorator declared in: client/html/basket/mini/decorators/global/mydecorator
It needs to be named "Client_Html_Basket_Mini_Decorator_Optiphar" and stored in "ai-project/client/html/src/Client/Html/Basket/Mini/Decorator/Optiphar.php". The configuration must be
Code: Select all
client/html/basket/mini/decorators/local = array( 'Optiphar' )
-
- Posts: 26
- Joined: 22 Jun 2015, 09:12
Re: Creating a subcomponent
Yay Error gone! Altho I have no clue what to do now, since I thought that this file would extend/overwrite this file:aimeos wrote:For a local decorator, your file name is wrong and it's stored in the wrong directory.Bananamoon wrote: I've been trying to actually implement this, for the mini basket but fail to complete it so far.
Here's what I got:This decorator is stored in: ai-project/client/html/basket/mini/decorators/local/Medecorator.phpCode: Select all
class Client_Html_Common_Decorator_Optiphar extends Client_Html_Common_Decorator_Abstract implements Client_Html_Common_Decorator_Interface { }
In the shop config file I have this decorator declared in: client/html/basket/mini/decorators/global/mydecorator
It needs to be named "Client_Html_Basket_Mini_Decorator_Optiphar" and stored in "ai-project/client/html/src/Client/Html/Basket/Mini/Decorator/Optiphar.php". The configuration must be
Code: Select all
client/html/basket/mini/decorators/local = array( 'Optiphar' )
Code: Select all
class Client_Html_Basket_Mini_Main_Default
extends Client_Html_Abstract
My main purpose is to show the products I put in my basket, instead of just the amount of products. I would like to add that to the cache so it loads quicker, so I figured I have to extend/overwrite above file and rewrite the _setViewParams.
Thanks again for your help! You're awesome!