16. E – Commerce Website PHP Tutorial – Quantity Control In Shopping Cart

http://mgrboston.com/tags/drum-instructors

Series: http://www.developphp.com/video/PHP#eCommerce-Website-Tutorial
Source Download: http://www.developphp.com/video/PHP/PayPal-IPN-PHP-Instant-Payment-Notification-Script
In this 16th video we will learn to allow the user to adjust item quantities inside of the PHP shopping cart. The E – Commerce Web Site we will be assembling is one in which all of the inventory is in a MySQL database and we offer a custom PHP cart for a unique shopping experience.

source

32 thoughts on “16. E – Commerce Website PHP Tutorial – Quantity Control In Shopping Cart”

  1. buying viagra over the counter in canada my code is not working , can you please help me out ?

    here <html>
    <form action="cart.php?update" method="post">
    <input type="text" value="<?php echo $values["item_quantity"]; ?>" name="quantity" /><br/>
    <input type="submit" name="adjustBtn'.$item_id.'" value="Change">
    <input name="item_to_adjust" type="hidden" value="'.$item_id.'" />
    </form>

    <function code>
    <?php
    if(isset($_POST['item_to_adjust']) && $_POST['item_to_adjust'] != ""){

    $item_to_adjust = $_POST['item_to_adjust'];
    $quantity = $_POST['quantity'];
    $i = 0 ;

    foreach($_SESSION["shopping_cart"] as $each_item){

    $i++;

    while(list($key,$value) = each($each_item)){
    if($key == "item_id" && $value == $item_to_adjust){

    array_splice($_SESSION["shopping_cart"], $i-1,1, array(array("item_id" => $item_to_adjust,"quantity" => $quantity)));

    }

    }

    }

    }

    ?>

  2. What is obvious and easy to understand is explained in great detail. What is not so easy to understand has to be teased out from a morass of non-essential digressions. In the end, that proved to be, at least in my case, an effective teaching method.

  3. Dear Adam Khoury, I need Your assistance in the Card.php file as it is showing me error as " Fatal error: Call to undefined function money_format() in D:wamp3wampwwwBilalEcommerce10-5-2015cart.php on line 120  " 

    MY line No 16:  $pricetotal = money_format("%10.2n", $pricetotal);

    Waiting for you sir……….

  4. I have a question regarding the while loop used inside the foreach loop that is used to break down the session variable to make changes to the shopping cart item quantities. I don't understand the code below. I get how it all works, just not why you need to put the code inside the while loop and why you need to run the loop while the list() is equal to the each() values because the code is already run for each value in the session right? So what am I not grasping? I know its probably something easy to get and I just haven't really figured out the while loop yet. I would really appreciate your help. And your training videos are the best I've seen by the way. keep up the good work.

     foreach($_SESSION['cart_array'] as $each_item) {
    $i++;
    while(list($key, $value) = each($each_item)) {
         if($key == "item_id" && $value == $pid) {
              array_splice($_SESSION["cart_array"],$i-1,1,array(array("item_id" => $pid, "quantity" => $each_item['quantity'] + 1)));
              $wasFound = true;
              }
         } 
    }

  5. I know Adam is busy working something else, I dont think he has time to answer all viewers questions. My question is for some of you who watched this video . . . If you look at 11:04 , I can change quantity for the latest item it was droped into shopping cart, but I cannot change quantity items for the previous items. Did I miss something, help please, and thanks !!

  6. how can we update quantity of every product to just click by single button… there are many buttons named 'change'. please also teach us how can we update quantity by just clicking one button called "Update Shopping Cart".. I hope you'll understand what i want to say..Thanx… Just add functionality don't remove change buttons..

  7. Hi Adam!!!

    I am new in E-Commerce web site design field and I am finding your tutorial really helpful.

    I just want say thank you for the time you've invested to share your knowledge and helping a number of students out there with similar projects at University.
    We rarely find that in depth explanation such as you have done here…
    Thanks a million once again.

  8. You Are Great Teacher !!!!!!
    btw i need some help ,
    in inventory edit , my 1st entry is no getting edited at all ,, all other entries are editable but not 1st , also no matter what Product id i pass from inventory_list to edit, last products name gets fetched ,
    please help,
    im waiting for your reply !

  9. pls adam how can we use dropdown menu to change the quantity and get the price to change. I tried using textbox like you showed us but the quantity doesnt change till i click the change the button twice and when i have more than one item in the cart,clicking on change for one quantity resets the other quantities to one.

  10. any idea how i want decrease quantity item from database, mean when someone buying, the quantity item decrease. like in my store have 30 cap then someone buy 3 item = mean now in database have 27, the system auto decrease quantity in database,can u make tutor for that…

  11. To check that $quantity is a number you can do :
    if (is_numeric($quantity) == false || $quantity < 0)
    {
    $quantity = 1;
    }
    $quantity = round ($quantity);
    I also added <0 so you cannot have a value of -1, and round so you cannot have 1.4

  12. well i have made a drop down menu so they can only pick to change the number to max of 5 as i dont think i need it to be higher than that i will post it at develop php and zook i put the header code on the end of the new section 3 so just like we did before

  13. @p0ker1sc00l
    Check to where the header-commands leed, And if you have put the sections in the same order as Adam did.
    Might help… If not check the variablenames for misspelling. Especially around the POST-Sector and the names of the form. That should make it.

  14. @cockerspanielhome I agree man, the source code is the last thing I am waiting for. Understanding is what matter. That’s why I keep watching these videos over and over again until I get the logic of why is he doing it that way

  15. Learning how do all this is more important than just getting the source code. I plan on watching this series over and over till I start understand how all this code works and produces your finished product.

    Thank you,

    Eric

Leave a Reply

Your email address will not be published. Required fields are marked *