Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

classes/shopping_cart : add a field to cart / product


Recommended Posts

Hi

 

I need to allow my customer to provide me with 1 additional information when ordering the product.

Basically : I want him to tell me, when chosing his product "I reserve it for that date". This date will be stored in the order table. I need him to have this date selected when chosing the product, therefore I cannot use a contribution allowing the user to select the "delivery date".

 

My idea :

1. add a "timestamp" field in the product info "cart" form. This field will use a specific format

2. retreive its value to pass it into my shopping_cart

 

therefore I have to change various functions in the "classes/shopping_cart.php" : I need to be able to retreive the "timestamp" from my product_info.php file, and to insert it into my customer cart

 

=> this field should be called in the application_top thanks to the POST var :

$cart->add_cart($HTTP_POST_VARS['products_id'][$i], $HTTP_POST_VARS['timestamp'][$i], $HTTP_POST_VARS['cart_quantity'][$i], $attributes, false);

 

=> the add_cart() of classes/shopping_cart.php should have one additional entry field, $timestamp

function add_cart($products_id, $timestamp, $qty = '1', $attributes = '', $notify = true)

[...]

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

$this->contents[$products_id_string] = array('timestamp' => $timestamp);

// 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_timestamp, customers_basket_date_added) values ('" . (int)$customer_id . "', '" . tep_db_input($products_id_string) . "', '" . (int)$qty . "', '" . $timestamp . "', '" . date('Ymd') . "')");

 

could someone who knows OSCommerce confirm that my understanding is correct ?

 

Thanks in advance for your help

 

Kindest Regards

 

Rosanna

Link to comment
Share on other sites

Dear Burt

 

Thanks for your answer & confirmation.

 

Basically, the need is very similar to what would be done with a "hotel reservation" :

1. customer picks a products

2. he tells "I reserve it for date XXX"

3. depending on the date, the total price (option) is different (e.g. Sunday is more expensive than Mondays)

4. he can even pick several time a product for various dates

 

therefore, in his shopping cart, he will have for exemple 5 products,

product A date : Monday 06/01/2008, price : 55

product A date : Saterday 06/08/2008, price : 85

product A date : Wednesday 06/12/2008, price : 55

product B date : Saterday 06/08/2008, price 75

product C date : Wednesday 06/12/2008, price 45

 

I have already done my little "product_info.php" page with a calendar which gives back the day number & the date (timestamp), and selects automatically the option thanks to the day number :o) now, my only problem will be to get the timestamp value, and include it in a new field of the customer cart table, and then in the customer order table (as the timestamp will be associated with the product)

 

Thanks for your advice : in fact, I am effectively going to do all my various tests on a development server :) but needed to check if my understanding of the classes/shopping_cart was correct (am a bit new in php development, and it already took me some time to understand when on earth was this code !! :) )

 

Do you think I will also have to change similarly the restore_contents() function :

[...]

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

// TBC : add Timestamp

$timestamp = $this->contents[$products_id]['timestamp'];

// TBC : add Timestamp

 

$product_query = tep_db_query("select products_id from " . TABLE_CUSTOMERS_BASKET . " where customers_id = '" . (int)$customer_id . "' and products_id = '" . tep_db_input($products_id) . "'");

if (!tep_db_num_rows($product_query)) {

// TBC : add Timestamp

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

// TBC : add Timestamp

if (isset($this->contents[$products_id]['attributes'])) {

reset($this->contents[$products_id]['attributes']);

while (list($option, $value) = each($this->contents[$products_id]['attributes'])) {

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 . "')");

}

}

} else {

tep_db_query("update " . TABLE_CUSTOMERS_BASKET . " set customers_basket_quantity = '" . $qty . "' where customers_id = '" . (int)$customer_id . "' and products_id = '" . tep_db_input($products_id) . "'");

}

}

 

 

Kindest Regards

 

Rosanna

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...