Forum

Thread tagged as: Question, FoxyCart

Adding the quantity of an individual item to the quantity_max attribute - FoxyCa...

Hi,

I have a shop that has products where stock is tracked on a option level (in this case "size").

I want to pass the quanity level of that individual item into the value of the quantity_max attribute, so when the user enters the FoxyCart payment process, they can not increase the stock level by more than what is available.

Is this possible?

Hamish Henderson

Hamish Henderson 0 points

  • 6 years ago
Drew McLellan

Drew McLellan 2638 points
Perch Support

How is it passed? As a hidden field?

I would like to pass it as a hidden field. Is there a tag for pulling all the option quantities?

Drew McLellan

Drew McLellan 2638 points
Perch Support

What does the template look like at the moment? I can help you work from there.

Hey,

Ok - so this is the "product" template - specifically the perch form:

                <perch:form id="foxy_cart" method="post" action="<perch:setting id="perch_shop_foxy_url" />">
                <h2 class="productTitle"><perch:shop id="productTitle" /></h2>  
                <span class="product-price-detail">$<perch:shop id="productPrice" /></span>


                <div class="size-guide-container">

                    <div class="product-sizes">
                        <perch:if exists="productOptions_html">
                            <perch:shop id="productOptions_html" encode="false" type="hidden" />
                        </perch:if>
                    </div>

                    <!-- Size Guide trigger modal -->
                    <div class="size-gide-link-container">
                        <a class="size-guide-link" href="img/size-guide.png" data-lightbox="image-1" data-title="Size Guide">Size Guide</a>
                    </div>

                </div>

                <div class="buttons"><perch:input type="submit" value="Add to Cart"/></div>

                <div class="product-description">
                    <perch:shop id="productDescHTML" type="textarea" textile="true" editor="markitup" size="m autowidth" encode="false" order="5" />
                </div>

                <perch:input type="hidden" name="name" value="<perch:shop id="productTitle" order="1" />" />
                <perch:input type="hidden" name="code" value="<perch:shop id="productCode" />" order="2" />
                <perch:input type="hidden" name="price" value="<perch:shop id="productPrice" />" order="3" />
                <perch:input type="hidden" name="weight" value="5.00" />


                <perch:if exists="productFoxyCategory">
                    <perch:input type="hidden" name="category" value="<perch:shop id="productFoxyCategory" />" />
                </perch:if>

                </perch:form> 

This piece of code brings up a series of size options

<perch:shop id="productOptions_html" encode="false" type="hidden" />

Essentially, I want to stop people from adding more to the cart than is actually in stock - so if a t-shirt in size 8 has a qty of 5, I want to pass through that number into a attribute called "quantity_max". This will restrict the user once they are in foxycart from increasing the QTY to more than the number passed.

The issue is, I need to get the QTY for ALL options, and then based on what they select, populate the field attribute quantity_max using JS I'm guessing?

Thank you for your help! (majorly lost here).

Drew McLellan

Drew McLellan 2638 points
Perch Support

So that's usin the shop/product_options.html template, which looks like this:

<div>
    <perch:label for="<perch:shop id="optionTitle" />"><perch:shop id="optionTitle" /></perch:label>
    <perch:input type="select" name="<perch:shop id="optionTitle" />" options="<perch:shop id="optionValue" />" />
</div>

You should be able to test for the qty field you're looking for and then add your additional hidden input.

How do you "see" the qty field?

optionValue is the size (S,M,L etc)

Is there a tag I can use that will show me:

S - QTY 3 M - QTY 8 L - QTY 10

Drew McLellan

Drew McLellan 2638 points
Perch Support

I'm not sure what you mean by how do I see it.

Are the options not being output?

The only output is the Option Value - e.g. "S" or "M" or "L" - not the quantity associated with each option.

Is there an equivalent tag for "<perch:shop id="optionValue" />" to show the quantity associated with a option? Something like e.g. "<perch:shop id="optionCount" />"?

It looks like this guy was having the same issue - https://support.grabaperch.com/index.php?pg=forums.posts&id=6583&pc=2 (have a look towards the end of the conversation).

I'm a bit apprehensive about using his solution at the end before checking that there is no other (better) approach first...

Rachel Andrew

Rachel Andrew 394 points
Perch Support

No please don't use anything dug up from the old forum. That is a very old thread about a previous version of the shop.

To see what is available use you can use the following: https://solutions.grabaperch.com/development/using-perch-showall

Hi Rachel,

I had a look and the closest thing I could see was "<perch:shop id="productCountByOptions" />" which doesn't return a value that makes any sense.

I'm guessing then that there isn't a solution? I feel like I am missing something... is it possible to display to quantity of a option, not just the "name" of that option?

Hamish

Drew McLellan

Drew McLellan 2638 points
Perch Support

I really don't know. I'll have to get a copy installed and set up in the same way and have a look.