Forum

Thread tagged as: Problem, Error, Shop

Product variants not adding to cart

ETA: I see now that the correct SKUs are not adding to the cart. I've found some similar issues in the forum, but I still can't figure out how to fix this. I've updated my template code below to include only the relevant part.

Original post: I have set up products with size variants in Perch Shop, and these will load to the cart, but without their variant pricing (pricing shows up as zero). I'm seeing an error in the Perch debug in the cart whenever a product with a variant is loaded in. If I set the overall price for the item, then that price will show up in the cart, but I still see the debug error. Variant pricing is also not showing up in the Products page of the admin dashboard.

Page with the error on the development server: https://138.197.208.91/shop/cart — you have to add an item to the cart here https://138.197.208.91/shop to see the error

Error Text: Invalid query: SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'LIMIT 1' at line 2

How Products are set up: screenshot

screenshot

screenshot

My product template:

<!-- Buy Product / Start -->
            <div class="row no-neg-margin buy-product">

                <div class="col col-sm-6 col-md-12 col-lg-6 product-detail-image">
                    <img class="hidden" src="<perch:shop id="image" type="image" label="Main product image" required="true" />" alt="<perch:shop id="title" type="text" label="Title" required="true" />" />
                    <img src="<perch:shop id="image2" type="image" label="Second product image" required="true" />" alt="<perch:shop id="title" type="text" label="Title" required="true" />" />
                </div>
                <div class="col col-lg-1"></div>
                <div class="col col-sm-6 col-md-5 col-lg-5 product-detail-text">
                    <h1 class="product-title"><perch:shop id="title" type="text" label="Title" required="true" /></h1>
                    <span class="product-description">
                        <h2 class="product-subtitle">
                            <perch:categories id="category" set="products" label="Category">
                                <perch:category id="catTitle" />
                            </perch:categories>
                        </h2>
                        <p><perch:shop id="description" type="textarea" label="Description" markdown="false" /></p>
                    </span>
                    <div class="pd-purchase">

                        <perch:if id="catalog_only" value="0">
                          <perch:form id="add_to_cart" app="perch_shop" action="/shop/cart">

                            <perch:if exists="has_variants">
                              <perch:productopts>
                                <perch:productvalues>
                                  <perch:before><ul></perch:before>

                                    <li class="shop-sizes-buttons">
                                      <label>
                                        <perch:shop id="on_sale" type="checkbox" value="1" />
                                        <perch:form id="add_to_cart" app="perch_shop" action="/shop/cart">
                                        <perch:input id="product" type="hidden" env-autofill="false" value="<perch:shop id="productID" type="hidden" env-autofill="false" />" />
                                        <perch:input class="btn1 pd-purchase-button" id="options" name="opt-<perch:productvalue id="optionID" />[]"
                                          value="<perch:productvalue id="valueTitle" />" type="submit" />
                                      </label>
                                    </li>

                                  <perch:after></ul></perch:after>
                                </perch:productvalues>
                              </perch:productopts>

                              <perch:else />
                                  <perch:shop id="on_sale" type="checkbox" value="1" />
                                  <perch:form id="add_to_cart" app="perch_shop" action="/shop/cart">
                                  <perch:input id="product" type="hidden" env-autofill="false" value="<perch:shop id="productID" type="hidden" env-autofill="false" />" />
                                  <perch:input type="submit" class="btn default-primary btn2 pd-purchase-button" value="Add to cart" />
                                  </perch:form>
                                  </perch:form>

                            </perch:if>

                            <perch:input id="product" type="hidden" value="<perch:shop id="productID" type="hidden" env-autofill="false" />" />
                            <perch:input type="hidden" value="Add to cart" />
                          </perch:form>
                        <perch:else />
                          <p>This item is available for sale at our mill and ranch only.</p>
                        </perch:if>

                    </div>

                    <div class="hidden">
                        <perch:shop id="price" type="shop_currency_value" label="Price" divider-before="Pricing" size="s" min="0" step="any" />
                        <perch:shop id="sale_price" type="shop_currency_value" label="Sale price" size="s" min="0" step="any" />
                        <perch:shop id="trade_price" type="shop_currency_value" label="Trade price" size="s" min="0" step="any" runway="true" />
                        <perch:shop id="on_sale" type="checkbox" value="1" label="Use sale price" />
                        <perch:shop id="tax_group" type="shop_tax_group" label="Tax group" required="true" />

                        <perch:shop id="stock_status" type="shop_stock_status" label="Stock status" divider-before="Stock" required="true" />
                        <perch:shop id="stock_level" type="number" label="Stock level" size="s" />
                        <perch:shop id="stock_location" type="shop_stock_location" label="Count stock" />
                        <perch:shop id="max_in_cart" type="number" label="Max quantity in cart" size="s" />

                        <perch:shop id="requires_shipping" type="shop_requires_shipping" label="Requires shipping" divider-before="Shipping" />
                        <perch:shop id="weight" type="number" label="Shipping weight" size="s" />
                        <perch:shop id="width" type="number" label="Width" size="s" />
                        <perch:shop id="height" type="number" label="Height" size="s" />
                        <perch:shop id="depth" type="number" label="Depth" size="s" />
                    </div>

                </div>

            </div>
            <!-- Buy Product / End -->
Lindsay Masten

Lindsay Masten 0 points

  • 3 years ago

I am looking into this, but will also monitor for additional help.

Drew McLellan

Drew McLellan 2638 points
Perch Support

The problem is highlight a couple of lines above the error:

SELECT valueSKUCode FROM perch3_shop_option_values WHERE valueID IN ('add to cart') AND optionID IN (1)

That add to cart looks like the label of your button rather than the product option. If you use the examples from the docs, does that work correctly?