Forum

Thread tagged as: Problem, Shop

Variants not added to cart

Hi

I've got a situation where single-priced products are added to my cart, but products with variants are not. My code is;

product_details.html

<div class="col-sm-5">
    <h1><perch:shop id="title" type="text" label="Title" required="true" order="2" /></h1>
    <perch:if exists="has_variants">
    <div class="row">
    <div class="col-xs-12">
    <perch:shop id="description" type="textarea"  />
    <h5>Purchase options</h5>
    <div class="variants">
        <perch:variants>

            <div class="variant">
                <perch:variant id="productVariantDesc" type="text" />
                <perch:variant id="price" type="shop_currency_value" />
                <perch:form id="add_to_cart_variants" app="perch_shop" action="/shop/cart" class="add-to-cart-form">
                    <perch:input id="product" type="hidden" env-autofill="false" value="<perch:variant id="productID" type="hidden" env-autofill="false" />" />
                    <perch:input type="submit" value="Add to cart" class="btn btn-primary btn-sm"/>
                </perch:form>
            </div>
        </perch:variants>
    </div>
    </div>
    </div>
    <perch:else />
        <div class="row">
        <div class="col-xs-12">
            <perch:shop id="price" type="shop_currency_value"   />
            <perch:shop id="sale_price" type="shop_currency_value"   />
            <perch:shop id="trade_price" type="shop_currency_value"  />
            <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" value="Add to cart" />
    </perch:form>
        </perch:form>
    </div>
    </div>
    </perch:if>
</div>
<div class="col-sm-7">
        <div class="product-pic">
            <div id="slider2">
                <ul class="bxslider">
                    <perch:if exists="image"><li><a class="fancybox" data-fancybox-group="gallery" href="<perch:shop id="image" label="Image" type="image" width="700"/>" ><img src="<perch:shop type="image" id="image" width="700" height="700" crop="true" label="Image" />"  /></a></li></perch:if>
                    <perch:if exists="image2"><li><a class="fancybox" data-fancybox-group="gallery" href="<perch:shop id="image2" label="Image" type="image" width="700"/>" ><img src="<perch:shop type="image" id="image2" width="700" height="700" crop="true" label="Image" />"  /></a></li></perch:if>
                    <perch:if exists="image3"><li><a class="fancybox" data-fancybox-group="gallery" href="<perch:shop id="image2" label="Image" type="image" width="700"/>" ><img src="<perch:shop type="image" id="image3" width="700" height="700" crop="true" label="Image" />"  /></a></li></perch:if>
                    <perch:if exists="image4"><li><a class="fancybox" data-fancybox-group="gallery" href="<perch:shop id="image2" label="Image" type="image" width="700"/>" ><img src="<perch:shop type="image" id="image4" width="700" height="700" crop="true" label="Image" />"  /></a></li></perch:if>
                    <perch:if exists="image5"><li><a class="fancybox" data-fancybox-group="gallery" href="<perch:shop id="image2" label="Image" type="image" width="700"/>" ><img src="<perch:shop type="image" id="image5" width="700" height="700" crop="true" label="Image" />"  /></a></li></perch:if>
                    <perch:if exists="image6"><li><a class="fancybox" data-fancybox-group="gallery" href="<perch:shop id="image2" label="Image" type="image" width="700"/>" ><img src="<perch:shop type="image" id="image6" width="700" height="700" crop="true" label="Image" />"  /></a></li></perch:if>
                    <perch:if exists="image7"><li><a class="fancybox" data-fancybox-group="gallery" href="<perch:shop id="image2" label="Image" type="image" width="700"/>" ><img src="<perch:shop type="image" id="image7" width="700" height="700" crop="true" label="Image" />"  /></a></li></perch:if>
                 </ul>
            </div>
        </div>
        <div class="product-features">
            <div class="product-sidebar">
                <h4>Product Features</h4>
                <perch:shop id="code-text" type="textarea" />
                <perch:shop id="key" type="textarea" />
            </div>
        </div>
</div>

stotto_cart.html

<perch:if id="product_count" match="gt" value="0">
<div class="box shop shoppingcart">
    <perch:form id="cart" app="perch_shop" class="cart">
        <perch:input type="submit" value="Update" hidden="true" aria-hidden="true" />

        <table class="cart">
            <tr>
                <th></th>
                <th>Quantity</th>
                <th class="money">Price</th>
                <th class="money">Total</th>
            </tr>
            <perch:cartitems>
                <tr>
                    <td>
                        <div class="media">
                            <div class="img">
                                <perch:cartitem id="image" type="image" width="80" height="80" density="1.6" crop="true" output="tag" />
                            </div>

                            <div class="bd">
                                <h3><perch:cartitem id="title" /> <i><perch:cartitem id="variant_desc" /></i></h3>
                                <div class="desc">
                                    <perch:cartitem id="description" type="textarea" markdown="true" />
                                    <button type="submit" class="remove_cart" name="del:<perch:cartitem id="identifier" />" value="1">
                                        Remove
                                    </button>
                                </div>

                            </div>
                        </div>
                    </td>
                    <td>
                        <perch:input id="qty:<perch:cartitem id="identifier" />" value="<perch:cartitem id="quantity" />" type="number" min="0" />
                    </td>
                    <td class="money">
                        <perch:cartitem id="price_without_tax" />
                    </td>
                    <td class="money">
                        <perch:cartitem id="total_without_tax_formatted" />
                    </td>
                </tr>
            </perch:cartitems>

            <perch:if id="total_discounts" match="gt" value="0.00">
                <tr class="total">
                    <th colspan="3">
                        Discount (<perch:shop id="discount_code" />)
                    </th>
                    <td class="money">
                        <perch:shop id="total_discounts" />
                    </td>
                </tr>
            </perch:if>



            <perch:if id="total_discounts" match="gt" value="0.00">
                <tr class="total">
                    <th colspan="3">
                        Sub total
                    </th>
                    <td class="money">
                        <perch:shop id="total_items_discounted" />
                    </td>
                </tr>
            <perch:else />
                <tr class="total">
                    <th colspan="3">
                        Sub total
                    </th>
                    <td class="money">
                        <perch:shop id="total_items" />
                    </td>
                </tr>
            </perch:if>
            <perch:if id="shipping_weight" match="gt" value="0.00">
                <tr class="total">
                    <th colspan="3">
                        <perch:shop id="shipping_method" />
                        <perch:if id="shipping_without_tax" match="gt" value="0.00">
                            <small class="note">Price subject to delivery location, set on the next step</small>
                        </perch:if>
                    </th>
                    <td class="money">
                        <perch:if id="shipping_without_tax" value="0.00">
                            FREE
                        <perch:else />
                            <perch:shop id="shipping_without_tax" />
                        </perch:if>                     
                    </td>
                </tr>

                <perch:if id="total_shipping_discount" match="gt" value="0.00">
                    <tr>
                        <th colspan="3">
                            Shipping discount <perch:if exists="discount_code">(<perch:shop id="discount_code" />)</perch:if>
                        </th>
                        <td class="money">
                            -<perch:shop id="total_shipping_discount" />
                        </td>
                    </tr>
                    <tr>
                        <th colspan="3">
                            Total
                        </td>
                        <th class="money">
                            <perch:shop id="total_items" />
                        </td>
                    </tr>
                </perch:if>
            </perch:if>

            <tr class="total">
                <th colspan="3">
                    Tax
                </th>
                <td class="money">
                    <perch:shop id="total_tax" />
                </td>
            </tr>
            <tr class="total">
                <th colspan="3">
                    Grand total
                </th>
                <td class="money">
                    <perch:shop id="grand_total_formatted" />
                </td>
            </tr>
        </table>

        <div class="buttons">
            <a href="/shop/checkout" class="checkout button">Checkout now</a>
            <button type="submit" class="update button knockback">Update cart</button>
            <perch:input type="cms" />

        </div>

    </perch:form>
</div>
<perch:else />
    <perch:shop id="empty_cart_message" encode="false" />
</perch:if>

Do I need to add code to my cart to allow variants? I've looked on the docs, but the examples seem to be the form before the cart, rather than the cart.

Debug from cart page;

ebug Message - Perch Runway 3.0.5
SELECT p.pagePath, pr.routePattern, pr.routeRegExp, p.pageTemplate, pr.routeOrder, s.settingValue AS siteOffline FROM perch2_pages p LEFT JOIN perch2_page_routes pr ON p.pageID=pr.pageID LEFT JOIN perch2_settings s ON s.settingID='siteOffline' UNION SELECT NULL AS pagePath, pr2.routePattern, pr2.routeRegExp, pr2.templatePath AS pageTemplate, pr2.routeOrder, NULL AS siteOffline FROM perch2_page_routes pr2 WHERE templateID!=0 ORDER BY routeOrder ASC, pagePath ASC
Matched page: /shop/cart, so not using routes.
Using master page: /templates/pages/cart.php
SELECT * FROM perch2_pages WHERE pagePath='/shop/cart' LIMIT 1
SELECT * FROM perch2_shop_cart WHERE cartID=239
SELECT * FROM perch2_shop_cart WHERE cartID=239
SELECT * FROM perch2_shop_sales WHERE saleFrom<='2017-05-31 15:18:00' AND saleTo>'2017-05-31 15:18:00' AND saleActive=1 AND saleDeleted IS NULL ORDER BY saleOrder ASC
SELECT DISTINCT settingID, settingValue FROM perch2_settings WHERE userID=0
Using template: /templates/pages/attributes/seo.html
------------------------------ Calculating cart ------------------------------
SELECT * FROM perch2_shop_cart WHERE cartID=239
SELECT * FROM perch2_shop_cart WHERE cartID=239
SELECT * FROM perch2_shop_tax_locations WHERE locationID=1 AND locationDeleted IS NULL LIMIT 1
SELECT locationID FROM perch2_shop_tax_locations WHERE locationIsHome=1 LIMIT 1
SELECT * FROM perch2_shop_tax_locations WHERE locationID=1 AND locationDeleted IS NULL LIMIT 1
SELECT * FROM perch2_shop_currencies WHERE currencyID=47 LIMIT 1
SELECT COUNT(productID) AS product_count, SUM(itemQty) AS item_count FROM perch2_shop_cart_items WHERE cartID=239
Tax mode: inc
SELECT * FROM perch2_shop_cart_items WHERE cartID=239 ORDER BY itemID ASC
Using template: /templates/shop/cart/stotto_cart.html
SELECT regionKey, regionHTML FROM perch2_content_regions WHERE regionPage='/shop/cart' OR regionPage='*' ORDER BY regionPage DESC
SELECT pageID FROM perch2_pages WHERE pagePath='/shop/cart' LIMIT 1
INSERT INTO perch2_content_regions(regionKey,regionPage,regionHTML,regionOptions,pageID) SELECT 'footer' AS regionKey,'/shop/cart' AS regionPage,'<!-- Undefined content: footer -->' AS regionHTML,'' AS regionOptions,'39' AS pageID FROM (SELECT 1) AS dtable WHERE ( SELECT COUNT(*) FROM perch2_content_regions WHERE regionKey='footer' AND (regionPage='/shop/cart' OR regionPage='*') )=0 LIMIT 1
UPDATE perch2_content_regions SET regionOrder=0 WHERE regionPage='/shop/cart' AND regionKey='footer' LIMIT 1
Debug Message - Perch Runway 3.0.5
SELECT p.pagePath, pr.routePattern, pr.routeRegExp, p.pageTemplate, pr.routeOrder, s.settingValue AS siteOffline FROM perch2_pages p LEFT JOIN perch2_page_routes pr ON p.pageID=pr.pageID LEFT JOIN perch2_settings s ON s.settingID='siteOffline' UNION SELECT NULL AS pagePath, pr2.routePattern, pr2.routeRegExp, pr2.templatePath AS pageTemplate, pr2.routeOrder, NULL AS siteOffline FROM perch2_page_routes pr2 WHERE templateID!=0 ORDER BY routeOrder ASC, pagePath ASC
Matched page: /shop/cart, so not using routes.
Using master page: /templates/pages/cart.php
SELECT * FROM perch2_pages WHERE pagePath='/shop/cart' LIMIT 1
SELECT * FROM perch2_shop_cart WHERE cartID=239
SELECT * FROM perch2_shop_cart WHERE cartID=239
SELECT * FROM perch2_shop_sales WHERE saleFrom<='2017-05-31 15:18:00' AND saleTo>'2017-05-31 15:18:00' AND saleActive=1 AND saleDeleted IS NULL ORDER BY saleOrder ASC
SELECT DISTINCT settingID, settingValue FROM perch2_settings WHERE userID=0
Using template: /templates/pages/attributes/seo.html
------------------------------ Calculating cart ------------------------------
SELECT * FROM perch2_shop_cart WHERE cartID=239
SELECT * FROM perch2_shop_cart WHERE cartID=239
SELECT * FROM perch2_shop_tax_locations WHERE locationID=1 AND locationDeleted IS NULL LIMIT 1
SELECT locationID FROM perch2_shop_tax_locations WHERE locationIsHome=1 LIMIT 1
SELECT * FROM perch2_shop_tax_locations WHERE locationID=1 AND locationDeleted IS NULL LIMIT 1
SELECT * FROM perch2_shop_currencies WHERE currencyID=47 LIMIT 1
SELECT COUNT(productID) AS product_count, SUM(itemQty) AS item_count FROM perch2_shop_cart_items WHERE cartID=239
Tax mode: inc
SELECT * FROM perch2_shop_cart_items WHERE cartID=239 ORDER BY itemID ASC
Using template: /templates/shop/cart/stotto_cart.html
SELECT regionKey, regionHTML FROM perch2_content_regions WHERE regionPage='/shop/cart' OR regionPage='*' ORDER BY regionPage DESC
SELECT pageID FROM perch2_pages WHERE pagePath='/shop/cart' LIMIT 1
INSERT INTO perch2_content_regions(regionKey,regionPage,regionHTML,regionOptions,pageID) SELECT 'footer' AS regionKey,'/shop/cart' AS regionPage,'<!-- Undefined content: footer -->' AS regionHTML,'' AS regionOptions,'39' AS pageID FROM (SELECT 1) AS dtable WHERE ( SELECT COUNT(*) FROM perch2_content_regions WHERE regionKey='footer' AND (regionPage='/shop/cart' OR regionPage='*') )=0 LIMIT 1
UPDATE perch2_content_regions SET regionOrder=0 WHERE regionPage='/shop/cart' AND regionKey='footer' LIMIT 1
Request time: 0.0681
Process time: 0.0678
Memory: 6.2333

and my diagnostics

Summary information

Perch Runway: 3.0.5, PHP: 5.4.45, MySQL: 5.5.54, with MySQLi
Server OS: Linux, cgi-fcgi
Installed apps: content (3.0.5), assets (3.0.5), categories (3.0.5), perch_shop_orders (1.2), perch_shop_products (1.2), perch_shop (1.2), perch_members (1.6.1)
App runtimes: <?php $apps_list = array( 'perch_members', 'perch_shop', );
PERCH_LOGINPATH: /perch
PERCH_PATH: /home/fullfatwebsite/public_html/stotto/perch
PERCH_CORE: /home/fullfatwebsite/public_html/stotto/perch/core
PERCH_RESFILEPATH: /home/fullfatwebsite/public_html/stotto/perch/resources
Image manipulation: GD
PHP limits: Max upload 25M, Max POST 128M, Memory: 256M, Total max file upload: 25M
F1: 0c66c2e1f82f9e0b7617b2cb8270f2c7
Resource folder writeable: Yes
DOCUMENT_ROOT: /home/fullfatwebsite/public_html/stotto
HTTP_HOST: stotto.fullfatwebsitedesign.co.uk
REQUEST_URI: /perch/core/settings/diagnostics/
SCRIPT_NAME: /perch/core/settings/diagnostics/index.php
Wayne Hooper

Wayne Hooper 6 points

  • 4 years ago
Drew McLellan

Drew McLellan 2638 points
Perch Support

What happens?

It takes you to the cart page, but doesn't enter the product. I have a WIP version on here and if you enter a single priced product like this it enters.

Hi Wayne

You've got two </perch:form> closing tags in your product detail template. Could that be breaking the variant form?

If not maybe strip the logic down to the basics and take out the if statement so you're just testing variants.

Jon

Thanks so far.

I've taken the extra closing tag out - same result.

And I've tried taking the if statement out - Same result;

<div class="col-sm-5">
    <h1><perch:shop id="title" type="text" label="Title" required="true" order="2" /></h1>
    <div class="row">
    <div class="col-xs-12">
    <perch:shop id="description" type="textarea"  />
    <h5>Purchase options</h5>
    <div class="variants">
        <perch:variants>

            <div class="variant">
                <perch:variant id="productVariantDesc" type="text" />
                <perch:variant id="price" type="shop_currency_value" />
                <perch:form id="add_to_cart_variants" app="perch_shop" action="/shop/cart" class="add-to-cart-form">
                    <perch:input id="product" type="hidden" env-autofill="false" value="<perch:variant id="productID" type="hidden" env-autofill="false" />" />
                    <perch:input type="submit" value="Add to cart" class="btn btn-primary btn-sm"/>
                </perch:form>
            </div>
        </perch:variants>
    </div>
    </div>
    </div>
</div>
<div class="col-sm-7">
        <div class="product-pic">
            <div id="slider2">
                <ul class="bxslider">
                    <perch:if exists="image"><li><a class="fancybox" data-fancybox-group="gallery" href="<perch:shop id="image" label="Image" type="image" width="700"/>" ><img src="<perch:shop type="image" id="image" width="700" height="700" crop="true" label="Image" />"  /></a></li></perch:if>
                    <perch:if exists="image2"><li><a class="fancybox" data-fancybox-group="gallery" href="<perch:shop id="image2" label="Image" type="image" width="700"/>" ><img src="<perch:shop type="image" id="image2" width="700" height="700" crop="true" label="Image" />"  /></a></li></perch:if>
                    <perch:if exists="image3"><li><a class="fancybox" data-fancybox-group="gallery" href="<perch:shop id="image2" label="Image" type="image" width="700"/>" ><img src="<perch:shop type="image" id="image3" width="700" height="700" crop="true" label="Image" />"  /></a></li></perch:if>
                    <perch:if exists="image4"><li><a class="fancybox" data-fancybox-group="gallery" href="<perch:shop id="image2" label="Image" type="image" width="700"/>" ><img src="<perch:shop type="image" id="image4" width="700" height="700" crop="true" label="Image" />"  /></a></li></perch:if>
                    <perch:if exists="image5"><li><a class="fancybox" data-fancybox-group="gallery" href="<perch:shop id="image2" label="Image" type="image" width="700"/>" ><img src="<perch:shop type="image" id="image5" width="700" height="700" crop="true" label="Image" />"  /></a></li></perch:if>
                    <perch:if exists="image6"><li><a class="fancybox" data-fancybox-group="gallery" href="<perch:shop id="image2" label="Image" type="image" width="700"/>" ><img src="<perch:shop type="image" id="image6" width="700" height="700" crop="true" label="Image" />"  /></a></li></perch:if>
                    <perch:if exists="image7"><li><a class="fancybox" data-fancybox-group="gallery" href="<perch:shop id="image2" label="Image" type="image" width="700"/>" ><img src="<perch:shop type="image" id="image7" width="700" height="700" crop="true" label="Image" />"  /></a></li></perch:if>
                 </ul>
            </div>
        </div>
        <div class="product-features">
            <div class="product-sidebar">
                <h4>Product Features</h4>
                <perch:shop id="code-text" type="textarea" />
                <perch:shop id="key" type="textarea" />
            </div>
        </div>
</div>

Is the ID wrong on the variant add to cart form? Shouldn't it be add_to_cart?

Well spotted Jonathan.

I must have changed it when I was getting Variants to show. I've now changed it and its working fine.

Thank you.