Ok I have some code that loops data in a CSV and attempts to create or update a product in lemonstand.
It works great apart from the Category assignment which is not sticking. I'm trying to put all new products into a 'hidden from site' category so that the shop administrator can later decide which category they want to place them on the site.
Heres the simplified code:
<?php
//For Access to Lemonstand API
$Phpr_InitOnly = true;
include '../../index.php';
//The Holding Category for Newly added PRoducts
$default_category =
Shop_Category::create()->find_by_code('product-manage');
//process csv
if (($handle = fopen($csv, "r")) !== FALSE) {
while (($data = fgetcsv($handle, 1000, ',','"'))
!== FALSE) {
if($row > 0){
//attempt load product
$product = Shop_Product::create()->find_by_sku($data[0]);
if($product){
/* UPDATE A FEW THINGS */
$productdata = array('name'=>$data[1],'price'=>$data[3]);
} else {
/* CREATE PRODUCT
AND PLACE IT IN A DEFAULT HOLDING CATEGORY*/
$product = Shop_Product::create();
$productdata = array('sku'=>$data[0],
'name'=>$data[1],
'short_description'=>$data[2],
'price'=>$data[3],
'weight' => $data[5],
'url_name' => $data[0],
'category_list' => $default_category);
}
//enable product on site
$productdata['enabled'] = 1;
//save data
$product->save($productdata);
}
}
fclose($handle);
echo '[SUCCESS]';
exit;
}
The documentation says that Shop_Product->category_list should be an object of Db_DataCollection with each element in the collection an object of Shop_Category class.
Ok so thats probably where I am going wrong. But how do I put
Shop_Category::create()->find_by_code('product-manage');into a Db_DataCollection object?
If that is infact the problem here.
Help much appreciated as always

Help












