Product adding/updating programmatically

Hey



I still use trial CS cart and so far i really like it. I used Magento before and CS cart suits me better for now. The only thing i miss here is some kind of “developer documentation” or anything like that. When you need to do something in CS cart i am kind of lost. Not sure where to check and by searching on Google there are not many tips and tricks published by other users. I have some experiences with Magento before and there are a lot of articles, blogs, sites etc. with useful data, tips, tricks and code samples. Here i just found Hooks base but even this is not very well documented and you almost need to know what you are serching for.



I want to add a new product(s) to the store programmatically. I want to make some kind of API for adding or updating products from XML feed later. I know i can insert data directly to database in proper tables but with pictures, product options etc this is annoying. So is there any CS cart function which i can use for creating/updating/adding product to CS cart. If so which function is this and which attributes do i need and in what format? any samples maybe?



Anyone can post any simple sample for adding a new product with data such as product name, code, picture, options (maybe), price, list price…



Basically i need something like CSV product import does but without generating CSF file first and then import it but directly import products from XML to CS cart.

You're here too soon I'm afraid. CS-Cart 3.1.1 API - this should make it much easier than it currently is to alter data from other sources.



The release date isn't yet known, but given the rate of development, I wouldn't expect it to be much further round the corner.

@StellarBytes thanks for reply. Yeah i read about CS cart 3.1.1 and API feature and waiting for this. I am sure this is also possible now by using some of the function and code from CS cart just didn't figure out which one and how. It's something similar than adding product manually in admin panel i just want to make it a little bit faster and automate the process. I did something similar in Magento before even if i didn't use any kind of API just build in functions so i guess it's also possible here. So any tips maybe?

So in case if anyone is interested into this i guess i figure out. At least it works for me. It's kind of strange that additional categories and main categories must be applied separatly othwerwise you will probably receive “404 product not found” when clicking on product in admin panel. It's created and it's visible but can't edit it in admin panel. So here is how i do it so far without product options and without pictures. I need to figure out this as well. Here is the source:



define('AREA', 'A');
define('AREA_NAME', 'admin');
define('ACCOUNT_TYPE', 'admin');

require 'prepare.php'; //path to prepare.php on root
require 'init.php'; //path to init.php on root

// *** product array I guess you can also post less data than bellow

$produkt[product] ="Product name";
$produkt[company_id] ="0";
$produkt[categories] = array("119", "120", "123"); //additional categories array
$produkt[main_category] ="121"; //main category id (i think must be different than additional cat ids above
$produkt[price] ="39.96";
$produkt[full_description] ="This is full description
....";
$produkt[status] ="A";
$produkt[options_type] ="P";
$produkt[exceptions_type] ="F";
$produkt[product_code] ="EAN123";
$produkt[list_price] ="49.95";
$produkt[amount] ="50";
$produkt[zero_price_action] ="R";
$produkt[tracking] ="B";
$produkt[min_qty] ="0";
$produkt[max_qty] ="0";
$produkt[qty_step] ="0";
$produkt[list_qty_count] ="0";
$produkt[tax_ids] ="";
$produkt[page_title] ="Page title @ domain.com";
$produkt[meta_description] ="Meta description";
$produkt[meta_keywords] ="Meta keywords";
$produkt[usergroup_ids] ="0";
$produkt[timestamp] ="";
$produkt[avail_since] ="";
$produkt[out_of_stock_actions] ="N";
$produkt[details_layout] ="default";
$produkt[feature_comparison] ="N";
$produkt[is_edp] ="N";
$produkt[edp_shipping] ="N";
$produkt[unlimited_download] ="N";
$produkt[short_description] ="This is product short desc";
$produkt[popularity] ="56";
$produkt[search_words] ="";
$produkt[weight] ="0.00";
$produkt[free_shipping] ="N";
$produkt[shipping_freight] ="0.00";
$produkt[min_items_in_box] ="0";
$produkt[max_items_in_box] ="0";


$product_id = fn_update_product($produkt); // update/insert product into CS cart - return product id
//for updating a product:
// $product_id = fn_update_product($produkt, "1234"); //update product with ID 1234

// ******** Apply product to subcategories from array above
foreach ($produkt[categories] as $cats){

echo "$cats
"; //just echo

$_data = array (
'product_id' => $product_id, //this is returned product id
'link_type' => 'A', //A for other categories
'category_id' => "$cats", //for every category id in array
'position' => '0', //not really sure i guess could be 0 for all subcats
);

db_query("INSERT INTO ?:products_categories ?e", $_data); //insert to DB otherwise you will get 404 error (product without cats)
fn_update_product_count(array("$cats")); //i guess it update product count in this category

}
unset($_data); //unset $_data

// ********** Apply Main cat - just one so without foreach but same procedure as above for subcats just set to M (main) instead of A

$_data = array (
'product_id' => $product_id,
'link_type' => 'M',
'category_id' => $produkt[main_category],
'position' => '0',
);

db_query("INSERT INTO ?:products_categories ?e", $_data);
fn_update_product_count(array($produkt[main_category]));

unset($_data);




Thats it it works for me now i just need to parse different XML feeds and need to figure out the solution for product variants and pictures.

how will you proceed if you need not only to add new products but also update the existing ones?

One of the problems is non-unique product_code field. But this is the only way to determine whether the product already exists and must be updated or new product must be created instead. Just creating Unique key on product_code field won't solve this.

iam testing your code now. how u get product features ?