我是Shopware的新手。 我知道如何添加自定义属性,但我无法找到如何使其可搜索。我被困。 有必要将ISBN字段添加到产品中,并使其与项目编号一样可搜索。 我看到了this并下载了这个插件的#34; ZIP包"在那里,但我从中得到的一切都是搜索结果页面上的致命错误:
Facet ShopwarePlugins\SwagESProduct\SearchBundle\SalesFacet not supported in engine/Shopware/Bundle/SearchBundleDBAL/ProductNumberSearch.php on line 196 Stack trace: #0 engine/Shopware/Bundle/SearchBundleDBAL/ProductNumberSearch.php(149): Shopware\Bundle\SearchBundleDBAL\ProductNumberSearch->getFacetHandler(Object(ShopwarePlugins\SwagESProduct\SearchBundle\SalesFacet)) #1 engine/Shopware/Bundle/SearchBundleDBAL/ProductNumberSearch.php(96): Shopware\Bundle\SearchBundleDBAL\ProductNumberSearch->createFacets(Object(Shopware\Bundle\SearchBundle\Criteria), Object(Shopware\Bundle\StoreFrontBundle\Struct\ShopContext)) #2 engine/Shopware/Bundle/SearchBundle/ProductSearch.php(65): Shopware\Bundle\SearchBundleDBAL\ProductNumberSearch->search(Object(Shopware\Bundle\SearchBundle\Criteria), Object(Shopware\Bundle\StoreFrontBundle\Struct\ShopContext)) #3 engine/Shopware/Controllers/Frontend/Search.php(76): Shopware\Bundle\SearchBundle\ProductSearch->search(Object(Shopware\Bundle\SearchBundle\Criteria), Object(Shopware\Bundle\StoreFrontBundle\Struct\ShopContext)) #4 engine/Library/Enlight/Controller/Action.php(159): Shopware_Controllers_Frontend_Search->defaultSearchAction() #5 engine/Library/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 engine/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 vendor/symfony/http-kernel/HttpCache/HttpCache.php(448): Shopware\Components\HttpCache\AppCache->forward(Object(Symfony\Component\HttpFoundation\Request), true) #11 vendor/symfony/http-kernel/HttpCache/HttpCache.php(344): Symfony\Component\HttpKernel\HttpCache\HttpCache->fetch(Object(Symfony\Component\HttpFoundation\Request), true) #12 engine/Shopware/Components/HttpCache/AppCache.php(178): Symfony\Component\HttpKernel\HttpCache\HttpCache->lookup(Object(Symfony\Component\HttpFoundation\Request), true) #13 vendor/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 {main}
请大家解释一下如何在Shopware中搜索产品属性并给出正常的工作示例? Shopware版本为5.2.21以防万一。
这就是我的所作所为:
发动机/ Shopware /插件/社区/前/ IsbnSearch / bootstrap.php中:
use ShopwarePlugins\IsbnSearch\SearchTermQueryBuilder\SearchTermQueryBuilder; /** * Class Shopware_Plugins_Frontend_IsbnSearch_Bootstrap */ class Shopware_Plugins_Frontend_IsbnSearch_Bootstrap extends Shopware_Components_Plugin_Bootstrap { public function install() { $this->subscribeEvent( 'Enlight_Bootstrap_AfterInitResource_shopware_search_es.search_term_query_builder', 'decorateSearchTermQueryBuilder' ); return true; } public function decorateSearchTermQueryBuilder() { $searchTermQueryBuilder = new SearchTermQueryBuilder( $this->get('shopware_search_es.search_term_query_builder') ); Shopware()->Container()->set('shopware_search_es.search_term_query_builder', $searchTermQueryBuilder); } }
发动机/ Shopware /插件/社区/前/ IsbnSearch / SearchTermQueryBuilder / SearchTermQueryBuilder.php:
namespace ShopwarePlugins\IsbnSearch\SearchTermQueryBuilder; use ONGR\ElasticsearchDSL\Query\BoolQuery; use ONGR\ElasticsearchDSL\Query\MultiMatchQuery; use Shopware\Bundle\SearchBundleES\SearchTermQueryBuilderInterface; use Shopware\Bundle\StoreFrontBundle\Struct\ShopContextInterface; class SearchTermQueryBuilder implements SearchTermQueryBuilderInterface { /** * @var SearchTermQueryBuilderInterface */ private $decoratedQueryBuilder; /** * @param SearchTermQueryBuilderInterface $decoratedQueryBuilder */ public function __construct(SearchTermQueryBuilderInterface $decoratedQueryBuilder) { $this->decoratedQueryBuilder = $decoratedQueryBuilder; } /** * @param ShopContextInterface $context * @param $term * @return BoolQuery */ public function buildQuery(ShopContextInterface $context, $term) { $query = $this->decoratedQueryBuilder->buildQuery($context, $term); $matchQuery = new MultiMatchQuery( ['attributes.properties.swag_es_product.isbn'], $term ); $query->add($matchQuery, BoolQuery::SHOULD); return $query; } }
我删除了剩下的代码。因为它只是抛出上面的错误。但看起来还不够。 这里是如何创建属性的:
$service = $this->container->get('shopware_attribute.crud_service'); $service->update('s_articles_attributes', 'isbn', 'string'); $service->update('s_articles_attributes', 'isbn', 'string', [ 'label' => 'ISBN', 'supportText' => 'ISBN', 'helpText' => 'ISBN', 'translatable' => true, 'displayInBackend' => true, 'entity' => 'Shopware\Models\Article\Article', 'position' => 140, 'custom' => true, 'unique' => true, ]);