Jump to content
  • Checkout
  • Login
  • Get in touch


The e-commerce.

get_qty_price_xml_feed problems


Recommended Posts



Iam having problems with the get_qty_price_xml_feed addon, i just cant seem to get it working, if i set the test mode on, and try and load the get_qty_price_xml_feed.php file in the browser the page is just blank and also if I set the live mode on and run the get_qty_price_xml_feed.php file then the page in the browser is also blank, but the prices on my site is just blank. Can anyone help?


I have the XML file on my server and can get it dropped in by my supplier so have set the get method to off. The inventory.tmp file in my admin section conatins all the xml data that is contained within the pricelist.xml file, so it is doing something correctly, i just cant get it to update prices when the live mode is on, and doesn't display anything when the test mode is on either , where it should display something like

007623 7.41 30

007629 4.55 83

007702 4.54 90

008020 2.58 50

that is stated in the accompanying documentation


The get_qty_price_xml_feed.php file i have set looks like this





// 1.00 Original release




/* Name this file get_xml_inventory.php or whatever you want, just change it in the cron job below also.

This program must reside in your admin directory! If you want it elsewhere you will have to hard code the paths below


Use the following cron job to execute this. Edit the absolute path to your admin directory.


php /absolute/path/to/shop/admin/get_xml_inventory.php




// have to include the admin configure file



// set options


// Set mode of operation // use for setting test mode or live mode.

$test_mode = 1; // 1 = test mode, 0 = live mode



// file and directory names - must be absolute paths and not URLs

$working_dir = DIR_FS_ADMIN; // Uses admin directory from configure.php file

$local_file = DIR_FS_ADMIN . 'pricelist.xml'; // Uses admin directoy / local and temp file name where you will store the file on your server

$temp_file = DIR_FS_ADMIN . 'inventory.tmp'; // It will run cleaner if you create these files manually beforehand.



// this is the method you will use to get your data feed

$get_method = 'off'; // valid values are 'ftp' or 'http' or 'off' NOTE that http method uses curl and so will not work under xampp

// Off is useful for testing or when a supplier 'puts' a file on your server instead of you having to go out and get it


// these are required if you use ftp as your get method

$ftp_server = ''; // Change to fully qualified domain name

$ftp_user_name = ''; // Change to your user name

$ftp_user_passs = ''; // Change to your password

$remote_dir = '' ; // Change to something other than entry directory

$remote_file = ''; // name of products file to get from vendor


// this is required is you use the http get method. It should be a valid URL that you get get with a browser

$url_to_file = ''; // If http is Get_method this must be a valid URL to the file


// These are general options

$use_map = 0; // set to 1 to enable map

$use_markup = 0; //set to 1 to enable markup calculations




/* Set your common field

For this to work your data feed must have a unique field (like products_id or products_model) that mataches one for one with a field in

your database.in order to work properly. Some shops have

installed custom fields. This is where you will define that field. */

define('PRODUCT_MODEL', 'product_model'); // default is 'products_model' Change to whatever your common field is


// //////////////// There are three additional edits below. FIND THEM! /////////////////////////////




// Let's change to the working directory

// this does not work under xampp so just comment it out


// Start the download

switch ($get_method) {

case "off":


case "ftp":


// open some file to write to.

$handle = fopen($local_file, 'w');


// set up basic connection

$conn_id = ftp_connect($ftp_server);


// login with username and password

$login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass);


// change directory if need to

if (isset($remote_dir)) {

ftp_chdir($conn_id, $remote_dir);



// try to download $remote_file and save it to $handle

if (ftp_fget($conn_id, $handle, $remote_file, FTP_ASCII, 0)) {

echo "successfully written to $local_file\n"; // may have to comment this out after testing

} else {

echo "There was a problem while downloading $remote_file to $local_file\n"; // may have to comment this out after testing



// close the connection and the file handle




// end of php-ftp code


case "http":


// following uses curl as php code

$ch = curl_init($url_to_file);

$fp = fopen($local_file, "w");


curl_setopt($ch, CURLOPT_FILE, $fp);

curl_setopt($ch, CURLOPT_HEADER, 0);





// end of php-curl code





// let's get the database open now

// include the database functions



// make a connection to the database... now

tep_db_connect() or die('Unable to connect to database server!');


// open the xml file and build structure

$handle = @fopen($local_file,"r");

// open tmp file for writing

$tmp_handle = @fopen($temp_file,"w");


if ($handle) {

while (!feof($handle)){

$buffer = fgets($handle,4096);


// ************************** Possible edit needed here **************************************

// sanitize garbage delivered by supplier into valid XML file, if necessary. Populate and uncomment as necessary

$buffer = str_replace('<','<',$buffer);

$buffer = str_replace('>','>',$buffer);

// $buffer = str_replace('','',$buffer);

// $buffer = str_replace('','',$buffer);

// $buffer = str_replace('','',$buffer);

// $buffer = str_replace('','',$buffer);

// *******************************************************************************

if($buffer) {





// complete repairing xml file


// initialize some variables

$name = '';

$value = '';


// create new reader and open file

$xml = new XMLReader();



// read each line of the file

while ($xml->read()){

// echo $xml->nodeType . "<BR>\n"; // debug


// assign element node name to $name

if ($xml->nodeType == XMLreader::ELEMENT) {

$name = $xml->name;



// assign element value to $value

if (in_array($xml->nodeType, array(XMLReader::TEXT, XMLReader::CDATA, XMLReader::WHITESPACE, XMLReader::SIGNIFICANT_WHITESPACE)) && $name!='CDATA'){

$value= $xml->value;



// ************************************* This block needs to be edited to match your xml file. ONLY THE NAMES IN CAPS NEED TO BE CHANGED *************

// assign each value to specific variables

if ($name == "<itemProductCode>") $itemno = trim($value); // this may match your products_id or it may match your products_model or a custome field.

if ($name == "<itemPhysicalQty>") $cost = trim($value);

if ($name == "<itemPrice>") $qty = trim($value);

// if ($name == "MFGINO") $model = trim($value); // this may or may not be necessary. The others are necessary.

// **********************************************************



// ends getting data and populating local variables


//reset name/value values

if ($xml->nodeType == XMLReader::END_ELEMENT){

$name = 'CDATA';

$value = '';



// **************************** This (name == 'Table') needs to be changed to the nametag that surrounds each produt. ************************

// only continue if we reach the product end tag

if ($xml->nodeType == XMLReader::END_ELEMENT && $xml->name == 'CDATA'){



if ($use_markup == true) { // requires a markup column in the categories table with markeup amount as decimal ( .20 as 20%)


$sql = "select categories.markup from categories,products_to_categories,products where products.products_id = '" . $itemno . "' and products.products_id = products_to_categories.products_id and products_to_categories.categories_id = categories.categories_id";

$result = mysql_query($sql);

$markup = mysql_fetch_row($result);

$price = (int)($cost * (1+ $markup))+.99; // go ahead and change the .99 to whatever you want

$cost = $price;



// are we going to use MAP pricing? Requires a products_map column in the products table, with a value for map, NULL if no MAP

if ($use_map == true) {

$sql = "select products_map from products where products_id = '" . $itemno . "'";

$result = mysql_query($sql);

$map = mysql_fetch_row($result);

if (!(is_null($map[0]))) {

$cost = $map[0];





// OK, let's build and execute the sql statement for this item

$sql = "update products set products_quantity = '" . $qty . "', products_price = '" . $cost . "' where " . PRODUCTS_MODEL . "= '" . $itemno . "'";




if ($test_mode == true) {

echo "<table border=1>";

echo " <tr>";

echo " <td>" . $itemno . "</td><td>" . $cost . "</td><td>" . $qty . "</td>";

echo " </tr>";

echo "</table>";

} else {

$result = mysql_query($sql); // this executes the sql



} // back up to process next item


// and finally, close the db and we are done.





Any help would be much appreciated



Link to comment
Share on other sites


This topic is now archived and is closed to further replies.

  • Create New...