|

help with using product controller
Posted 23 March 2010 - 07:56 PM #1
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
Posted 24 March 2010 - 05:40 PM #2
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;
}
Posted 24 March 2010 - 08:45 PM #3
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.

Posted 07 April 2010 - 10:16 AM #4
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
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.
Posted 19 April 2010 - 05:04 PM #6
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
Posted 21 April 2010 - 10:22 PM #7
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.
Posted 22 April 2010 - 06:02 PM #8
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