Page 1 of 1
Decorator get no result
Posted: 13 May 2022, 07:44
by ahmed31916
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":
At the end, NO result appear. Where is the problem?
Re: Decorator get no result
Posted: 13 May 2022, 13:47
by ahmed31916
@Aimeos
Where is the problem?
Re: Decorator get no result
Posted: 14 May 2022, 07:18
by aimeos
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
Re: Decorator get no result
Posted: 14 May 2022, 08:12
by ahmed31916
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'],
]
]
]
],
],
Re: Decorator get no result
Posted: 15 May 2022, 10:49
by ahmed31916
Unfortunately, the problem is still not resolved.
"Aimeos\Base\View\Helper\Partial\Standard::transform(): Argument #1 ($file) must be of type string, array given"
Re: Decorator get no result
Posted: 16 May 2022, 06:38
by aimeos
Remove the configuration because it's wrong:
Code: Select all
'common' => [
'partials' => [
'products' => [
'decorators' => [
'global' => ['ProductWomenTemplate'],
]
]
]
],
Re: Decorator get no result
Posted: 16 May 2022, 07:51
by ahmed31916
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;
}
}
Re: Decorator get no result
Posted: 17 May 2022, 14:32
by aimeos
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.
Re: Decorator get no result
Posted: 17 May 2022, 20:31
by ahmed31916
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)
Re: Decorator get no result
Posted: 18 May 2022, 06:07
by aimeos
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"