Skip to Content
3
Former Member
Jul 26, 2018 at 04:56 PM

b2bcustomer assigned to more than one b2bunit but not showing up

722 Views

Hi Experts,

I have a requirement where a b2bcustomer can switch between b2bunit to place a order. On switch I set defaultB2BUnit to selected unit and it works fine.

Below is the code snippet I use to list all b2bunits. Works fine with groovy script via HAC (Admin user) but fails with java controller.

The current logged in b2bcustomer doesn't have visibility to assigned b2bunits

Hmc:

alt text

Code snippet:

 final B2BCustomerModel user = (B2BCustomerModel) userService.getUserForUID(customerData.getUid());
 final Set<UserGroupModel> groups = userService.getAllUserGroupsForUser(user);
 for (final UserGroupModel group : groups)
 {
     if (group instanceof B2BUnitModel)
     {
 
         B2BUnitModel unit = (B2BUnitModel) group;
         try
         {
             B2BUnitModel unitModel= b2BUnitService.getUnitForUid(group.getUid());
             //Failed to get unit: 0001074238
             //de.hybris.platform.servicelayer.exceptions.UnknownIdentifierException: UserGroupModel with uid '0001074238' not found!
         }
         catch (final Exception e)
         {
             e.printStackTrace();
         }
 
         LOG.info(unit.getUid()); // Looks good
         LOG.info(unit.getName); // null
         LOG.info(unit.getCostCenters()); //null
     }
 }

I tried with Flexible search query to retrieve the b2bunits. Works great via hac but same exception at controller

 private B2BUnitModel getB2BUnit(final String uID)
 {
     final String UNIT_QUERY = " select {u.pk} from {b2bunit as u } where {u.uid}=?uID ";
     List<B2BUnitModel> resultList = new ArrayList<B2BUnitModel>();
     final FlexibleSearchQuery flexQuery = new FlexibleSearchQuery(UNIT_QUERY);
     flexQuery.addQueryParameter("uID", uID);
     final SearchResult<B2BUnitModel> searchResult = flexibleSearchService.search(flexQuery);
 
     if (searchResult != null)
     {
         resultList = searchResult.getResult();
     }
     for (final B2BUnitModel unit : resultList)
     {
         LOG.info("resultList.size() " + resultList.size());
         return unit;
     }
     return null;
 }

 

Attachments