Results 1 to 10 of 13

Hybrid View

  1. #1
    Join Date
    Feb 2007
    Location
    Leicester UK
    Posts
    219
    Plugin Contributions
    0

    Default Re: Real time XML product feed integration?

    Seems it might be more difficult than I first thought.

    Anyone care to take a look at the code and help out a little?

    My XML knowledge is pretty good but my PHP knowledge is not up to much.

  2. #2
    Join Date
    Feb 2007
    Location
    Glasgow, UK
    Posts
    1
    Plugin Contributions
    0

    Default Re: Real time XML product feed integration?

    The OP was looking for code to import not export a product feed and this isn't any help to them either

    Placing this code in the root of your Zen Cart install will generate an XML export of the products.

    Tested on v1.3.7.

    Code:
    <?php
    require("includes/application_top.php");
    ?>
    <?php
      // We'll be outputting XML
    header('Content-type: application/xml');
    ?>
    <?php
    
      /**
       * Get the default language for the site
       * @return array An array containing the lanugage id and two-letter code.
       */
    
    function get_default_language() {
      global $db;
    
      $sql = "select languages_id, code from ".TABLE_LANGUAGES.", ".TABLE_CONFIGURATION." where configuration.configuration_value=languages.code AND configuration.configuration_key='DEFAULT_LANGUAGE'";
    
      $result = $db->Execute($sql);
    
      return array('code' => $result->fields['code'],
          'languages_id' => $result->fields['languages_id']);
    }
    
    
    /**
     * Fetch back a list of products with their details in the language specified by $language_id.
     * @param int $language_id Specify the language that product descriptions should be returned as.
     * @return queryFactory A list of products wrapped in a queryFactory. 
     */
    
    function get_product_list($language_id) {
    
      global $db;
    
      $sql = "select p.products_id as id, p_d.products_name as name, p_d.products_description as description, p_d.products_url as url, p.products_image as image, p.products_quantity as stock, m.manufacturers_name as manufacturers_name, p.products_price as price from ".TABLE_PRODUCTS." as p inner join ".TABLE_PRODUCTS_DESCRIPTION." as p_d on p.products_id=p_d.products_id left outer join ".TABLE_MANUFACTURERS." as m on p.manufacturers_id=m.manufacturers_id where p_d.language_id=".$language_id;
    
      $result = $db->Execute($sql);
    
      return $result;
    }
    
    
    /**
     * Fetch back a list of products and their categories.
     * This a 1-to-many relationship
     * @return array An array keyed by the product and listing the categories it's in.
     */
    
    function get_product_categories() {
    
      global $db;
    
      $sql = "select products_id as p_id, categories_id as cat_id from ".TABLE_PRODUCTS_TO_CATEGORIES." order by products_id";
    
      $result = $db->Execute($sql);
    
      //Loop and store result as a hash with the product_id the key
    
      $product_categories = array();
    
      while(!$result->EOF) {
    
        $key = $result->fields['p_id'];
    
        if (array_key_exists($key, $product_categories)) {
          
          array_push($product_categories[$key], $result->fields['cat_id']);
    
        } else { 
          $product_categories[$key] = array($result->fields['cat_id']);
        }
        
        $result->MoveNext();
      }
    
      return $product_categories;
    }
    
    
    /**
     * Get the list of categories for the specified language.
     * @param int $language_id The language of the category name and description.
     * @return array An array keyed by category id and storing its name and description.
     */
    
    function get_categories($language_id) {
    
      global $db;
    
      $sql = "select categories_id, categories_name as name, categories_description as description from ".TABLE_CATEGORIES_DESCRIPTION." where language_id=".$language_id;
    
      $result = $db->Execute($sql);
    
      //convert this to hash with the category id as the key
    
      $categories = array();
      
      if ($result->RecordCount() > 0) {
        while(!$result->EOF) {
    
          $categories[$result->fields['categories_id']] = array("name" => $result->fields['name'],
                                    "description" => $result->fields['description']);     
          $result->MoveNext();
        }
      }
    
      return $categories;
    }
    
    /**
     * Fetch back all the attributes used to make up a product feed..
     * @param int $language_id The language used within the feed.
     * @return array The product, product description and categories.
     */
    
    function get_products($language_id) {
    
      $products = get_product_list($language_id);
      $categories = get_categories($language_id);
      $product_categories = get_product_categories();
      
      return array($products, $product_categories, $categories);
    }
    
    /**
     * On which server are we running?
     * @global const $request_type 
     * @return const HTTP_SERVER or HTTPS_SERVER.
     */
    
    function get_server() {
      global $request_type; //SSL or NONSSL ?
    
      $server = HTTP_SERVER;
    
      if ($request_type == 'SSL') {
        if (ENABLE_SSL == 'true') {
          $server = HTTPS_SERVER ;
        }
      }
    
      return $server;
    }
    
    ?>
    <?php
    
    $server_protocol = get_server(); //SSL or NONSSL ?
    
    $lang = get_default_language();
    $result = get_products($lang['languages_id']);
    
    $products = $result[0];
    $product_categories = $result[1];
    $categories = $result[2];
    
    
    //Ready to start flushing output buffers?
    while (ob_get_level()) {
        ob_end_flush();
    }
    
    if (ob_get_length() === false) {
        ob_start();
    }
    
    
    //Write the response
    
    echo "<?xml version=\"1.0\"?>"."\n";
    
    echo "<products>"."\n";
    
    //flush
    ob_flush();
    flush();
    
    if ($products->RecordCount() >0) {
      while(!$products->EOF) {
    
        echo "<product id=\"".$products->fields['id']."\">"."\n";
        echo "<name lang=\"".$lang['code']."\"><![CDATA[".$products->fields['name']."]]></name>"."\n";
        echo "<description lang=\"".$lang['code']."\"><![CDATA[".$products->fields['description']."]]></description>"."\n";
        echo "<url lang=\"".$lang['code']."\">".zen_href_link("product_info", "products_id=".$products->fields['id']."&language=".$lang['code'], $request_type, false)."</url>"."\n";
    
        //Product image is optional
        
        if (zen_not_null($products->fields['image'])) {
          echo "<image>".$server_protocol."/".DIR_WS_IMAGES.$products->fields['image']."</image>"."\n";
        } 
    
        //echo the categories that the product belongs to
        
        if (array_key_exists($products->fields['id'], $product_categories)) {
          foreach($product_categories[$products->fields['id']] as $cat_id) {
        echo "<category lang=\"".$lang['code']."\"><![CDATA[".$categories[$cat_id]['name']."]]></category>"."\n";
          }
        }
    
        //Product manufacturer is optional
        if (zen_not_null($products->fields['manufacturers_name'])) {
          echo "<manufacturer><![CDATA[".$products->fields['manufacturers_name']."]]></manufacturer>"."\n";
        }
    
        echo "<price>".$products->fields['price']."</price>"."\n";
        echo "<stock>".$products->fields['stock']."</stock>"."\n";
        echo "</product>"."\n";
        $products->MoveNext();
    
        //flush
        ob_flush();
        flush();
      }
     }
    echo "</products>"."\n";
    ?>
    
    <?php
    require(DIR_WS_INCLUDES."application_bottom.php");
    ?>
    I haven't done any number formatting on the price element, so you may want to look at satpromo's code for that.

    Does anyone have an example 3rd party product feed?

  3. #3
    Join Date
    Oct 2006
    Location
    Suffolk UK
    Posts
    55
    Plugin Contributions
    1

    help question Re: Real time XML product feed integration?

    Does anyone know if this principal would work with setup of a connection to a couriers NDXML job booking system.

    I am trying to get connected to a courier system , which uses NDXML

    Please help... anyone

    any posts you have seen that integrate xml would be great if you found them usefull when integrating XML into Zen so please let me know.

    Kind regards

    Jamie 2K

    Quote Originally Posted by freezing_cold View Post
    The OP was looking for code to import not export a product feed and this isn't any help to them either

    Placing this code in the root of your Zen Cart install will generate an XML export of the products.

    Tested on v1.3.7.

    Code:
    <?php
    require("includes/application_top.php");
    ?>
    <?php
      // We'll be outputting XML
    header('Content-type: application/xml');
    ?>
    <?php
     
      /**
       * Get the default language for the site
       * @return array An array containing the lanugage id and two-letter code.
       */
     
    function get_default_language() {
      global $db;
     
      $sql = "select languages_id, code from ".TABLE_LANGUAGES.", ".TABLE_CONFIGURATION." where configuration.configuration_value=languages.code AND configuration.configuration_key='DEFAULT_LANGUAGE'";
     
      $result = $db->Execute($sql);
     
      return array('code' => $result->fields['code'],
          'languages_id' => $result->fields['languages_id']);
    }
     
     
    /**
     * Fetch back a list of products with their details in the language specified by $language_id.
     * @param int $language_id Specify the language that product descriptions should be returned as.
     * @return queryFactory A list of products wrapped in a queryFactory. 
     */
     
    function get_product_list($language_id) {
     
      global $db;
     
      $sql = "select p.products_id as id, p_d.products_name as name, p_d.products_description as description, p_d.products_url as url, p.products_image as image, p.products_quantity as stock, m.manufacturers_name as manufacturers_name, p.products_price as price from ".TABLE_PRODUCTS." as p inner join ".TABLE_PRODUCTS_DESCRIPTION." as p_d on p.products_id=p_d.products_id left outer join ".TABLE_MANUFACTURERS." as m on p.manufacturers_id=m.manufacturers_id where p_d.language_id=".$language_id;
     
      $result = $db->Execute($sql);
     
      return $result;
    }
     
     
    /**
     * Fetch back a list of products and their categories.
     * This a 1-to-many relationship
     * @return array An array keyed by the product and listing the categories it's in.
     */
     
    function get_product_categories() {
     
      global $db;
     
      $sql = "select products_id as p_id, categories_id as cat_id from ".TABLE_PRODUCTS_TO_CATEGORIES." order by products_id";
     
      $result = $db->Execute($sql);
     
      //Loop and store result as a hash with the product_id the key
     
      $product_categories = array();
     
      while(!$result->EOF) {
     
        $key = $result->fields['p_id'];
     
        if (array_key_exists($key, $product_categories)) {
     
          array_push($product_categories[$key], $result->fields['cat_id']);
     
        } else { 
          $product_categories[$key] = array($result->fields['cat_id']);
        }
     
        $result->MoveNext();
      }
     
      return $product_categories;
    }
     
     
    /**
     * Get the list of categories for the specified language.
     * @param int $language_id The language of the category name and description.
     * @return array An array keyed by category id and storing its name and description.
     */
     
    function get_categories($language_id) {
     
      global $db;
     
      $sql = "select categories_id, categories_name as name, categories_description as description from ".TABLE_CATEGORIES_DESCRIPTION." where language_id=".$language_id;
     
      $result = $db->Execute($sql);
     
      //convert this to hash with the category id as the key
     
      $categories = array();
     
      if ($result->RecordCount() > 0) {
        while(!$result->EOF) {
     
          $categories[$result->fields['categories_id']] = array("name" => $result->fields['name'],
                                    "description" => $result->fields['description']);     
          $result->MoveNext();
        }
      }
     
      return $categories;
    }
     
    /**
     * Fetch back all the attributes used to make up a product feed..
     * @param int $language_id The language used within the feed.
     * @return array The product, product description and categories.
     */
     
    function get_products($language_id) {
     
      $products = get_product_list($language_id);
      $categories = get_categories($language_id);
      $product_categories = get_product_categories();
     
      return array($products, $product_categories, $categories);
    }
     
    /**
     * On which server are we running?
     * @global const $request_type 
     * @return const HTTP_SERVER or HTTPS_SERVER.
     */
     
    function get_server() {
      global $request_type; //SSL or NONSSL ?
     
      $server = HTTP_SERVER;
     
      if ($request_type == 'SSL') {
        if (ENABLE_SSL == 'true') {
          $server = HTTPS_SERVER ;
        }
      }
     
      return $server;
    }
     
    ?>
    <?php
     
    $server_protocol = get_server(); //SSL or NONSSL ?
     
    $lang = get_default_language();
    $result = get_products($lang['languages_id']);
     
    $products = $result[0];
    $product_categories = $result[1];
    $categories = $result[2];
     
     
    //Ready to start flushing output buffers?
    while (ob_get_level()) {
        ob_end_flush();
    }
     
    if (ob_get_length() === false) {
        ob_start();
    }
     
     
    //Write the response
     
    echo "<?xml version=\"1.0\"?>"."\n";
     
    echo "<products>"."\n";
     
    //flush
    ob_flush();
    flush();
     
    if ($products->RecordCount() >0) {
      while(!$products->EOF) {
     
        echo "<product id=\"".$products->fields['id']."\">"."\n";
        echo "<name lang=\"".$lang['code']."\"><![CDATA[".$products->fields['name']."]]></name>"."\n";
        echo "<description lang=\"".$lang['code']."\"><![CDATA[".$products->fields['description']."]]></description>"."\n";
        echo "<url lang=\"".$lang['code']."\">".zen_href_link("product_info", "products_id=".$products->fields['id']."&language=".$lang['code'], $request_type, false)."</url>"."\n";
     
        //Product image is optional
     
        if (zen_not_null($products->fields['image'])) {
          echo "<image>".$server_protocol."/".DIR_WS_IMAGES.$products->fields['image']."</image>"."\n";
        } 
     
        //echo the categories that the product belongs to
     
        if (array_key_exists($products->fields['id'], $product_categories)) {
          foreach($product_categories[$products->fields['id']] as $cat_id) {
        echo "<category lang=\"".$lang['code']."\"><![CDATA[".$categories[$cat_id]['name']."]]></category>"."\n";
          }
        }
     
        //Product manufacturer is optional
        if (zen_not_null($products->fields['manufacturers_name'])) {
          echo "<manufacturer><![CDATA[".$products->fields['manufacturers_name']."]]></manufacturer>"."\n";
        }
     
        echo "<price>".$products->fields['price']."</price>"."\n";
        echo "<stock>".$products->fields['stock']."</stock>"."\n";
        echo "</product>"."\n";
        $products->MoveNext();
     
        //flush
        ob_flush();
        flush();
      }
     }
    echo "</products>"."\n";
    ?>
     
    <?php
    require(DIR_WS_INCLUDES."application_bottom.php");
    ?>
    I haven't done any number formatting on the price element, so you may want to look at satpromo's code for that.

    Does anyone have an example 3rd party product feed?
    Last edited by jamie2k; 25 May 2008 at 06:03 PM. Reason: typo

  4. #4
    Join Date
    Dec 2008
    Posts
    2
    Plugin Contributions
    0

    Default Re: Real time XML product feed integration?

    I need a programmer who can load an xml product feed into our Zen Cart we want to integrate Tech Data into our site. Can anyone help with that. Will pay!

  5. #5
    Join Date
    Oct 2006
    Posts
    5,477
    Plugin Contributions
    11

    Default Re: Real time XML product feed integration?

    Quote Originally Posted by lmelton View Post
    I need a programmer who can load an xml product feed into our Zen Cart we want to integrate Tech Data into our site. Can anyone help with that. Will pay!
    Post the details in the Commercial help forum will be better.
    I no longer provide installation support on forum for all my modules. However, if there are real bugs with the modules please feel free to contact me

  6. #6
    Join Date
    Mar 2009
    Posts
    2
    Plugin Contributions
    0

    Default Re: Real time XML product feed integration?

    I've found a company that can help with this problem. For not a lot of money they can host your zencart shop. I have a shop with them. They also have a module that in my case is taking my suppliers xml product feed and keeps my product inventory updated in real time. Saving me hours of time.

    If you want to learn more then visit http://www.pcs-pcs.com/solutions.html

    I hope that helps

  7. #7
    Join Date
    Apr 2009
    Location
    Athens, Europe
    Posts
    125
    Plugin Contributions
    0

    Default Re: Real time XML product feed integration?

    Quote Originally Posted by freezing_cold View Post
    The OP was looking for code to import not export a product feed and this isn't any help to them either

    Placing this code in the root of your Zen Cart install will generate an XML export of the products.

    Tested on v1.3.7.

    Code:
    <?php
    require("includes/application_top.php");
    ?>
    <?php
      // We'll be outputting XML
    header('Content-type: application/xml');
    ?>
    <?php
    
      /**
       * Get the default language for the site
       * @return array An array containing the lanugage id and two-letter code.
       */
    
    function get_default_language() {
      global $db;
    
      $sql = "select languages_id, code from ".TABLE_LANGUAGES.", ".TABLE_CONFIGURATION." where configuration.configuration_value=languages.code AND configuration.configuration_key='DEFAULT_LANGUAGE'";
    
      $result = $db->Execute($sql);
    
      return array('code' => $result->fields['code'],
          'languages_id' => $result->fields['languages_id']);
    }
    
    
    /**
     * Fetch back a list of products with their details in the language specified by $language_id.
     * @param int $language_id Specify the language that product descriptions should be returned as.
     * @return queryFactory A list of products wrapped in a queryFactory. 
     */
    
    function get_product_list($language_id) {
    
      global $db;
    
      $sql = "select p.products_id as id, p_d.products_name as name, p_d.products_description as description, p_d.products_url as url, p.products_image as image, p.products_quantity as stock, m.manufacturers_name as manufacturers_name, p.products_price as price from ".TABLE_PRODUCTS." as p inner join ".TABLE_PRODUCTS_DESCRIPTION." as p_d on p.products_id=p_d.products_id left outer join ".TABLE_MANUFACTURERS." as m on p.manufacturers_id=m.manufacturers_id where p_d.language_id=".$language_id;
    
      $result = $db->Execute($sql);
    
      return $result;
    }
    
    
    /**
     * Fetch back a list of products and their categories.
     * This a 1-to-many relationship
     * @return array An array keyed by the product and listing the categories it's in.
     */
    
    function get_product_categories() {
    
      global $db;
    
      $sql = "select products_id as p_id, categories_id as cat_id from ".TABLE_PRODUCTS_TO_CATEGORIES." order by products_id";
    
      $result = $db->Execute($sql);
    
      //Loop and store result as a hash with the product_id the key
    
      $product_categories = array();
    
      while(!$result->EOF) {
    
        $key = $result->fields['p_id'];
    
        if (array_key_exists($key, $product_categories)) {
          
          array_push($product_categories[$key], $result->fields['cat_id']);
    
        } else { 
          $product_categories[$key] = array($result->fields['cat_id']);
        }
        
        $result->MoveNext();
      }
    
      return $product_categories;
    }
    
    
    /**
     * Get the list of categories for the specified language.
     * @param int $language_id The language of the category name and description.
     * @return array An array keyed by category id and storing its name and description.
     */
    
    function get_categories($language_id) {
    
      global $db;
    
      $sql = "select categories_id, categories_name as name, categories_description as description from ".TABLE_CATEGORIES_DESCRIPTION." where language_id=".$language_id;
    
      $result = $db->Execute($sql);
    
      //convert this to hash with the category id as the key
    
      $categories = array();
      
      if ($result->RecordCount() > 0) {
        while(!$result->EOF) {
    
          $categories[$result->fields['categories_id']] = array("name" => $result->fields['name'],
                                    "description" => $result->fields['description']);     
          $result->MoveNext();
        }
      }
    
      return $categories;
    }
    
    /**
     * Fetch back all the attributes used to make up a product feed..
     * @param int $language_id The language used within the feed.
     * @return array The product, product description and categories.
     */
    
    function get_products($language_id) {
    
      $products = get_product_list($language_id);
      $categories = get_categories($language_id);
      $product_categories = get_product_categories();
      
      return array($products, $product_categories, $categories);
    }
    
    /**
     * On which server are we running?
     * @global const $request_type 
     * @return const HTTP_SERVER or HTTPS_SERVER.
     */
    
    function get_server() {
      global $request_type; //SSL or NONSSL ?
    
      $server = HTTP_SERVER;
    
      if ($request_type == 'SSL') {
        if (ENABLE_SSL == 'true') {
          $server = HTTPS_SERVER ;
        }
      }
    
      return $server;
    }
    
    ?>
    <?php
    
    $server_protocol = get_server(); //SSL or NONSSL ?
    
    $lang = get_default_language();
    $result = get_products($lang['languages_id']);
    
    $products = $result[0];
    $product_categories = $result[1];
    $categories = $result[2];
    
    
    //Ready to start flushing output buffers?
    while (ob_get_level()) {
        ob_end_flush();
    }
    
    if (ob_get_length() === false) {
        ob_start();
    }
    
    
    //Write the response
    
    echo "<?xml version=\"1.0\"?>"."\n";
    
    echo "<products>"."\n";
    
    //flush
    ob_flush();
    flush();
    
    if ($products->RecordCount() >0) {
      while(!$products->EOF) {
    
        echo "<product id=\"".$products->fields['id']."\">"."\n";
        echo "<name lang=\"".$lang['code']."\"><![CDATA[".$products->fields['name']."]]></name>"."\n";
        echo "<description lang=\"".$lang['code']."\"><![CDATA[".$products->fields['description']."]]></description>"."\n";
        echo "<url lang=\"".$lang['code']."\">".zen_href_link("product_info", "products_id=".$products->fields['id']."&language=".$lang['code'], $request_type, false)."</url>"."\n";
    
        //Product image is optional
        
        if (zen_not_null($products->fields['image'])) {
          echo "<image>".$server_protocol."/".DIR_WS_IMAGES.$products->fields['image']."</image>"."\n";
        } 
    
        //echo the categories that the product belongs to
        
        if (array_key_exists($products->fields['id'], $product_categories)) {
          foreach($product_categories[$products->fields['id']] as $cat_id) {
        echo "<category lang=\"".$lang['code']."\"><![CDATA[".$categories[$cat_id]['name']."]]></category>"."\n";
          }
        }
    
        //Product manufacturer is optional
        if (zen_not_null($products->fields['manufacturers_name'])) {
          echo "<manufacturer><![CDATA[".$products->fields['manufacturers_name']."]]></manufacturer>"."\n";
        }
    
        echo "<price>".$products->fields['price']."</price>"."\n";
        echo "<stock>".$products->fields['stock']."</stock>"."\n";
        echo "</product>"."\n";
        $products->MoveNext();
    
        //flush
        ob_flush();
        flush();
      }
     }
    echo "</products>"."\n";
    ?>
    
    <?php
    require(DIR_WS_INCLUDES."application_bottom.php");
    ?>
    I haven't done any number formatting on the price element, so you may want to look at satpromo's code for that.

    Does anyone have an example 3rd party product feed?
    Hallo, this worked just fine for its purpose on 1.3.9h.

    I performed some php modifications to suit the needs of the xml specifications they asked me.

    It saved me from a lot of trouble:

    The only xml customizable feeder available is from magneticone and it is encoded (ioncube or zend).

    It is very strong but it had some issues with the second language of my site. Moreover, I wanted to add a <date> YYY-MM-DD HH:MM </date> field at the top of the file, and they told me that this is not possible ... OK!

    Thanx!



    Kind regards,
    orange_juice
    http://www.dodeca.eu/
    Zen Cart is simply Jamming

 

 

Similar Threads

  1. XML product feed
    By DaMixa in forum Setting Up Categories, Products, Attributes
    Replies: 3
    Last Post: 13 Sep 2011, 08:34 AM
  2. Replies: 1
    Last Post: 25 Oct 2010, 03:34 PM
  3. Xml Feed
    By jewelrylady in forum All Other Contributions/Addons
    Replies: 3
    Last Post: 8 Jun 2006, 05:17 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
disjunctive-egg