This Forum Has Been Replaced. Please Visit Our New Forum At http://mycb.university
Welcome To The Connected Business Community Forum.
0 votes
52 views
Hi,

I'm working on getting the Add to Cart form to change the text on the button based on the available stock for an item. When the item has stock, the button will read, "Add to Cart." When there is 0 or less stock available, it will say, "Pre-Order." This would be implemented in helper.product.xml.config. However, when I try to implement it using code to check for stock, it will only use the "Out of Stock" option no matter how many are in stock. I've fooled around with several configurations but for some reason it doesn't seem to be working.

Here's the code I'm using:

<xsl:choose>
                                <xsl:when test="current()/ITEM_FREESTOCK > 0">
                                  <button title="Add To Shoppping Cart" type="submit" id="{concat('AddToCart_', $item_counter)}" class="btn btn-success addtocartbutton content"
                                     name="{concat('AddToCart_', $item_counter)}"
                                     data-contentkey="shoppingcart.cs.33"
                                     data-contentvalue="{FIELD/EDITCART_BUTTON_CAPTION}"
                                     data-contenttype="string resource"
                                     value="{FIELD/ADDTOCART_BUTTON_CAPTION}"
                                     >
                                  <i class="fa fa-shopping-cart"></i> <span class="cartlbl"> Add To Cart</span>
                                </button>
                                </xsl:when>
                            
                                <xsl:otherwise>
                                  <button title="Add To Shoppping Cart" type="submit" id="{concat('AddToCart_', $item_counter)}" class="btn btn-success addtocartbutton content"
                                     name="{concat('AddToCart_', $item_counter)}"
                                     data-contentkey="shoppingcart.cs.33"
                                     data-contentvalue="{FIELD/EDITCART_BUTTON_CAPTION}"
                                     data-contenttype="string resource"
                                     value="{FIELD/ADDTOCART_BUTTON_CAPTION}"
                                     >
                                  <i class="fa fa-shopping-cart"></i> <span class="cartlbl"> Pre-Order Now</span>
                                </button>
                                </xsl:otherwise>
                              </xsl:choose>

Any suggestions for getting this to work?
asked Sep 29, 2017 in eCommerce by AtlasEric (120 points) | 52 views

1 Answer

0 votes
Hi,

The best way to change the text based on available stock is thru product_ajax.js > setStockIndicator > ajax success call function.

Hope this helps!
answered Sep 19 by gerald (560 points)
134 questions
168 answers
370 users