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 16 Oct 2023 02:50 PM by  J T
Promotion Code
 1 Replies
Sort:
You are not authorized to post a reply.
Author Messages


New Member


Posts:1
New Member


--
14 Oct 2023 04:34 AM
    Hello

    For one of the products I sell I have many colour options and, I'd like to offer a promotion where customers can buy a mix and match of a products colour and save 5 percent on the relevant products.

    Effectively a bulk buy pricing tier that is applied based on the different products you have in your cart. We might have one promotion on Jeans, a different promotion on shirts and another on shoes. I don't want someone to have to buy three of the same shirt to receive the discount, maybe they want to buy any mix of colours.

    So the discount should work with 1 x Blue, 1 x Green and 1 x Red shirt but also apply if someone just adds 3 x Red shirts to cart.

    I have the code working on the individual colour. Say you have 3 Red in cart or 3 Blue in cart it will discount both Blue and Red. But I can't seem to get the code to recognize that perhaps the total of Red and Blue products is above 3. Would someone more knowledgeable have any ideas on where I went wrong?
     

    <xsl:transform version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
      <xsl:output method="xml" indent="yes"/>

      <!-- Variant IDs for which the discount is applicable -->
      <xsl:variable name="discountVariantIDs" select="1323, 1322"/>

      <xsl:template match="/">
        <xsl:variable name="totalQuantity" select="sum(/in/this/salesOrderDetail[productVariantID = $discountVariantIDs]/quantity)" />
        <xsl:if test="$totalQuantity >= 3">
          <out>
            <discountAmount>
              <!-- Calculate discount: 5% of the total price for the specified variant IDs -->
              <xsl:value-of select="-0.05 * sum(/in/this/salesOrderDetail[productVariantID = $discountVariantIDs]/price * /in/this/salesOrderDetail[productVariantID = $discountVariantIDs]/quantity)" />
            </discountAmount>
          </out>
        </xsl:if>
      </xsl:template>
    </xsl:transform>
     

    0


    Basic Member


    Posts:394
    Basic Member


    --
    16 Oct 2023 02:50 PM

    Hi Matt

    I think you need to sum the quantity from the /in/salesOrder/salesOrderDetails node instead of the /in/this/salesOrderDetail.  The /in/this/ is meant to iterate through each order detail.

    <xsl:variable name="totalQuantity" select="sum(/in/salesOrder/salesOrderDetails/salesOrderDetail[productVariantID = $discountVariantIDs]/quantity)" />

     I hope this helps!

    0
    You are not authorized to post a reply.