How to achieve AddToCart Without quantity?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • aveeva
    New Member
    • Apr 2019
    • 33

    How to achieve AddToCart Without quantity?

    I am following the below module,

    In this post, we will see a simple PHP Ajax example for making a shopping cart application using Bootstrap Popover. This PHP Ajax shoppi...


    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.
  • Luuk
    Recognized Expert Top Contributor
    • Mar 2012
    • 1043

    #2
    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'
    Code:
    		if(product_quantity > 0)
    		{
    			$.ajax({
    				url:"action.php",
    				method:"POST",
    				data:{product_id:product_id, product_name:product_name, product_price:product_price, product_quantity:product_quantity, action:action},
    				success:function(data)
    				{
    					load_cart_data();
    					alert("Item has been Added into Cart");
    				}
    			});
    		}
    		else
    		{
    			alert("lease Enter Number of Quantity");
    		}

    Comment

    • aveeva
      New Member
      • Apr 2019
      • 33

      #3
      I just want to conform myself, your code as same as above shown code? May I know what change in the code?

      Comment

      • Luuk
        Recognized Expert Top Contributor
        • Mar 2012
        • 1043

        #4
        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.

        Comment

        • zmbd
          Recognized Expert Moderator Expert
          • Mar 2012
          • 5501

          #5
          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.

          Comment

          • HelenMkt
            New Member
            • Mar 2019
            • 7

            #6
            Try quantity = 1 would be a simple solution

            Comment

            • gits
              Recognized Expert Moderator Expert
              • May 2007
              • 5388

              #7
              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.

              Comment

              Working...