Hi all,
anyone aware of a mod / extension / way that I could get opencart to automatically check a CSV or similar on a daily basis, check through a stock column and update opencart as a result?
The file I want to check is as follows:
File Url: http://www.domain.com/file-that-you-want-to-get.xml
Root (Products), Node (Product), Element names:
1) ProductID
(2) Name
(3) Xline "true or false, If true, will be discontinued when stocks run out"
(4) InStock "In Stock, Out of Stock or Discontinued"
(5) Stock "if Xline true will show remaining stock, otherwise will always show 99"
I use the same product ID on my 'model' in opencart as is used in the feed so I essentially want to
- grab the file
- match the IDs to my models
- check if the in stock status should be 'in stock' or 'out of stock'
- updated as needed
Any thoughts or suggestions on automating this are most certainly welcome
anyone aware of a mod / extension / way that I could get opencart to automatically check a CSV or similar on a daily basis, check through a stock column and update opencart as a result?
The file I want to check is as follows:
File Url: http://www.domain.com/file-that-you-want-to-get.xml
Root (Products), Node (Product), Element names:
1) ProductID
(2) Name
(3) Xline "true or false, If true, will be discontinued when stocks run out"
(4) InStock "In Stock, Out of Stock or Discontinued"
(5) Stock "if Xline true will show remaining stock, otherwise will always show 99"
I use the same product ID on my 'model' in opencart as is used in the feed so I essentially want to
- grab the file
- match the IDs to my models
- check if the in stock status should be 'in stock' or 'out of stock'
- updated as needed
Any thoughts or suggestions on automating this are most certainly welcome
Last edited by itrends on Tue May 29, 2012 11:42 pm, edited 1 time in total.
For anyone that is interested, I managed to work this out. Here is my code
You'll see I put a sleep delay in there of 200 seconds to make sure the file was fully downloaded as it can be quite large.
Code: Select all
$xml = file_get_contents("http://domain.com/file-that-you-want-to-get.xml"); // your file is in the string "$xml" now.
file_put_contents("/path_to_file/public_html/stock-today.xml", $xml); // now your xml file is saved.
sleep(200);
$con = mysql_connect("localhost","datebase_username","database_password");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("database_name", $con);
$url = "/path/to/file/public_html/stock-today.xml";
$xml = simplexml_load_file($url);
foreach($xml->Product as $Product)
{
mysql_query("UPDATE product SET quantity=$Product->Stock WHERE model=$Product->ProductID ");
}
mysql_close($con);
No reason why not - best bet is to backup your database and then test.
I'm not looking to suppor this or anything but it should be good for some time in the future as it is independent of any opencart files and only needs to touch one table in the database that I can't imagine would change now.
I'm not looking to suppor this or anything but it should be good for some time in the future as it is independent of any opencart files and only needs to touch one table in the database that I can't imagine would change now.
Hi,
Thanks for an awesome script!
Would it be possible to also update the stock levels for product separate options? For example, there would be separate codes for Adidas black shirt and adidas white shirt (the product is the same, only the options quantity differ)
Anyone's help would be really appreaciated.
Thanks for an awesome script!
Would it be possible to also update the stock levels for product separate options? For example, there would be separate codes for Adidas black shirt and adidas white shirt (the product is the same, only the options quantity differ)
Anyone's help would be really appreaciated.
Hi there,
Can someone help me with a few pointers where this should be placed and perhaps some usefell url's for understanding the ways to customize this? I like to get into this but my search keywords dont seem to give usefull results.
If there is someone with some of these tip or usefull links about these kinda imports, plz let me know!
Thx in Advance.
Can someone help me with a few pointers where this should be placed and perhaps some usefell url's for understanding the ways to customize this? I like to get into this but my search keywords dont seem to give usefull results.
If there is someone with some of these tip or usefull links about these kinda imports, plz let me know!
Thx in Advance.
Online Media Development
http://www.vuuredesign.nl/
Your code may work, but its scripted very badly, you shouldnt be added the mysql database details directly to the page, they should be pulled from pre existing variables already loaded.
Plus your databse calls should be handled seperately in a model file.
Plus your databse calls should be handled seperately in a model file.
I realise this is an old post but I feel this should be addressed.
The database details are not visible to anyone, nor can they be accessed by anything other than the server. The server RUNS the PHP script to generate the desired outcome.
In regards to separating the database calls. You would like the OP to follow the full MVC architecture for a simple script?
Anyway, back on topic. I am also trying to get this to work but for some reason it just wont update the product quantity. No errors. I cleaned up the code a little to make it easier to read and is below (I changed the sleep to 10 seconds as I am currently testing with a small file). Can anyone identify the issue?
Code: Select all
<?php
$xml = file_get_contents("https://www.supplierwebsite.com.au/supplier-feed.xml");
file_put_contents("/home/project_folder/public_html/supplier-feed.xml", $xml);
sleep(10);
$dbhost = 'localhost';
$dbuser = 'user';
$dbpass = 'pass';
$db = 'database';
$con = mysql_connect($dbhost, $dbuser, $dbpass);
if (!$con) {
die('Could not connect: ' . mysql_error());
}
mysql_select_db($db, $con);
$url = "https://www.mywebsite.com.au/supplier-feed.xml";
$xml = simplexml_load_file($url);
foreach($xml->product as $product) {
mysql_query("UPDATE oc_product SET quantity = $product->PRODUCT_QUANTITY WHERE model=$product->MODEL");
}
mysql_close($con);
?>
A ... really untrustworthy code ...
A few example on how to gather the data in a more solid way are demonstrated in the catalog/model/shipping folder. The RFC standards has increased their security measures to capture data from XML data since then. Besides, MySQL has been deprecated since ages as the MySQLi extension takes the lead.
At this point, if you are unsure on how to proceed, the best option would be to create a new service request in the Commercial Support section of the forum to get this done as a custom job.
A few example on how to gather the data in a more solid way are demonstrated in the catalog/model/shipping folder. The RFC standards has increased their security measures to capture data from XML data since then. Besides, MySQL has been deprecated since ages as the MySQLi extension takes the lead.
At this point, if you are unsure on how to proceed, the best option would be to create a new service request in the Commercial Support section of the forum to get this done as a custom job.
Dedication and passion goes to those who are able to push and merge a project.
Regards,
Straightlight
Programmer / Opencart Tester
Thank you. I used the code in the original post and updated accordingly. Please note that I NEVER use any new code on a live site unless I am absolutely certain it is safe and error free.
On that note, it would be beneficial to elaborate on your statement so we can obtain a deeper understanding of what aspects are considered unsafe.
You are most likely correct, but I do like to gain knowledge myself so I can make minor updates if necessary.straightlight wrote: ↑Tue Oct 09, 2018 8:58 amAt this point, if you are unsure on how to proceed, the best option would be to create a new service request in the Commercial Support section of the forum to get this done as a custom job.
Who is online
Users browsing this forum: No registered users and 67 guests