As i understand your query, here is the method to get the api data, into xml format first.
$xml contain xml response you have made to get the data from api.
$soap_do = curl_init();
curl_setopt($soap_do, CURLOPT_URL, $url );
curl_setopt($soap_do, CURLOPT_RETURNTRANSFER, true );
curl_setopt($soap_do, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($soap_do, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($soap_do, CURLOPT_POST, true );
curl_setopt($soap_do, CURLOPT_HTTPHEADER, $headers);
curl_setopt($soap_do, CURLOPT_POSTFIELDS, $xml);
$result = curl_exec($soap_do);
curl_close($soap_do);
//echo $result;
//echo $result_array = json_encode($result);
//echo $description = $result->extendeddescription;
$p = xml_parser_create();
xml_parse_into_struct($p, $result, $vals, $index);
xml_parser_free($p);
After you can break the xml into array and get the value.
here $vals
contains the valid array of xml comes data.
If you want to import the product as find into xml array you need to run new product making script with valid input param comes form api.
The Below code, you can used to add or update new category
$category = Mage::getModel('catalog/category');
$category->setStoreId(0);
$categoryName = $cate;
$rootCategory['name'] = $categoryName;
$rootCategory['path'] = "1/2";
//$rootCategory['display_mode'] = "PRODUCTS";
$rootCategory['is_active'] = 1;
$category->addData($rootCategory);
try
{
$category->save();
$CategoryId = $category->getId();
}
catch (Exception $e)
{
echo "categories not found";
}
And for product adding you need to follow the below script with valid input params
$obj = Mage::getModel('catalog/product');
$_product = $obj->load($productid); // Enter your Product Id in $product_id
// get Product's name
$name = $_product->getName();
//get product's short description
$shortdes = $_product->getShortDescription();
//get Product's Long Description
$des = $_product->getDescription();
//get Product's Regular Price
//echo $_product->getPrice();
//get Product's Special price
//echo $_product->getSpecialPrice();
//get Product's Url
//echo $_product->getProductUrl();
//get Product's image Url
//echo $_product->getImageUrl();
//echo "<pre>";print_r($_GET);exit;
/*********Getting values*********/
$optionval1 = $_GET['optionval1'];
$optionval2 = $_GET['optionval2'];
$optionval3 = $_GET['optionval3'];
$optionval4 = $_GET['optionval4'];
$image = $_GET['image'];
//print_r($image);
$image_parts = explode('/',$image);
$count = count($image_parts);
$final_image = $image_parts[$count-1];
//echo "<pre>";print_r($image_parts[$count-1]);exit;
$price = $_GET['price'];
$product = Mage::getModel('catalog/product');
$product_sku = time();
$product->setSku($product_sku);
$product->setName($name);
$product->setDescription($des);
$product->setShortDescription($shortdes);
//-- price section
$product->setPrice($price);
//$product->setSpecialPrice(10);
//----- company address and map
$product->setTypeId('simple');
$product->setAttributeSetId(9); // default
$product->setCategoryIds(array(20)); // need to look these up
$product->setWeight(1.0);
$product->setTaxClassId(2); // taxable goods
$product->setVisibility(3); // search
$product->setStatus(1); // enabled
$productQty = '1';
//$stockData=$product->getStockData();
$stockData['qty']=$productQty;
$stockData['is_in_stock']=1;
$stockData['manage_stock']=1;
$stockData['use_config_manage_stock']=0;
$product->setStockData($stockData);
// adding images to product
$abspath = getcwd();
$path = "./final_images/new/".$final_image;
//print_r($path);
?>
<?php
if (file_exists($path)) {
$product->addImageToMediaGallery($path,array('image','small_image','thumbnail'),false,false);
}
$product->setWebsiteIds(array(Mage::app()->getStore(true)->getWebsite()->getId()));
$product->save();
/*********** custom option for cart ***********/
$new_product_id=$product->getId();
$product = Mage::getModel('catalog/product')->load($new_product_id);
$optionData = array(
'is_require' => false,
'title' => 'Select Font',
'type' => 'drop_down',
'sort_order' => 0,
'values' => array(
array(
'is_delete' => 0,
'title' => '12',
'price_type' => 'fixed',
'price' => '',
'sku' => '',
'sort_order' => 0,
),
array(
'title' => '18',
'price_type' => 'fixed',
'price' => '',
'sku' => '',
'sort_order' => 1,
)),
);
$product->setHasOptions(1);
$option = Mage::getModel('catalog/product_option')
->setProductId($new_product_id)
->setStoreId(1)
->addData($optionData);
$option->save();
$product->addOption($option);
Mage::app()->setCurrentStore(Mage_Core_Model_App::ADMIN_STORE_ID);
$product->save();
/*********** custom option for cart end***********/
$productid = $product->getId();
$result['product'] = $productid;
echo $result['product'];
Hope this will help you, or make sense what you should need to do.
Disclaimer: This is not a solution to the XML-RPC issue, but a workaround you could attempt
This solution will use direct SQL which is safe in this instance as there are not any default triggers which would be thrown on updating of the weight attribute.
Find out your weight attribute id & type. You can do this by navigating through Catalog
→ Attributes
→ Manage Attributes
. Filter by the weight attribute and edit it.
In the URL you will find the attribute_id
, like this:
www.yourstore.com/admin/catalog_product_attribute/edit/attribute_id/65/key/...
Once you have the attribute code, you just need to know whether the value is in int, decimal or text format, which will be stored in the _int
, _decimal
, _varchar
EAV tables.
Magento by default creates the weight
attribtue in the varchar
table.
Your solution script would be:
<?php
$connection_write = Mage::getSingleton('core/resource')->getConnection('core_write');
$attribute_id = 65; //your weight attribute id
$products = array(1,2,3,4); //your product id array
foreach ($products as $product_id){
$sql = 'UPDATE `catalog_product_entity_varchar` SET `value` = ? WHERE `entity_id` = ? AND `attribute_id` = ?';
//this is assuming it is stored within the varchar table (other options are _int or _decimal)
$connection_write->query($sql, array("3.14", $product_id, $attribute_id);
//should this be in the _int or _decimal table, you'd omit the quotation marks around the value
}
echo "Complete";
?>
Once you run your script, your products will update extremely quickly, likely in a matter of seconds.
Heads up:
- To be safe, backup your website & database prior to running the script
- Run a full cache & reindex thereafter
Let me know if you have any troubles.
Best Answer
the best way is using MAGMI. you can find that open source project in the following url http://sourceforge.net/projects/magmi/ . The tutorial of how to use it -> http://wiki.magmi.org/index.php?title=Main_Page .
Magmi’s speed is very evident whenever you import a large number of SKUs. We’ve seen import speeds of as many as 2-3,000 products per minute. The speed depends on such things as the number of fields to be imported and whether images are imported from the same server or from remote URLs.
You can also build scripts to automatically run that could pull a file from a remote server and update the products using a cron job.