Created
April 28, 2011 14:27
-
-
Save EdwardIII/946446 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env php | |
<?php | |
include_once ('magento_keys.php'); | |
function get_root_category_id ($default_categories){ | |
global $session_id, $proxy; | |
if($default_categories['name'] == 'Root Catalog'){ | |
if($default_categories['children'][0]['name'] == 'Default Category'){ | |
print "Found root category.\n"; | |
return $default_categories['children'][0]['category_id']; | |
}else{ | |
die("Couldn't find default category"); | |
} | |
}else{ | |
die("Couldn't find root catalogue."); | |
} | |
} | |
function find_category_by_name($value, $genre){ | |
foreach($value as $category){ | |
if($category['name'] == $genre) return $category['category_id']; | |
if(isset($category['children'])){ | |
$result = find_category_by_name($category['children'], $genre); | |
if(!empty($result)){ | |
return $result; | |
} | |
} | |
} | |
} | |
$proxy = new SoapClient($mage_url); | |
try {$session_id = $proxy->login($mageapiUser, $mageapiKey);} | |
catch (Exception $e) | |
{echo '...ERROR: '. $e->getMessage() . "\n"; exit();} | |
$default_categories = $proxy->call($session_id, 'category.tree'); | |
$default_category_id = get_root_category_id($default_categories); | |
if (($handle = fopen("products.csv", "r")) !== FALSE) { | |
while (($row = fgetcsv($handle, 0, ",")) !== FALSE) { | |
list($name, $sku, $price, $instruments, $genres, $artist) = $row; | |
$product = array ( | |
'store' => 'admin', | |
'websites' => 'base', | |
'attribute_set' => 'Default', | |
'type' => 'simple', | |
'sku' => $sku, | |
'has_options' => 0, | |
'name' => $name, | |
'meta_title' => '', | |
'meta_description' => '', | |
#'category_ids' => $instruments . '|' . $genres , | |
'image' => '', | |
'small_image' => '', | |
'thumbnail' => '', | |
'url_key' => str_replace(' ', '_', strtolower($name) ), | |
'custom_design' => '', | |
'page_layout' => 'No layout updates', | |
'options_container' => 'Block after Info Column', | |
'gift_message_available' => 'Use config', | |
'price' => $price, | |
'special_price' => '', | |
'cost' => '', | |
'weight' => '', | |
'status' => 'Enabled', | |
'visibility' => 'Catalog, Search', | |
'is_imported' => 'No', | |
'tax_class_id' => 'Taxable Goods', | |
'is_recurring' => 'No', | |
'description' => '', | |
'short_description' => '', | |
'meta_keyword' => '', | |
'custom_layout_update' => '', | |
'news_from_date' => '', | |
'news_to_date' => '', | |
'special_from_date' => '', | |
'special_to_date' => '', | |
'custom_design_from' => '', | |
'custom_design_to' => '', | |
'qty' => 500, | |
'min_qty' => 0, | |
'use_config_min_qty' => 1, | |
'is_qty_decimal' => 1, | |
'backorders' => 0, | |
'use_config_backorders' => 0, | |
'min_sale_qty' => 1, | |
'use_config_min_sale_qty' => 1, | |
'max_sale_qty' => 1, | |
'use_config_max_sale_qty' => 0, | |
'is_in_stock' => 1, | |
'low_stock_date' => '2010-12-21 09:36:26', | |
'use_config_notify_stock_qty' => '', | |
'manage_stock' => 1, | |
'use_config_manage_stock' => 0, | |
'stock_status_changed_automatically' => 1, | |
'use_config_qty_increments' => 1, | |
'qty_increments' => 0, | |
'use_config_enable_qty_increments' => 1, | |
'enable_qty_increments' => 0, | |
'product_name' => $name, | |
'store_id' => 0, | |
'product_type_id' => 'simple', | |
'product_status_changed' => '', | |
'product_changed_websites' => '' | |
); | |
$proxy->call($session_id, 'product.create', $product); | |
#TODO: Assign to category | |
} | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment