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 13 Mar 2011 04:52 PM by  Steve L
How to vary price based on custom attributes (color, size, fabric, etc.).
 0 Replies
Sort:
You are not authorized to post a reply.
Author Messages


Veteran Member


Posts:2957
Veteran Member


--
13 Mar 2011 04:52 PM
    Here's a common question on how to allow customers to choose size, color, etc and vary the price of a product based on the selection without creating a product variant entry for each possible combination. In v2.0, you can now create price modifier rules that trigger on form inputs you added in product's Dynamic Form Code.

    Suppose, you need to provide the option of choosing the size and color. You want to charge $2 extra for Large and $1 extra for the color "Red":

    In the product's Dynamic Form Code, add the following HTML and ASP.NET code (you can also download the free Visual Studio Express edition to help you draw HTML and drag-and-drop ASP.NET controls without coding and then paste into the textbox). Essentially we're putting two dropdown boxes called CustomSizeDropDownList and CustomColorDropDownList so customers can select between size and color:

    <table cellpadding="3" cellspacing="0" style="width: 100%">
    <tr>
    <td style="width: 80px" width="100">
    Fabric:</td>
    <td>
    <asp:DropDownList ID="CustomSizeDropDownList" runat="server" Width="200px"
    AutoPostBack="True" CausesValidation="True">
    <asp:ListItem>Small</asp:ListItem>
    <asp:ListItem>Medium</asp:ListItem>
    <asp:ListItem>Large</asp:ListItem>
    </asp:DropDownList>
    </td>
    </tr>
    <tr>
    <td style="width: 80px">
    Color:</td>
    <td>
    <asp:DropDownList ID="CustomColorDropDownList" runat="server" Width="200px"
    AutoPostBack="True" CausesValidation="True">
    <asp:ListItem>Blue</asp:ListItem>
    <asp:ListItem>Brown</asp:ListItem>
    <asp:ListItem>Green</asp:ListItem>
    <asp:ListItem>Red</asp:ListItem>
    </asp:DropDownList>
    </td>
    </tr>
    </table>

    Now in the product variant pricing's Modifier Rule, you want to trigger a price modifier based on the selected values. We store the selected price addition value in a variable and towards the end, we perform a sum of the base price with the values of the variables:

    <xsl:transform version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema">
    <xsl:template match="/">

    <xsl:variable name="sizeAdd">
    <xsl:choose>
    <xsl:when test="in/this/salesOrderDetail/dynamicFormResult/fields/field[@id = 'CustomSizeDropDownList']/selected = 'Large'">2.00</xsl:when>
    <xsl:otherwise>0.00</xsl:otherwise>
    </xsl:choose>
    </xsl:variable>

    <xsl:variable name="colorAdd">
    <xsl:choose>
    <xsl:when test="in/this/salesOrderDetail/dynamicFormResult/fields/field[@id = 'CustomColorDropDownList']/selected = 'Red'">1.00</xsl:when>
    <xsl:otherwise>0.00</xsl:otherwise>
    </xsl:choose>
    </xsl:variable>

    <out>
    <price>
    <xsl:value-of select="in/product/productVariant/basePrice + $sizeAdd + $colorAdd" />
    </price>
    </out>
    </xsl:template>
    </xsl:transform>

    In future versions, we'll make it even easier by wrapping visual user interface around these XSL rules so you won't need to code anything! :)


    0
    You are not authorized to post a reply.