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>