Developer forum

Forum » Feature requests » Create interface for custom sales discount provider using voucherlist

Create interface for custom sales discount provider using voucherlist

Martin Jensen
Reply

Hi

Im trying to create a custom sales discount provider that utilizes a voucherlist.

Unfortunately the VoucherList class (VoucherList.vb) only looks for specific derived types when dealing with voucherlists. The following methods are the culprits:

GetUnusedVoucherLists

CheckDiscount

GetDiscountForList

This makes it hard to create a custom discount provider that uses a voucherlist and at the same time keep as much of the standard functionality as possible (mailing vouchers to users etc.).

 

Optimally I would like some interface to implement when creating my custom provider. ex:

Public Class MyCustomVoucherListDiscountProvider
        Inherits SalesDiscountProvider
        Implements IUsesVoucherList

 

version: 8.8.1


Replies

 
Nicolai Pedersen
Reply

Hi Martin

I can see that - that is some ugly code... Will add an item regarding this, but cannot promise anything. TFS#38789.

What are you trying to achieve - maybe ther is another approach.

BR Nicolai

 
Martin Jensen
Reply

L8 response -> I need to add some extra configuration fields to the discountprovider that is then used in the processOrder() function. This is something the customer needs to be able to configure themselves so im not sure a complicated workaround is a good option. We even talked about just rewriting the original OrderFieldDiscountUniqueVoucher.vb and then recompile the dll.. Thats a whole other kind of hell though :/ So instead ill keep poking you with this thread :)

 
Anders Ebdrup
Anders Ebdrup
Reply

Hi Nicolai,

 

Have you had time to think about a solution or a workaround for this issue without having to compile our own version of Dynamicweb?

 

Best regards, Anders

 
Nicolai Pedersen
Reply

We did not fix that specific problem, but we added a PromoCodeChecker feature: https://doc.dynamicweb.com/api/html/19274ddd-dfd4-ea82-964a-a1de6d0653af.htm

Will that solve you problem?

BR Nicolai

 
Anders Ebdrup
Anders Ebdrup
Reply

Hi Nicolai,

 

That sounds a bit interesting, but I still need to be able to send out the voucher codes by using the standard functionality in DW.

Can we do that in some kind of way?

 

Best regards, Anders

 
Nuno Aguiar Dynamicweb Employee
Nuno Aguiar
Reply

Hi Nicolai,

 

Can you confirm that's only available in package 1.4, and that DW 9.3.4 ships with package 1.3.4?

 

I was trying to refactor my code to use this method, but I can't seem to find it.

 

Best Regards,

Nuno

 
Nicolai Pedersen
Reply

@Anders: The sending is handled by Dynamicweb voucher module. The above API is to check against those vouchers in custom code. So I think the answer is yes???

@Nuno: Sounds right.

 
Anders Ebdrup
Anders Ebdrup
Reply

Hi Nicolai,

 

The issue is that I have a custom discount provider which uses vouchers, and I need to send out these vouchers and I would love to be able to use the standard functionality in DW to do this, but right now the discount types are hardcoded into the system

 
Anders Ebdrup
Anders Ebdrup
Reply

Hello again,

 

Will it be possible to send out vouchers with a custom voucher discount provider in a future version of 9.3?

 

Best regards, Anders

 
Nicolai Pedersen
Reply

Hi Anders

Can you ellaborate? The providers calculate the discount based on the provider. How and to who should it send what?

NP

 
Anders Ebdrup
Anders Ebdrup
Reply

Hi Nicolai,

 

Yes for sure. Please see this screenshot: https://www.screencast.com/t/26BQ8Tu35R where you cannot see the associated discount provider and it is not possible to send out the vouchers as information about the discount is not avaiable as tags in the mail.

 

Best regards, Anders

 
Anders Ebdrup
Anders Ebdrup
Reply

Hi Nicolai,

 

Can this be solved in the 9-branch? Or can I use some work around to do this right?

 
Nicolai Pedersen
Reply

Hi Anders

I am very confused... Can you describe what you want?

BR Nicolai

 
Anders Ebdrup
Anders Ebdrup
Reply

Hi Nicolai,

 

When do you expect a release of DW to hit the streets with this change?

 

Best regards, Anders

 
Anders Ebdrup
Anders Ebdrup
Reply

Hi Nicolai,

 

Has this issue been addressed yet`?

 

Best regards, Anders

 
Anders Ebdrup
Anders Ebdrup
Reply

Hi Nicolai,

 

Can you please give me an update on this one?

 

Best regards, Anders

 
Nicolai Pedersen
Reply

Hi Anders

It has been implemented and will arrive with 9.4. TFS#43842.

You get a Dynamicweb.Ecommerce.Orders.SalesDiscounts.IProductDiscount (https://doc.dynamicweb.com/api/html/9f6f7ce8-9a59-203a-8863-b26464baf16d.htm) that needs to be implemented on a SalesDiscount provider.

BR Nicolai

 
Anders Ebdrup
Anders Ebdrup
Reply

Absolutely awesome! Thank you! :-)

 
Tobias Belling
Reply

Hi Nicolai.

Does it work with the old salesdiscount or the new discount matrix?

Best Regards,
Tobias B. Christensen

 
Nicolai Pedersen
Reply

The IProductDiscount interface is only for salesdiscounts providers - discount matrix cannot be extended.

BR Nicolai

 
Anders Ebdrup
Anders Ebdrup
Reply

Hi Nicolai,

 

This is still not working - please see the voucher list from the backend https://www.screencast.com/t/P4MyiBX3Wd where I am missing my custom discount provider.

The custom discount provider is not available due to this code block:

Private Shared Function CheckDiscount(salesDiscount As SalesDiscount, listId As String) As Boolean
    Select Case salesDiscount.DiscountType
        Case GetType(OrderFieldDiscountUniqueVoucher).FullName
            Dim orderFieldDiscountUniqueVoucher As New OrderFieldDiscountUniqueVoucher()
            orderFieldDiscountUniqueVoucher.LoadParametersFromXml(salesDiscount.Parameters)
            Return (orderFieldDiscountUniqueVoucher.ListId = listId)
        Case GetType(ProductOrderFieldDiscountUniqueVoucher).FullName
            Dim productOrderFieldDiscountUniqueVoucher As New ProductOrderFieldDiscountUniqueVoucher()
            productOrderFieldDiscountUniqueVoucher.LoadParametersFromXml(salesDiscount.Parameters)
            Return (productOrderFieldDiscountUniqueVoucher.ListId = listId)
        Case Else
            Return False
    End Select
End Function

 

Where only the two internal voucher discount providers is selected. Can this method be extended to also use the new interface?

 

Best regards, Anders

 
Nicolai Pedersen
Reply

Hi Anders

I seem to have mixed up 2 different things - the product discount and voucher discounts... So it is not possible to make this as it is right now.

I've implemented IVoucherlistDiscount interface instead of the hardcoded provider names. In testing, will be out as soon as possible /(Next Tuesday)

BR Nicolai

 
Anders Ebdrup
Anders Ebdrup
Reply

Thanks, will this be available in 9.4.x (Ecommerce 1.4.x)?

 
Nicolai Pedersen
Reply

It currently is not (TFS#38789).

It has not been tested yet, so I cannot merge it just yet... Awaiting test and will merge if QA ok's it.

BR Nicolai