Recently I needed a way of importing listings from another site into a 68 Classifieds site. As of right now 68 Classifieds doesn’t have an api so the only real way of doing it is to create some custom code to interact with the script. In this post I will outline how I got it working so if you ever have the need you can do it too. Keep in mind this is very crude and just enough to get the job I needed done.
The Data
The data you are importing needs to be a delmited file. I used a pipe delimited text file with the following lines:
OWNER|TITLE|SECTION|LINK|DESCRIPTION|PRICE|MAKE|MODEL|HOURS|SERIAL|LOCATION| 1|Test Import|1|http://yoursite.com|Test desc|2399|Ford|Taurus|55000|none|My Town 1|Test Import 2|1|http://yoursite.com|Test desc 2|2399|Toyota|Tundra|55000|none|My Town
The first line is just the header which is not used but I included it for reference. The next two lines are two different vehicles to import. The important step is to make sure the lines align with the heading line and to have each on their own line.
The Import Script
The import script is where all the processing will be. This file is designed to be saved in your 68 Classifieds root. You can view and download the full file from GitHub. I will go through all the sections below so you can see how to modify it suit your needs.
At the top of this file is this section:
$expiration = '30'; // Change 30 to the number of days these should expire. $make_extra_field_id = 6; // The id of the make extra field $model_extra_field_id = 7; // The id of the model extra field $hours_extra_field_id = 8; // The id of the hours extra field $serial_extra_field_id = 9; // The id of the serial extra field $location_extra_field_id = 10; // The id of the location extra field
This allows you define what extra fields you are using and have them line up with your data.txt file. As you can see I am setting the expiration for 30 days, then defining the id of each extra field I am using.
The next part you will probably want to modify is the for loop. Inside this loop I am assigning out the data. This looks like this:
$data['owner'] = $arr[0]; $data['title'] = $arr[1]; $data['section'] = $arr[2]; $data['url'] = $arr[3]; $data['description'] = $arr[4]; $data['price'] = $arr[5];
Basically the $arr[number] is a map to the data file. So $arr[0] is the data in the first pipe and on on. Just remember it always starts with zero instead of one.
The final piece of data is the extra fields which look like this:
$extra['make'] = $arr[6]; extra_field($listingid, $make_extra_field_id, $extra['make']);
The first line $extra['make'] = $arr[6]; is just like above this maps to 5th deliminator in the data file. Next we call the function extra_field which takes the listingid, the extra field id, and finally the text as parameters.
The Full File
Wrap Up
Trying to explain this was actually a lot harder than I thought. So if you need any clarification on anything please comment below.
