Jump to content
Latest News: (loading..)
CotswoldEngraver

CSV feed import renaming file question

Recommended Posts

Not sure if this is possible to achieve but here goes.

I have a data feed for stock level from my supplier. The suppliers csv file is 'placed' in a folder by my supplier once a day which I then use to update my stock levels via the Get Price Quantity Update Feed using a cron. This all works absolutely fine.

The issue I have is that my suppliers csv filename changes every day because they use a date stamp as the filename. The folder where the csv is stored will have the latest file stored in a list of previously uploaded files in date order. I have asked them if they can supply me with a fixed filename but this is not possible as the file is generated by their stock control system daily and needs to be the date and time for their stock tracking.

Now to my question; is there a way of automatically renaming the file before importing it in to my site so that the add on can read a static filename? Can this be done with a standalone php file and a cron or would a line in my htaccess file work? All help gratefully received.

Kind regards Andy

Share this post


Link to post
Share on other sites

Yes.  Look at these PHP functions (note this is off the top of my head, but it'll give you a starting point);

glob
filemtime
rename
 

 


This is a signature that appears on all my posts.  
IF YOU MAKE A POST REQUESTING HELP...please state the exact version
of osCommerce that you are using. THANKS

 
Get the latest current code (community-supported responsive 2.3.4.1BS Edge) here

 

Share this post


Link to post
Share on other sites
2 minutes ago, burt said:

Yes.  Look at these PHP functions (note this is off the top of my head, but it'll give you a starting point);

glob
filemtime
rename
 

 

thanks burt.

I'll look in to those

Share this post


Link to post
Share on other sites

A cron job could every 30 minutes or so use glob to get file names, filemtime to see if it's new, and rename or similar to change the file to a standard name. Perhaps instead you could consider modifying the CSV code (Easy Populate?) to generate the file name from the date and directly read that (rather than a fixed name)? It would have to check for the presence of the file, in case your supplier missed a day or is late.


If you are running the "official" osC 2.3.4 or 2.3.4.1 download, your installation is obsolete! Get (stable) Frozen or (unstable) Edge. See also the naming convention and the latest community-supported responsive "Edge" release

Share this post


Link to post
Share on other sites

Hi both.

Many thanks for your pointers on this topic.

After much experimenting I finally have a working version that sorts the files in the folder uploaded by my supplier, takes the newest one and then copies it back to the folder with a new static filename. The add on then just looks for the static filename and uploads that in to the website to update the product quantities.

I have included the additional code in to the Get Product Quantity script so the whole process runs automatically via a cron at midnight every night.

Although it is a small modification I am very pleased as this is the first time I have created a piece of code from scratch!

Thanks for your pointers.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×