Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

Help with 'Add to Cart' link from an external page !


superdevices

Recommended Posts

I need my customers to be able to Add to Cart from external HTML pages (product pages).

The problem arrises when a new customer comes to my site (not OSCommerce part). He doesn't have any cookies set.

When he clicks on 'Add to cart' link from a plain HTML page he is redirected to the 'cookie_usage.php' page istead of getting into the Cart.

On this step he gets a cookie from OSCommerce set !

Once he have a cookie everything starts to work.

Now if he presses the browser's Back button and then 'Add to Cart' again he will correctly add an item to cart.

I suggest that the problem comes from the option 'Force Cookie Use' set to 'True'. This is the requirement of 2checkout payment module and I can't turn it off.

 

Is there a workaround on how to avoid getting 'cookie_usage.php' when someone clicks 'Add to Cart' from a non-OSCommerce page ?

Is there a way to set a cookie prior to checking if it was set ?

 

Thanks in advance for your comments.

 

p.s. May there be a way to get 2checkout payment module working without 'Force Cookie Use' ?

Link to comment
Share on other sites

The fix was quite simple.

The main idea was to leave OSCommerce files intact and to make all changes in separate files.

Then I pointed all 'Add to Cart' links to the new files.

The new files correctly add products to cart and set up cookies and the user is redirected to the standart OSCommerce files and everything else works as usual.

 

I copied application_top.php to application_top_direct_link.php and index.php to add_product.php

Then I changed line 13 in add_product.php as follows.

find:

require('includes/application_top.php');

replace:

require('includes/application_top_direct_url.php');

 

Then I changed application_top_direct_link.php as follows.

find:

$session_started = false;

if (SESSION_FORCE_COOKIE_USE == 'True') {

tep_setcookie('cookie_test', 'please_accept_for_session', time()+60*60*24*30, $cookie_path, $cookie_domain);

 

if (isset($HTTP_COOKIE_VARS['cookie_test'])) {

tep_session_start();

$session_started = true;

}

 

replace:

$session_started = false;

if (SESSION_FORCE_COOKIE_USE == 'True') {

tep_setcookie('cookie_test', 'please_accept_for_session', time()+60*60*24*30, $cookie_path, $cookie_domain);

 

if (isset($HTTP_COOKIE_VARS['cookie_test'])) {

tep_session_start();

$session_started = true;

 

} else {

$user_agent = strtolower(getenv('HTTP_USER_AGENT'));

$spider_flag = false;

 

if (tep_not_null($user_agent)) {

$spiders = file(DIR_WS_INCLUDES . 'spiders.txt');

 

for ($i=0, $n=sizeof($spiders); $i<$n; $i++) {

if (tep_not_null($spiders[$i])) {

if (is_integer(strpos($user_agent, trim($spiders[$i])))) {

$spider_flag = true;

break;

}

}

}

}

 

if ($spider_flag == false) {

tep_session_start();

$session_started = true;

}

 

}

 

Now all 'add to cart' links from simple html pages should point to add_product.php instead of index.php

Example of a link: 'http://www.yoursite.com/catalog/add_product.php?cPath=24&sort=2a&action=buy_now&products_id=31'

 

You cans see this system working on http://www.spydevelopment.com

Link to comment
Share on other sites

Archived

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

×
×
  • Create New...