www.webdeveloper.com
Page 1 of 2 12 LastLast
Results 1 to 15 of 25

Thread: XML Stock feed in Oscommerce

  1. #1
    Join Date
    Feb 2006
    Posts
    10

    XML Stock feed in Oscommerce

    Hi All,

    I am looking to implement a live stock feed from my supplier into my Oscommerce store. Iam really new to coding and am eager to learn but this really goes way over my head.

    Basically the only information i need to take from the feed is the product code and whether it is in stock or not in stock, then allow the feed to amend this in my database?

    Is this actually possible? How would i start to implement this, i know something needs parsing but i don't even know what this means let alone how to do it.

    I have phpmyadmin installed by my webhost and have ran simple queries but anything else is basically beyond my knowledge.

    Any help or personally, or links to places where i can get some further information would be very most appreciated, its become a pain to try and check over 2000 products manually, to say the least.

    Thanks in advance.

    Donna

  2. #2
    Join Date
    Jul 2005
    Location
    USA
    Posts
    912
    How do you access the XML file? Does your server have DOMXML support enabled?
    Bitter web veteran

  3. #3
    Join Date
    Feb 2006
    Posts
    10

    Thumbs up

    Hi There,

    I'm not actually sure, i'm completely new to XML so know little if anything about it. If you can let me know how i find out this information i will get this to you promptly.

    I'm currently hostin with siteground (www.siteground.com) who seem to have anything and everything available....

    Best Regards

    Donna

  4. #4
    Join Date
    Jul 2005
    Location
    USA
    Posts
    912
    Create this file and try to execute:

    test.php
    PHP Code:
    <?
    echo function_exists("domxml_open_file") ? "true" "false";
    ?>
    If "true" is on the screen, you have XML support (if your PHP version is 4.x)
    Last edited by Webnerd; 02-15-2006 at 06:25 AM.
    Bitter web veteran

  5. #5
    Join Date
    Feb 2006
    Posts
    10
    Yup, it says true....so i guess thats a good thing right???

    Regards

    Donna

  6. #6
    Join Date
    Jul 2005
    Location
    USA
    Posts
    912
    That is good. Now, where is the XML coming from? What's the URL? Create this file and replace the HTTPRequest(yoururlhere) with the URL of the XML file (example: HTTPRequest("http://www.google.com");

    curl.php

    PHP Code:
    <?
       
    function HTTPRequest($url){

          
    $ch curl_init();

          
    curl_setopt($ch,CURLOPT_URL,$url);

          
    curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);

          
    curl_setopt($ch,CURLOPT_MUTE,1);

          
    curl_setopt($ch,CURLOPT_USERAGENT,$_SERVER["HTTP_USER_AGENT"]);

          
    curl_setopt($chCURLOPT_TIMEOUT10); //times out after 10

          
    curl_setopt($ch,CURLOPT_FOLLOWLOCATION,1);

          
    $data curl_exec ($ch);

          
    curl_close ($ch); 

          return 
    $data;

       }

    echo 
    HTTPRequest(yoururlhere);
    ?>
    Bitter web veteran

  7. #7
    Join Date
    Feb 2006
    Posts
    10

    Smile

    The url is coming from my supplier, i basically have th option to 'view xml file' or view in html? Shall i right click and view properties of the link to the xml file and use that as the path? When i click it it just views the xml document? I'm at work at the mo, but just trying to get someone to send me the link?

    Whats the next step, or do i need to complete that one before i can go any further?

    Best Regards

    Donna

    PS thanks so much for helping me out on this

  8. #8
    Join Date
    Jul 2005
    Location
    USA
    Posts
    912
    See if the function above works first. Copy the URL from the rick-click properties into the function and give it a shot
    Bitter web veteran

  9. #9
    Join Date
    Feb 2006
    Posts
    10

    Smile

    Ok, i;ve executed the file after adding the XML url but the page is blank? The Url (so i believe without being able to check it myself is XML feed

    Unfortunately my firewall stops me from going to lots of sites.

    Regards

    Donna

  10. #10
    Join Date
    Feb 2006
    Posts
    10

    Smile

    Quote Originally Posted by Trout69
    Ok, i;ve executed the file after adding the XML url but the page is blank? The Url (so i believe without being able to check it myself is XML feed

    Unfortunately my firewall stops me from going to lots of sites.

    Regards

    Donna
    Scrap that, its working now....i forgot to ctrl F5 to make sure....feed is showing.

    Regards

    Donna

  11. #11
    Join Date
    Jul 2005
    Location
    USA
    Posts
    912
    Did you ViewSource in the browser?
    Bitter web veteran

  12. #12
    Join Date
    Feb 2006
    Posts
    10

    Smile

    Its working now? The url of curl.php is www.ladyloving.dtotransport.com/curl.php

    Picks up the feed fine.

    Regards

    Donna
    Last edited by Trout69; 02-15-2006 at 07:39 AM.

  13. #13
    Join Date
    Jul 2005
    Location
    USA
    Posts
    912
    We will now need to parse the file using the domxml_open_mem function. I will show you how in a few minutes.
    Bitter web veteran

  14. #14
    Join Date
    Feb 2006
    Posts
    10

    Smile

    Fantastic, you really are a saint....I'm actually studying towards a degree in bus and computing, but am yet to touch on anythign like this, so hopefully i can feed back to the community once i do.

    Donna

  15. #15
    Join Date
    Jul 2005
    Location
    USA
    Posts
    912
    Okay, here it is. It returns an Array of the Product items.
    PHP Code:
    <?
       
    function HTTPRequest($url){

          
    $ch curl_init();

          
    curl_setopt($ch,CURLOPT_URL,$url);

          
    curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);

          
    curl_setopt($ch,CURLOPT_MUTE,1);

          
    curl_setopt($ch,CURLOPT_USERAGENT,$_SERVER["HTTP_USER_AGENT"]);

          
    curl_setopt($chCURLOPT_TIMEOUT10); //times out after 10

          
    curl_setopt($ch,CURLOPT_FOLLOWLOCATION,1);

          
    $data curl_exec ($ch);

          
    curl_close ($ch);

          return 
    $data;

       }

       
    $xmlData=HTTPRequest("http://dropship.sexshop365.co.uk/catalog/xml-feed/stock.xml");


       
    $xmlDom=domxml_open_mem($xmlData,DOMXML_LOAD_PARSING DOMXML_LOAD_DONT_KEEP_BLANKS,$errors);

       if(
    sizeof($errors)>0){

          echo 
    "<pre>";

          echo 
    print_r($errors,true);

          echo 
    "</pre>";

          exit;
       }

       
    $prods=$xmlDom->get_elements_by_tagname("PRODUCT");

       
    $items=Array();

       if(
    sizeof($prods)>0){

          foreach(
    $prods as $prod){

             
    $stock=$prod->get_elements_by_tagname("STOCK");

             if(
    sizeof($stock)>0){

                foreach(
    $stock as $stockentry){

                   
    $item=$prod->get_attribute("ITEM");

                   
    $instock=$stockentry->get_content()=="In Stock" true false;

                   if(
    $stockentry->has_attribute("Size")){

                      
    $size=$stockentry->get_attribute("Size");

                      
    $item=$item."[$size]";

                   }    
                   
                   
    $items[$item]=$instock;
                }
             }
          }
       }


       echo 
    "<pre>";

       
    print_r($items);

       echo 
    "</pre>";


    ?>
    Bitter web veteran

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles