cancel
Showing results for 
Search instead for 
Did you mean: 

How Can I custom method in Carts Controller (OCC)?

valitaruy
Member
0 Kudos

Hello guys, I have the following method which represent a REST inside of OCC Carts Controller:

@Secured({ "ROLE_CUSTOMERGROUP", "ROLE_CUSTOMERMANAGERGROUP", "ROLE_GUEST", "ROLE_TRUSTED_CLIENT" })
    @RequestMapping(value = "/{cartId}/addresses/delivery", method = RequestMethod.POST, consumes = {
            MediaType.APPLICATION_JSON_VALUE, MediaType.APPLICATION_XML_VALUE })
    @ResponseStatus(HttpStatus.CREATED)
    @ResponseBody
    @ApiOperation(nickname = "createCartDeliveryAddress", value = "Creates a delivery address for the cart.", notes = "Creates an address and assigns it to the cart as the delivery address.")
    @ApiBaseSiteIdUserIdAndCartIdParam
    public AddressWsDTO createCartDeliveryAddress(@ApiParam(value =
            "Request body parameter that contains details such as the customer's first name (firstName), the customer's last name (lastName), the customer's title (titleCode), the customer's phone (phone), "
                    + "the country (country.isocode), the first part of the address (line1), the second part of the address (line2), the town (town), the postal code (postalCode), and the region (region.isocode).\n\nThe DTO is in XML or .json format.", required = true) @RequestBody final AddressWsDTO address,
            @ApiParam(value = "Response configuration. This is the list of fields that should be returned in the response body.", allowableValues = "BASIC, DEFAULT, FULL") @RequestParam(defaultValue = DEFAULT_FIELD_SET) final String fields)
    {
        LOG.debug("createCartDeliveryAddress");
        validate(address, OBJECT_NAME_ADDRESS, getAddressDTOValidator());
        AddressData addressData = getDataMapper().map(address, AddressData.class, ADDRESS_MAPPING);
        addressData = createAddressInternal(addressData);
        setCartDeliveryAddressInternal(addressData.getId());
        return getDataMapper().map(addressData, AddressWsDTO.class, fields);
    }

I would like to modify the default mmapin from AddressWsDTO to AddressData object. As you can see this line makes the mapping:

AddressData addressData = getDataMapper().map(address, AddressData.class, ADDRESS_MAPPING);

But this mapping is only allowed for specific fields which are represented by variable ADDRESS_MAPPING.

I need to aggregate more fields but this class is read only. Additionally, the above variable is a private attribute of Carts Controller class.

private static final String ADDRESS_MAPPING = "firstName,lastName,titleCode,phone,line1,line2,town,postalCode,country(isocode),region(isocode),defaultAddress";

I would like to know if exists a way where I don't have to create another method in another controller for only modify this default mapping.

Thanks a lot in advance!

Accepted Solutions (0)

Answers (1)

Answers (1)

former_member844475
Discoverer
0 Kudos

Hello,

Here is the SAP CC doc to follow to be able to override any OCC controller :
https://help.sap.com/viewer/3476714bba0b4cb9b3eb58c270e44439/v2011/en-US/d46d19516961438f8939718e87e...