co-cart / co-cart

đź›’ CoCart is a free REST API designed to decouple your slow WooCommerce storefront and convert it blazing-fast, build in any web framework, and save you countless hours.

Home Page:https://cocartapi.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[Enhancement]: Add product validation for when attempting to update an item's quantity should the product no longer exists

seb86 opened this issue · comments

Describe the solution you'd like

Since the product is no longer valid, the item should be removed from the cart and add a notice to inform the customer it has done so as the cart response is returned.

Describe alternatives you've considered

No response

Additional context

This error only can occur if the product is no longer valid.

CRITICAL Uncaught TypeError: Argument 2 passed to CoCart_Cart_V2_Controller::validate_quantity() must be an instance of WC_Product or null, bool given.

After further reviewing. As the item no longer exists, the cart has already updated when checking for changes before the request proceeds with updating the item. Meaning that we don't need to add additional validation but reorder a validation that should have been running first to see if there is any data to validate to begin with.

This prevents any uncaught errors as we don't need to proceed with the update but return the error status.

@nicelittlethings This should be better for you if you had already downloaded and tried beta 1 that I uploaded previously. cart-rest-api-for-woocommerce-v3.7.7-beta.2.zip

You should get the following response when trying to update an item in cart that is no longer there.

{
    "code": "cocart_item_not_in_cart",
    "message": "Item specified does not exist in cart.",
    "data": {
        "status": 404
    }
}