on 2018 Mar 05 4:18 PM
Hi,I have a requirement whereby I want to hide a product on the front end based on the product attribute.I am trying to implement FacetSearchListener.But I am stuck up as to how should I start?Any help would be appreciated.
Request clarification before answering.
Hello ,
You can implement custom FacetSearchListener in new extension.
First generate new extension with 'ant extgen' command from yempty template.
Add two dependencies to extensioninfo.xml:
<requires-extension name="solrfacetsearch"/>
<requires-extension name="solrserver"/>
Add your new extension in localextension.xml:
<?xml version="1.0" encoding="UTF-8"?>
<hybrisconfig xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="resources/schemas/extensions.xsd">
<extensions>
<path dir="${HYBRIS_BIN_DIR}/custom" />
...
<extension name="myextension"/>
...
</extensions>
</hybrisconfig>
Then implement your listener:
public class DefaultFacetSearchListener implements FacetSearchListener
Write your logic to hide product by implementing beforeSearch method:
@Override
public void beforeSearch(final FacetSearchContext facetSearchContext) throws FacetSearchException
{
final SearchQuery searchQuery = facetSearchContext.getSearchQuery();
searchQuery.addRawQuery("name_text_en:(hero^100.0 OR hero*^50.0 OR hero~^25.0)");
}
And finally register bean in myextension-spring.xml:
<bean id="defaultFacetSearchListener" class="com.myextension.listener.DefaultFacetSearchListener">
</bean>
<bean id="defaultFacetSearchListenerDefinition" parent="solrListenerDefinition">
<property name="priority" value="150"/>
<property name="listener" ref="defaultFacetSearchListener"/>
</bean>
Regards,
Paweł Wrzask
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
| User | Count |
|---|---|
| 4 | |
| 2 | |
| 1 | |
| 1 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.