Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

Get Qty/Price XML Feed problems


Recommended Posts

After I run the Get Qty/Price XML Feed.php file in the browser, the page is blank and none of my prices and quantities are updated to match the xml file that i get from my supplier. Any help would be much appreciated, i have edited the \Get Qty/Price XML Feed.php file and it looks like this:

 

#

<?php

 

//

// 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

require('includes/configure.php');

 

// 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":

break;

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

ftp_close($conn_id);

fclose($handle);

 

// end of php-ftp code

break;

case "http":

default:

// 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);

 

curl_exec($ch);

curl_close($ch);

fclose($fp);

// end of php-curl code

}

 

 

 

// let's get the database open now

// include the database functions

require('includes/functions/database.php');

 

// 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) {

fwrite($tmp_handle,$buffer);

}

}

}

// complete repairing xml file

 

// initialize some variables

$name = '';

$value = '';

 

// create new reader and open file

$xml = new XMLReader();

$xml->open($temp_file);

 

// 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.

tep_db_close();

 

?>

 

I am definately missing something but i cant find what.

 

Any help would be much appreciated

 

Peter

Link to comment
Share on other sites

Have you tried reading the code and setting the parameter to the values required to get it to run in live mode?

 

G

Need help installing add ons/contributions, cleaning a hacked site or a bespoke development, check my profile

 

Virus Threat Scanner

My Contributions

Basic install answers.

Click here for Contributions / Add Ons.

UK your site.

Site Move.

Basic design info.

 

For links mentioned in old answers that are no longer here follow this link Useful Threads.

 

If this post was useful, click the Like This button over there ======>>>>>.

Link to comment
Share on other sites

Hi Geoff cheers for your reply, I have tried it in live mode,but it does exactly the same. Have changed the code within the .php file to the parameters i think make the document work. However it does nothing. Iam not a programmer so am not entirely sure as to what the parameters should be. Would you be able to help with any of the code

 

Regards

 

Peter

Link to comment
Share on other sites

Normally the problem is a parameter has not been set properly or the xml is not in the expected format.

 

The first thing to do it to get it to download manually.

 

HTH

 

G

Need help installing add ons/contributions, cleaning a hacked site or a bespoke development, check my profile

 

Virus Threat Scanner

My Contributions

Basic install answers.

Click here for Contributions / Add Ons.

UK your site.

Site Move.

Basic design info.

 

For links mentioned in old answers that are no longer here follow this link Useful Threads.

 

If this post was useful, click the Like This button over there ======>>>>>.

Link to comment
Share on other sites

  • 5 months later...

I have also problem with the Get Qty/Price XML Feed addon. After I run the Get Qty/Price XML Feed.php file in the browser, the page is blank.

 

The XML file from the supplier looks like this.

 

−<STOREITEMS>

−<PRODUCT ITEM="0100" NAME="A">

<STOCK>In Stock.</STOCK>

</PRODUCT>

−<PRODUCT ITEM="0200" NAME="B">

<STOCK>No Stock.</STOCK>

</PRODUCT>

−<PRODUCT ITEM="0300" NAME="C">

<STOCK>No Stock.</STOCK>

</PRODUCT>

</STOREITEMS>

 

In the php file I have changed

 

on line 171

if ($name == "ITEMNO") $itemno = trim($value); to

if ($name == "PRODUCT ITEM") $itemno = trim($value);

and on line 173

if ($name == "QTYOH") $qty = trim($value); to

if ($name == "STOCK") $qty = trim($value);

 

I have left line 172 unchanged

if ($name == "PRC1") $cost = trim($value);

 

Thank you in advance for any help!

Link to comment
Share on other sites

  • 2 years later...

Hopefully some one can help me troubleshoot to get this to work correctly.

 

So far I have the automated download of the feed to my server working.

In test mode, I get the list displayed to my screen.

I have the markup and what the price ends in (like .99) working, though I had to hard code the markup percent in the php file since it would not pull from the database column created for that function. I'm satisfied with this so no help need here.

 

The problem that I am looking for help with is that the MAP function is not working. (This is pulled from the database as well so I'm wondering if the markup and MAP problems are related.) The column is in the database and named the same; products_map. I am able to download the MAP file via EasyPopulate and it shows the correct MAPs if the product has a MAP.

 

The script out of the box as written gives an error for the markup, which I am throwing it out there in case it is related to the MAP problem.

 

$price = (int)($cost * (1+$markup))+.95;

 

gives the error "Unsupported operand types". So I changed it to:

 

$price = (int)($cost * 1.2)+.95;

 

and it works

 

Code for the MAP portion is:

 

// 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];
}
}

 

Both use map and use markup are set to true.

 

Let me know what additional information you need. Running 2.3.3.

Link to comment
Share on other sites

Can anyone shed some light on why the MAP portion might not be working?

 

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];

 

This is the last piece and I should have it running correctly.

 

Thanks in advance.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...