【发布时间】:2021-06-08 17:22:08
【问题描述】:
我希望主商店搜索包含产品属性。
例如,如果我有一个名为“color”的产品属性,并且有人搜索“red”,我想在搜索结果中包含具有此属性项的产品。
到目前为止,我已经创建了一个订阅 Product Search Criteria Event 的自定义插件。这是我的事件订阅者类:
<?php declare(strict_types=1);
namespace MyPlugin\Subscriber;
use Shopware\Core\Framework\DataAbstractionLayer\Event\EntityLoadedEvent;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Shopware\Core\Content\Product\ProductEvents;
use Shopware\Core\Content\Product\Events\ProductSearchCriteriaEvent;
class CustomSubscriber implements EventSubscriberInterface
{
public static function getSubscribedEvents(): array
{
return [
ProductEvents::PRODUCT_SEARCH_CRITERIA => 'onProductSearch'
];
}
public function onProductSearch(ProductSearchCriteriaEvent $event)
{
$criteria = $event->getCriteria();
$criteria->addAssociation('properties');
dump($event);
}
}
我可以从 dump() 中看到已添加关联。但搜索结果不会改变。我不知道从这里去哪里。
【问题讨论】:
标签: shopware