Shopware 6 在店面搜索中包含属性

Shopware 6 Include properties in storefront search

我希望主要商店搜索包括产品属性。

例如,如果我有一个名为“颜色”的产品 属性,并且有人搜索“红色”,我想在搜索结果中包含具有此 属性 项的产品.

到目前为止,我已经创建了一个订阅 产品搜索条件事件 的自定义插件。这是我的活动订阅者 class:

<?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()中可以看出已经添加了关联。但搜索结果没有改变。我不确定从这里到哪里去。

我之前在我的插件中这样做过:https://github.com/mnaczenski/MNExtendSearch/blob/master/src/Service/MySearchKeywordAnalyser.php#L113

基本上,您扩展 SearchKeywordAnalyser 并将您的自定义数据添加到搜索索引。