Developer forum

Forum » Development » Fixed amount discount for productgroep

Fixed amount discount for productgroep


Reply

Hi All,

 

Ik would like to add a discount to my shoppingcart when a customer adds a product from a specific productgroup. The discount should be added once, not for each product which is added. As far as I know this is not possible witht the default discount options, so I tried writing a custom SalesDiscountProvider.

 

Does anyone has a suggestion which AddInParameters to use, and how to use them? I read the documentation which is available, but that didn't help me. A code example would be appreciated!

 

Kind regards,

Jan Michiel Bruijn


Replies

 
Reply

I would simply use a Dynamicweb.Extensibility.Editors.ProductGroupParameterEditor for specifying the group. The rest of the interface is built automatically.

 
Reply

Hi Lars,

 

Thanks for your reply. I created my custom discount, using the ProductGroupParameterEditor. This works fine, the interface is built correcty, and the discout is added to my cart once. But, the discount is added for products of others groups too. I don't know how to check if the discount needs to be added. Do you have a code sample of how to check the products in the cart and the groups selected woth the discount?

 

Jan Michiel Bruijn

 
Reply

Please note that the parameter editor only allows the user to interact with your code and manipulate with the value of a property in the SalesDiscount class. You need to implement the rules that apply in order to grant the discount yourself. Thus, you need to check whether or not to grant this discount, and you could do so by matching the products in the OrderLines collection of the Order object against the range of groups chosen with the parameter editor by the administrator in backend.

 

The Groups property of the Product object contains a collection of Groups where the current product is present, and by matching each group's ID property against the selected ones, you can verify whether to grant the discount or not.

 

I'm sorry, I don't have an example, but please let me know if this is not adequate to get you closer to what you're trying to acheive.

 
Reply

Lars,

 

My problem is that I don't know how to save the group which is selected when the discount is created, and how to retrieve it to check if the discount needs to be applied. You say it needs to be assigned to a property of the SalesDiscount class, but which property? Currently my code has the following property, I know that when the property is set, the value contains the selected groupId, but I don't know how to handle the value. You can can see the question marks in my code, I hope you can tell me what to put there.

 

 

[AddInParameter("ProductGroups"),
AddInParameterEditor(typeof(ProductGroupParameterEditor), "")]
public string ProductGroups
{
 get { return ??; }
 set { ?? = value; }
}
 

 

Thank again!

Jan Michiel Bruijn

 
Reply

Don't worry about that. The property value is automatically filled when your discount class is invoked, so the get method should simply return the selected value without you doing anything to save or load this piece of information. The Extensibility API does that for you.

 
Reply

Lars,

 

That's it! Thanks!

 

Jan Michiel Bruijn

 
Reply

No problem, let me know how you get along:)

 

You must be logged in to post in the forum