【问题标题】:Shopware 6 Include properties in storefront searchShopware 6 在店面搜索中包含属性
【发布时间】: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


    【解决方案1】:

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

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

    【讨论】:

    • 非常感谢您分享您的插件。它工作得很好!我应该说的一件事是我忘记使用 - bin/console dal:refresh:index 更新索引 - 一旦我这样做了,它就像一个魅力。再次感谢!
    猜你喜欢
    • 2022-07-07
    • 2022-10-02
    • 1970-01-01
    • 2022-11-12
    • 2023-01-29
    • 2023-01-20
    • 1970-01-01
    • 2023-03-13
    • 2021-08-01
    相关资源
    最近更新 更多