Remote Import / Export

Hi there,



Apologies if this is the wrong area to post this but…



Is is possible to trigger an import / export remotely, i.e. from a windows PC?



I would like to trigger an import / export from Excel to allow integration with SAGE’s import / export. I have read about a CS-CART import / export API, but cannot find any documentation for this :frowning:



Many thanks,



David

You need to save your Excel file as a CSV with the field names at the top of each column. Then go to Import in the admin area and import, specifying comma-delimited format.



Importing orders is a bit more complicated. You have to import the customer (if you want them to have an account), then import the order (with no products, assigning it to the newly created customer id), then import the order’s products via a 3rd file. The internal CSCart PHP function to get a product’s Item ID is fn_generate_cart_id($product_code, array(), false); You then import the order items using the order id (created in step 2) and the Item ID in 2 columns, specifying price, amount, etc. The Item ID is unique per order/item… so you could even use a random number or 1,2,3, etc if you don’t want to tie into the php code.



Example for order import:


Order ID,Shipping: first name,Shipping: last name,Shipping: address,Shipping: Address (line 2),Shipping: city, ....
,Joe,Blow,11 Main St,Some City




Example for order items import (where 8173 is the order # from previous step). Example shows 2 orders (8173 and 8174):


Order ID,Item ID,Product Code,Product Name,Price,Quantity
8173,1,9781545655,Some Cool Product,12.99,4
8173,2,9787623212,Another Cool Product,13.95,8
8173,3,9782305328,Cool Product Accessory,2.99,4
8174,1,9796632722,Hot Product,43.95,1




Best way to tackle is to export orders and order items and look at the output, then import same formatting.



Alternatively, if PHP savy, program all of this as an addon (example is abbreviated):


function ob_erase($buffer) {
return '';
}
$patternz = array();
require_once(ADMIN_DIR . "exim" . DS . "exim.users.php");
$patternz['users'] = $pattern;

require_once(ADMIN_DIR . "exim" . DS . "exim.orders.php");
$patternz['orders'] = $pattern;

$customer_data = array(
'email' => strtolower($order[0]['buyer_email']),
'user_login' => "some login",
// etcetera
);

// suppress the HTTP redirect, import, then flush output
ob_start('ob_erase');
fn_import($patternz['users'], array($customer_data), array('lang_code' => 'EN', 'delimiter' => 'S'));
ob_end_clean();




The ob_erase function can be tweaked to regex out the customer # and order # needed for the next step.

Thanks so much for your reply, and for such a detailed reponse. I’ll take a better look at this later on today and pay with some examples.



Did this code come from looking through the CS-CART PHP code, or is there documentation with examples somewhere?

This code is not included in CS Cart, but it uses the internal functions that are used on the admin pages to import/export.



Unfortunately, the import process of importing an order, then importing it’s products isn’t very viable for everyday use.