php - Magento 1.9 API Create Product XML Stock Feed -


im tackling project friend ecommerce store up. 1 of suppliers has xml stock feed available feed store. ive spent time putting code snippets try , achieve code starting bit fuzzy.

code

// begin soap requests $client = new soapclient($mydomain.'/api/?wsdl'); $session = $client->login($myapilogin, $myapikey); class prod {       function prod ($aa)      {         foreach ($aa $k=>$v)             $this->$k = $aa[$k];     } }  function readdatabase($filename)  {     // read xml database of aminoacids     $data = implode("", file($filename));     $parser = xml_parser_create();     xml_parser_set_option($parser, xml_option_case_folding, 0);     xml_parser_set_option($parser, xml_option_skip_white, 1);     xml_parse_into_struct($parser, $data, $values, $tags);     xml_parser_free($parser);      // loop through structures     foreach ($tags $key=>$val) {         if ($key == "product") {             $prodranges = $val;             // each contiguous pair of array entries              // lower , upper range each molecule definition             ($i=0; $i < count($prodranges); $i+=2) {                 $offset = $prodranges[$i] + 1;                 $len = $prodranges[$i + 1] - $offset;                 $tdb[] = parseprod(array_slice($values, $offset, $len));             }         } else {             continue;         }     }     return $tdb; } function parseprod($mvalues)  {     ($i=0; $i < count($mvalues); $i++) {         $mol[$mvalues[$i]["tag"]] = isset($mvalues[$i]["value"]) ? $mvalues[$i]["value"] : '';     }     return new prod($mol); }  $db = readdatabase($filename); var_dump($db); ?> 

initially had issues structure of xml data found snippet allowed me slice piece of xml document. dont have issue anymore because cleaned xml data using xslt structure easier work with. goal sync product catalogue suppliers xml stock feed. approach xml product data array can loop through see if product exists in store. if check stock , price, if same nothing, if different update product record. if product doesnt exist catalog_create.product() using array values.

what end when code executes array $db has objects (prod) contain keys , values product information needed create/update products.

xml structure

<products>   <product>     <name></name>     <code></code>     <description></description>     <thumbnail></thumbnail>     <image1></image1>     <image2></image2>     <image3></image3>     <prod-code></prod-code>     <prod-description></prod-description>     <prod-instock></prod-instock>     <prod-wholesaleprice></prod-wholesaleprice>     <prod-rrp></prod-rrp>   </product> </products> 

sorry don't have specific question i'm looking guidance , bit of navigating in right direction.

thanks, max


Comments

Popular posts from this blog

python Tkinter Capturing keyboard events save as one single string -

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

javascript - Z-index in d3.js -