Decorator get no result

Help for integrating the Laravel package
Forum rules
Always add your Laravel, Aimeos and PHP version as well as your environment (Linux/Mac/Win)
Spam and unrelated posts will be removed immediately!
User avatar
ahmed31916
Posts: 47
Joined: 14 Apr 2022, 12:15

Decorator get no result

Post by ahmed31916 » 13 May 2022, 07:44

Hello,

I'm trying to add new data to the view object required by the product template, (from my extension).
I create decorator path "myextension\src\Client\Html\Common\Decorator\my_product_decorator.php", and put this code in it:

Code: Select all

namespace Aimeos\Client\Html\Common\Decorator;

class my_product_decorator 
            extends \Aimeos\Client\Html\Common\Decorator\Base 
            implements \Aimeos\Client\Html\Common\Decorator\Iface
{
    public function data( \Aimeos\Base\View\Iface $view, array &$tags = [], string &$expire = null ) : \Aimeos\Base\View\Iface
	{
        $view = parent::data( $view, $tags, $expire );
        $view->descripto= 'some description';

        return $view;	
    }
}
and put the "config/shop.php" like this:

Code: Select all

	'client' => [
		'common' => [
			'partials' => [
				'product' => [
					'decorators' => [
						'global' => 'my_product_decorator',
					]
				]
			]
		],
		],
	],
Now, I'm trying to get the value of the "descripto" from the decorator, so I add this in "myextension\templates\client\html\common\partials\products.php":

Code: Select all

<?= $this->get( 'descripto' ) ?>
At the end, NO result appear. Where is the problem?

User avatar
ahmed31916
Posts: 47
Joined: 14 Apr 2022, 12:15

Re: Decorator get no result

Post by ahmed31916 » 13 May 2022, 13:47

@Aimeos
Where is the problem?

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

Re: Decorator get no result

Post by aimeos » 14 May 2022, 07:18

First, you should use another class name like "ProductMyproject" (replace "Myproject" by your project name).

Then, your configuration is wrong and you have to configure the decorator for a component (or all components), e.g.:

Code: Select all

	'client' => [
		'html' => [
			'catalog' => [
				'detail' => [
					'decorators' => [
						'global' => ['ProductMyproject'],
					]
				]
			]
		],
	],
https://aimeos.org/docs/2022.x/config/c ... il/#global
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, Image give us a star

User avatar
ahmed31916
Posts: 47
Joined: 14 Apr 2022, 12:15

Re: Decorator get no result

Post by ahmed31916 » 14 May 2022, 08:12

Thanks, I edit it, and got this error: "Aimeos\Base\View\Helper\Partial\Standard::transform(): Argument #1 ($file) must be of type string, array given"

the complete error trace:
https://flareapp.io/share/V7jLOMjm#F65

the config:

Code: Select all

	'html' => [
		'common' => [
			'partials' => [
				'products' => [
					'decorators' => [
						'global' => ['ProductWomenTemplate'],
					]
				]
			]
		],
	],

User avatar
ahmed31916
Posts: 47
Joined: 14 Apr 2022, 12:15

Re: Decorator get no result

Post by ahmed31916 » 15 May 2022, 10:49

Unfortunately, the problem is still not resolved.

"Aimeos\Base\View\Helper\Partial\Standard::transform(): Argument #1 ($file) must be of type string, array given"

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

Re: Decorator get no result

Post by aimeos » 16 May 2022, 06:38

Remove the configuration because it's wrong:

Code: Select all

		'common' => [
			'partials' => [
				'products' => [
					'decorators' => [
						'global' => ['ProductWomenTemplate'],
					]
				]
			]
		],
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, Image give us a star

User avatar
ahmed31916
Posts: 47
Joined: 14 Apr 2022, 12:15

Re: Decorator get no result

Post by ahmed31916 » 16 May 2022, 07:51

Nothing changed :| .

I want to know is the namespace is correct? and the return value is $view?
and the aregument interface of the function is correct?

Code: Select all

namespace Aimeos\Client\Html\Common\Decorator;

class my_product_decorator 
            extends \Aimeos\Client\Html\Common\Decorator\Base 
            implements \Aimeos\Client\Html\Common\Decorator\Iface
{
    public function data( \Aimeos\Base\View\Iface $view, array &$tags = [], string &$expire = null ) : \Aimeos\Base\View\Iface
	{
        $view = parent::data( $view, $tags, $expire );
        $view->descripto= 'some description';

        return $view;	
    }
}

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

Re: Decorator get no result

Post by aimeos » 17 May 2022, 14:32

Namespace is correct but your configuration is not because "common/partial/products" is now an array but it must be a string. Check again and clear the Laravel config cache if necessary.
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, Image give us a star

User avatar
ahmed31916
Posts: 47
Joined: 14 Apr 2022, 12:15

Re: Decorator get no result

Post by ahmed31916 » 17 May 2022, 20:31

thanks for your response.
is now an array but it must be a string
would you write a complete config for it, please! (it made me tired)

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

Re: Decorator get no result

Post by aimeos » 18 May 2022, 06:07

Like written, the correct configuration is:

Code: Select all

	'client' => [
		'html' => [
			'catalog' => [
				'detail' => [
					'decorators' => [
						'global' => ['ProductMyproject'],
					]
				]
			]
		],
	],
and remove:

Code: Select all

		'common' => [
			'partials' => [
				'products' => [
					'decorators' => [
						'global' => ['ProductWomenTemplate'],
					]
				]
			]
		],
If you want to use different product partials use this instead:

Code: Select all

		'common' => [
			'partials' => [
				'products' => 'common/partials/product-woman'
			]
		],
The template file must be in: "templates/client/html/common/partials/product-woman.php"
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, Image give us a star

Post Reply