Search code examples
commerceserver2007microsoft-commerce-server

How to make a discount apply to only one shipping method in Commerce Server 2007?


I searched and searched for an answer for this seemingly simple question in Commerce Server 2007, but have found nothing useful. This seems like something that should be possible. How to make a discount apply to only one shipping method in Commerce Server 2007?


Solution

  • I've run into this problem before, I had a scenario where the standard delivery option was the only one that would ever be discounted and the next day and international options would always be full price.

    In this instance I wrote a custom pipeline component which removed any shipping discounts if any other shipping method other than the standard was selected.

    I added this scriptor component into the total pipeline below the ShippingDiscountAdjust component, it's a bit of a hack as I've hardcoded the standard deliveries id in, but that won't ever change so I could get away with it:

        function MSCSExecute(config, orderform, context, flags)
    
            Dim shipments        ' SimpleList of shipments in the basket
            Dim shipment        ' An shipment dictionary from the list
            Dim sShipmentID
    
            ' Save shipping discounts for each shipment (as written by ShippingDiscountAdjust)
            If not isNull(orderForm.Value("shipments")) then
                Set shipments = orderForm.Value("shipments")    
                For Each shipment in shipments            
                   sShipmentID = shipment("shipping_method_id")
                Next
    
                if sShipmentID <> "{00000000-0000-0000-0000-005719007655}" and orderForm.value("_cy_shipping_discounts_total") > 0 then
                    orderform.value("_shipping_discount_description") = ""
    
                    For Each shipment in shipments            
                         orderForm.value("_cy_shipping_total") =orderForm.value("_cy_shipping_total")  + shipment.value("_cy_shipping_discounts_subtotal")
                         shipment.value("_cy_shipping_discounts_subtotal") = 0
                    Next
    
                    orderForm.value("_cy_shipping_discounts_total") = 0
                end if
            End If
    
            MSCSExecute = 1
        end function
    
        sub MSCSOpen(config)
    
        end sub
    
    
        sub MSCSClose()
    
        end sub