Important Notice from AspDotNetStorefront
It is with dismay that we report that we have been forced, through the action of hackers, to shut off write-access to this forum. We are keen to leave the wealth of material available to you for research. We have opened a new forum from which our community of users can seek help, support and advice from us and from each other. To post a new question to our community, please visit: http://forums.vortx.com
Results 1 to 4 of 4

Thread: Variants with different minimum quantity XMLPackage (radio buttons)

  1. #1
    usascholar is offline Member
    Join Date
    Jan 2010
    Posts
    64

    Question Variants with different minimum quantity XMLPackage (radio buttons)

    Hi Guys,

    I just got a new package, but it is limited to only providing the minimum quantity of the default variant, when selecting different variants. It is much like the dropdown variant XMLPackage which does the same in V 9.3.1.0

    Basically I wanted to change the form Quantity text box to the appropriate "minimumQuantity" that is associated with the particular variant selected. Currently it's not dynamic, and is stuck with the default variant MinimumQuantity.

    I believe this code is the culprit that limits the functionality:

    Code:
                      function SetCartVariant(selValue)
                      {
                        //alert("AddToCartForm_"+prodid+"_"+varid);
                        var theForm;
                        //v9 compatibility check
                        if(document.forms["aspnetForm"])
                        {
                            theForm = document.forms["aspnetForm"];
                        }
                        else{ //v8
    		                theForm = document.forms["AddToCartForm_<xsl:value-of select="/root/QueryString/productid" />_<xsl:value-of select="$defaultVariant" />"];
                        }
                        if(selValue=='')
                        {
                        alert('Please select a variant to add to the cart');
                        return false;
                        }
                        else
                        {
                            //v9 compatibility check
                            if(theForm.VariantID_<xsl:value-of select="/root/Products/Product/ProductID" />_<xsl:value-of select="$defaultVariant" />)
    		                {
    		                    theForm.VariantID_<xsl:value-of select="/root/Products/Product/ProductID" />_<xsl:value-of select="$defaultVariant" />.value=selValue;
                        }
                      else{
                      theForm.VariantID.value=selValue;
                      }
                      VariantMinimumQty_<xsl:value-of select="/root/Products/Product/ProductID" />_<xsl:value-of select="$defaultVariant" /> = VarMinQty[selValue];
                      SelectedVariantInventory_<xsl:value-of select="/root/Products/Product/ProductID" />_<xsl:value-of select="$defaultVariant" /> = VarInventory[selValue];
                      }
                      }
                      theForm.Quantity_<xsl:value-of select="/root/Products/Product/ProductID" />_<xsl:value-of select="$defaultVariant" />.value= VarMinQty[<xsl:value-of select="$defaultVariant" />];
                      SelectedVariantInventory_<xsl:value-of select="/root/Products/Product/ProductID" />_<xsl:value-of select="$defaultVariant" /> = VarInventory[<xsl:value-of select="$defaultVariant" />];

    In the code above I had added the following to see if I could update the Quantity box of the product page:
    theForm.Quantity_<xsl:value-of select="/root/Products/Product/ProductID" />_<xsl:value-of select="$defaultVariant" />.value= VarMinQty[<xsl:value-of select="$defaultVariant" />];

    But it doesn't seem to make a difference, as it only changes it on first page load.

    Any insight would be helpful.

    Here is more of the functions around the code:
    Code:
                <div class="productPage">
                   <xsl:apply-templates select="/root/Products/Product[isdefault = 1]" />
                </div>
                <xsl:if test="count(/root/Products/Product) &gt; 1">
                    <script type="text/javascript">
                      var VarMinQty = new Array();
                      var VarInventory = new Array();
                      <xsl:for-each select="/root/Products/Product">
                        <xsl:choose>
                          <xsl:when test="MinimumQuantity &gt; 0">
                            VarMinQty[<xsl:value-of select="VariantID" />] = <xsl:value-of select="MinimumQuantity" />;
                          </xsl:when>
                          <xsl:otherwise>
                            VarMinQty[<xsl:value-of select="VariantID" />] = 1;
                          </xsl:otherwise>
                        </xsl:choose>
                        VarInventory[<xsl:value-of select="VariantID" />] = <xsl:value-of select="Inventory" />;
                      </xsl:for-each>
    
                      function SetCartVariant(selValue)
                      {
                        //alert("AddToCartForm_"+prodid+"_"+varid);
                        var theForm;
                        //v9 compatibility check
                        if(document.forms["aspnetForm"])
                        {
                            theForm = document.forms["aspnetForm"];
                        }
                        else{ //v8
    		                theForm = document.forms["AddToCartForm_<xsl:value-of select="/root/QueryString/productid" />_<xsl:value-of select="$defaultVariant" />"];
                        }
                        if(selValue=='')
                        {
                        alert('Please select a variant to add to the cart');
                        return false;
                        }
                        else
                        {
                            //v9 compatibility check
                            if(theForm.VariantID_<xsl:value-of select="/root/Products/Product/ProductID" />_<xsl:value-of select="$defaultVariant" />)
    		                {
    		                    theForm.VariantID_<xsl:value-of select="/root/Products/Product/ProductID" />_<xsl:value-of select="$defaultVariant" />.value=selValue;
                        }
                      else{
                      theForm.VariantID.value=selValue;
                      }
                      VariantMinimumQty_<xsl:value-of select="/root/Products/Product/ProductID" />_<xsl:value-of select="$defaultVariant" /> = VarMinQty[selValue];
                      SelectedVariantInventory_<xsl:value-of select="/root/Products/Product/ProductID" />_<xsl:value-of select="$defaultVariant" /> = VarInventory[selValue];
                      }
                      }
                      theForm.Quantity_<xsl:value-of select="/root/Products/Product/ProductID" />_<xsl:value-of select="$defaultVariant" />.value= VarMinQty[<xsl:value-of select="$defaultVariant" />];
                      SelectedVariantInventory_<xsl:value-of select="/root/Products/Product/ProductID" />_<xsl:value-of select="$defaultVariant" /> = VarInventory[<xsl:value-of select="$defaultVariant" />];
                      
                      function getElementsByClass(searchClass,node,tag)
                      {
                        var classElements = new Array();
                        if (node == null)
                          node = document;
                        if (tag == null)
                          tag = '*';
                        var els = node.getElementsByTagName(tag);
                        var elsLen = els.length;
                        var pattern = new RegExp("(^|\\s)"+searchClass+"(\\s|$)");
                        for (i = 0, j = 0; i &lt; elsLen; i++) 
                        {
                          if (pattern.test(els[i].className) ) 
                          {
                            classElements[j] = els[i];
                            j++;
                          }//if (pattern.test(els[i].className) )
                          
                        }//for (i = 0, j = 0; i &lt; elsLen; i++)
                        
                        return classElements;
                      }//function getElementsByClass(searchClass,node,tag)
                      
                      
                      function UpdatePrice(varID)
                      {
                        if(varID == 0)
                        varID = <xsl:value-of select="/root/Products/Product/VariantID" />;
                        var currentpriceID = 'variantPrice' + varID;
                        var prices = getElementsByClass('varPrice',document.getElementById('productPriceWrap'));
                        
                        for(i=0; i&lt;prices.length; i++)
                        {
                          if(prices[i].id == currentpriceID)
                          {
                            prices[i].style.display = 'block';
                          }//if
                          else
                          {
                            prices[i].style.display = 'none';
                          }//else
                          
                        }//for(i=0; i&lt;prices.length; i++)
                        }//  function UpdatePrice(varID)
    
    
                        function SyncVariantPrice()
                        {
                        var varOpts = getElementsByClass('varOption');
                        var selectedVariant;
                        for( i=0; i&lt;varOpts.length; i++)
                        {
                            if(varOpts[i].checked == true)
                            {
                                selectedVariant = varOpts[i].value;
                            }
                        }
                        if (selectedVariant != null)
                        {
                          UpdatePrice(selectedVariant);
                        }//if
                        else
                        {
                          UpdatePrice(<xsl:value-of select="$defaultVariant" />);
                        }// else
                        
                      }// function SyncVariantPrice()
                      
                      <xsl:if test="count(/root/Products/Product) &gt; 1" >
                        SyncVariantPrice();
                      </xsl:if>
                      
                      function AddOnClick()
                      {
    
                        var cartButtons = getElementsByClass('AddToCartButton');
                        for(var i=0; i&lt;cartButtons.length; i++)
                        {
                          //alert(cartButtons[i].onclick);
                          var oldOnClick = cartButtons[i].onclick;
                          cartButtons[i].onclick = function()
                          {
                            var varOpts = getElementsByClass('varOption');
                            var selectedVariant;
                            for( i=0; i&lt;varOpts.length; i++)
                            {
                                if(varOpts[i].checked == true)
                                {
                                    selectedVariant = varOpts[i].value;
                                }
                            }
                            ValidateVariant(selectedVariant, oldOnClick);
                          }//function()
    
                        }// for(var i=0; i&lt;cartButtons.length; i++)
                        
                      }// function AddOnClick()
    
    
                      function ValidateVariant(selectedVariant, oldOnClick)
                      {
                        if(selectedVariant == '')
                        {
                          alert('Please select a size');
                          return false;
                        }//if
                        else
                        {
                          return oldOnClick();
                        }//else
                        
                      }// function ValidateVariant(selectedVariant, oldOnClick)
                      
                      
                      AddOnClick();
                      SyncVariantPrice();
                      
                    </script>
                </xsl:if>
                </xsl:template>

    Thanks
    A
    Last edited by usascholar; 03-13-2013 at 01:25 PM.

  2. #2
    usascholar is offline Member
    Join Date
    Jan 2010
    Posts
    64

    Default

    Ok Guys,


    I have found an issue with the code. The original code has this at the top (see code below). In the code the variable VarMinQty is not being passed the MinimumQuantity from the variant at all, is this a bug or a code error in the original XMLPackage?

    Here is the code that doesn't seem to be working:

    Code:
               <div class="productPage">
                   <xsl:apply-templates select="/root/Products/Product[isdefault = 1]" />
                </div>
                <xsl:if test="count(/root/Products/Product) &gt; 1">
                    <script type="text/javascript">
                      var VarMinQty = new Array();
                      var VarInventory = new Array();
    
                      <xsl:for-each select="/root/Products/Product">
                        <xsl:choose>
                          <xsl:when test="MinimumQuantity &gt; 1">
                            VarMinQty[<xsl:value-of select="VariantID" />] = <xsl:value-of select="MinimumQuantity" />;
                          </xsl:when>
                          <xsl:otherwise>
                            VarMinQty[<xsl:value-of select="VariantID" />] = 1;
                          </xsl:otherwise>
                        </xsl:choose>
                        VarInventory[<xsl:value-of select="VariantID" />] = <xsl:value-of select="Inventory" />;
    
                      </xsl:for-each>
    Any suggestions to have it populate the VarMinQty variable properly?

    A

  3. #3
    mmcgeachy is offline Senior Member
    Join Date
    Sep 2008
    Posts
    174

    Default

    Just to be clear you are talking about product.VariantsInDropDown.xml.config or something else. If so the code you have and what I show don't exactly match up. In particular the for-each and what the select shows as /root/ProductVariants/Variant instead of /root/Products/Product. Therefore Try changing it to the select to /root/ProductVariants/Variant and see if that fixes the issue?

  4. #4
    usascholar is offline Member
    Join Date
    Jan 2010
    Posts
    64

    Default

    Quote Originally Posted by mmcgeachy View Post
    Just to be clear you are talking about product.VariantsInDropDown.xml.config or something else. If so the code you have and what I show don't exactly match up. In particular the for-each and what the select shows as /root/ProductVariants/Variant instead of /root/Products/Product. Therefore Try changing it to the select to /root/ProductVariants/Variant and see if that fixes the issue?
    Thanks... actually it was for:
    product.configurable-tabbedvariantradiobuttons.xml.config

    Apparently I needed to change the "/root/Products/Product" to "/root/ProductVariants/Variant" as you mentioned, then add the query below:

    Code:
      <query name="ProductVariants" rowElementName="Variant">
        <sql>
          <![CDATA[
                    select pv.VariantID, pv.Name, pv.Price, pv.Description, pv.ProductID, pv.Deleted, pv.MinimumQuantity,
                    pv.Published, pv.Points, pv.IsDefault, pv.DisplayOrder, p.HidePriceUntilCart, case p.TrackInventoryBySizeAndColor when 1 then isnull(i.quan, 0) else pv.inventory end Inventory,
                    case when pv.SalePrice is null then 0 else isnull(pv.SalePrice, 0) end SalePrice, case when pcl.productid is null then 0 else isnull(e.Price, 0) end ExtendedPrice
                    from dbo.productvariant pv with (nolock)
                        join dbo.product p with (nolock) on p.productid = pv.productid
                        left join dbo.ExtendedPrice e with (nolock) on pv.VariantID=e.VariantID and e.CustomerLevelID=@CustomerLevelID
                        left join dbo.ProductCustomerLevel pcl with (NOLOCK) on pcl.ProductID = p.ProductID and pcl.CustomerLevelID = @CustomerLevelID
                        left join dbo.Inventory i with (nolock) on i.VariantID = pv.VariantID
                    where pv.ProductID=@ProductID and pv.Deleted=0  and pv.Published = 1 
                         and ((@InvFilter = 0) or (case p.TrackInventoryBySizeAndColor when 1 then isnull(i.quan, 0) else pv.inventory end >= @InvFilter))
                    order by pv.IsDefault DESC, pv.DisplayOrder ASC
                ]]>
        </sql>
        <queryparam paramname="@CustomerLevelID" paramtype="system"     requestparamname="CustomerLevelID"                            sqlDataType="int" defvalue="0"  validationpattern="" />
        <queryparam paramname="@ProductID"       paramtype="request"    requestparamname="ProductID"                                  sqlDataType="int" defvalue="0"  validationpattern="" />
        <queryparam paramname="@InvFilter"       paramtype="appconfig"  requestparamname="HideProductsWithLessThanThisInventoryLevel" sqlDataType="int" defvalue="0"  validationpattern="" />
      </query>
    and lastly add the form code

    theForm.Quantity_<xsl:value-of select="/root/Products/Product/ProductID" />_<xsl:value-of select="$defaultVariant" />.value = VarMinQty[selValue];

    to the SetCartVariant function below:

    Code:
                      function SetCartVariant(selValue)
                      {
                      //alert("AddToCartForm_"+prodid+"_"+varid);
                      var theForm;
                      //v9 compatibility check
                      if(document.forms["aspnetForm"])
                      {
                      theForm = document.forms["aspnetForm"];
                      }
                      else{ //v8
                      theForm = document.forms["AddToCartForm_<xsl:value-of select="/root/QueryString/productid" />_<xsl:value-of select="$defaultVariant" />"];
                      }
                      if(selValue=='')
                      {
                      alert('Please select a variant to add to the cart');
                      return false;
                      }
                      else
                      {
                      //v9 compatibility check
                        if(theForm.VariantID_<xsl:value-of select="/root/Products/Product/ProductID" />_<xsl:value-of select="$defaultVariant" />)
                          {
                          theForm.VariantID_<xsl:value-of select="/root/Products/Product/ProductID" />_<xsl:value-of select="$defaultVariant" />.value=selValue;
                          }
                        else{
                          theForm.VariantID.value=selValue;
                          }
                          VariantMinimumQty_<xsl:value-of select="/root/Products/Product/ProductID" />_<xsl:value-of select="$defaultVariant" /> = VarMinQty[selValue];
                          SelectedVariantInventory_<xsl:value-of select="/root/Products/Product/ProductID" />_<xsl:value-of select="$defaultVariant" /> = VarInventory[selValue];
                          theForm.Quantity_<xsl:value-of select="/root/Products/Product/ProductID" />_<xsl:value-of select="$defaultVariant" />.value = VarMinQty[selValue];
                      }
                      }
    Now it seems to update the Quantity box appropriatly when I click on the radio buttons.

    Thanks for pointing me in the right direction!

    A