Thread tagged as: Problem, Shop

Perch Shop Cart Issue


I seem to have an issue with the cart in Perch shop.

I have page which requires a member to be logged in, once logged in they can purchase items.

If I have an empty cart and add multiple items (for example 3 separate items) to the cart in one go, my cart count updates on the page but if I then then visit the cart it displays a single item (the first one I clicked) and a quantity of 3 items.

The checkout displays the same.

However if I remove items from the cart and try adding an item individually, view cart , go back add an item etc. The items display correctly.

This seems like some kind of caching issue possibly? The same behaviour is replicated on my local wamp site and the test server.

My templates are below-

Layout to check if logged in and display my products:

<?php $pagePath = perch_page_attribute('pagePath', [], true); $cat = basename($pagePath); // get the last part of the URL //$cat = perch_page_attribute('bodyclass',[], true); // alternatively use css class to assign cat $categoryFilter = 'products/'. $cat; ?> <div class="container"> <div class="row"> <div class="col-md-11 col-md-offset-1"> <?php if($cat == 'specials'){ // specials page we need to check if logged in as only logged members can buy $specialsSubCategories = perch_categories([ 'skip-template' => true, 'filter'=> 'catParentID', 'match'=> 'eq', 'value'=> 11 // Category ID of specials ]); $template = 'products/product_list_register.html'; if (perch_member_logged_in()) { // logged in if (perch_member_has_tag('buyer')) { // only buyers can buy $template = 'products/product_list_buy.html'; } }else{ ?> <div class="message"> <p>You must be logged in to buy products</p> <p>Please <a href="/log-in">Login</a> or you can <a href="/shop/register">Register here</a></p> </div> <?php } // to handle sub category groupings we loop each sub category foreach ($specialsSubCategories as $specialsSubCategory) { ?> <h3><?php echo $specialsSubCategory['catTemplateTitle'];?></h3> <div class="row product-list"> <?php // var_dump($specialsSubCategory); $categoryFilter = $specialsSubCategory['catPath']; perch_shop_products([ 'category' => $categoryFilter, 'template' => $template, // this is in shop folder in templates ]); ?> </div> <?php } //end for each if (perch_member_logged_in()) { // logged in if (perch_member_has_tag('buyer')) { // only buyers can buy ?> <div class="panel-box"> <span><?php perch_shop_cart_item_count(); ?> item(s)</span> <a href="/shop/cart">go to cart</a> </div> <?php } } }else{ // normal product pages perch_shop_products([ 'category' => $categoryFilter, 'template' => 'products/product_list_default.html', // this is in shop folder in templates ]); } ?> </div> </div> </div>

Product Template:

<perch:form id="add_to_cart" app="perch_shop"> <div class="col-md-8"> <p><perch:shop id="title" /></p> </div> <div class="col-md-4"> <perch:input id="product" type="hidden" value="<perch:shop id="productID" type="hidden" />" /> <span><perch:shop id="current_price" type="shop_currency_value" /></span> <button class="btn btn-secondary">Add To Cart</button> <perch:input type="cms" /> </div> </perch:form>

My Cart

<perch:if id="product_count" match="gt" value="0"> <perch:form id="cart" app="perch_shop" class="cart"> <perch:input type="submit" value="Update" hidden="true" aria-hidden="true" /> <table> <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"> <p><perch:cartitem id="title" /> <i><perch:cartitem id="variant_desc" /></i></p> <div class="desc"> <perch:cartitem id="description" type="textarea" markdown="true" /> <button type="submit" class="remove_cart btn btn-secondary" 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="btn btn-primary">Checkout now</a> <button type="submit" class="btn btn-secondary">Update cart</button> <perch:input type="cms" /> </div> </perch:form> <perch:else /> <perch:shop id="empty_cart_message" encode="false" /> </perch:if>
Lee Goodman

Lee Goodman 0 points

  • 5 years ago
Drew McLellan

Drew McLellan 2638 points
Perch Support

Thanks Drew, it seems that might have fixed it.