Creating a subcomponent

How to configure and adapt Aimeos based shops as developer
Forum rules
Always add your Aimeos and PHP version as well as your environment (Linux/Mac/Win)
User avatar
aimeos
Administrator
Posts: 2934
Joined: 01 Jan 1970, 00:00

Re: Creating a subcomponent

Post by aimeos » 19 Aug 2015, 16:07

Luke wrote:are you able to give me an example directory structure and class name / filename
You don't need to create a new class for removing a component.
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'),
                ),
            ),
        ),
    ),
As the "client/html/catalog/detail" arrays are already existing, you only need to add the "default" and "subparts" lines including the brackets there. By reordering the list in "subparts", you can also move the parts to other positions :-)

Luke
Posts: 13
Joined: 14 Aug 2015, 21:34

Re: Creating a subcomponent

Post by Luke » 19 Aug 2015, 16:10

perfect thanks :)

Bananamoon
Posts: 26
Joined: 22 Jun 2015, 09:12
Location: Herentals
Contact:

Re: Creating a subcomponent

Post by Bananamoon » 20 Aug 2015, 13:04

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?

Code: Select all

class Client_Html_Catalog_RotexDetail_Default
   extends Client_Html_Catalog_Detail_Default
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 :D

User avatar
aimeos
Administrator
Posts: 2934
Joined: 01 Jan 1970, 00:00

Re: Creating a subcomponent

Post by aimeos » 20 Aug 2015, 13:33

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?
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:

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, ... )
  {
    // ...
  }
}
Add this and other decorators to the catalog detail client only with https://aimeos.org/docs/Configuration/C ... tors/local

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
Bananamoon wrote:And how does the default subcomponent will use this? Do you need to add your own subcomponent in the shop.php config file?
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/name

Bananamoon
Posts: 26
Joined: 22 Jun 2015, 09:12
Location: Herentals
Contact:

Re: Creating a subcomponent

Post by Bananamoon » 20 Aug 2015, 13:42

aimeos wrote:
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?
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:

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, ... )
  {
    // ...
  }
}
Add this and other decorators to the catalog detail client only with https://aimeos.org/docs/Configuration/C ... tors/local

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
Bananamoon wrote:And how does the default subcomponent will use this? Do you need to add your own subcomponent in the shop.php config file?
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/name
Alright! Makes sense :-) Does this also count for, say, Basket?

So you add a decorator in "client/html/basket/decorators/local"?
Thanks for your help, really appreciate it :-)

User avatar
aimeos
Administrator
Posts: 2934
Joined: 01 Jan 1970, 00:00

Re: Creating a subcomponent

Post by aimeos » 20 Aug 2015, 14:44

Bananamoon wrote: Alright! Makes sense :-) Does this also count for, say, Basket?
So you add a decorator in "client/html/basket/decorators/local"?
Like for every code in Aimeos: If it works for one thing, it works for all others which are similar as well ;-)
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 :-)

User avatar
aimeos
Administrator
Posts: 2934
Joined: 01 Jan 1970, 00:00

Re: Creating a subcomponent

Post by aimeos » 21 Aug 2015, 13:33

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! :-)

Bananamoon
Posts: 26
Joined: 22 Jun 2015, 09:12
Location: Herentals
Contact:

Re: Creating a subcomponent

Post by Bananamoon » 03 Sep 2015, 07:32

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! :-)
Hello! First of all, thanks for the update!

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 )
  {
    //
  }
}
This decorator is stored in: ai-project/client/html/basket/mini/decorators/local/Medecorator.php

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
I've tried to change my classname, tried to change the directory where it is stored, but I really have no clue what is going wrong?

Thanks for the help! :)

User avatar
aimeos
Administrator
Posts: 2934
Joined: 01 Jan 1970, 00:00

Re: Creating a subcomponent

Post by aimeos » 03 Sep 2015, 08:25

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:

Code: Select all

class Client_Html_Common_Decorator_Optiphar
    extends Client_Html_Common_Decorator_Abstract
    implements Client_Html_Common_Decorator_Interface
{
}
This decorator is stored in: ai-project/client/html/basket/mini/decorators/local/Medecorator.php
In the shop config file I have this decorator declared in: client/html/basket/mini/decorators/global/mydecorator
For a local decorator, your file name is wrong and it's stored in the wrong directory.

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' )

Bananamoon
Posts: 26
Joined: 22 Jun 2015, 09:12
Location: Herentals
Contact:

Re: Creating a subcomponent

Post by Bananamoon » 03 Sep 2015, 09:31

aimeos wrote:
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:

Code: Select all

class Client_Html_Common_Decorator_Optiphar
    extends Client_Html_Common_Decorator_Abstract
    implements Client_Html_Common_Decorator_Interface
{
}
This decorator is stored in: ai-project/client/html/basket/mini/decorators/local/Medecorator.php
In the shop config file I have this decorator declared in: client/html/basket/mini/decorators/global/mydecorator
For a local decorator, your file name is wrong and it's stored in the wrong directory.

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' )
Yay Error gone! Altho I have no clue what to do now, since I thought that this file would extend/overwrite this file:

Code: Select all

class Client_Html_Basket_Mini_Main_Default
	extends Client_Html_Abstract
I'm at loss, I guess I made the wrong extension or something? :P
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! :)

Post Reply