We are transitioning over to a new forum platform. Please post new issues there. Existing threads will be dealt with here unless you choose to move them over. Visit the new forum

Forum

Thread tagged as: Problem, Shop

Product without variant not added to cart

Hi! I'm using perch_shop_product(perch_get('product')); to display product on product.php page.

My template for product.html

<div class="gallery">
    <ul class="rslides">
        <li class="single-image">
            <img src="<perch:shop id="image" type="image" label="Main image" order="4" width="800" density="1.6" />">
        </li>
        <perch:shop id="image" type="image" width="80" height="80" density="1.6" crop="true" suppress="true"/>
        <perch:shop id="image" type="image" width="120" height="120" density="1.6" crop="true" suppress="true"/>
    <perch:repeater id="images" label="Images">


        <li class="single-image">
            <img src="<perch:shop id="more-images" type="image" label="Additional images" order="5" width="800" density="1.6" />">
        </li>
    </perch:repeater>
    </ul>
    <perch:shop id="image" type="image" width="80" height="80" density="1.6" crop="true" suppress="true"/>
    <perch:shop id="image" type="image" width="120" height="120" density="1.6" crop="true" suppress="true"/>
</div>


<div class="main-info">
    <div class="v-align">
        <h3 class="nazwa"><perch:shop id="title" type="text" label="Title" required="true" order="2" />
            <span class="cena">
                <perch:if exists="on_sale">
                        <span class="on-sale"><perch:shop id="price" type="shop_currency_value" label="Price" divider-before="Pricing" size="m" min="0" step="any" /></span>
                        <span class="on-sale-price"><perch:shop id="sale_price" type="shop_currency_value" label="Sale price" size="m" min="0" step="any"  /></span>
                 <perch:else />
                        <perch:shop id="price" type="shop_currency_value" label="Price" divider-before="Pricing" size="m" min="0" step="any" />                          
                </perch:if>

                <perch:shop id="trade_price" type="shop_currency_value" label="Trade price" size="m" min="0" step="any" runway="true" />
                <perch:shop id="on_sale" type="checkbox" value="1" label="Use sale price" suppress="true" />
                <perch:shop id="tax_group" type="shop_tax_group" label="Tax group" required="true" suppress="true" />
            </span>
        </h3>


        <perch:shop id="description" type="textarea" label="Description" editor="markitup" order="3" markdown="true" size="s" />

        <perch:shop id="status" type="shop_status" label="Status" suppress="true"/>

        <perch:shop id="brand" type="shop_brand" label="Brand" allowempty="true" suppress="true" />

        <perch:categories id="category" set="products" label="Category" suppress="true">
            <perch:category id="catTitle" />
        </perch:categories>

        <perch:shop id="catalog_only" type="shop_catalog_only" label="Catalog only" suppress="true" />
        <perch:shop id="slug" type="slug" editable="true" indelible="true" label="Slug" for="title sku" order="10" divider-before="Meta data" suppress="true" />

        <perch:shop id="sku" type="text" label="SKU" required="true" order="1" suppress="true" />


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


        <perch:form id="add_to_cart" app="perch_shop" action="/shop/cart/">
                <perch:if exists="has_variants">
                    <div class="variants">
                    <perch:input id="product" class="cs-select cs-skin-border" type="select" options="<perch:shop id="_variant_opts" type="hidden" />" placeholder="Wybierz..." required="true" />
                    </div>
                <perch:else />
                    <perch:input id="product" type="hidden" value="<perch:shop id="productID" type="hidden" env-autofill="false" />" />
                </perch:if>
                <perch:input type="submit" class="button" value="Dodaj do koszyka" />
        </perch:form>

    </div>    
</div>

When product have variants there is no problem, it is easily added to the cart.

But when product have no variants at all, it is only basic item whitout variants, stock level set for 1000, Count stock centrally for the product, when I add it to the cart nothing happens.

Debug after adding product with no variants

SELECT * FROM perch2_pages WHERE pagePath='/shop/cart/index.php' LIMIT 1
[1] SELECT * FROM perch2_shop_cart WHERE cartID=114
[1] SELECT * FROM perch2_shop_cart WHERE cartID=114
[25] SELECT DISTINCT settingID, settingValue FROM perch2_settings WHERE userID=0
[1] SELECT itemID, itemQty FROM perch2_shop_cart_items WHERE cartID=114 AND productID=0
[1] SELECT * FROM perch2_shop_products WHERE productID=0 AND productDeleted IS NULL LIMIT 1
Limiting based on stock.

Can You help me understand, where is the problem? Thank You!

Maciej Pieńczewski

Maciej Pieńczewski 0 points

  • 3 years ago
Drew McLellan

Drew McLellan 2638 points
Perch Support

productID=0 rings alarm bells.

Can you try changing this:

<perch:input id="product" type="hidden" value="<perch:shop id="productID" type="hidden" env-autofill="false" />" />

to:

<perch:input id="product" type="hidden" value="<perch:shop id="productID" type="hidden" />" env-autofill="false" />

It worked!

Thanks Drew!