PDA

View Full Version : XML Stock Update For osCommerce


hazzardouz
04-21-2010, 04:41 PM
I am trying to get my osCommerce store to keep my stock levels upto date via a XML feed that the dropship company provides. As far as I can work out the script would have to match the product 'code' then display the 'stock'. (those are the field names, also the same field names in osCommerce) Please could somebody help me with this. Thank you.

Stock XML Feed: http://www.1on1dropship.co.uk/members_area/feeds.2.0/status-xml.asp

Below is an example of how an item loads on the XML feed:

<stockreport>
<timestamp>21/04/2010 16:24:37</timestamp>
<version>2.0</version>

<products>

<product type="main">
<code>N0507</code>
<name>Jump Start Foot Pump</name>
<stock>1</stock>
<status>In Stock</status>
</product>

Alex Vincent
04-21-2010, 06:58 PM
Someone marked this post as moderated. I don't see why - it looks like a legitimate request for help.

hazzardouz
04-22-2010, 11:41 PM
I am not quite sure where im going wrong here?
I have also attached a copy of my product_info.php
If somebody could help me please. Thank you.


<?php

class ProductStock {

private $last_elem = '';
private $in_correct_elem = false;
private $product = '';
public $stock_info = false;

function __construct($product, $xml_file) {
$this->product = $product;

$xml_parser = xml_parser_create();
xml_set_element_handler($xml_parser, array($this, 'startElement'), array($this, 'endElement'));
xml_set_character_data_handler($xml_parser, array($this, 'handleData'));

$fp = @fopen($xml_file, 'r');
if (!$fp) {
echo "Error opening XML file.";
return;
}

while ($data = fread($fp, 1024)) {
if (!xml_parse($xml_parser, $data, feof($fp))) {
echo 'Error parsing XML.';
return;
}
}
}

function startElement($parser, $element, $attribs) {
$this->last_elem = $element;
if (isset($attribs['NAME']) && $attribs['NAME'] == $this->product) $this->in_correct_elem = true;
}

function handleData($parser, $data) {
if ($this->in_correct_elem && $this->last_elem == 'STOCK') $this->stock_info = $data;
}

function endElement($parser, $element) {
$this->last_elem = '';
$this->in_correct_elem = false;
}

}

$myparser = new ProductStock ($products_name, 'http://www.1on1dropship.co.uk/members_area/feeds.2.0/status-xml.asp');
if (!$myparser->stock_info) echo "Product not found.";
else echo $myparser->stock_info;

?>