Jump to content

Edit History

Elvinas

Elvinas


grammar

So I coded myself a custom PrestaShop theme, and I added my customized JavaSript, to update, delete and remove items from the cart via AJAX.

Here's the code snippet:

$.post(prestashop.urls.pages.cart, {
        token: prestashop.static_token,
        id_product: idProduct,
        id_customization: idCustomization,
        qty: 21212112,
        add: 1,
        action: 'update'

    }, function(response) {
        console.log(response);
    }, 'json');

The problem I'm having is quite strange. So this AJAX post request calls the CartController at root_directory/controllers/CartController.php and even though I have already defined the quantity limit for my products, somehow it still hapilly updates the quantity over the specified limit which doesn't make any sense.

After making this request I'm getting such response:

{
    "hasError": true,
    "errors": [
        "The product is no longer available in this quantity."
    ],
    "quantity": 21212112
}

Even though the error states and the product is no longer available in this quantity. Im my cart the quantity amount that I specified was actually updated, and it should respect this quantity limit, so I imagine after refreshing the cart should stay the same without updating the amount. I'm really not sure why PrestaShop does that.

I tried looking at other PrestaShop websites and it looks it is working correctly, and I don't understand what is wrong with mine, only the JavaScript part I'm handling myself but the controllers are not touched they are original ones. Also DEBUG mode is enabled currently if that helps. Prestashop version is 1.7.7.4

Any help would be really appreciated.

Elvinas

Elvinas

So I coded myself a custom PrestaShop theme, and I added my customized JavaSript, to update, delete and remove items from the cart via AJAX.

Here's the code snippet:

$.post(prestashop.urls.pages.cart, {
        token: prestashop.static_token,
        id_product: idProduct,
        id_customization: idCustomization,
        qty: 21212112,
        add: 1,
        action: 'update'

    }, function(response) {
        console.log(response);
    }, 'json');

The problem I'm having is quite strange. So this AJAX post request calls the CartController at root_directory/controllers/CartController.php and even though I have already defined the quantity limit for my products, somehow it still hapilly updates the quantity over the specified limit which doesn't make any sense.

After making this request I'm getting such response:

{
    "hasError": true,
    "errors": [
        "The product is no longer available in this quantity."
    ],
    "quantity": 21212112
}

Even though the error states and the product is no longer available in this quantity. Im my cart the quantity amount that I specified was actually updated, and it should respect this quantity limit, so I imagine after refreshing the cart should stay the same without updating the amount. I'm really not sure why PrestaShop does that.

I tried looking at other PrestaShop websites and it looks it is working correctly, and I don't understand what is wrong with mine, only the JavaScript part I'm handling myself but the controllers are not touched they are original ones. Also DEBUG mode is enabled currently if that helps.

Any help would be really appreciated.

×
×
  • Create New...