Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

Replace 'Add to Cart' button with 2 buttons: 'Add to Cart and Continue Shopping' and 'Add to Cart and Checkout'


little mouse

Recommended Posts

Posted

I want to replace 'Add to cart' button with 2 button: 'Add to Cart and Continue Shopping' and 'Add to Cart and Checkou'.

When click on 'Add to Cart and Continue Shopping' button, it will add item you choose into cart and link to home page. Then if you click Cart in home page, you will see that item.

When click on 'Add to Cart and Checkout, it will perform features of 'Add to Cart' and 'Check Out' button.

Please help me if you know!

Thank in advance.

Regard,

Little Mouse

Posted

How I would do it?

 

I would edit the application_top page (catalog/includes/application_top.php)..

Towards the bottom of this page you will see the switch statement:

switch ($HTTP_GET_VARS['action']) {

 

The - case 'add_product' - is the section that adds a product to your cart when the $HTTP_GET_VARS['action'] = 'add_product'

 

The problem here for you is that the part above that states:

$goto = FILENAME_SHOPPING_CART;

Would send you to the shopping cart page.

 

So I would add another case statement, send it my own $HTTP_GET_VARS['action'] variable from the button, then staying pretty much with the original -

 

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

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

}

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

break;

 

except add my own such as:

 

case 'my_link' : if (isset($HTTP_POST_VARS['products_id']) && is_numeric($HTTP_POST_VARS['products_id'])) {

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

}

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

break;

 

The set the href on the button as:

tep_href_link(FILENAME_DEFAULT, 'action=my_link')

This owuld add the product to the cart then send you back to the home page

 

You could then add to your case statement to redirect wherever you wanted by adding an if statement.

 

Such as if you wanted to go to the checkout page:

 

case 'my_link' : if (isset($HTTP_POST_VARS['products_id']) && is_numeric($HTTP_POST_VARS['products_id'])) {

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

}

if(isset($HTTP_GET_VARS['my_checkout']))

{ $goto = FILENAME_CHECKOUT_SHIPPING;

}

elseif(isset($HTTP_GET_VARS['my_home']))

{ $goto = FILENAME_DEFAULT;

}

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

break;

 

Then create two buttons with href as follows:

add to cart go to home page -

tep_href_link(FILENAME_DEFAULT, tep_get_all_get_params() . 'action=my_link&my_home=true'))

 

add to cart go to checkout -

tep_href_link(FILENAME_DEFAULT, tep_get_all_get_params() . 'action=my_link&my_checkout=true')

 

I do not guranteed the above to work as is.. may need some tweaking, wont know till its tried..

And I did not try it, but it would work..

Lloyd

Posted
How I would do it?

 

I would edit the application_top page (catalog/includes/application_top.php)..

Towards the bottom of this page you will see the switch statement:

switch ($HTTP_GET_VARS['action']) {

 

The - case 'add_product' - is the section that adds a product to your cart when the $HTTP_GET_VARS['action'] = 'add_product'

 

The problem here for you is that the part above that states:

$goto = FILENAME_SHOPPING_CART;

Would send you to the shopping cart page.

 

So I would add another case statement, send it my own $HTTP_GET_VARS['action'] variable from the button, then staying pretty much with the original -

 

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

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

}

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

break;

 

except add my own such as:

 

case 'my_link' : if (isset($HTTP_POST_VARS['products_id']) && is_numeric($HTTP_POST_VARS['products_id'])) {

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

}

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

break;

 

The set the href on the button as:

tep_href_link(FILENAME_DEFAULT, 'action=my_link')

This owuld add the product to the cart then send you back to the home page

 

You could then add to your case statement to redirect wherever you wanted by adding an if statement.

 

Such as if you wanted to go to the checkout page:

 

case 'my_link' : if (isset($HTTP_POST_VARS['products_id']) && is_numeric($HTTP_POST_VARS['products_id'])) {

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

}

if(isset($HTTP_GET_VARS['my_checkout']))

{ $goto = FILENAME_CHECKOUT_SHIPPING;

}

elseif(isset($HTTP_GET_VARS['my_home']))

{ $goto = FILENAME_DEFAULT;

}

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

break;

 

Then create two buttons with href as follows:

add to cart go to home page -

tep_href_link(FILENAME_DEFAULT, tep_get_all_get_params() . 'action=my_link&my_home=true'))

 

add to cart go to checkout -

tep_href_link(FILENAME_DEFAULT, tep_get_all_get_params() . 'action=my_link&my_checkout=true')

 

I do not guranteed the above to work as is.. may need some tweaking, wont know till its tried..

And I did not try it, but it would work..

 

 

Thank you very much!

 

What osCommerce version did you say?

I don't know why, but when i run my site is not true, please detail more because I want :

 

Replace the Add to Cart feature on the product info page with two buttons:

• “Add to Cart and Continue Shopping”

• “Add to Cart and Check Out”

Posted

I use OSC 2.2

 

Where and what page are you putting the buttons? Since $HTTP_POST_VARS['products_id'] is sent by a form you will need to place the buttons within the form that sends this variable. Either that or create another form for the buttons and write the product_id into the form as the page loads, prefer the first method..

Lloyd

Posted

Thank you very much!

I'm sorry because there are mistake in my question.

What osCommerce version did you say?

I don't know why, but when i run my site is not true, please detail more because I want :

 

Replace the Add to Cart feature on the product info page with two buttons:

• “Add to Cart and Continue Shopping” : add to cart and link to product_info page

• “Add to Cart and Check Out”: add to cart and perform feature of 'CheckOut' button.

Please tell me clearly!

I replace FILENAME_DEFAULT with FILENAME_PRODUCT_INFO but when I click on “Add to Cart and Continue Shopping” button it display:"Product not found". If I choose more than 1 product, on 'Cart' (shopping_cart.php) only has 1 item(that latest choice).

Thank in advance!

Posted

I want to place these 2 buttons on product_info page.

- 'Add to Cart and Continue Shopping' will perform feature of 'Add to Cart' button and 'Continue Shopping' button. It don't link to Shopping_Cart page. After adding to cart, it still on product_info page.

- 'Add to Cart and Checkout': will perform feature of 'Add to Cart' button and 'Checkout' button

Thank for your help!

Archived

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

×
×
  • Create New...