Note that there are some explanatory texts on larger screens.

plurals
  1. POHow do I update a database table using data from xml-rpc?
    primarykey
    data
    text
    <p>I'd like to say thank you for any replies right away. I will truly appreciate your help. </p> <p><em>UPDATE</em> I just read on this site someone mention xml datatypes and stored procs. Now I thinking searching for xml-rpc and update database wasn't enough. I'm searching for how to use xml data to update a database. But if you still have thoughts on my questions below, I'd appreciate them. </p> <p>I've Googled and searched this site on the possibility and the how of using data pulled from a remote server via xml-rpc to update a database table and I could find nothing about how to do such a thing. I did find tons of good info on xml-rpc (I'm brand new at it) and a SQL command to update a database table is pretty simple. But how on earth do I use the data I grab using xml-rpc to update a table? </p> <p>I think it's because I probably don't fully understand xml-rpc. I have a shopping cart and all I want to do right now is pull the stock levels from my supplier. When users click on the link to a product I need to grab the real time stock levels and insert these stock level numbers into my product inventory table for that particular product (so it's on the fly).</p> <p>I took a peek at the php file where the cart script looks grabs the stock level of the item from the database. It seems I would add two things right before that grab. 1. The xml-rpc call to get stock levels by sku and 2. A SQL update command to insert that data into the database. </p> <p>But once I do the xml-rpc call is made and it returns the stock levels, where does this data go? From my reading, it looks like this data is revealed to user by some kind of print or display results directly to the web browser. But instead of doing that I need to move this data into a database table. </p> <p>Any thoughts? Is this possible?</p> <p>This is the function I've edited to try to grab the stock levels and update the table: I've added these two sections to the existing function - <strong>// Grab inventory level by sku from supplier</strong>, <strong>// Update inventory table by sku</strong></p> <pre><code> /** * Show the inventory management quick view on the manage products page if inventory tracking is on for a product * * @return void **/ private function GetInventoryLevels() { $GLOBALS['ISC_CLASS_ADMIN_ENGINE']-&gt;LoadLangFile('products'); if(isset($_REQUEST['p']) &amp;&amp; isset($_REQUEST['i']) &amp;&amp; isset($_REQUEST['v']) &amp;&amp; isset($_REQUEST['t'])) { $prodId = (int)$_REQUEST['p']; $invType = (int)$_REQUEST['i']; $variationId = (int)$_REQUEST['v']; $combinations = array(); // First determine if inventory tracking is by product or by option if ($invType == 1) { **// Grab inventory level by sku from supplier** $server_url = "http://gg.com/ttt/webservices/index.php"; $prodcurrentinv = ""; if (function_exists('xmlrpc_encode_request')) { $request = xmlrpc_encode_request("catalog.getStockQuantity(sku)", array($prodcurrentinv)); $context = stream_context_create(array('http' =&gt; array( 'method' =&gt; "POST", 'header' =&gt; "Content-Type: text/xml", 'content' =&gt; $request ))); $file = file_get_contents($server_url, false, $context); $response = xmlrpc_decode($file); if (xmlrpc_is_fault($response)) { trigger_error("xmlrpc: $response[faultString] ($response[faultCode])"); } else { print '&lt;pre&gt;'; print_r($response); print '&lt;/pre&gt;'; } } else { print '&lt;div style="color:red;"&gt;Sorry, you don\'t seem to have the xmlrpc module compiled in.&lt;/div&gt;'; } print '&lt;hr/&gt;'; require_once 'XML/RPC2/Client.php'; // since we're using a 'catalog' function, we need to make sure it prefixes the function // name when it's called on the server. (The XML_RPC2 docs suggest that you could use // 'catalog.getStockQuantity(sku)' as the class function name, but that's not correct. $options = array( 'prefix' =&gt; "catalog." ); $client = XML_RPC2_Client::create($server_url, $options); $result = $client-&gt;getStockQuantity(sku)($prodcurrentinv); print '&lt;pre&gt;'; print_r($result); print '&lt;/pre&gt;'; print '&lt;hr/&gt;'; **// Update inventory table by sku** $query = sprintf("update prodcurrentinv from [|PREFIX|]products where productcode='%d'",) // Simply query the products table for current and low stock levels $query = sprintf("select prodcurrentinv, prodlowinv from [|PREFIX|]products where productid='%d'", $GLOBALS['ISC_CLASS_DB']-&gt;Quote($prodId)); $result = $GLOBALS['ISC_CLASS_DB']-&gt;Query($query); if($row = $GLOBALS['ISC_CLASS_DB']-&gt;Fetch($result)) { printf("&lt;b style='font-size:13px; padding-bottom:5px'&gt;%s&lt;/strong&gt;", GetLang("UpdateInventoryLevels")); echo "&lt;table border='0'&gt;"; echo "&lt;tr&gt;"; echo "&lt;td valign='top'&gt;&lt;img src='images/nodejoin.gif' style='padding-top:5px' /&gt;&lt;/td&gt;"; printf("&lt;td&gt;%s:&lt;/td&gt;", GetLang("CurrentStock")); printf("&lt;td&gt;&lt;input type='text' size='3' value='%d' name='stock_level_%d' id='stock_level_%d' /&gt;&lt;/td&gt;", $row['prodcurrentinv'], $prodId, $prodId); echo "&lt;/tr&gt;"; echo "&lt;tr&gt;"; echo "&lt;td&gt;"; printf("&lt;td&gt;%s:&lt;/td&gt;", GetLang("LowStockLevel")); printf("&lt;td&gt;&lt;input type='text' size='3' value='%d' name='stock_level_notify_%d' id='stock_level_notify_%d' /&gt;&lt;/td&gt;", $row['prodlowinv'], $prodId, $prodId); echo "&lt;/tr&gt;"; echo "&lt;/table&gt;"; printf("&lt;input class='StockButton' type='button' value='%s' onclick='UpdateStockLevel(%d, 0)' style='margin-left:110px' /&gt;&amp;nbsp; &lt;img src='images/ajax-blank.gif' id='loading%d' /&gt;", GetLang("Save"), $prodId, $prodId); } } else { $optionIds = array(); // Fetch out the variation combinations for this product $query = "SELECT * FROM [|PREFIX|]product_variation_combinations WHERE vcproductid='".$prodId."'"; $result = $GLOBALS['ISC_CLASS_DB']-&gt;Query($query); while($combination = $GLOBALS['ISC_CLASS_DB']-&gt;Fetch($result)) { $combinations[] = $combination; $optionIds = array_merge($optionIds, explode(",", $combination['vcoptionids'])); } $optionIds = array_unique($optionIds); // Now fetch out the options we need to get if(!empty($optionIds)) { $optionIds = implode(",", $optionIds); // Get the combination options $variations = array(); $query = "SELECT * FROM [|PREFIX|]product_variation_options WHERE voptionid IN (".$optionIds.")"; $result = $GLOBALS['ISC_CLASS_DB']-&gt;Query($query); while($variation = $GLOBALS['ISC_CLASS_DB']-&gt;Fetch($result)) { $variations[$variation['voptionid']] = array($variation['voname'], $variation['vovalue']); } } printf("&lt;b style='font-size:13px'&gt;%s&lt;/strong&gt;&lt;div style='padding:20px 20px 0px 20px'&gt;", GetLang("UpdateInventoryLevels")); foreach($combinations as $row) { $output = ""; $options = explode(",", $row['vcoptionids']); foreach($options as $option) { $output .= isc_html_escape($variations[$option][0]) . ": " . isc_html_escape($variations[$option][1]) . ", "; } $output = trim($output, ', '); echo "&lt;strong&gt;&lt;em&gt;" . $output . "&lt;/em&gt;&lt;/strong&gt;"; echo "&lt;br /&gt;"; echo "&lt;table border='0' style='padding-bottom:10px'&gt;"; echo "&lt;tr&gt;"; echo "&lt;td valign='top'&gt;&lt;img src='images/nodejoin.gif' style='padding-top:5px' /&gt;&lt;/td&gt;"; printf("&lt;td&gt;%s:&lt;/td&gt;", GetLang("CurrentStock")); printf("&lt;td&gt;&lt;input type='text' size='3' value='%d' name='stock_level_%d_%d' id='stock_level_%d_%d' /&gt;&lt;/td&gt;", $row['vcstock'], $prodId, $row['combinationid'], $prodId, $row['combinationid']); echo "&lt;/tr&gt;"; echo "&lt;tr&gt;"; echo "&lt;td&gt;"; printf("&lt;td&gt;%s:&lt;/td&gt;", GetLang("LowStockLevel")); printf("&lt;td&gt;&lt;input type='text' size='3' value='%d' name='stock_level_%d_%d' id='stock_level_notify_%d_%d' /&gt;&lt;/td&gt;", $row['vclowstock'], $prodId, $row['combinationid'], $prodId, $row['combinationid']); echo "&lt;/tr&gt;"; echo "&lt;/table&gt;"; } echo "&lt;/div&gt;"; printf("&lt;input class='StockButton' type='button' value='%s' onclick='UpdateStockLevel(%d, 1)' style='margin-left:130px' /&gt;&amp;nbsp; &lt;img src='images/ajax-blank.gif' id='loading%d' /&gt;", GetLang('Save'), $prodId, $prodId); } } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload