CSV Datatype for Feedme.
You can also use this plugin as a scaffold to easily add your own custom Datatypes to Feedme.
To install Feedme Helper, follow these steps:
- Download & unzip the file and place the
feedmecsv
directory into yourcraft/plugins
directory - -OR- do a
git clone https://github.com/surprisehighway/feedmehelper.git
directly into yourcraft/plugins
folder. You can then update it withgit pull
- -OR- install with Composer via
composer require surprisehighway/feedmehelper
- Install plugin in the Craft Control Panel under Settings > Plugins
- The plugin folder should be named
feedmehelper
for Craft to see it. GitHub recently started appending-master
(the branch name) to the name of the folder for zip file downloads.
Feedme Pro is required to use custom DataTypes.
Feedme Helper works on Craft 2.4.x and Craft 2.5.x.
Important: Your CSV file must have a header row. This is used by FeedMe to identify columns for field mapping and to save the feed settings.
header1,"Header Two",header3
"Row One","Data Column two",123456
"Row two","Row two data Column two",654321
- Create a new Feed, setting your Feed URL and selecting
CSV Feed
from Feed Type dropdown. - Carry on with normal FeedMe import settings and field mapping.
- Add a new datatype Class under
integrations/datatypes
- In the plugin file
init()
function, import the class. - In the plugin file add your datatype to the Feedme
registerFeedMeDataTypes()
hook.
public function init()
{
Craft::import('plugins.feedmehelper.integrations.feedme.datatypes.CsvFeedMeDataType');
Craft::import('plugins.feedmehelper.integrations.feedme.datatypes.MyCustomFeedMeDataType');
}
public function registerFeedMeDataTypes()
{
return array(
new CsvFeedMeDataType(),
new MyCustomFeedMeDataType(),
);
}
Whatever your external data source is in the end your datatype class needs to parse the data into an associative array that is returned to Feedme. The array keys are used to save the feed settings in the database, (which is why CSV data needs a header row).
Currently the Feedme docs for adding Datatypes are incomplete, so hopefully this might be helpful to someone else.
<?php
namespace Craft;
class MyCustomFeedMeDataType extends BaseFeedMeDataType
{
public function getFeed($url, $primaryElement, $settings)
{
// Do stuff here... see the CSV or Default FeedMe datatypes for examples...
return $associative_array;
}
}
All credit goes to Engram Design for the fantasic FeedMe plugin and default JSON
datatype which this CSV
adapter is derived from.
Brought to you by Mike Kroll and Surprise Highway