Crediting Volume with a Coupon

Coupons reduce the total of an order. This much is obvious; however, some may have that a coupon reduces the qualifying volume, as well.

Suppose you want the Associate to receive the full qualifying volume even if they use a coupon. In that case, you can change use the GetCouponAdjustedVolume Hook with the following in your Extension.



Overriding the Base Functionality

Full Example

namespace Demo
{
    public class ExtensionEntry : IExtension
    {
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddScoped<IHook<GetCouponAdjustedVolumeHookRequest, GetCouponAdjustedVolumeHookResponse>, GetCouponVolume>(); 
        }

        public class GetCouponVolume : IHook<GetCouponAdjustedVolumeHookRequest, GetCouponAdjustedVolumeHookResponse>
        {
            public GetCouponAdjustedVolumeHookResponse Invoke(GetCouponAdjustedVolumeHookRequest request,Func<GetCouponAdjustedVolumeHookRequest, GetCouponAdjustedVolumeHookResponse> func)
            {
                return new GetCouponAdjustedVolumeHookResponse
                {
                    CouponAdjustedVolume = new CouponAdjustedVolume { Cv = request.Volume.Cv, Qv = request.Volume.Qv }
                };
            }
        
    }
}

Let's break this example into sections:

1. Declare GetCouponVolume Class

In ExtensionEntry.cs, declare a class called GetCouponVolume that inherits the IHook interface:

namespace Demo
{
    public class ExtensionEntry : IExtension
    {
          public class GetCouponVolume : IHook<GetCouponAdjustedVolumeHookRequest, GetCouponAdjustedVolumeHookResponse>

IHook is a generic interface that represents any Hook in the system. We're using it to grab the GetCouponAdjustedVolume Hook.

2. Invoke the GetCouponAdjustedVolume Hook

Next, invoke the Hook within the GetCouponVolume class:

{
      public GetCouponAdjustedVolumeHookResponse Invoke(GetCouponAdjustedVolumeHookRequest request, Func<GetCouponAdjustedVolumeHookRequest, GetCouponAdjustedVolumeHookResponse> func)
}

3. Return the Hook response

In the Hook, return the Hook response:

return new GetCouponAdjustedVolumeHookResponse

4. Adjust the volume

In the Hook response, adjust the volume with the CouponAdjustedVolume class:

        return new GetCouponAdjustedVolumeHookResponse
        {
          CouponAdjustedVolume = new CouponAdjustedVolume { Cv = request.Volume.Cv, Qv = request.Volume.Qv }
        };

5. Register the Hook

Finally, register the Hook under the ConfigureServices method:

services.AddScoped<IHook<GetCouponAdjustedVolumeHookRequest, GetCouponAdjustedVolumeHookResponse>, GetCouponVolume>(); 

Did this page help you?