Jump to content

  • You cannot start a new topic
  • You cannot reply to this topic

help with using product controller Rate Topic   - - - - -

 
  • scottemick
  • Member
  • Members
  • Join Date: 17-Mar 10
  • 79 posts

Posted 23 March 2010 - 07:56 PM #1

I'm trying to use curl to log in to admin, and then use the add mode of products.php to add new products from another php script. The other php page is a web service using nusoap that my .net backend will be updating cscart from our backend systems. Does anyone have experience with this at all? Is it necessary for me to login since the scripts are on the same server? Is there something special I need to do? Any information at all appreciated greatly.

Our old integration did everything itself directly with the database & files etc, but I wanted to make this new integration like an add on that would be compatible with updates and a larger spectrum of cscart configurations.

Also I don't know how I am supposed to structure my webservice into the addons directory. All the addons seem geared to enhancing the look and feel of the website somehow rather than interacting with the underlying business logic to add/change/delete products/orders/categories/customers etc. Also the addons seem to rely on inserting themselve via hooks and pre/post controllers. My addon will manipulate the controllers, not be called by them.

Though I don't think it would be good practice, Is it possible to include the product.php file into my php script and pass the product_data and images in as parameters?

Thanks,

Scott

 
  • scottemick
  • Member
  • Members
  • Join Date: 17-Mar 10
  • 79 posts

Posted 24 March 2010 - 05:40 PM #2

I have been experimenting more with curl, but I still cannot get logged in for some reason. This is very frustrating isn't there any documentation on this or anyone who has any experience with this? It seems like no one knows anything in the forums about this product, maybe I wasted my money on buying it.

function AddProduct($product_data, $FileBytes){
$filename = "/media/data/www/webservice/image_upload/$code.jpg";
UploadFile($FileBytes,$filename);
// INIT CURL
$ch = curl_init('http://webserv01.gva-twn.com/cscart/admin.php');
// ENABLE HTTP POST
curl_setopt ($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION,1);
curl_setopt($ch, CURLOPT_HEADER,0);
curl_setopt ($ch, CURLOPT_COOKIEJAR, 'cookie.txt');
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($ch, CURLOPT_POSTFIELDS, $parameters);
//login to the admin section
$parameters= array('return_url' => 'admin.php', 'user_login' => 'root', 'password' => 'password', 'dispatch[auth.login]' => 'Sign in');
$returndata1 = curl_exec ($ch);
$date = new DateTime();
$datef = $date->format( 'mdYHis');
file_put_contents("returndata1_$datef.txt", $returndata1, FILE_APPEND);
$httpCode1 = curl_getinfo($ch, CURLINFO_HTTP_CODE);
$err1 = curl_error($ch);

curl_setopt($ch, CURLOPT_URL, 'http://webserv01.gva-twn.com/cscart/admin.php?dispatch=products.add');
//post the data to new products.php
$parameters = array('file_product_main_image_icon[0]' => '@'.$filename);
foreach ($product_data as $key => $value) {
$parameters['product_data['.$key.']'] = $value;
}
$returndata2 = curl_exec ($ch);
file_put_contents("returndata2_$datef.txt", $returndata1, FILE_APPEND);
$httpCode2 = curl_getinfo($ch, CURLINFO_HTTP_CODE);
$err2 = curl_error($ch);
if ($httpCode1==0) {
return "error from first post $err1";
}
elseif ($httpCode2==0) {
return "error from second post $err2";
}
else {
return $returndata2;
}

 
  • scottemick
  • Member
  • Members
  • Join Date: 17-Mar 10
  • 79 posts

Posted 24 March 2010 - 08:45 PM #3

I just wanted to report I have been able to:

1. call a php nusoap webservice from VB.Net
2. That webservice then uses curl to login to admin and post a new product including picture using the products.php mode=add

So I have all the information necessary to build my web service completely now for cscart integration via web service!

I'm very happy now. :)

 
  • samhn
  • Junior Member
  • Members
  • Join Date: 10-Sep 09
  • 15 posts

Posted 07 April 2010 - 10:16 AM #4

Hi Scottemick,

Can you share the way you did it? I also have RMS and I'm interested in how to update products from RMS through webservices and also download orders.

Regards,
Samhn

 
  • TexasGuy
  • Senior Member
  • Members
  • Join Date: 18-Mar 10
  • 546 posts

Posted 07 April 2010 - 04:12 PM #5

I just wanted to report I have been able to:

1. call a php nusoap webservice from VB.Net
2. That webservice then uses curl to login to admin and post a new product including picture using the products.php mode=add

So I have all the information necessary to build my web service completely now for cscart integration via web service!

I'm very happy now. :)


Why not just make a PHP webservice that would insert directly to MySQL where you would post the needed info?

Curl is such a crude solution for this.

 
  • scottemick
  • Member
  • Members
  • Join Date: 17-Mar 10
  • 79 posts

Posted 19 April 2010 - 05:04 PM #6

I did write a integration between Dynamics GP and cscart previously that accessed the GP Dynamics database directly and the cscart database directly, though not with a webservice. To use it, we had to have access to the mysql port on the web server.

For the 2nd generation product I wanted to use the api's that were available with cscart and Great Plains because the cscart database structure has changed a few times, and I wanted to have the product be installed as an add-on. So I thought using the controllers would be the way to go. On the GP side, I have gotten rid of having to poll the database every 15 min and look for changes to update cscart. Instead I am now using econnect's outgoing service to automatically generate message queue entries for any objects that are changed. So when i get an item in the outgoing queue, my code will call the webservice which calls the cscart/admin.php?dispatch=products.add, which in turn calls the products.php page with mode=add.

I had to use curl because in order to call a controller I had to be logged in it seemed. Do you know of a better way to access cscart's controllers? I'm really trying to make this a long-term stable solution.

Thanks,

Scott

 
  • tbirnseth
  • CS Cart Expert
  • Authorized Reseller
  • Join Date: 08-Nov 08
  • 12156 posts

Posted 21 April 2010 - 10:22 PM #7

The "best way" is as you're doing it.
1) Login to the admin area of the cart with an appropriate login
2) POST the appropriate data to a controller in the appropriate mode.
3) Read/parse the results.

Doing DB to DB is faster but is then sensitive to any underllying changes in the DB that happen in upgrades. Using controller/mode and POSTing the data provides you the greatest "insulation" for the future.

Another way (though I don't recommend it) is to add your addon to the list of "secure controllers". This will allow you to access your addon without logging in. The addon is respponsible for ensure ing the integrity of the caller. Hence you could then access your addon via http://yoursite.com/...your_addon.mode. Of course you will have to remove the "if( !defined('AREA') )" code and insert your own security logic.

EZ Merchant Solutions: Custom (USA based) B2B Development, Consulting, Development and Special Projects (get a quote here).
Commercial addons, payment methods and modifications to meet your business and operations needs.


 
  • scottemick
  • Member
  • Members
  • Join Date: 17-Mar 10
  • 79 posts

Posted 22 April 2010 - 06:02 PM #8

Thanks that is a really great idea to save a step with logging in, that would cut the time in half. But optimally I really could get away with only one login per product-category-orders synchronization session because I have curl saving the cookie.

And though I don't want to, because I am running out of time to put out my 2nd integration solution I may have to go with Texas Guy's idea initially though because it is a still a struggle for me to understand the whole process though I am getting better.

Back to studying this again -
http://docs.cs-cart....ame=controllers