Define a new method for product item class
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!
Define a new method for product item class
Hi
What is the best solution to show only active properties on the product's detail page? (The properties must be shown regardless of status in admin panel - no changes there)
Here's something I came up with, that does work but doesn't seem right:
In `my_ext/controller/frontend/src/Controller/Frontend/Product/Decorator/ActiveProperties.php` a new method is added to product item class
Then in `my_ext/client/html/src/Client/Html/Catalog/Detail/RtlDetail.php` I get active properties:
Is there a way to add decorators to product item?
What is the best solution to show only active properties on the product's detail page? (The properties must be shown regardless of status in admin panel - no changes there)
Here's something I came up with, that does work but doesn't seem right:
In `my_ext/controller/frontend/src/Controller/Frontend/Product/Decorator/ActiveProperties.php` a new method is added to product item class
Code: Select all
namespace Aimeos\Controller\Frontend\Product\Decorator;
class ActiveProperties extends Base
{
public function __construct(\Aimeos\Controller\Frontend\Iface $controller, \Aimeos\MShop\Context\Item\Iface $context)
{
parent::__construct($controller, $context);
\Aimeos\MShop\Product\Item\Standard::method('getEnabledPropertyItems', function ($type = null) use ($context) {
$list = [];
$types = [];
foreach ($this->propItems as $prop) {
$types[] = $prop->getType();
}
$manager = \Aimeos\MShop::create($context, 'product/property/type');
$filter = $manager->filter(true)->add('product.property.type.code', '==', $types);
$enabledTypes = $manager->search($filter)->walk(fn (&$type) => $type = $type->getCode());
foreach ($this->propItems as $propId => $propItem) {
if (($type === null || in_array($propItem->getType(), (array) $type))
&& ($propItem->isAvailable()
&& $enabledTypes->in($propItem->getType()))
) {
$list[$propId] = $propItem;
}
}
return map($list);
});
}
}
Code: Select all
$propItems = $productItem->getEnabledPropertyItems();
Aimeos version: ~2021.07
Laravel version: ^8.40
PHP: 7.4.9
Laravel version: ^8.40
PHP: 7.4.9
Re: Define a new method for product item class
You can't create a decorator for an item but you can create a decorator for the product or product/property manager which intercepts the get()/find()/search() methods and removes the properties you don't want. The "Depth" decorator could be a good start:
https://github.com/aimeos/aimeos-core/b ... /Depth.php
https://github.com/aimeos/aimeos-core/b ... /Depth.php
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, give us a star
If you like Aimeos, give us a star