Posting in the Magento forums has been disabled pending the implementation of a new and improved forum solution which should better serve the community.

For new questions please post at magento.stackexchange.com, the community-run support site for the Magento community. We will be providing updates on the new forum solution soon. For questions or concerns please email community@magento.com.

Magento Forum

API add only SKU, no Attributes -> in Admin frontend not editable
 
Rico Winter
Sr. Member
 
Avatar
Total Posts:  108
Joined:  2009-03-20
Leipzig
 

Hi there,

I have trouble with the Magento Product API.

If i use the API to add products to Magento, it adds only the SKU, no attributes or something…

The code i use looks like

$SKU = (string)$article->Number
$newProductData = array(
        
'store' => (string)$article->ShopNumber,
        
'name' => (string)$article->Description,
        
'description' => (string)$article->LongText,
        
'short_description' => (string)$article->Extension,
        
'color' => (string)$article->FreeField1,
        
'status' => (string) "1",
        
'weight' => (string)$article->Weight,
        
'price' => (string)$article->FreeField8,
        
'category_ids' => 0
        
);
$result$client->call($sess_id'product.create', array('simple'1$SKU$newProductData));

print_r($newProductData) output is

Array ( [store] => 0 [name] => Testproduct [description] => Description Text is uses here
[short_description] => Short [color] => green [status] => 1 [weight] => 0,046 [price] => 10.99 [category_ids] => 0 )

Added products can’t be edited in the admin frontend....  Magento hide the Options for renaming, description, images, a.s.o.

Anyone an idea whats going wrong?

Thx for help

Rico

 
Magento Community Magento Community
Magento Community
Magento Community
 
Rico Winter
Sr. Member
 
Avatar
Total Posts:  108
Joined:  2009-03-20
Leipzig
 

I change the source to add more attributes (*required one).

But there are still no attributes available… Seems like the API dont use them… I dont know, where the bug is.
To get a better understanding, I post the whole source.. Maybe any suggestions how to solve the problem?

Thx

<?php
//Definitionen
define('NL',"<br>");
$hostp 'localhost/magento';
$host 'http://'.$hostp.'/index.php/api/soap/?wsdl';
$apiuser'admin';
$apikey '123456';
$time_start microtime(true);
$file ='C:\data.xml';
if (!
file_exists($file))
{
    
die('Datei existiert nicht');
}

// Datei zum einlesen Ã¶ffnen
$sx simplexml_load_file($file);
echo 
"==> Stelle Verbindung zur Magento API her".NL;

// Soap Verbindung zu Magento herstellen
$client= new SoapClient($host);
try 
{
  $sess_id
$client->login($apiuser$apikey);
  echo 
"==> Verbindung hergestellt!".NL;
}
catch (Exception $e
{
  
echo "Error: ".$e->getMessage();
  exit();
}

//Artikelzähler
$i 0;

// Bearbeitung
foreach ($sx->Articles->children() as $article)
{
        
// Produkt Timer
        
$a_s microtime(true);
        
        
// Produkt Attribute
        
$SKU = (string)$article->Number
        
$newProductData = array(
        
'store' => (string)$article->ShopNumber,
        
'name' => (string)$article->Description,
        
'description' => (string)$article->LongText,
        
'short_description' => (string)$article->Extension,
        
'color' => (string)$article->FreeField1,
        
'status' => (string)'1',
        
'weight' => (string)$article->Weight,
        
'price' => (string)$article->FreeField8,
        
'tax_class_id' => (string)'1',
        
'category_ids' => (string)'0',
        
'manage_stock' => (string)'1',
        
'qty' => (string)$article->Stock        
        
);
        
$att_set = (string)'1';
        
$p_type = (string)'simple';
        
$options = array($p_type$att_set$SKU$newProductData);
        
//Produkt anlegen
        
try
        
{
            
//Produkt im Katalog enthalten
            //$filter = array('sku' => array('like'=>$SKU));
            //$products = $client->call($sess_id, 'product.list', array($filter));
            //print($products);
            //if ($products)
            //{
            //    $result= $client->call($sess_id, 'product.update', array('simple', 1, $SKU, $newProductData));
            //}
            //}
            //else
            //{
                //Produkt Ã¼ber API hinzufügen
                
$result$client->call($sess_id'product.create'$options);
                
//echo $newProductData['short_description'];
                //$result = $SKU;
            //}
        
}
        
catch (Exception $e
        
{
              
echo "==> Fehler: ".$e->getMessage().NL;
              exit();
        
}
        
// Auswertung / Produkt
        
$a_e microtime(true);
        
$a_t $a_e $a_s;
        echo 
"==> Erfolgreich: Artikel ".$result." erstellt. (".$a_t."sek)".NL;
        
$i++;
        
}
// Gesamt Auswertung
$time_end microtime(true);
$time $time_end $time_start;
echo 
"==> Fertig! Es wurden ".$i." Artikel angelegt. Dauer ".$time." Sekunden".NL;

?>
 
Magento Community Magento Community
Magento Community
Magento Community
 
Rico Winter
Sr. Member
 
Avatar
Total Posts:  108
Joined:  2009-03-20
Leipzig
 

Nobody knows?

I dont find the error, the expected array should have a valid format and the required fields, that Magento expects are added too… But still only adds the SKU only… No name, no description, no status, no price…

I’m going crazy with this API....

 
Magento Community Magento Community
Magento Community
Magento Community
 
Rico Winter
Sr. Member
 
Avatar
Total Posts:  108
Joined:  2009-03-20
Leipzig
 

Here the Output from API produkt.info

Product craeted manually (Admin Panel)

array(33) { ["product_id"]=> string(1) “1” ["sku"]=> string(7) “skutest” ["set"]=> string(1) “4” ["type"]=> string(6) “simple” ["categories"]=> array(1) { [0]=> string(1) “3” } ["websites"]=> array(1) { [0]=> string(1) “1” } ["created_at"]=> string(19) “2009-03-30 07:20:03” ["updated_at"]=> string(19) “2009-03-30 07:21:04” ["type_id"]=> string(6) “simple” ["name"]=> string(15) “Zahnbürste X11” ["description"]=> string(61) “Zahnbürste X11 Das beste auf dem Markt! Jetzt ganz neu” ["short_description"]=> string(19) “Nur für kurze Zeit” ["weight"]=> string(6) “0.0200” ["status"]=> string(1) “1” ["url_key"]=> string(14) “zahnburste-x11” ["url_path"]=> string(19) “zahnburste-x11.html” ["visibility"]=> string(1) “4” ["category_ids"]=> array(1) { [0]=> string(1) “3” } ["has_options"]=> string(1) “0” ["image_label"]=> string(0) “” ["small_image_label"]=> string(0) “” ["thumbnail_label"]=> string(0) “” ["gift_message_available"]=> string(1) “2” ["price"]=> string(9) “2999.0000” ["tax_class_id"]=> string(1) “0” ["tier_price"]=> array(0) { } ["enable_googlecheckout"]=> string(1) “1” ["meta_title"]=> string(0) “” ["meta_keyword"]=> string(0) “” ["meta_description"]=> string(0) “” ["custom_design"]=> string(0) “” ["custom_layout_update"]=> string(0) “” ["options_container"]=> string(10) “container2” }

(same) Product created with magento API
(SKU Changed)

array(9) { ["product_id"]=> string(1) “5” ["sku"]=> string(6) “100009” ["set"]=> string(1) “1” ["type"]=> string(6) “simple” ["categories"]=> array(0) { } ["websites"]=> array(1) { [0]=> string(1) “1” } ["created_at"]=> string(19) “2009-03-30 07:34:49” ["updated_at"]=> string(19) “2009-03-30 07:34:49” ["type_id"]=> string(6) “simple” }

 
Magento Community Magento Community
Magento Community
Magento Community
 
Rico Winter
Sr. Member
 
Avatar
Total Posts:  108
Joined:  2009-03-20
Leipzig
 

After 5 days exploring and testing, i found the bug, the Attribute Set ID was wrong…
sick
So it works fine:

<?php
//Definitionen
define('NL',"<br>");
$hostp 'localhost/magento';
$host 'http://'.$hostp.'/index.php/api/soap/?wsdl';
$apiuser'admin';
$apikey '123456';
$time_start microtime(true);
$file ='C:\data.xml';


if (!
file_exists($file))
{
    
die('Datei existiert nicht');
}

// Datei zum einlesen Ã¶ffnen
$sx simplexml_load_file($file);
echo 
"==> Stelle Verbindung zur Magento API her".NL;

// Soap Verbindung zu Magento herstellen
$client= new SoapClient($host);
try 
{
  $sess_id
$client->login($apiuser$apikey);
  echo 
"==> Verbindung hergestellt!".NL;
}
catch (Exception $e
{
  
echo "Error: ".$e->getMessage();
  exit();
}

//Artikelzähler
$i 0;

//Attribut Sets laden
$attributeSets $client->call($sess_id'product_attribute_set.list');
$att_set current($attributeSets);
//Produkttyp festlegen
$p_type = (string)'simple';


// Bearbeitung
foreach ($sx->Articles->children() as $article)
{
        
// Produkt Timer
        
$a_s microtime(true);
        
        
// Produkt Attribute
        
$SKU = (string)$article->Number
        
$newProductData = array(
            
'name' => (string)$article->Description,
            
'websites' => array(1),
            
'short_description' => (string)$article->Extension,
            
'description' => (string)$article->LongText,
            
'price' => $article->FreeField8,
            
'store' => $article->ShopNumber,
            
'color' => (string)$article->FreeField1,
            
'status' => '1',
            
'weight' => $article->Weight,
            
'tax_class_id' => '1',
            
'category_ids' => '2',
            
'manage_stock' => '1',
            
'qty' => $article->Stock        
        
);

        
//Produkt anlegen
        
try
        
{
            
//Produkt im Katalog enthalten
            //$filter = array('sku' => array('like'=>$SKU));
            //$products = $client->call($sess_id, 'product.list', array($filter));
            //print($products);
            //if ($products)
            //{
            //    $result= $client->call($sess_id, 'product.update', array('simple', 1, $SKU, $newProductData));
            //}
            //}
            //else
            //{
                //Produkt Ã¼ber API hinzufügen    
            
$result$client->call($sess_id'product.create', array($p_type$att_set['set_id']$SKU$newProductData));
            
$client->endSession($sess_id);
            
            
//}
        
}
        
catch (Exception $e
        
{
              
echo "==> Fehler: ".$e->getMessage().NL;
              exit();
        
}
        
// Auswertung / Produkt
        
$a_e microtime(true);
        
$a_t $a_e $a_s;
        echo 
"==> Erfolgreich: Artikel ".$result." erstellt. (".$a_t."sek)".NL;
        
$i++;
        
}
// Gesamt Auswertung
$time_end microtime(true);
$time $time_end $time_start;
$client->endSession($sess_id);
echo 
"==> Fertig! Es wurden ".$i." Artikel angelegt. Dauer ".$time." Sekunden".NL;

?>
 
Magento Community Magento Community
Magento Community
Magento Community
 
prabha_ewall
Jr. Member
 
Total Posts:  11
Joined:  2012-05-28
 

Anyone of you please upload sample product xml file.

 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
Back to top