cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Adding a new parameter to Commercecartservice

1,386

Hello guys,

What are the steps or what is the best practice for adding a new parameter to an existing method of CommerceCartService?

Thanks in advance for your time and help.

Accepted Solutions (1)

Accepted Solutions (1)

geffchang
Active Contributor

The best practice is to extend CommerceCartParameter. In beans.xml, do something like:

<bean>
  <property name="customProperty" type="String">
    <description>My custom property</description>
  </property>
  ...
</bean>

See Extending CommerceCartService: https://help.sap.com/viewer/9d346683b0084da2938be8a285c0c27a/1905/en-US/8bbe2c6a866910149e5ff3b87c0b...

Answers (1)

Answers (1)

Hi Pavel,

I can only share my opinion. I do not know what is your case, but something like this probably may work for you.

Of course don't forget to override the DefaultCommerceCartService to point to the extended version ExtendedDefaultCommerceCartService.

public class ExtendedDefaultCommerceCartService extends DefaultCommerceCartService implements ExtendedCommerceCartService {
@Overridepublic void recalculateCart(CommerceCartParameter parameter, boolean force, boolean newParam) throws CalculationException {
super.recalculateCart(parameter,force); // do what ever you need to do with the newest parameter.
}
}

Best Regards,