Results 1 to 8 of 8
  1. #1
    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&amp;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!

  2. #2
    Join Date
    Mar 2004
    Posts
    16,042
    Plugin Contributions
    5

    Default Re: Adding products to cart with CURL?

    can you please give more detail like exactly what you are trying to do and why?
    Zen cart PCI compliant Hosting

  3. #3
    Join Date
    Oct 2005
    Posts
    9
    Plugin Contributions
    0

    Default 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.

  4. #4
    Join Date
    Feb 2006
    Posts
    656
    Plugin Contributions
    0

    Default 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.
    I Think, Therefore I Zen. I Zen, Therefore, I AM!
    Personalized Flowers!
    Flowertown Speaking Roses
    using version 1.5.7-06232020

  5. #5
    Join Date
    Jun 2006
    Posts
    57
    Plugin Contributions
    0

    Default 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.

  6. #6
    Join Date
    Sep 2003
    Location
    Ohio
    Posts
    69,402
    Plugin Contributions
    6

    Default 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
    Linda McGrath
    If you have to think ... you haven't been zenned ...

    Did YOU buy the Zen Cart Team a cup of coffee and a donut today? Just click here to support the Zen Cart Team!!

    Are you using the latest? Perhaps you've a problem that's fixed in the latest version: [Upgrade today!]
    Officially PayPal-Certified! Just click here

    Try our Zen Cart Recommended Services - Hosting, Payment and more ...
    Signup for our Announcements Forums to stay up to date on important changes and updates!

  7. #7
    Join Date
    Jan 2004
    Posts
    66,444
    Plugin Contributions
    279

    Default 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.
    .

    Zen Cart - putting the dream of business ownership within reach of anyone!
    Donate to: DrByte directly or to the Zen Cart team as a whole

    Remember: Any code suggestions you see here are merely suggestions. You assume full responsibility for your use of any such suggestions, including any impact ANY alterations you make to your site may have on your PCI compliance.
    Furthermore, any advice you see here about PCI matters is merely an opinion, and should not be relied upon as "official". Official PCI information should be obtained from the PCI Security Council directly or from one of their authorized Assessors.

  8. #8
    Join Date
    Jun 2006
    Posts
    57
    Plugin Contributions
    0

    Default 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.

 

 

Similar Threads

  1. v139h Adding products with multiple attributes shopping cart
    By TAIHCM in forum Setting Up Categories, Products, Attributes
    Replies: 0
    Last Post: 22 Feb 2012, 08:20 PM
  2. Replies: 0
    Last Post: 26 Jan 2012, 02:39 PM
  3. Problem with adding products to cart
    By dealbyethan.com in forum General Questions
    Replies: 1
    Last Post: 27 Apr 2009, 03:05 AM
  4. Adding Shopping Cart with options total to Products Page
    By PhilCrandlemire in forum Templates, Stylesheets, Page Layout
    Replies: 10
    Last Post: 29 May 2008, 10:28 PM
  5. Intercepting order and adding to cart with PHP cURL
    By jds580s in forum General Questions
    Replies: 4
    Last Post: 29 Oct 2007, 08:39 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
disjunctive-egg