Zen Cart Logo
Forums / General Questions / Adding products to cart with CURL?

Adding products to cart with CURL?

Locked

Views: 4,255

Results 1 to 8 of 8
This thread is locked. New replies are disabled.
18 May 2006, 4:53 PM
#1
borkybrown avatar

borkybrown

New Zenner

Join Date:
Oct 2005
Posts:
9
Plugin Contributions:
0

Adding products to cart with CURL?

I am trying to use CURL functions in PHP to add products to a cart. However, after trying a few different ways of passing the form fields, I haven't had any success. I have not found a way yet to enable Zen Cart to correctly receive/interpret the form field values for products_id and cart_quantity.

Here is essentially what I am trying to do:

<?php $url = "https://localhost/shop/index.php?main_page=product_info&action=add_product"; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url ); curl_setopt($ch, CURLOPT_POST, 1 ); curl_setopt($ch, CURLOPT_POSTFIELDS, "products_id=55&cart_quantity=1&" ); curl_exec( $ch ); ?>

Can anyone shed some light on this? Any ideas on how can I get this to work?

Thanks!

18 May 2006, 5:41 PM
#2
merlinpa1969 avatar

merlinpa1969

Totally Zenned

Join Date:
Mar 2004
Posts:
13,031
Plugin Contributions:
4

Re: Adding products to cart with CURL?

can you please give more detail like exactly what you are trying to do and why?

18 May 2006, 6:19 PM
#3
borkybrown avatar

borkybrown

New Zenner

Join Date:
Oct 2005
Posts:
9
Plugin Contributions:
0

Re: Adding products to cart with CURL?

Sure, I am just trying to add products to a Zen Cart shopping cart through a customized UI page separate from Zen Cart. In other words, I don't want to have to create a special customized page within the Zen Cart framework and/or use or modify other Zen Cart functions to add the products to the cart.

I have been able to get things to work just fine by submitting the form from an HTML/Javascript page (as standard Zen Cart product pages do), but I have realized that a better, less browser-dependent method is to implement my error checking and submitting the form on the server-side, via PHP (and CURL).

So I just need to get CURL to submit the form the same way as standard Zen Cart product pages do.

21 May 2006, 3:26 AM
#4
wtashby avatar

wtashby

Totally Zenned

Join Date:
Feb 2006
Posts:
594
Plugin Contributions:
0

Re: Adding products to cart with CURL?

Just wondering if you have looked into EasyPopulate? Uses a Tab file to upload everything via the admin, and is easy to use.

10 Aug 2006, 2:15 PM
#5
redxiii avatar

redxiii

New Zenner

Join Date:
Jun 2006
Posts:
58
Plugin Contributions:
0

Re: Adding products to cart with CURL?

I am also looking for a way to Add Products into Cart without using the Product Info's form. I need it to have my Custom Products, those hidden from the public Catalog, to be included in a Member's Cart.

It might be useful too when we provide custom-made/case-to-case/quotation-based products in links inside emails.

And like bb, I thought I could make CURL work as well.

$url = zen_href_link(zen_get_info_page($productid), zen_get_all_get_params(array('action')) . 'action=add_product');
$postdata['products_id'] = $productid;
$postdata['cart_quantity'] = 1;
$postdata['submit'] = 1;

$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, $url );
curl_setopt($ch, CURLOPT_POST, 1 );
curl_setopt($ch, CURLOPT_POSTFIELDS, $postdata );

curl_exec( $ch );
curl_close( $ch );

Need immediate assistance. Thanks.

10 Aug 2006, 4:50 PM
#6
ajeh avatar

ajeh

Oba-san

Join Date:
Sep 2003
Location:
Ohio
Posts:
62,757
Plugin Contributions:
1

Re: Adding products to cart with CURL?

Instead, you might look at the:
/includes/main_cart_actions.php

And see how those relate to the:
/includes/classes/shopping_cart.php

10 Aug 2006, 5:15 PM
#7
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,513
Plugin Contributions:
176

Re: Adding products to cart with CURL?

I'm trying to understand "whose" shopping cart you would be trying to add these products to.

using cURL would add the products to someone else's cart, not the person browsing your site.

If you're wanting to add stuff to the current customer's cart, you'll need to get a bit more creative.

You could try passing the current zenid

Or you could use their "next click" to add the extra items

Or you could use the notifier/observer system to auto-add things to the cart based on customer actions.

Really depends on what "exactly" you want to do .... which you haven't explained in full detail.

11 Aug 2006, 3:07 AM
#8
redxiii avatar

redxiii

New Zenner

Join Date:
Jun 2006
Posts:
58
Plugin Contributions:
0

Re: Adding products to cart with CURL?

Full detail, well, my previous post's practically all what I want to say. I have this logged-in required Custom Order page where customers actually create a custom product once submitted. So my form tag's action does the usual checking and process the adding of product (insert into tables products, products_description, products_to_categories and custom), then adds the newly created product (I used mysql_insert_id for the id) to the shopping cart.

So everything comes down to one single line.

$_SESSION['cart']->add_cart($newly_created_productid); // function from /includes/classes/shopping_cart.php (Thanks, Ajeh!)
// zen_redirect(zen_href_link(FILENAME_SHOPPING_CART, '')); // optional

Thank heavens it's over. And thanks guys for everything.