Jump to content

Prestashop product quantity limit does not work


Recommended Posts

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.

Edited by Elvinas
grammar (see edit history)
Link to comment
Share on other sites

47 minutes ago, ndiaga said:

Hi,

Of  course  if    this    qty=21212112    is  bigger  than  what  is  available  you  will see that  message.

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

 

Sorry, but this is not what I'm asking, I get this error but the quantity to the cart is still added, that's the problem. The error is fine.

Link to comment
Share on other sites

2 hours ago, ndiaga said:

You  are  adding  the  quantity  without  verify  the  stock.

Check  how  the  stock  verification  is  done  from  product  details   page.

Isn't the cart controller supposed to check the stock quantity? If I'm getting an error then definitely there is some kind of check.
But I can't find the reason why does it pass easily, although error code is generated. Should I look at cart controller class?

Link to comment
Share on other sites

Unfortunately there is no PHP file, all there is is some JavaScript and I see that it reaches this method: protected function processChangeProductInCart()

in controllers/CartController.php. Sorry for asking too much I got stuck for a couple of days. Everything else is the same, I mean original files and such.

Since when I install a fresh copy of Prestashop I see that AJAX request is similar and it works correctly, but I'm not sure why in my case using this custom ajax request doesn't trigger the right actions so the stock limit is not respected.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...