Forum

Thread tagged as: Shop

cart delete item

Hi,

what is the best way to delete a item from a cart. There is no documentation on this.
looks like I need to call: public function update_from_form($SubmittedForm)

advice please

tony

Tony Monckton

Tony Monckton 0 points

  • 5 years ago
Drew McLellan

Drew McLellan 2638 points
Perch Support

Form which context do you wish to remove the item?

If you want to add a button to the cart display, there's a good example here: https://github.com/PerchCMS/perchdemo-nest/blob/master/public_html/perch/templates/shop/cart/cart.html

Hi,

delete item now works. but Quality does not update! do I need an update button?

thanks in advance

tony

<perch:if id="product_count" match="gt" value="0">
    <perch:form id="cart" app="perch_shop">
        <perch:input type="submit" value="Update" hidden="true" aria-hidden="true" />
        <perch:cartitems>
            <div id="item_<perch:cartitem id="identifier" />" class="myCart_item">
                <div class="myCart_wrap">
                    <perch:input id="" type="submit" value="Update" hidden="true" aria-hidden="true" />
                    <div class="myItem_image">
                        <perch:cartitem id="image" class="cartitem_image" type="image" height="375" crop="true" output="tag" />
                    </div>
                    <div class="myItem_title">
                        <h3><perch:cartitem id="title" /></h3>
                    </div>
                    <div class="myItem_desc">
                        <div style="width:95%;">
                            <h5 style="line-height:20px;"><perch:cartitem id="description" type="textarea" markdown="true" /></h5>
                        </div>
                        <div style="width:95%;">
                            <h5 style="line-height:20px;"><perch:cartitem id="variant_desc" /></h5>
                        </div>
                    </div>
                    <div class="myItem_prices">
                        <table class="myItem_prices" style="float:left;width:95%;" border=0 >
                            <tr>
                                <td>Qty:</td>
                                <td>
                                <perch:input id="qty:<perch:cartitem id="identifier" />" value="<perch:cartitem id="quantity" />" type="number" min="0" />
                                </td>
                            </tr>
                            <tr><td>Price:&nbsp;</td><td><perch:cartitem id="price_without_tax_formatted" /></td></tr>
                            <tr><td>Total:&nbsp;</td><td><perch:cartitem id="total_without_tax_formatted" /></td></tr>
                            <tr><td>&nbsp;</td><td>&nbsp;</td></tr>
                            <tr>
                                <td>&nbsp;</td>
                                <td>
                                    <button type="submit" class="remove_cart" name="del:<perch:cartitem id="identifier" />" value="1" onkeypress="return event.keyCode != 13;"  >Remove</button>
                                </td>
                            </tr>
                        </table>
                    </div>
                </div>
            </div>
            <div class="clearfix"></div>
        </perch:cartitems>
    </perch:form>
</perch:if>
Drew McLellan

Drew McLellan 2638 points
Perch Support

How are you submitting the form after changing the qty?

Hi,

I have no update button. I have nothing submitting of the form after change the quantity.

tony

Rachel Andrew

Rachel Andrew 394 points
Perch Support

So you will need to add that to your form.

I've add a button to cart.html, but it doesn't update the qty. qty stays the same!

<button type="submit" class="update_cart" name="qty:<perch:cartitem id="identifier" />" value="1" >Update</button>

tony

Drew McLellan

Drew McLellan 2638 points
Perch Support

If you take a look at the default cart.html template that is part of the app, you'll see a working example of this.

At the top of your form, add a hidden button to catch all default submissions:

<perch:input type="submit" value="Update" hidden="true" aria-hidden="true" />

And then whenever you want the update button, add one:

<perch:input type="submit" value="Update" />

cool, that works

many thanks

tony