Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

Is the Guest basket stored in the SQL database?


dimports

Recommended Posts

I'm trying to locate where the guest's shopping basket is stored until they login and merged with their member shopping cart. I know its not in the customers_basket table in the SQL database because a customer_id is required. So where is the basket stored until they login???

 

I would like to located it so I can distribute links for specific products to be added to guest shopping carts with custom prices and shipping.

Link to comment
Share on other sites

I'm trying to locate where the guest's shopping basket is stored until they login and merged with their member shopping cart. I know its not in the customers_basket table in the SQL database because a customer_id is required. So where is the basket stored until they login???

 

I would like to located it so I can distribute links for specific products to be added to guest shopping carts with custom prices and shipping.

 

in the session

Treasurer MFC

Link to comment
Share on other sites

thanks for the reply. so it is stored in the cookie. So when adding a product to your cart (as a guest), the product_id is written to a cookie?

 

The reason for my confusion is that in the product_info.php file, the Add to Cart button uses the add_cart function to add the product to the user's cart. But this same function requires a customer_id for it to work. So what function is being used to add products to guest baskets (into the session cookie)? I don't see conditions being placed to use one add_cart function is customer is signed in or if user is a guest. It seems to be using the same add_cart function:

 

    function add_cart($products_id, $qty = '1', $attributes = '', $notify = true, $product_promo = '0', $promo_ship = '0') {
     global $new_products_id_in_cart, $customer_id;

     $products_id = tep_get_uprid($products_id, $attributes);
     if ($notify == true) {
       $new_products_id_in_cart = $products_id;
       tep_session_register('new_products_id_in_cart');
     }

     if ($this->in_cart($products_id)) {
       $this->update_quantity($products_id, $qty, $attributes);
     } else {
       $this->contents[] = array($products_id);
       $this->contents[$products_id] = array('qty' => $qty);
// insert into database
       if (tep_session_is_registered('customer_id')) tep_db_query("insert into " . TABLE_CUSTOMERS_BASKET . " (customers_id, products_id, customers_basket_quantity, customers_basket_date_added, product_promo, promo_ship) values ('" . (int)$customer_id . "', '" . tep_db_input($products_id) . "', '" . $qty . "', '" . date('Ymd') . "', '" . $product_promo . "', '" . $promo_ship . "')");

       if (is_array($attributes)) {
         reset($attributes);
         while (list($option, $value) = each($attributes)) {
           $this->contents[$products_id]['attributes'][$option] = $value;
// insert into database
           if (tep_session_is_registered('customer_id')) tep_db_query("insert into " . TABLE_CUSTOMERS_BASKET_ATTRIBUTES . " (customers_id, products_id, products_options_id, products_options_value_id) values ('" . (int)$customer_id . "', '" . tep_db_input($products_id) . "', '" . (int)$option . "', '" . (int)$value . "')");
         }
       }
     }
     $this->cleanup();

// assign a temporary unique ID to the order contents to prevent hack attempts during the checkout procedure
     $this->cartID = $this->generate_cart_id();
   }

Link to comment
Share on other sites

In other words, why is there not a condition in the above function for:

 

if (tep_session_is_registered('customer_id'))

tep_db_query("insert into " . TABLE_CUSTOMERS_BASKET . " (customers_id, products_id, customers_basket_quantity, customers_basket_date_added, product_promo, promo_ship) values ('" . (int)$customer_id . "', '" . tep_db_input($products_id) . "', '" . $qty . "', '" . date('Ymd') . "', '" . $product_promo . "', '" . $promo_ship . "')");

 

else

//insert product to guest session cookie

Link to comment
Share on other sites

In other words, why is there not a condition in the above function for:

 

if (tep_session_is_registered('customer_id'))

tep_db_query("insert into " . TABLE_CUSTOMERS_BASKET . " (customers_id, products_id, customers_basket_quantity, customers_basket_date_added, product_promo, promo_ship) values ('" . (int)$customer_id . "', '" . tep_db_input($products_id) . "', '" . $qty . "', '" . date('Ymd') . "', '" . $product_promo . "', '" . $promo_ship . "')");

 

else

//insert product to guest session cookie

 

only the session id is stored in the cookie, the rest is stored in the session variables.

Treasurer MFC

Link to comment
Share on other sites

geez, what a tough one. im still not clear exactly where the cart forks into adding products to guests or to logged in customers. Or is it the case that products are initially entered into session variables regardless of being a guest or customer?

 

Which file handles entering these products into the session variables? I tried locating it in the session.php files under the functions and classes folders but no luck. Did I overlook it?

Link to comment
Share on other sites

geez, what a tough one. im still not clear exactly where the cart forks into adding products to guests or to logged in customers. Or is it the case that products are initially entered into session variables regardless of being a guest or customer?

 

Which file handles entering these products into the session variables? I tried locating it in the session.php files under the functions and classes folders but no luck. Did I overlook it?

 

 

The cart class is instanciated and registered in the session as a session variable.

Then products are added to that class instance.

 

if ($this->in_cart($products_id)) {

$this->update_quantity($products_id, $qty, $attributes);

} else {

$this->contents[] = array($products_id);

$this->contents[$products_id] = array('qty' => $qty);

 

 

if the customer is also known (registered in the same session) then we also add the stuff to the table.

 

// insert into database

if (tep_session_is_registered('customer_id')) tep_db_query("insert into " . TABLE_CUSTOMERS_BASKET . " (customers_id, products_id, customers_basket_quantity, customers_basket_date_added, product_promo, promo_ship) values ('" . (int)$customer_id . "', '" . tep_db_input($products_id) . "', '" . $qty . "', '" . date('Ymd') . "', '" . $product_promo . "', '" . $promo_ship . "')");

 

 

so if you want to know if a particular product is in the cart for the session,

you ask the cart instance by this for instance :

 

$cart->in_cart($products_id);

 

 

all these session variables reside in memory and are ofcourse lost when the session ends i.e. the client closes the browser

Treasurer MFC

Link to comment
Share on other sites

maybe it would help explain if I showed you what I'm trying to do:

 

http://www.dakabegroup.com/capitalmonuments/bears/index.php

 

This particular product has a custom price and shipping cost that is aside from the original price and shipping in my catalog. So I've created extra varibles in the add_cart function to take into consideration custom price and shipping if available (you can see this in the add-cart function above). This of course only works with signed in customers. But I need this to work with guests so they can checkout using the custom price and shipping cost. I plan to further use this concept for instant checkouts on my ebay auction descriptions which usually tend to have custom prices and shipping costs.

Link to comment
Share on other sites

boxtel.. THANKS for all your input! I now see a few more things I can do after your responses after being stuck for so long. Ill keep you all posted on the efforts. Anybody leave input on this thread in the meantime. Thanks again boxtel.

Link to comment
Share on other sites

maybe it would help explain if I showed you what I'm trying to do:

 

http://www.dakabegroup.com/capitalmonuments/bears/index.php

 

This particular product has a custom price and shipping cost that is aside from the original price and shipping in my catalog. So I've created extra varibles in the add_cart function to take into consideration custom price and shipping if available (you can see this in the add-cart function above). This of course only works with signed in customers. But I need this to work with guests so they can checkout using the custom price and shipping cost. I plan to further use this concept for instant checkouts on my ebay auction descriptions which usually tend to have custom prices and shipping costs.

 

It will also not work for customers this way. The table basket is only used to store the cart for the time being. As soon as the customer is back that stuff is reloaded into the session cart which is used in the checkout process.

 

I would therefore not mess with the cart but extend the products table with the promo info and adjust the price calculations accordingly.

Treasurer MFC

Link to comment
Share on other sites

hmmm, that makes sense. But I have further adjusted the shopping cart's calculation function to use the promo info in the basket if it is available, otherwise use the original pricing info.

 

I have thought to extend the products table with the promo info, but I foresee carts being mixed up with each other because I may have several promo infos for the same product. I say this because the promo info can be dynamically written to the products table, but the promo info in the table would be used as a temporary scratch pad that changes frequently. Couldn't this be a problem for multiple instances of different promotional prices? Or do you really think it is impossible for two people to checkout at the same exact second, leaving the promo info to be dnamically changed very very frequently?

Link to comment
Share on other sites

hmmm, that makes sense. But I have further adjusted the shopping cart's calculation function to use the promo info in the basket if it is available, otherwise use the original pricing info.

 

I have thought to extend the products table with the promo info, but I foresee carts being mixed up with each other because I may have several promo infos for the same product. I say this because the promo info can be dynamically written to the products table, but the promo info in the table would be used as a temporary scratch pad that changes frequently. Couldn't this be a problem for multiple instances of different promotional prices? Or do you really think it is impossible for two people to checkout at the same exact second, leaving the promo info to be dnamically changed very very frequently?

 

not sure what your promo's are supposed to do but you need to keep your datamodel sound. The cart normally only holds the product id's and the quantities as it should. All other stuff is derived, prices, descriptions, etc.

 

if promo's are related to products but you can have more than 1 for the same product, you need an additional promo table linked to the product_id.

Treasurer MFC

Link to comment
Share on other sites

the promo info is just the promo price and promo shipping cost. The most important requirement for this task is to be able to pass custom pricing and shipping cost to the cart.

 

For now, I think i will concentrate on trying to add this promo info the same way attributes are handled. From what I see in the function, only product ID and attributes are stored in the session. So I will try to include promo price and shipping cost to that.

 

if theres a better approach to passing pricing variable o the cart, please do let me know what you think. thanks again.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...