# \[ gelöst \] WaWi Import - Zugriff auf Attribute

**URL:** https://forum.shopware.com/t/gelost-wawi-import-zugriff-auf-attribute/4045
**Category:** Shopware 3.5
**Tags:** programming
**Created:** [25. August 2011 um 11:44 UTC](https://forum.shopware.com/t/gelost-wawi-import-zugriff-auf-attribute/4045 "2011-08-25T11:44:21Z")
**Posts on this page:** 1
**Showing post:** 4

<div class="post-metadata">

### Author: ![klexl](https://avatars.discourse-cdn.com/v4/letter/k/dc4da7/32.png) [@klexl](https://forum.shopware.com/u/klexl)
#### Post date: [30. August 2011 um 07:32 UTC](https://forum.shopware.com/t/gelost-wawi-import-zugriff-auf-attribute/4045/4 "2011-08-30T07:32:48Z")

</div>

Hallo Heiner, Vielen Dank für Deine Antwort. Über den Warenwirtschaftsexport funktinoiert das leider nicht, das ist fest in der Software verdrahtet dass zusätzliche Felder immer als Attribute ausgespuckt werden. Ich kann mich nur entscheiden welche id das Attribut bekommt (1-20). Der php Quelltext für den Import sieht so aus - könnte sein dass du den schon mal gesehen hast 🙂 [code]\<?php error\_reporting(“E\_ALL”);  
ini\_set(“display\_errors”,1);  
ini\_set(“display\_startup\_errors”, 1);  
ini\_set(“max\_execution\_time”, 0);  
/\*\*

- Shopware API Beispiel: Artikel im XML - Format importieren
- 
- @author Heiner Lohaus [hl@shopware2.de](mailto:hl@shopware2.de) \* @package Shopware 2.08.01 \* @subpackage API \*/ /\* Klassen laden, Aliase erstellen und Einstellungen vornehmen \*/ require\_once(realpath(dirname(\_\_FILE\_\_)).’/…/api/api.php’); api = new sAPI(); if (\_REQUEST[“sAPI”]!=api-\\>sSystem-\\>sCONFIG["sAPI"]&&count(\_SERVER[‘argv’]) \< 1) { #exit; } $import =& $api-\>import-\>shopware; $xml =& $api-\>convert-\>xml; $mapping =& $api-\>convert-\>mapping; $import-\>sDeleteAllCategories(); $import-\>sDeleteAllArticles(); $data\_path = current(glob($api-\>sPath."/files/import/articles/\*.xml")); if(empty($data\_path)) { #print "-- ERROR – Keine XML Datei gefunden! no Data path: $data\_path  
"; echo " **– ERROR – Keine XML Datei gefunden! no Data path: $data\_path**  
"; die(); } $xml-\>sSettings[‘encoding’] = “ISO-8859-1”; $data = $api-\>convert-\>xml-\>decode($data\_path); #if(!@unlink($data\_path)) # exit; if(isset($data[“shopware”][“categories”])) { $xml-\>fix\_array($data[“shopware”][“categories”],“category”); $categories = $data[“shopware”][“categories”]; $categorymask = array ( “parent”=\>“parentID”, “description”, “id”, “description”, “position”, “alias”, “metakeywords”, “metadescription”, “cmsheadline”, “cmstext”, “template”, “aliassql” ); $categories = $mapping-\>convert\_array ($categorymask, $categories); foreach ($categories as $category) { $import-\>sCategory($category); } #$import-\>sDeleteOtherCategories($categories); } if(isset($data[“shopware”][“articles”])) { $xml-\>fix\_array($data[“shopware”][“articles”],“article”); $articles =& $data[“shopware”][“articles”]; echo "

### Importvorgang gestartet!

"; echo "Es werden: **“.count($articles).”** Artikel importiert!  
"; echo "Bitte haben Sie einen Moment Geduld.  
Das Importieren der Artikel kann mehrere Minuten in Anspruch nehmen.

“; $articlemask = array ( “ordernumber”, “articledetailsID” =\> array(“isset”), “articleID” =\> array(“isset”), “name” =\> array(“isset”), “description” =\> array(“isset”), “description\_long” =\> array(“isset”), “shippingtime” =\> array(“isset”), “shippingfree” =\> array(“isset”), “laststock” =\> array(“isset”), “releasedate” =\> array(“isset”), “topseller” =\> array(“isset”), “free” =\> array(“isset”), “keywords” =\> array(“isset”), “minpurchase” =\> array(“isset”), “packunit” =\> array(“isset”), “purchasesteps” =\> array(“isset”), “maxpurchase” =\> array(“isset”), “purchaseunit” =\> array(“isset”), “status\_description” =\> array(“isset”), “referenceunit” =\> array(“isset”), “suppliernumber” =\> array(“isset”), “additionaltext”, “active” =\> array(“isset”), “instock” =\> array(“isset”), “stockmin” =\> array(“isset”), “esd” =\> array(“isset”), “weight” =\> array(“isset”), “position” =\> array(“isset”), “taxID” =\> array(“isset”), “supplierID” =\> array(“isset”), “unitID” =\> array(“isset”), “tax” =\> array(“isset”), “supplier” =\> array(“isset”), “added” =\> array(“isset”), “mainnumber” =\> array(“empty”), “attr” =\> array( “isset”, “field” =\> “attributes” ), “downloads” =\> array(“isset”), “informations” =\> array(“isset”), “images” =\> array(“isset”), “prices” =\> array(“isset”), “relationships” =\> array(“isset”), “categories” =\> array(“isset”), “configurator” =\> array(“isset”) ); $articlemask = $mapping-\>prepare\_mask ($articlemask); $insert\_articles = array(); $i=0; foreach ($articles as $article) { $testarray = $article; $i++; echo "  
“.$i.”. Artikel '”.($article[‘name’])."’ mit der Artikelnummer **‘".($article[‘ordernumber’])."’** erfolgreich importiert!  
"; $xml-\>fix\_array($article[‘attributes’],“attribute”); $xml-\>fix\_array($article[‘downloads’],“download”); $xml-\>fix\_array($article[‘images’],“image”); $xml-\>fix\_array($article[‘categories’],“category”); $xml-\>fix\_array($article[‘prices’],“price”); $xml-\>fix\_array($article[‘crossselling’],“article”); $xml-\>attr\_as\_key($article[‘attributes’],“id”); $article = $mapping-\>convert\_line($articlemask, $article, true); if(!$article\_insert = $import-\>sArticle($article)) continue; $article = array\_merge($article, $article\_insert); if(empty($article[“mainnumber”])) { if(isset($article[“crossselling”])) $import-\>sArticleCrossSelling (array(“articleID”=\>$article[“articleID”]), $article[“crossselling”]); if(isset($article[“images”])) { $inserts = array(); $import-\>sDeleteOtherArticleImages ($article[“articleID”], $inserts); foreach ($article[“images”] as $image) { //echo "Anzahl importierter Artikel: “.$i.”  
"; //echo "

```
".print\_r($image)."

```

“; $image[“link”] = $api-\>sPath.”/files/import/images/".basename($image[“link”]); $image[“articleID”] = $article[“articleID”]; $image[“ordernumber”] = $article[“ordernumber”]; //$image[“position”] = $article[“position”]; //$insert = $import-\>sArticleImage($image); //echo "

```
".print\_r($insert)."

```

“; if($insert = $import-\>sArticleImage($image)) { $inserts = $insert; } else { echo " **» WARNUNG: es konnte kein Artikelbild für den Artikel importiert werden. Grund: Bild-Datei fehlt auf dem Server** ”; } //@unlink($image[“link”]); } } if(isset($article[“downloads”])) { $download\_path = $api-\>sPath.$api-\>sSystem-\>sCONFIG[‘sARTICLEFILES’]."/". $sql = “SELECT filename FROM s\_articles\_downloads WHERE articleID={$article[“articleID”]}”; $downloads = $api-\>sDB-\>GetCol($sql); foreach ($downloads as $download) { if(file\_exists($download\_path.$download)) @unlink($download\_path.$download); } $sql = “DELETE FROM s\_articles\_downloads WHERE articleID={$article[“articleID”]}”; $api-\>sDB-\>Execute($sql); $inserts = array(); foreach ($article[“downloads”] as $download) { $download[“link”] = $api-\>sPath."/files/import/pdf/".basename($download[“filename”]); $download[“filename”] = basename($download[“link”]); $download[“new\_link”] = $api-\>sPath.$api-\>sSystem-\>sCONFIG[‘sARTICLEFILES’]."/".$download[“filename”] ; if(file\_exists($download[“link”])){ @unlink($download[“new\_link”]); if(!copy($download[“link”],$download[“new\_link”])) continue; //@unlink($download[“link”]); } else { continue; } $download[“size”] = filesize($download[“new\_link”]); $download[“description”] = $api-\>sDB-\>qstr($download[“description”]); $download[“filename”] = $api-\>sDB-\>qstr($download[“filename”]); $sql = " INSERT INTO s\_articles\_downloads (articleID, description, filename, size) VALUES ({$article[“articleID”]}, {$download[“description”]}, {$download[“filename”]}, {$download[“size”]}); “; $api-\>sDB-\>Execute($sql); $insert = $api-\>sDB-\>Insert\_ID(); } } if(isset($article[“categories”])) $import-\>sArticleCategories (array(“articleID”=\>$article[“articleID”]), $article[“categories”]); } if(isset($article[“prices”])) { foreach ($article[“prices”] as $price) { $import-\>sArticlePrice(array( “articledetailsID”=\>$article[“articledetailsID”], “price”=\>$price[“net\_price”], “pricegroup”=\>$price[“pricegroup”], “net\_pseudoprice”=\>$price[“net\_pseudoprice”], “net\_pseudoprice”=\>$price[“pseudoprice”], “pseudoprice”=\>$price[“net\_pseudoprice”], “from”=\>$price[“from”] )); } } $insert\_articles = $article[“articledetailsID”]; if(isset($article[‘configurator’])) { $import-\>sArticleConfigurator(array( ‘articleID’ =\> (int) $article[‘articleID’], ‘values’ =\> $article[‘configurator’][‘values’][‘value’], ‘type’ =\> $article[‘configurator’][‘type’], ‘tax’ =\> $article[‘tax’], )); } } //$import-\>sDeleteOtherArticles($insert\_articles); //echo "  
deleteotherarticles”; } echo "  
Es wurden “.$i.” Artikel importiert!

"; //$import-\>sDeleteEmptyCategories(); $import-\>sDeleteCache(); echo “Importvorgang abgeschlossen!”; ?\> [/code]

---

_[View the full topic](https://forum.shopware.com/t/gelost-wawi-import-zugriff-auf-attribute/4045)._
