VikG Posted November 13, 2013 Share Posted November 13, 2013 Hello everyone! I am new here so hopefully I do this right! I have made a PHP script after a lot of google searches to make it work. It works great however I need the following string to show the available stock to be in fact 100 pieces less than it actually is on the xml: $prodarray = "\"$product_record->Product_Code\"".","."$product_record->Available_Stock-48".",All\n"; This will then write to a CSV file for example: "SKU1",500,All This is exported and run on a cron. So instead of 500 I would want it to be 100 units less to 400. How easy is it to do this? TIA Quote Link to comment Share on other sites More sharing options...
kicken Posted November 13, 2013 Share Posted November 13, 2013 Just subtract 100 from $product_record->Available_Stock before sticking it into the string. Eg: $stock = $product_record->Available_Stock - 100; Then use $stock in your CSV string. Quote Link to comment Share on other sites More sharing options...
VikG Posted November 13, 2013 Author Share Posted November 13, 2013 That worked a treat. Thank you very much kicken. I have noticed a small flaw. If stock level is below 100 it goes minus. Is it possible to set minimum value as 0? Thanks Quote Link to comment Share on other sites More sharing options...
Irate Posted November 13, 2013 Share Posted November 13, 2013 Use a conditional statement. $stock = ($product_record->Available_Stock > 100) ? $product_record->Available_Stock - 100 : 0; Quote Link to comment Share on other sites More sharing options...
VikG Posted November 13, 2013 Author Share Posted November 13, 2013 Hi Irate, thank you very much. That is also working perfectly, Quote Link to comment Share on other sites More sharing options...
Irate Posted November 15, 2013 Share Posted November 15, 2013 You're welcome Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.