Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The problem was my code was not running until after the code to get and display the product data because I was using info from the product data that was only being called once. So the product data had be be called first in order for my code to run. So to fix this, I had to create a new function that would get the sku and pass it to my code before the code that called the product data to be displayed on the page. I copied the existing function to get the product data, renamed it to GetRealTimeStockLevels and added my code to the bottom of it. I put the call for the function above the call for the product data and it worked like I wanted. I'm glad I got this worked out, now I can add the same feature to the checkout page. </p> <p>Below is the function call at the start of the page and then the function I created to run my update code. </p> <pre><code> public function __construct($productid=0) { // Get the stock level from supplier and update the database $this-&gt;_GetRealtimeStockLevels($productid); // Load the data for this product $this-&gt;_SetProductData($productid); public function _GetRealtimeStockLevels($productid=0) { if ($productid == 0) { // Retrieve the query string variables. Can't use the $_GET array // because of SEO friendly links in the URL SetPGQVariablesManually(); if (isset($_REQUEST['product'])) { $product = $_REQUEST['product']; } else if(isset($GLOBALS['PathInfo'][1])) { $product = preg_replace('#\.html$#i', '', $GLOBALS['PathInfo'][1]); } else { $product = ''; } $product = $GLOBALS['ISC_CLASS_DB']-&gt;Quote(MakeURLNormal($product)); $productSQL = sprintf("p.prodname='%s'", $product); } else { $productSQL = sprintf("p.productid='%s'", (int)$productid); } $query = " SELECT p.*, FLOOR(prodratingtotal/prodnumratings) AS prodavgrating, pi.*, ".GetProdCustomerGroupPriceSQL().", (SELECT COUNT(fieldid) FROM [|PREFIX|]product_customfields WHERE fieldprodid=p.productid) AS numcustomfields, (SELECT COUNT(reviewid) FROM [|PREFIX|]reviews WHERE revstatus='1' AND revproductid=p.productid AND revstatus='1') AS numreviews, (SELECT brandname FROM [|PREFIX|]brands WHERE brandid=p.prodbrandid) AS prodbrandname, (SELECT COUNT(imageid) FROM [|PREFIX|]product_images WHERE imageprodid=p.productid) AS numimages, (SELECT COUNT(discountid) FROM [|PREFIX|]product_discounts WHERE discountprodid=p.productid) AS numbulkdiscounts FROM [|PREFIX|]products p LEFT JOIN [|PREFIX|]product_images pi ON (pi.imageisthumb=1 AND p.productid=pi.imageprodid) WHERE ".$productSQL; if(!isset($_COOKIE['STORESUITE_CP_TOKEN'])) { // ISC-1073: don't check visibility if we are on control panel $query .= " AND p.prodvisible='1'"; } $result = $GLOBALS['ISC_CLASS_DB']-&gt;Query($query); $row = $GLOBALS['ISC_CLASS_DB']-&gt;Fetch($result); if (!$row) { return; } $this-&gt;_product = $row; $this-&gt;_prodid = $row['productid']; $this-&gt;_prodname = $row['prodname']; $this-&gt;_prodsku = $row['prodcode']; $GLOBALS['CurrentProductLink'] = ProdLink($this-&gt;_prodname); $server_url = "http://ms.com/fgy/webservices/index.php"; $request = xmlrpc_encode_request("catalog.getStockQuantity", array($this-&gt;_prodsku)); $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); $query = sprintf("UPDATE [|PREFIX|]products SET prodcurrentinv='$response' where prodcode='%s'", $GLOBALS['ISC_CLASS_DB']-&gt;Quote($this-&gt;_prodsku)); $result = $GLOBALS['ISC_CLASS_DB']-&gt;Query($query); } </code></pre>
    singulars
    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.
    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