Posts

Showing posts with the label help.hybris

Hybris enumtype static Vs dynamic

In Hybris, we can declare two type of enum, Static and Dynamic. Which basically differ by dynamic attribute (dynamic="false" and dynamic="true"). In simple words, I can say static enum( dynamic="false" ) is generated as the Java enum. In which list of values can only be changed during compilation time by changing the items.xml. In case of the dynamic enum( dynamic="true" ) we can change(add/remove) its values at runtime using hmc or Impex. Regardless of an Enum type(Static/Dynamic), all its values get stored in  enumerationvalues  table. You can fetch all values using below flexible query. select * from { enumerationvalue } Static Enum: <enumtype code="FixedValueType" autocreate="true" generate="true"> <value code="value1"/> <value code="value2"/> </enumtype> By default, the dynamic attribute is false(dynamic="false"). You

get models by example in Hybris

Sometimes, we are required to fetch data from our custom Item type in Hybris. So first thing comes to our mind is to write flexible search query. But you really don't need to do that if you know Hybris OOTB has  getModelByExample  and  getModelsByExample  API of  flexibleSearchService , using which we can easily get the desired results. Scenario Find CustomProduct having the same name Solution You can create a method in DAO class. In which you need to create example model by setting required field (e.g name). Now call getModelsByExample method of the flexibleSearchService with exampleModel. public List < CustomProductModel > findProductHavingSameName ( final String name ) { CustomProductModel exampleModel = new CustomProductModel (); exampleModel . setName ( name ); return getFlexibleSearchService (). getModelsByExample ( exampleModel ); }

How to configure catalog sync cronjob in Hybris?

Image
 How to create custom catalog synchronization job in Hybris? Scenario My client wants to have product catalog sync cronjob. So the first thing that came to my mind was, It's quite easy, by creating an instance of  CatalogSyncCronJob  and assign it to appropriate sync job(Product Sync stage to Online) and trigger. But it won't work like that. CatalogVersionSyncJob is designed to run only once with each instance.  So if we create sync job instance by ImpEx/HMC, it will not get any newly / modified items in the second execution. because system needs a new instance for each sync execution! Wondering, how catalog synchronization works when we do it form Hybris HMC(Catalog Management Tool > Synchronization)? If we execute catalog sync from Catalog Management Tool, then each time, Hybris internally creates a new instance of selected sync job. Hence, it can detect new or modified items to sync. Solution We can write the custom job, which basically does t

How to redirect or forward request in Hybris?

What is basic difference between request Redirect Vs Forward? Redirect:  Server sends a header (in response) back to the browser/client, which contain redirect URL, then browser initiates a new request to redirect URL. Browser creates a new request to the redirected URL. The browser displays the redirected URL. The client browser is involved. Redirect is slower. When can we use Redirect? @RequestMapping(value = "/originalurl", method = {RequestMethod.POST}) public String method(final Model model) { // ... return "redirect:/redirectToGeturl"; } Usually, when data is posted to the server, we should redirect to get method(URL). So browser displays redirected URL(/redirectToGeturl). Which also prevent data resubmission on browser refreshed(F5) as the request to will go to redirected URL(/redirectToGeturl). Forward:  Within the server, control can be forwarded to target resource(URL). Which is done by container internally so browser/clie

How to remove or update all data records in Hybris?

Scenario 1: I want to remove all the data from the Hybris ItemType. Solution: If you want to remove all records for particular itemType. Then you can do it using HAC Impex import. Open HAC (/hac) Go to console > ImpEx Import Run the below Impex (Change MyItemType with the ItemType for which you want to remove the data) $targetType=MyItemType REMOVE $targetType[batchmode=true];itemtype(code)[unique=true] ;$targetType Scenario 2: Sometimes, you want to remove selected data based on some condition or probably want to run complex SQL query. Then we wish if we could do it by writing SQL query, as many of developers are aware of syntax and its resources are easily available. Solution: Yes, you can do it in Hybris HAC also. Only thing is you should know the appropriate table and attribute/fields names in DB. If you don't, you can always run the select flexible search query and can see generated SQL query. Open HAC (/hac) Go to console > FlexibleSearch Se

How to block certain URLs access for some user type in Hybris?

Scenario: How to block certain URLs access for some user type in Hybris? Solution: In general, we should maintain spring  Authorities/group  for such users so that it can be blocked from  spring-security . But in my case, I don't have that choice. There are already many userType which can be identified when the user logged in and stored it in session. Here I have to use same. So I have decided to use Spring AOP to serve my aspect around the point-cut(custom annotation). In this post, I am not going to cover AOP in detail. If you don't know anything about  Spring AOP . You should first  explore it  first. 1. Create Annotation AllowUsers and BlockUsers package com . hybris . storefront . annotations ; import java . lang . annotation . ElementType ; import java . lang . annotation . Retention ; import java . lang . annotation . RetentionPolicy ; import java . lang . annotation . Target ; @Retention ( RetentionPolicy . RUNTIME ) @Target ( { ElementType . M