Olaf posted on 2008-02-14 13:22:50 #
In many webshops the customer has to login/register after the product selection is done. With the db_cart class it's possible to handle shopping carts with and without a customer ID.
Important
If you don't want to use a customer ID you need to leave the property in the constructor empty (or use a zero):
$object = new db_cart();
or if you don't know if a customer is logged in use the code like:
if (empty($customer)) $customer = 0;
$object = new db_cart($cutomer);
The most popular forum posts:
Comments / discussions
xkarlos posted on 2008-02-14 17:44:38 #
Thank you for this post,
this was think I didnt know !!!!
xkarlos posted on 2008-02-14 19:17:46 #
I am sorry but I still do not know how to do it:
If I use $object = new db_cart();
how can I get the customer id number ?
thank you
Olaf posted on 2008-02-14 19:54:45 #
Quote from: xkarlos
"I am sorry but I still do not know how to do it:
If I use $object = new db_cart();
how can I get the customer id number ?
thank you"
in this case the default value "0" (zero) is used...
xkarlos posted on 2008-02-14 22:53:20 #
I try to describe my problem in detail,
becouse it doesnot work me.
I have two pages : 1 - site with products and shown the total value of the shopping cart, 2 - page with the shopping cart.
When I add in page 1 things to the cart, the total value shows good,
bud in the 2nd page is nothing in the basket.
In page 1 I have: $myCart = new db_cart(0);
In page 2 I have: $myCheckout = new db_cart(0);
But it still doesnot work.
In your example files you have there :
$_SESSION['custom_num'] = $cust->cust_no;
$_SESSION['email'] = $cust->email;
(I dont have it there, is that required ?)
Shall i have in all pages the same db cart object ?
many thanks for your help here
Olaf posted on 2008-02-15 06:57:51 #
Hi,
the two session variables are an example if you have some other customer database.
please post the PHP code from your second page.
xkarlos posted on 2008-02-15 17:10:25 #
// use the DB constants or some diffenrent
$myCheckout = new db_cart();
// update a single order row
if (isset($_POST['add']) && $_POST['add'] == "Update") {
$myCheckout->update_row($_POST['row_id'], $_POST['quantity']);
}
// update shipment and process or go back to products
if (isset($_POST['submit'])) {
// first update eventually modified data
$myCheckout->update_shipment($_POST['name'], $_POST['name2'], $_POST['address'], $_POST['address2'], $_POST['postal_code'], $_POST['place'], $_POST['country'], $_POST['message']);
if ($_POST['submit'] == "Order now!") {
$myCheckout->check_out($cust_email); // place here the mail from your customer or a variable
} else {
header("Location: ".PROD_IDX);
}
}
if (!$myCheckout->check_return_shipment()) {
// get the external customer data here
$cust_conn = mysql_connect(DB_SERVER, DB_USER, DB_PASSWORD);
mysql_select_db(DB_NAME, $cust_conn);
// the exampple query for customer data (the default shipment address)
$cust_sql = sprintf("SELECT name, name2, address, address2, postal_code, place, country FROM db_cart_example_customer WHERE cust_no = %d", $cust_no);
$cust_result = mysql_query($cust_sql) or die(mysql_error());
$cust_obj = mysql_fetch_object($cust_result);
$myCheckout->ship_name = $cust_obj->name;
$myCheckout->ship_name2 = $cust_obj->name2;
$myCheckout->ship_address = $cust_obj->address;
$myCheckout->ship_address2 = $cust_obj->address2;
$myCheckout->ship_pc = $cust_obj->postal_code;
$myCheckout->ship_city = $cust_obj->place;
$myCheckout->ship_country = $cust_obj->country;
mysql_free_result($cust_result);
$myCheckout->insert_new_shipment();
} else {
$myCheckout->set_shipment_data();
}
// show all rows in this order
$myCheckout->show_ordered_rows();
?>
Olaf posted on 2008-02-15 17:31:15 #
Hi, I removed your code since it doesn't show something new :)
check the sessions, place this code on the top of both pages
print_r($_SESSION)
and compare the result (the order id) and check also the database records
xkarlos posted on 2008-02-15 17:55:38 #
page 1: Array ( [order_id] => 69 )
page 2: Array ( [order_id] => 69 )
Its same, but I dont know what could it be ?
do you have any idea ?
PS: When I use db_cart(0) - is it possible to do shopping by more than one customers in the same time ?
Olaf posted on 2008-02-15 18:25:16 #
The "Customer id" (zero) is only used for a check, the important thing is the "Order Id", while there are more than one "unknown" customers on your site the "Order id" is used to separate the order rows.
I think there is something wrong with the sessions, do you have the test application on some public web server?
xkarlos posted on 2008-02-15 18:45:20 #
I found out tha during the shopping I have no record in table db_cart_orders.
Only in db_cart_rows. I think this could be the problem.
Becouse there are SQL querys WHERE .... and the result of COUNT * for these querys is 0.
In this moment I dont have it on public server :(
Olaf posted on 2008-02-15 19:00:02 #
locate inside the class file this function: function get_order($customer)
and add and "echo" before this row:
$sql_new = sprintf("INSERT INTO %s (customer, order_date) VALUES (%d, NOW())", ORDERS, $customer);
test this query in phpmyadmin too
xkarlos posted on 2008-02-22 14:52:29 #
I think I have the reason of these problems:
it is this SQL command:
DELETE FROM db_cart_orders WHERE open = 'y' AND order_date < (NOW() - 715112448) AND customer = 0 )
every time I check the page 2 this script is run and delete the orders,
which are opened too. I think something is wrong with the date.
if I comment this SQL command it seems to work correctly.
what do you think about it ?
Olaf posted on 2008-02-23 08:21:52 #
do you hard coded the time value?
what do you use in the db_config file?
default is:
define("VALID_UNTIL", 7 * 86400); // 7 days
you value is about today-8276 days ;)
try the default value again
xkarlos posted on 2008-02-23 16:20:46 #
I have the default value :
define("VALID_UNTIL", 7 * 86400);
But in the SQL there is * 86400 again. is this correct ?
sprintf("DELETE FROM %s WHERE open = 'y' AND order_date < (NOW() - %d)", ORDERS, VALID_UNTIL * 86400);
Olaf posted on 2008-02-23 22:49:37 #
sorry can't follow you... what you have posted before is wrong (post 389)