Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

possible to pre-populate cart?


WhereAmI

Recommended Posts

hi,

 

is the following possible:

 

i send an email to my customer with a link. they click the link and it opens my shop, but with specific products already added to the basket. they mail can contain a couple links, each link will add a specific list of products to their shopping cart if clicked.

 

they can then just go to check-out and pay for the list of products.

 

thanks for the info!

hugh

Link to comment
Share on other sites

If the email is sent as an HTML page containing a form that POSTs to your store (destination most likely the shopping_cart.php file). The information to POST will be the product_ids of the products to add to the cart.

 

If you wish to add multiple products, then you will need to POST the product ids as an array and modify the includes/application_top.php file to step through the product_id array if an array is provided vice a single product id.

"Great spirits have always found violent opposition from mediocre minds. The latter cannot understand it when a man does not thoughtlessly submit to hereditary prejudices but honestly and courageously uses his intelligence." - A. Einstein

Link to comment
Share on other sites

If the email is sent as an HTML page containing a form that POSTs to your store (destination most likely the shopping_cart.php file). The information to POST will be the product_ids of the products to add to the cart.

 

If you wish to add multiple products, then you will need to POST the product ids as an array and modify the includes/application_top.php file to step through the product_id array if an array is provided vice a single product id.

 

 

thanks Daemonj, that did the trick. i am passing a comma delimited value as the hidden field. in application_top i then parse the posted value and loop through the resulted array. this way, the same loop works even with single productIds...

 

thanks again :D

hugh

Link to comment
Share on other sites

Awesome idea Hugh. B)

 

Glad to hear that you got it working.

"Great spirits have always found violent opposition from mediocre minds. The latter cannot understand it when a man does not thoughtlessly submit to hereditary prejudices but honestly and courageously uses his intelligence." - A. Einstein

Link to comment
Share on other sites

I think this is the thing that I've been looking for. I'm going to also try it and see how it works for me. The difference I'm using is actually having an HTML page with a form that will go directly to the shopping cart. Thanks Jim for the helpful post.

Link to comment
Share on other sites

i got a PM from a forum user, asking me to post code snippets of how i resolved this problem, so here goes:

 

first, you need to post a form with a list of productIDs as a hidden field. this need to be posted to "shopping_cart.php?action=add_product", like follow:

 

<form name="cart_quantity" action="shopping_cart.php?action=add_product" method="post">

<input type="hidden" name="products_id" value="1,8,10">

<input type="submit" name="Submit" value="Submit">

</form>

 

then, alter your "includes\application_top.php" in the "add_product" section to look like follow:

 

case 'add_product' : if (isset($HTTP_POST_VARS['products_id'])) {

include '../myincludes/parsecsvline.php' ;

$arr = parseCSVline ($HTTP_POST_VARS['products_id']) ;

 

foreach ($arr as $value)

{

if (is_numeric($value)){

$cart->add_cart($value, $cart->get_quantity(tep_get_uprid($value, $HTTP_POST_VARS['id']))+1, $HTTP_POST_VARS['id']);

}

}

}

tep_redirect(tep_href_link($goto, tep_get_all_get_params($parameters)));

break;

 

the above will loop through the comma seperated value you posted. you'll see i added a function that will parse the comma seperated (or just a single) values into an array. its a function i found somewhere on the internet, so you might have one of your own that can do the same job:

 

<?

function parseCSVline($line) {

unset($arr);

 

$quote= ""; $quoteflag= 0; $backslash= 0; $itemindex= 0; unset($item);

for ($i= 0; $i < strlen($line); $i++) {

$c= $line{$i};

 

if ($c == "\\") {

$backslash= 1-$backslash;

if ($backslash == 0) $item.= $c;

}

else {

if ($c == "\"" or $c == "'") {

if($backslash == 0) {

if ($item == "" and $quoteflag == 0) {

$quote= $c; $quoteflag= 1;

 

}

else {

if ($c == $quote) {

if ($quoteflag == 0) {

print_r($arr);

return "parse error at position ".$i.": quote not expected\n";

}

 

$quoteflag= 0;

}

else $item.= $c;

}

}

else $item.= $c;

$backslash= 0;

}

else {

if ($c == ",") {

if ($backslash == 0) {

if ($quoteflag == 1) {

$item.= $c;

}

else {

$arr[]= $item;

unset($item);

}

}

else $item.= $c;

 

$backslash= 0;

}

else {

$item.= $c; // sommige backslash-dingen moeten gebackslasht blijven, bv. \t misschien, maar goed, andere keer

$backslash= 0;

}

}

}

 

 

 

$itemindex++;

}

 

if ($quoteflag == 1) return "parse error at position ".$i.": quote expected\n";

if ($backslash == 1) return "parse error at position ".$i.": backslash expected\n";

 

$arr[]= $item;

 

return $arr;

}

?>

 

I hope the above helps you with your project... :)

 

regards

hugh

Link to comment
Share on other sites

  • 3 weeks later...

Archived

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

×
×
  • Create New...