Reputation: 267
I'm trying to create my custom web service and I want to apply a global discount in the cart and recalculate it. I've created a custom addOn for my OCC call, but I'm struggling with the DTO concept and how to implement my method. Basically, the code I use to add a global discount so far is this:
recalculating via the calculation service
applyDiscount(@RequestParam(required = true) Double value) cartService.addGlobalDiscountValue(cartModel, new DiscountValue(“description”, double, value, cartModel.getCurrency().getIsocode())); calculationService.calculateTotals(cartModel, false);
Where should I implement the DTO? Can I use GlobalDiscountRowDTO ? And how to modify the code to be sure I'm using the best practices?
Thanks!
Upvotes: 1
Views: 713
Reputation: 273
You can not use GlobalDiscountRowDTO, this is in the optional platformwebservices extension which seems to be not shared with OCC extensions because it's a different API (there are various REST APIs, v1, v2, and platformwebservices). Instead define your own DTO in your addOn's *-beans.xml.
Also heads up that a DiscountValue is not persisted (try applying the DiscountValue, then go to your cart on the frontend and modify the cart contents, the discount will be gone). Instead check out the DiscountModel class which can be persisted.
Upvotes: 1
Reputation: 181
Please note that *DTO classes are called *Data (e.g. GlobalDiscountRowData) classes in Hybris. The purpose of Data classes is to pass information from Model layer to the View layer (for example web controller will return Data objects and not a Model objects).
Before to start create custom logic please check Out Of The Box (OOTB) functionality like: DefaultDiscountDao, DefaultDiscountService, FindOrderDiscountValuesStrategy, etc.
To find out base practices the Hybris packages and extensions are good point to start. Just look the OOTB classes and class relations and context xml definitions.
Upvotes: 1