Results 1 to 3 of 3
  1. #1
    Join Date
    Jul 2021
    Location
    Fukuoka Japan
    Posts
    125
    Plugin Contributions
    2

    Default Adding Quote Feature in Zen Cart

    [Note: remember to include site URL, ZC version, list of plugins, PHP version, etc ... read the Posting Tips shown above for information to include in your post here.
    And, remove this comment before actually posting!]

    I am trying to add a feature where customers can add products not registered in the product database to a quote. I created a quote table with the following columns: id, products_model, quantity, price, subtotal, status, created_at, customers_id, product_name, remark, and quote_number.

    When accessing the URL like https://domain.jp/index.php?main_pag...ZXX&quantity=1, the product model XZXX with quantity 1 gets added to the quote list, which shows the product number, quantity, unit price, subtotal, status, and a checkbox for purchasing.

    I have written the code to add the selected item to the cart, but after checking the checkbox and clicking the purchase button, it gets registered in the customers_basket table but does not show up in the shopping cart immediately. After logging out and logging back in, the cart is updated with the product. Can anyone explain why the product does not appear in the shopping cart right after purchase?

    PHP Code:
    // Update session after purchase process 
    if (isset($_POST['submit_purchase'])) {
        foreach (
    $_POST['purchase'] as $id => $purchase) {
            if (
    $purchase == 'on') {
                
    // Retrieve product information from quotes table for selected items
                
    $product_query $db->Execute("SELECT products_model, quantity FROM quotes WHERE id = " . (int)$id);
                
    $products_model $product_query->fields['products_model'];
                
    $quantity $product_query->fields['quantity'];
                
                
    // Get corresponding products_id using products_model
                
    $product_id_query $db->Execute("SELECT products_id FROM products WHERE products_model = '" zen_db_input($products_model) . "'");

                if (
    $product_id_query->RecordCount() > 0) {
                    
    $products_id $product_id_query->fields['products_id'];

                    
    // Before adding to the cart, check if the product already exists in the cart
                    
    $basket_check_query $db->Execute("SELECT products_id FROM customers_basket WHERE customers_id = $customers_id AND products_id = $products_id");

                    if (
    $basket_check_query->RecordCount() > 0) {
                       
    $cart->add_cart($products_id$quantity, [], true);
                        
    // If the product already exists in the cart, update the quantity
                        
    $db->Execute("UPDATE customers_basket 
                                      SET customers_basket_quantity = customers_basket_quantity + 
    $quantity 
                                      WHERE customers_id = 
    $customers_id AND products_id = $products_id");
                    } else {
                        
    // If the product does not exist in the cart, add it
                        
    $date_added date('Ymd');                 
                        
    $db->Execute("INSERT INTO customers_basket (customers_id, products_id, customers_basket_quantity, customers_basket_date_added)
                                      VALUES (
    $customers_id, '" zen_db_input($products_id) . "', $quantity, '" zen_db_input($date_added) . "')");
                    }
                } else {
                    
    // Error handling if product is not found (optional)
                    
    echo "The specified product was not found.";
                }
            }
        }
        
    // Redirect to update changes
        
    zen_redirect(zen_href_link(FILENAME_SHOPPING_CART'''SSL'));


  2. #2
    Join Date
    Sep 2009
    Location
    Stuart, FL
    Posts
    13,342
    Plugin Contributions
    94

    Default Re: Adding Quote Feature in Zen Cart

    Erm, possibly because while you've added the product to the customer's basket you've not added it to their cart?

  3. #3
    Join Date
    Jul 2021
    Location
    Fukuoka Japan
    Posts
    125
    Plugin Contributions
    2

    Default Resolved: Adding Quote Feature in Zen Cart

    Quote Originally Posted by lat9 View Post
    Erm, possibly because while you've added the product to the customer's basket you've not added it to their cart?
    Thank you. I thought it was enough to insert into the customers_basket table, but it turns out that $_SESSION['cart'] was also necessary

    PHP Code:
      // Use products_model to get the corresponding products_id
    $product_id_query $db->Execute("SELECT products_id FROM products WHERE products_model = '" zen_db_input($products_model) . "'");

    if (
    $product_id_query->RecordCount() > 0) {
        
    $products_id $product_id_query->fields['products_id'];

        
    // Check if the product is already in the cart before adding to customers_basket
        
    $basket_check_query $db->Execute("SELECT products_id FROM customers_basket WHERE customers_id = $customers_id AND products_id = $products_id");

        if (
    $basket_check_query->RecordCount() > 0) {
           
    $cart->add_cart($products_id$quantity, [], true);
            
    // If the product is already in the cart, update the quantity
            
    $db->Execute("UPDATE customers_basket 
                          SET customers_basket_quantity = customers_basket_quantity + 
    $quantity 
                          WHERE customers_id = 
    $customers_id AND products_id = $products_id");
        } else {
            
    // If the product is not in the cart, add a new product
            
    $date_added date('Ymd');                 
            
    $db->Execute("INSERT INTO customers_basket (customers_id, products_id, customers_basket_quantity, customers_basket_date_added)
                          VALUES (
    $customers_id, '" zen_db_input($products_id) . "', $quantity, '" zen_db_input($date_added) . "')");
        }
    } else {
        
    // Error handling if the product is not found (optional)
        
    echo "The specified product was not found.";
    }
    // Redirect to reflect the changes
    zen_redirect(zen_href_link(FILENAME_SHOPPING_CART'''SSL')); 

 

 

Similar Threads

  1. Is This Feature in Zen Cart?
    By ecroswell21 in forum General Questions
    Replies: 1
    Last Post: 12 Jun 2010, 10:50 PM
  2. Zen Cart Wishlist feature?
    By autoace in forum All Other Contributions/Addons
    Replies: 8
    Last Post: 1 Dec 2009, 07:22 PM
  3. Forum Feature in Zen Cart ?
    By ValhallaSoapGal in forum General Questions
    Replies: 2
    Last Post: 5 Dec 2008, 08:30 PM
  4. Zen Cart Functionality - quote->bid->price->pay->complete ?
    By snowglaes in forum General Questions
    Replies: 1
    Last Post: 16 May 2007, 05:28 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
disjunctive-egg
Zen-Cart, Internet Selling Services, Klamath Falls, OR