Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

Adding product to cart via Ajax


dbfriends

Recommended Posts

Hi,

 

I'm currently using osCommerce for my first commercial project, and I'm really impressed with it. I'm wondering if anyone can help me with the one problem I'm still having, though...

 

I'm creating a photography site for a client, and have got 99% of the coding done. I've even written something so that uploaded images are automatically added to the products list, given an ID, and a downloadable full-size version is put into the appropriate folder.

 

The only problem I'm having is that the client wants to have an "Add to shopping cart" HTML link underneath pictures in his main gallery - not just within osCommerce itself. The site uses lots of Ajax, and at the moment I've got it set up so that clicking the link loads the URL:

 

catalog/product_info.php?action=add_product&cPath=55&products_id=4

 

It also sends "id[1]=1&products_id=4" as POST data, to emulate the button being clicked.

 

Then things start getting weird. If I go to the shopping cart, the subtotal suggests that the images have been added (ie it goes up each time I click) - but they're not visible, so can't be deleted and so on.

 

Am I missing something really obvious?

 

Thanks in advance for any help!

Link to comment
Share on other sites

This could be because the add_product looks for the products_id as posted variable hidden within a form.

 

try the follwoing instead

 

/catalog/produict_info.php?products_id=PRODUCTS_ID&action=buy_now

 

Just change the PRODUCTS_ID to the ID you want to add.

Link to comment
Share on other sites

This could be because the add_product looks for the products_id as posted variable hidden within a form.

 

try the follwoing instead

 

/catalog/produict_info.php?products_id=PRODUCTS_ID&action=buy_now

 

Just change the PRODUCTS_ID to the ID you want to add.

 

Thanks for the suggestion. I tried that, but it didn't seem to add anything at all? Anything else I could try?

Link to comment
Share on other sites

  • 2 weeks later...

Just to add to this topic, in case it's of any use to someone else. I still don't know why the first example I gave wasn't working, but the reason the buy_now one wasn't behaving is because my product had attributes (in my case, Download: Immediately) that needed to be chosen from the drop-down box.

Link to comment
Share on other sites

Archived

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

×
×
  • Create New...