Welcome, Guest
  • Author Topic: Cart Cannot Update Accordingly - Need Help  (Read 1876 times)

    cyh123

    • Server what's that
    • *
    • Posts: 4
      • View Profile
    Cart Cannot Update Accordingly - Need Help
    « on: 10/17/07, 05:23 »
    Dear Mr/Ms

    Below attached the script.

    When i choose the "Save Changes" button the total item and total price will always reset to "0", cannot add up.  This problem also same when i change the quantity and press enter  +  press check out button.

    Need your kind & expertize advice.  Thank U so much.


    show_cart.php

    <?php
      include ('book_sc_fns.php');
      // The shopping cart needs sessions, so start one
      session_start();

      @ $new = $_GET['new'];

      if($new)
      {
        //new item selected
        if(!isset($_SESSION['cart']))
        {
          $_SESSION['cart'] = array();
          $_SESSION['items'] = 0;
          $_SESSION['total_price'] ='0.00';
        }

        if(isset($_SESSION['cart'][$new]))
          $_SESSION['cart'][$new]++;
        else
          $_SESSION['cart'][$new] = 1;

        $_SESSION['total_price'] = calculate_price($_SESSION['cart']);
        $_SESSION['items'] = calculate_items($_SESSION['cart']);
      }

      if(isset($_POST['save']))
      {   
        foreach ($_SESSION['cart'] as $isbn => $qty)
        {
          if($_POST[$isbn]=='0')
            unset($_SESSION['cart'][$isbn]);
          else
            $_SESSION['cart'][$isbn] = $_POST[$isbn];
        }
        $_SESSION['total_price'] = calculate_price($_SESSION['cart']);
        $_SESSION['items'] = calculate_items($_SESSION['cart']);
      }

      do_html_header('Your shopping cart');

      if($_SESSION['cart']&&array_count_values($_SESSION['cart']))
        display_cart($_SESSION['cart']);
      else
      {
        echo '<p>There are no items in your cart</p>';
        echo '<hr />';
      }
      $target = 'index.php';

      // if we have just added an item to the cart, continue shopping in that category
      if($new)
      {
        $details =  get_book_details($new);
        if($details['catid'])   
          $target = 'show_cat.php?catid='.$details['catid'];
      }
      display_button($target, 'continue-shopping', 'Continue Shopping'); 

      // use this if SSL is set up
      // $path = $_SERVER['PHP_SELF'];
      // $server = $_SERVER['SERVER_NAME'];
      // $path = str_replace('show_cart.php', '', $path);
      // display_button('https://'.$server.$path.'checkout.php',
      //                  'go-to-checkout', 'Go To Checkout'); 

      // if no SSL use below code
      display_button('checkout.php', 'go-to-checkout', 'Go To Checkout'); 

     
      do_html_footer();
    ?>




    Jorge Solis

    • Global Moderator
    • Systems Administrator
    • *****
    • Posts: 14616
      • View Profile
    Re: Cart Cannot Update Accordingly - Need Help
    « Reply #1 on: 10/17/07, 05:46 »
    Your cart is session based, and seems session are not working well:

    if(!isset($_SESSION['cart']))
        {
          $_SESSION['cart'] = array();
          $_SESSION['items'] = 0;
          $_SESSION['total_price'] ='0.00';
        }

    It enters here all the time. Do some quick test. Add something to the cart, then add this line:

    var_dump($_SESSION);

    And check if your data is stored there

    Jorge

    cyh123

    • Server what's that
    • *
    • Posts: 4
      • View Profile
    Re: Cart Cannot Update Accordingly - Need Help
    « Reply #2 on: 10/17/07, 10:13 »
    TQ for the suggestion

    Tried Refresh - still cannot update

    Tried with var_dump($_SESSION); - also same.

    any other suggestion....or relate to file permission ....  Kindly advice

    TQVM

    Jorge Solis

    • Global Moderator
    • Systems Administrator
    • *****
    • Posts: 14616
      • View Profile
    Re: Cart Cannot Update Accordingly - Need Help
    « Reply #3 on: 10/17/07, 11:47 »
    var_dump is to show what the session haves, not to update your cart

    Jorge