我是 Shopware 的新手。我了解如何添加自定义属性,但我找不到如何使其可搜索。我被困。有必要在产品中添加 ISBN 字段,使其与商品编号一样可搜索。我看到了这个并在那里下载了“这个插件的 ZIP 包”,但是我从中得到的一切都是搜索结果页面上的致命错误:
在第 196 行的 engine/Shopware/Bundle/SearchBundleDBAL/ProductNumberSearch.php 中不支持 Facet ShopwarePlugins\SwagESProduct\SearchBundle\SalesFacet 堆栈跟踪: #0 引擎/Shopware/Bundle/SearchBundleDBAL/ProductNumberSearch.php(149):Shopware\Bundle\SearchBundleDBAL\ProductNumberSearch->getFacetHandler(Object(ShopwarePlugins\SwagESProduct\SearchBundle\SalesFacet)) #1 引擎/Shopware/Bundle/SearchBundleDBAL/ProductNumberSearch.php(96):Shopware\Bundle\SearchBundleDBAL\ProductNumberSearch->createFacets(Object(Shopware\Bundle\SearchBundle\Criteria), Object(Shopware\Bundle\StoreFrontBundle\Struct\ShopContext )) #2 引擎/Shopware/Bundle/SearchBundle/ProductSearch.php(65): Shopware\Bundle\SearchBundleDBAL\ProductNumberSearch->search(Object(Shopware\Bundle\SearchBundle\Criteria), Object(Shopware\Bundle\StoreFrontBundle\Struct\ShopContext )) #3 引擎/Shopware/Controllers/Frontend/Search.php(76): Shopware\Bundle\SearchBundle\ProductSearch->search(Object(Shopware\Bundle\SearchBundle\Criteria), Object(Shopware\Bundle\StoreFrontBundle\Struct\ShopContext )) #4 引擎/库/Enlight/Controller/Action.php(159):Shopware_Controllers_Frontend_Search->defaultSearchAction() #5 引擎/库/Enlight/Controller/Dispatcher/Default.php(523): Enlight_Controller_Action->dispatch('defaultSearchAc...') #6 engine/Library/Enlight/Controller/Front.php(223): Enlight_Controller_Dispatcher_Default->dispatch(Object(Enlight_Controller_Request_RequestHttp), Object(Enlight_Controller_Response_ResponseHttp)) #7 引擎/Shopware/Kernel.php(180): Enlight_Controller_Front->dispatch() #8 vendor/symfony/http-kernel/HttpCache/HttpCache.php(491): Shopware\Kernel->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true) #9 engine/Shopware/Components/HttpCache/AppCache.php(255): Symfony\Component\HttpKernel\HttpCache\HttpCache->forward(Object(Symfony\Component\HttpFoundation\Request), true, NULL) #10 供应商/symfony/http-kernel/HttpCache/HttpCache.php(448): Shopware\Components\HttpCache\AppCache->forward(Object(Symfony\Component\HttpFoundation\Request), true) #11 供应商/symfony/http-kernel/HttpCache/HttpCache.php(344): Symfony\Component\HttpKernel\HttpCache\HttpCache->fetch(Object(Symfony\Component\HttpFoundation\Request), true) #12 引擎/Shopware/Components/HttpCache/AppCache.php(178): Symfony\Component\HttpKernel\HttpCache\HttpCache->lookup(Object(Symfony\Component\HttpFoundation\Request), true) #13 供应商/symfony/http-kernel/HttpCache/HttpCache.php(210): Shopware\Components\HttpCache\AppCache->lookup(Object(Symfony\Component\HttpFoundation\Request), true) #14 engine/Shopware/Components/HttpCache/AppCache.php(114): Symfony\Component\HttpKernel\HttpCache\HttpCache->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true) #15 shopware.php(117): Shopware\Components\HttpCache\AppCache->handle(Object(Symfony\Component\HttpFoundation\Request)) #16 {主要}
请大家解释一下如何使产品属性在 Shopware 中可搜索并给出正常工作示例?Shopware 版本是 5.2.21 以防万一。
这是我所做的:
engine/Shopware/Plugins/Community/Frontend/IsbnSearch/Bootstrap.php:
使用 ShopwarePlugins\IsbnSearch\SearchTermQueryBuilder\SearchTermQueryBuilder; /** * 类 Shopware_Plugins_Frontend_IsbnSearch_Bootstrap */ 类 Shopware_Plugins_Frontend_IsbnSearch_Bootstrap 扩展 Shopware_Components_Plugin_Bootstrap { 公共函数安装() { $this->subscribeEvent( 'Enlight_Bootstrap_AfterInitResource_shopware_search_es.search_term_query_builder', 'decorateSearchTermQueryBuilder' ); 返回真; } 公共函数 decorateSearchTermQueryBuilder() { $searchTermQueryBuilder = 新的 SearchTermQueryBuilder( $this->get('shopware_search_es.search_term_query_builder') ); Shopware()->Container()->set('shopware_search_es.search_term_query_builder', $searchTermQueryBuilder); } }
引擎/商店软件/插件/社区/前端/IsbnSearch/SearchTermQueryBuilder/SearchTermQueryBuilder.php:
命名空间 ShopwarePlugins\IsbnSearch\SearchTermQueryBuilder; 使用 ONGR\ElasticsearchDSL\Query\BoolQuery; 使用 ONGR\ElasticsearchDSL\Query\MultiMatchQuery; 使用 Shopware\Bundle\SearchBundleES\SearchTermQueryBuilderInterface; 使用 Shopware\Bundle\StoreFrontBundle\Struct\ShopContextInterface; 类 SearchTermQueryBuilder 实现 SearchTermQueryBuilderInterface { /** * @var SearchTermQueryBuilderInterface */ 私人 $decoratedQueryBuilder; /** * @param SearchTermQueryBuilderInterface $decoratedQueryBuilder */ 公共函数 __construct(SearchTermQueryBuilderInterface $decoratedQueryBuilder) { $this->decoratedQueryBuilder = $decoratedQueryBuilder; } /** * @param ShopContextInterface $context * @param $term * @return 布尔查询 */ 公共函数 buildQuery(ShopContextInterface $context, $term) { $query = $this->decoratedQueryBuilder->buildQuery($context, $term); $matchQuery = 新的 MultiMatchQuery( ['attributes.properties.swag_es_product.isbn'], $期限 ); $query->add($matchQuery, BoolQuery::SHOULD); 返回$查询; } }
我删除了代码的其余部分。因为它只是抛出了上面的错误。但看起来还不够。以下是属性的创建方式:
$service = $this->container->get('shopware_attribute.crud_service'); $service->update('s_articles_attributes', 'isbn', 'string'); $service->update('s_articles_attributes', 'isbn', 'string', [ '标签' => 'ISBN', 'supportText' => 'ISBN', 'helpText' => 'ISBN', '可翻译' => 真的, 'displayInBackend' => 真, '实体' => 'Shopware\Models\Article\Article', '位置' => 140, '自定义' => 真的, '独特' => 真的, ]);