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: Variant Out Of Stock

  1. #1
    ssgumby is offline Senior Member
    Join Date
    Feb 2009
    Posts
    683

    Default Variant Out Of Stock

    Is there someway to indicate one specific variant is out of stock? For example, our old site would change the text color in the drop to be grey for the out of stock variants. The way ASPDNSF works it doesnt show the customer it is out of stock it just lets them try to add then gives them a popup saying something about it exceeds quantity.

    So in essence a dropdown like below the medium is out of stock. How could I gray it out?

    Small $29.99
    Medium $39.99
    Large $49.99

    Thanks

  2. #2
    George the Great is offline Senior Member
    Join Date
    Nov 2006
    Location
    Cleveland, OH
    Posts
    1,792

    Default

    What version of AspDotNetStorefront are you running? Depending on the configuration you have set up, the variant that is out of stock won't even show in the variant dropdown. My guess is that you're seeing that error when there is only, for example, one left and you try and add 2 to the cart?

    In any case, I have a simple modification to the variantsindropdown xmlpackage that you can use to disable/gray-out the items in the dropdown. It involves removing inventory filters from the ProductVariants query, adding a --SELECT ONE-- option to the dropdown list with javascript to disable the add to cart and add to wish list buttons if a variant isn't selected (a simple technique to prevent the user from adding an item to the cart because it was selected by default even though it's out of stock), and modifications to the individual options to honor appconfig settings.

    The page will work as follows. The Add to Cart and Add to Wishlist buttons will be disabled by default when the page loads, and the dropdown box selected value will be "--SELECT ONE--". Changing the dropdown to a value other than "--SELECT ONE--" will enable the buttons, and if you then change back to "--SELECT ONE--" the buttons will disable again. If you have the appconfig DisplayOutOfStockOnProductPages set to "true", then any variants that have inventory less than HideProductsWithLessThanThisInventoryLevel appconfig parameter will be grayed-out/disabled. If all variants in the list are grayed-out/disabled then they won't be able to add an item to the cart. If the appconfig DisplayOutOfStockOnProductPages is set to "false", then any variants that have inventory less than the value specified in the HideProductsWithLessThanThisInventoryLevel appconfig parameter will not be included in the dropdown list. The only thing you'll need to be wary of is changing the text for the Add to Cart and Add to Wish List buttons. Because those buttons do not have IDs, finding the correct buttons involves looking at the elements of the AddToCartForm until you find the buttons with the text "Add to Cart" and "Add to Wish List". If you need to change your text (or if you already have) just replace the text in the XmlPackage with the text that you are now using for the buttons.

    Here's the new variantsindropdown xmlpackage:
    Code:
    <?xml version="1.0" standalone="yes" ?>
    <package version="2.1" displayname="Variants in Drop Down" debug="false" includeentityhelper="true">
    
    	<!-- ###################################################################################################### -->
    	<!-- Copyright AspDotNetStorefront.com, 1995-2009.  All Rights Reserved.					                -->
    	<!-- http://www.aspdotnetstorefront.com														                -->
    	<!-- For details on this license please visit  the product homepage at the URL above.		                -->
    	<!-- THE ABOVE NOTICE MUST REMAIN INTACT.                                                                   -->
    	<!--                                                                                                        -->
    	<!-- ###################################################################################################### -->
    
    
        <query name="Products" rowElementName="Product">
            <sql>
                <![CDATA[
                    exec dbo.aspdnsf_ProductInfo @ProductID, @CustomerLevelID, 1, 0, @affiliateID
                ]]>
            </sql>
            <queryparam paramname="@ProductID"       paramtype="request" requestparamname="ProductID"       sqlDataType="int" defvalue="0"  validationpattern="^\d{1,10}$" />
            <queryparam paramname="@CustomerLevelID" paramtype="runtime" requestparamname="CustomerLevelID" sqlDataType="int" defvalue="0"  validationpattern="" />
            <queryparam paramname="@affiliateID"     paramtype="system"  requestparamname="AffiliateID"     sqlDataType="int" defvalue="0"  validationpattern="" />
        </query>
    
        <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, 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
                    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>
    
        <PackageTransform>
            <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:aspdnsf="urn:aspdnsf" exclude-result-prefixes="aspdnsf">
                <xsl:output method="html" omit-xml-declaration="yes" />
    
                <xsl:param name="defaultVariant">
                    <xsl:choose>
                        <xsl:when test="count(/root/ProductVariants/Variant[IsDefault=1]) = 0"><xsl:value-of select="/root/ProductVariants/Variant[1]/VariantID" /></xsl:when>
                        <xsl:otherwise><xsl:value-of select="/root/ProductVariants/Variant[IsDefault=1]/VariantID" /></xsl:otherwise>
                    </xsl:choose>
                </xsl:param>
                <xsl:param name="LocaleSetting" select="/root/Runtime/LocaleSetting" />
                <xsl:param name="WebConfigLocaleSetting" select="/root/Runtime/WebConfigLocaleSetting" />
                <xsl:param name="XmlPackageName" select="/root/System/XmlPackageName" />
    
    
                <xsl:param name="SecID">
                    <xsl:choose>
                      <xsl:when test="count(/root/QueryString/sectionid) &gt; 0">
                        <xsl:value-of select="/root/QueryString/sectionid" />
                      </xsl:when>
                      <xsl:otherwise>0</xsl:otherwise>
                    </xsl:choose>
                </xsl:param>
    
                <xsl:param name="CatID">
                    <xsl:choose>
                      <xsl:when test="count(/root/QueryString/categoryid) &gt; 0">
                        <xsl:value-of select="/root/QueryString/categoryid" />
                      </xsl:when>
                      <xsl:otherwise>0</xsl:otherwise>
                    </xsl:choose>
                </xsl:param>
    
                <xsl:template match="/">
                    <xsl:apply-templates select="/root/Products/Product" />
                    <SCRIPT LANGUAGE="JavaScript">
                      var theForm = document.forms["AddToCartForm_<xsl:value-of select="/root/QueryString/productid" />_<xsl:value-of select="$defaultVariant" />"];
                      for(e = 0; e &lt; theForm.elements.length; e+=1)
                      {
                        if(theForm.elements[e].value == 'Add to Cart')
                        {
                          theForm.elements[e].disabled = 'true';
                        }
                        if(theForm.elements[e].value == 'Add to Wish List')
                        {
                          theForm.elements[e].disabled = 'true';
                        }
                      }
                      
                      var VarMinQty = new Array();
                      var VarInventory = new Array();
                      <xsl:for-each select="/root/ProductVariants/Variant">
                          <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 = 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');
                        for(e = 0; e &lt; theForm.elements.length; e+=1)
                        {
                          if(theForm.elements[e].value == 'Add to Cart')
                          {
                            theForm.elements[e].disabled = 'true';
                          }
                          if(theForm.elements[e].value == 'Add to Wish List')
                          {
                            theForm.elements[e].disabled = 'true';
                          }
                        }
                      }
                      else 
                      {
                        for(e = 0; e &lt; theForm.elements.length; e+=1)
                        {
                          if(theForm.elements[e].value == 'Add to Cart')
                          {
                            theForm.elements[e].disabled = '';
                          }
                          if(theForm.elements[e].value == 'Add to Wish List')
                          {
                            theForm.elements[e].disabled = '';
                          }
                        }
                      
                      theForm.VariantID.value=selValue;
                      VariantMinimumQty_<xsl:value-of select="/root/QueryString/productid" />_<xsl:value-of select="$defaultVariant" /> = VarMinQty[selValue];
                                SelectedVariantInventory_<xsl:value-of select="/root/QueryString/productid" />_<xsl:value-of select="$defaultVariant" /> = VarInventory[selValue];
                            }
                        }
                        SelectedVariantInventory_<xsl:value-of select="/root/QueryString/productid" />_<xsl:value-of select="$defaultVariant" /> = VarInventory[<xsl:value-of select="$defaultVariant" />];
                    </SCRIPT>
                    <xsl:comment>Copyright 1995-2009 AspDotNetStorefront.com</xsl:comment>
                </xsl:template>
    
    
            <xsl:template match="Product">
                <xsl:param name="pName" select="aspdnsf:GetMLValue(Name)"></xsl:param>
                <xsl:param name="pDescription" select="aspdnsf:GetMLValue(Description)"></xsl:param>
                <xsl:param name="pSEAltText" select="aspdnsf:GetMLValue(SEAltText)"></xsl:param>
                <xsl:param name="AltText">
                    <xsl:choose>
                        <xsl:when test="$pSEAltText=''"><xsl:value-of select="$pName" /></xsl:when>
                        <xsl:otherwise><xsl:value-of select="$pSEAltText" /></xsl:otherwise>
                    </xsl:choose>
                </xsl:param>
    
                <xsl:choose>
                  <xsl:when test="IsAKit=1">
                    <table border="0" width="100%" cellpadding="4" cellspacing="0">
                      <tr>
                        <td align="left" valign="top">
                          <xsl:value-of select="aspdnsf:LookupProductImage(ProductID, ImageFilenameOverride, SKU, 'medium', 1, $AltText)" disable-output-escaping="yes"/>
                        </td>
                        <td align="left" valign="top" width="100%">
                          <div>
                            <table width="100%" cellpadding="0" cellspacing="0">
                              <tr>
                                <td width="100%" align="left" valign="middle">
                                  <span class="ProductNameText">
                                    <xsl:value-of select="$pName" disable-output-escaping="yes" />
                                  </span>
                                </td>
                                <td align="right" valign="Middle">
                                  <nobr>
                                    <xsl:value-of select="aspdnsf:ProductNavLinks(ProductID, $CatID, $SecID)" disable-output-escaping="yes" />
                                  </nobr>
                                </td>
                              </tr>
                            </table>
                          </div>
                          <div>
                            <br />
                          </div>
                          <div>
                            <b>
                              <font color="red">
                                Display of Kit Products is not supported by this XmlPackage.<br /><br />XmlPackage=<xsl:value-of select="$XmlPackageName" />
                              </font>
                            </b>
                          </div>
                        </td>
                      </tr>
                    </table>
                  </xsl:when>
                  <xsl:when test="IsAPack=1">
                    <table border="0" width="100%" cellpadding="4" cellspacing="0">
                      <tr>
                        <td align="left" valign="top">
                          <xsl:value-of select="aspdnsf:LookupProductImage(ProductID, ImageFilenameOverride, SKU, 'medium', 1, $AltText)" disable-output-escaping="yes"/>
                        </td>
                        <td align="left" valign="top" width="100%">
                          <div>
                            <table width="100%" cellpadding="0" cellspacing="0">
                              <tr>
                                <td width="100%" align="left" valign="middle">
                                  <span class="ProductNameText">
                                    <xsl:value-of select="$pName" disable-output-escaping="yes" />
                                  </span>
                                </td>
                                <td align="right" valign="Middle">
                                  <nobr>
                                    <xsl:value-of select="aspdnsf:ProductNavLinks(ProductID, $CatID, $SecID)" disable-output-escaping="yes" />
                                  </nobr>
                                </td>
                              </tr>
                            </table>
                          </div>
                          <div>
                            <br />
                          </div>
                          <div>
                            <b>
                              <font color="red">
                                Display of Pack Products is not supported by this XmlPackage.<br /><br />XmlPackage=<xsl:value-of select="$XmlPackageName" />
                              </font>
                            </b>
                          </div>
                        </td>
                      </tr>
                    </table>
                  </xsl:when>
                  <xsl:otherwise>
                    <table border="0" width="100%" cellpadding="4" cellspacing="0">
                      <tr>
                        <td align="left" valign="top">
                          <xsl:value-of select="aspdnsf:LookupProductImage(ProductID, ImageFilenameOverride, SKU, 'medium', 1, $AltText)" disable-output-escaping="yes"/>
                        </td>
                        <td align="left" valign="top" width="100%">
                          <div>
                            <table width="100%" cellpadding="0" cellspacing="0">
                              <tr>
                                <td width="100%" align="left" valign="middle">
                                  <span class="ProductNameText">
                                    <xsl:value-of select="$pName" disable-output-escaping="yes" />
                                  </span>
                                  <br/>
                                </td>
                                <td align="right" valign="Middle">
                                  <nobr>
    								<xsl:value-of select="aspdnsf:ProductNavLinks(ProductID, /root/Runtime/EntityID, /root/Runtime/EntityName, /root/EntityHelpers/*[name()=/root/Runtime/EntityName]/descendant::Entity[EntityID=/root/Runtime/EntityID]/SEName, 0, 1, 1)" disable-output-escaping="yes" />
                                    <xsl:value-of select="aspdnsf:EmailProductToFriend(ProductID, $CatID)" disable-output-escaping="yes"/>
                                  </nobr>
                                </td>
                              </tr>
                            </table>
                          </div>
                          <div>
                          </div>
                          <div>
                            <xsl:value-of select="$pDescription" disable-output-escaping="yes"/>						 
                            <br/>
                            <br/>
                          </div>
                          <div>
                          </div>
                          <div>
                            Options: <select name="variants" onchange="SetCartVariant(this.value)">
                              <option value="" selected="selected">--SELECT ONE--</option>
                              <xsl:apply-templates select="/root/ProductVariants/Variant" />
                            </select>
    						  <xsl:if test="aspdnsf:AppConfigBool('DisplayOutOfStockProducts') = 'true'">
    							  <xsl:value-of select="aspdnsf:DisplayProductStockHint(ProductID, VariantID, 'Product')" disable-output-escaping="yes" />
    						  </xsl:if>
                            <div>
                              <br/>
                            </div>
                            <xsl:value-of select="aspdnsf:AddtoCartForm(ProductID, $defaultVariant, 1)" disable-output-escaping="yes"/>
                          </div>
                        </td>
                      </tr>                 
                    </table>
    				  <xsl:value-of select="aspdnsf:RelatedProducts(ProductID)" disable-output-escaping="yes"/>
    				  <xsl:value-of select="aspdnsf:RecentlyViewed(ProductID)" disable-output-escaping="yes"/>
    				  <xsl:value-of select="aspdnsf:ShowUpsellProducts(ProductID)" disable-output-escaping="yes"/>
    				  <xsl:value-of select="aspdnsf:AlsoBought(ProductID, VariantID)" disable-output-escaping="yes"/>
    				  <xsl:value-of select="aspdnsf:ProductSpecs(ProductID, 1)" disable-output-escaping="yes"/>
    				  <xsl:value-of select="aspdnsf:ProductRatings(ProductID, 0, 0, 0, 1)" disable-output-escaping="yes"/>
                    <xsl:value-of select="aspdnsf:Topic('imagepricetable')" disable-output-escaping="yes" />
                  </xsl:otherwise>
                </xsl:choose>
            </xsl:template>
    
    
          <xsl:template match="Variant">
            <xsl:param name="vName" select="aspdnsf:GetMLValue(Name)"></xsl:param>
            <xsl:param name="pSalesPromptName" select="aspdnsf:GetMLValue(/root/Products/Product/SalesPromptName)"></xsl:param>
            <xsl:param name="pTaxClassID" select="/root/Products/Product/TaxClassID" />
            <xsl:choose>
              <xsl:when test="aspdnsf:AppConfig('DisplayOutOfStockOnProductPages') = 'true'">
                <option value="{VariantID}">
                  <xsl:if test="Inventory &lt; aspdnsf:AppConfig('HideProductsWithLessThanThisInventoryLevel')">
                    <xsl:attribute name="disabled">disabled</xsl:attribute>
                  </xsl:if>
                  <xsl:value-of select="$vName" />*-*<xsl:value-of select="aspdnsf:GetVariantPrice(VariantID, number(HidePriceUntilCart), Price, SalePrice, ExtendedPrice, Points, $pSalesPromptName, $pTaxClassID)" disable-output-escaping="yes" />
                </option>
              </xsl:when>
              <xsl:otherwise>
                <xsl:if test="Inventory &gt; (number(aspdnsf:AppConfig('HideProductsWithLessThanThisInventoryLevel')) - 1)">
                  <option value="{VariantID}">
                    <xsl:value-of select="$vName" />*-*<xsl:value-of select="aspdnsf:GetVariantPrice(VariantID, number(HidePriceUntilCart), Price, SalePrice, ExtendedPrice, Points, $pSalesPromptName, $pTaxClassID)" disable-output-escaping="yes" />
                </option>
                </xsl:if>
              </xsl:otherwise>
            </xsl:choose>
            
          </xsl:template>
        </xsl:stylesheet>
    </PackageTransform>
    </package>
    <a href="http://www.aspdotnetstorefront.com">Shopping Cart Software</a>

  3. #3
    ssgumby is offline Senior Member
    Join Date
    Feb 2009
    Posts
    683

    Default

    Hi George,

    Much thanks for your input! I will take a look and what you have here and see how I can massage that into my xml packages I use.

    As for version I am on 8.0.1.2 and we get this error for all situations. For example we have 0 in stock they can attempt to add it and then get the error.

    My understanding of the HideProductsWithLessThanThisInventory is that it would only hide the product when all variants were out of stock but it won't hide a specific variant if just that specific one is out of stock.

    Thanks,
    Mike

  4. #4
    ssgumby is offline Senior Member
    Join Date
    Feb 2009
    Posts
    683

    Default

    Hi George,

    Your mod didnt quite work for me because I have modified xml packages so I couldnt quite match it all up. However, it gave me the right direction and I was able to modify it to gray out out out of stock variants and put an Out Of Stock message

    Code:
          <xsl:template match="Variant">
            <xsl:param name="vName" select="aspdnsf:GetMLValue(Name)"></xsl:param>
            <xsl:param name="pSalesPromptName" select="aspdnsf:GetMLValue(/root/Products/Product/SalesPromptName)"></xsl:param>
            <xsl:param name="pTaxClassID" select="/root/Products/Product/TaxClassID" />
            <xsl:choose>
              <xsl:when test="Inventory &lt; 1">
                <option value="{VariantID}" style="color:gray">
                  <xsl:value-of select="$vName" />&#0160;-&#0160;<xsl:value-of select="aspdnsf:GetVariantPrice(VariantID, number(HidePriceUntilCart), Price, SalePrice, ExtendedPrice, Points, $pSalesPromptName, $pTaxClassID)" disable-output-escaping="yes" />&#0160;-&#0160;Out Of Stock
                </option>
              </xsl:when>
              <xsl:otherwise>
                <option value="{VariantID}">
                  <xsl:if test="IsDefault=1">
                    <xsl:attribute name="selected">selected</xsl:attribute>
                  </xsl:if>
                  <xsl:value-of select="$vName" />&#0160;-&#0160;<xsl:value-of select="aspdnsf:GetVariantPrice(VariantID, number(HidePriceUntilCart), Price, SalePrice, ExtendedPrice, Points, $pSalesPromptName, $pTaxClassID)" disable-output-escaping="yes" />
                </option>
              </xsl:otherwise>
            </xsl:choose>
          </xsl:template>