Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

Using "Buy Now" Button.


Alex Bath

Recommended Posts

I have enabled the "Buy Now" button on my product listing pages however because all

my products have at least one attribute, due to other functionality I have written myself,

when you click on the "Buy Now" button you are taken to the product_info.php page

instead of directly to the shopping_cart.php page, which is what I want.

 

So....

 

I modified the function tep_has_product_attributes() in file general.php so that if there is

more than one attribute for the product it returns true, thus only taking you directly to the

cart if there are one or zero attributes.

 

But...

 

This means that the cart now shows products which have attributes as having no attributes

set if the "Buy Now" route was used. Also if the same product (with only one attribute) is

added using product_info and "Buy Now" you get two entries in the cart instead of one with

a quantity of two.

 

How...

 

What can I do to add the single attribute that exists to the product that I am adding to the

cart from the "Buy Now" button?

 

Any ideas?

Link to comment
Share on other sites

OK, I figured out how to do this myself. I have seen others asking similar questions so here is how

I did it...

 

in the includes/classes/shopping_cart.php file change :

 

function add_cart($products_id, $qty = '', $attributes = '', $category_id, $notify = true) {

global $new_products_id_in_cart, $customer_id;

 

$products_id = tep_get_uprid($products_id, $attributes);

if ($notify == true) {

$new_products_id_in_cart = $products_id;

tep_session_register('new_products_id_in_cart');

}

 

if ($this->in_cart($products_id)) {

$this->update_quantity($products_id, $qty, $attributes);

} else {

if ($qty == '') $qty = '1'; // if no quantity is supplied, then add '1' to the customers basket

 

...........

 

to

 

function add_cart($products_id, $qty = '', $attributes = '', $category_id, $notify = true) {

global $new_products_id_in_cart, $customer_id;

 

// if no attributes set see if there is a defualt (one), if so add it

if (!$attributes) {

$default_attribute = tep_db_query("select options_id, options_values_id from products_attributes where products_id = '"

. $products_id . "'");

if (tep_db_num_rows($default_attribute) == 1) {

$default_attribute_values = tep_db_fetch_array($default_attribute);

$attributes = array($default_attribute_values['options_id'] => $default_attribute_values['options_values_id']);

$defaulted_attribute = true;

}

}

 

$products_id = tep_get_uprid($products_id, $attributes);

if ($notify == true) {

$new_products_id_in_cart = $products_id;

tep_session_register('new_products_id_in_cart');

}

 

if ($this->in_cart($products_id)) {

if ($defaulted_attribute) {

$qty = $this->get_quantity($products_id) + 1;

} $this->update_quantity($products_id, $qty, $attributes);

} else {

if ($qty == '') $qty = '1'; // if no quantity is supplied, then add '1' to the customers basket

 

........

 

I have put the new code in bold typeface.

 

Regards

Alex.

Link to comment
Share on other sites

Archived

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

×
×
  • Create New...