By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
426,045 Members | 1,760 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 426,045 IT Pros & Developers. It's quick & easy.

How to achieve AddToCart Without quantity?

aveeva
P: 27
I am following the below module,

https://www.webslesson.info/2018/04/...-ajax-php.html

How can i use without quantity [Product Name, Price, total, Action] i tried lot fail again and again. I am learning stage in PHP, any help pls welcome.
4 Weeks Ago #1

✓ answered by Luuk

I did not test what happens when you use AddtoCar without quantity, but looking at the code is seems pretty obvious why you cannot add an object with quantity=0

Do examine this piece of code from 'index.php'
Expand|Select|Wrap|Line Numbers
  1.         if(product_quantity > 0)
  2.         {
  3.             $.ajax({
  4.                 url:"action.php",
  5.                 method:"POST",
  6.                 data:{product_id:product_id, product_name:product_name, product_price:product_price, product_quantity:product_quantity, action:action},
  7.                 success:function(data)
  8.                 {
  9.                     load_cart_data();
  10.                     alert("Item has been Added into Cart");
  11.                 }
  12.             });
  13.         }
  14.         else
  15.         {
  16.             alert("lease Enter Number of Quantity");
  17.         }

Share this Question
Share on Google+
6 Replies


Expert 100+
P: 1,035
I did not test what happens when you use AddtoCar without quantity, but looking at the code is seems pretty obvious why you cannot add an object with quantity=0

Do examine this piece of code from 'index.php'
Expand|Select|Wrap|Line Numbers
  1.         if(product_quantity > 0)
  2.         {
  3.             $.ajax({
  4.                 url:"action.php",
  5.                 method:"POST",
  6.                 data:{product_id:product_id, product_name:product_name, product_price:product_price, product_quantity:product_quantity, action:action},
  7.                 success:function(data)
  8.                 {
  9.                     load_cart_data();
  10.                     alert("Item has been Added into Cart");
  11.                 }
  12.             });
  13.         }
  14.         else
  15.         {
  16.             alert("lease Enter Number of Quantity");
  17.         }
4 Weeks Ago #2

aveeva
P: 27
I just want to conform myself, your code as same as above shown code? May I know what change in the code?
4 Weeks Ago #3

Expert 100+
P: 1,035
Because you show an 'external link' to the code, I have copied the code to this site, so everyone can see what piece is handling the quantity stuff.. (If they are really interested in the complete code, they can follow the link (for as long as it exists...))

I did not change the code, because to /me your problem is SOO obvious (sorry), so I just copied relevant piece of code.
3 Weeks Ago #4

zmbd
Expert Mod 5K+
P: 5,397
aveeva:

Luuk has given you a very good answer, what have you done to actually troubleshoot your code?

I've set Luuk's post#4 as best answer

In the future please keep in mind that we normally require that the relevant part of the code be inserted and formatted using the [CODE/] format tool to be part of your thread for several reasons:
1) Such links are can be transient (as Luuk pointed out).
2) As many of us answer questions at work while on breaks or between project down times - the companies we work for often block code sites
3) Links like this can lead to malicious websites. I actually used a service that checks sites such that you linked to for threats before allowing this thread to stay.
3 Weeks Ago #5

P: 6
Try quantity = 1 would be a simple solution
2 Weeks Ago #6

gits
Expert Mod 5K+
P: 5,282
no - its not. The question was why a quantity of 0 wont work and Luuk did show the code that is responsible for that. Code is always doing as it is written - if you write a condition that checks for a value > 0 then it will fail of course when the value is 0. Simple as that.

Why anyone would like to add any kind of item to a cart with a quantity of 0 is another question and somehow beyond my imagination-capabilities though.
2 Weeks Ago #7

Post your reply

Sign in to post your reply or Sign up for a free account.