I want to display names of cities according to state/region selected on Checkout page. I have inserted cities and regions in table via impex. Now I want to fetch the cityname according to regionisocode.
I have created custom facade and defined method getCity(final String city) and getCity(final String regionIso, final String cityIso). Declared bean in spring.xml. I have also created interface GrocerymateCheckoutService Please help me with writing its logic for implementation. Attaching class file for reference please help with logic in methods.What will be the code in below picture?
CodePudding user response:
To fetch items from database you can use FlexibleSearchService - it is the standard way of getting models from database. To follow Hybris convention you can create DAO in which you can write your query which should be something like
select {pk} from {City} where {cityName}=?cityName
,
then pass the query to flexible search service (don't forget to pass the cityName argument value as well.
CodePudding user response:
You can use getModelsByExample
public List<CityModel> getCityName(String name){
CityModel example = new CityModel();
example.setName(name);
List<CityModel> resultList = new ArrayList<>();
resultList = flexibleSearchService.getModelsByExample(example);
return resultList;
}