Forum

The forum is a free service supported by community members. Please consider opening a support ticket if you need timely help.

PrevPrev Go to previous topic
NextNext Go to next topic
Last Post 11 Oct 2018 01:03 PM by  Kenyatta Harris
Flat discount with coupon
 2 Replies
Sort:
You are not authorized to post a reply.
Author Messages


Basic Member


Posts:158
Basic Member


--
27 Sep 2018 08:35 PM
    Hi,

    I want to give a $50 discount to anyone with the coupon code I created. The coupon is for anything in the store. However the system is giving the discount based on each item in the cart. I can't use percentage because the prices vary. Here's the custom rule for flat discount with coupon. How do I change the amount to a flat rate of $50? If there is one item in the cart discount $50. if there is more than one item discount $50.

    <xsl:transform version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:template match="/">
    <out>
    <discountAmount>
    <!-- Coupon code is always tested in lowercase -->
    <xsl:if test="in/salesOrder/couponCodes[couponCode = 'free2']" >
    <xsl:value-of select="-0.10 * in/this/salesOrderDetail/amount" />
    </xsl:if>
    </discountAmount>
    </out>
    </xsl:template>
    </xsl:transform>

    Please advise,

    Kenyatta


    0


    Basic Member


    Posts:394
    Basic Member


    --
    10 Oct 2018 06:39 PM

    Hi Kenyatta

    The Storefront is Avalara certified for tax compliance. In normal accounting practice, a discount needs to be subtracted from something materially sold so that the appropriate tax due can be calculated for each product sold against its net final price after discount. This makes sense for the same reason you can't give a $50 discount if the user buys less than $50 as it will come to a negative total. A easy way is to check the order exceeds $50 subtotal and simply split the $50 discount proportionally to each sales order detail amount relative to the subtotal.

    <xsl:transform xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0">
    <xsl:template match="/">
    <out>
    <xsl:variable name="SubTotalExclDiscounts" select="sum(in/salesOrder/salesOrderDetails/salesOrderDetail/amount)"/>
    <xsl:if test="in/salesOrder/couponCodes[couponCode = 'free2'] and $SubTotalExclDiscounts > 50">
    <discountAmount>
    <xsl:value-of select="-50 * (/in/this/salesOrderDetail/amount div $SubTotalExclDiscounts)"/>
    </discountAmount>
    </xsl:if>
    </out>
    </xsl:template>
    </xsl:transform>


    0


    Basic Member


    Posts:158
    Basic Member


    --
    11 Oct 2018 01:03 PM

    Thank you JT... Works great!

    0
    You are not authorized to post a reply.