| Callbacks |
|
This page tries to explain the usage of callback functions. callbacks are php-functions used to filter and manipulate feed data. Each item in a feed is parsed by the callback function. In the feed configuration the default callback is set to generic_cb. You can change this to your own functions. Callback functions go into the feeds.php script, there is a 'edit callbacks' tab/link in the menu's
Generic structure callback functionsfunction yourcallback_cb(&$item) {
# your stuff here generic_cb($item); #more stuff here } Next to solving some encoding issues the function generic_cb maps the fields from the feed to the fields in the database. See this image ( connect the dots ). So after the call to generic_cb you have the deeplink in href ( $item['href'] ) the fields from 'Field Selection' in menu_1 to menu_9, the group (Select 0) in menu_0, the name of the feed ( = merchant ) in the field feed and the price in prijs If you insert you code before the call to generic_cb you must use the fields from the datafeed ( name, country etc) if you put your code after the call to generic_cb you must use the database fields ( title, menu_1 etc). This allows to use a single callback function for several feeds regardless the structure of the feed Excluding itemsYou can exclude items by clearing the 'title' feed or the complete $item array: function yourcallback_cb(&$item) {
generic_cb($item); if ( condition ) {
} for condition you can use any (pattern) matching on fields in the item array examples
Changing Valuesin the callback you can change any value as you like. function travel_cb(&$item) {
generic_cb($item); } Importing offers onlyAssuming you have a feed with 'old'-prices and 'current'-prices, and you wish to import the offers only. Assign the 'current' price to the field 'price' and the 'old' price to Select 9 ( you can pick any free field) function offersonly_cb(&$item) {
generic_cb($item); Cascading functionssimilar feeds ofter share similar problems, for example renaming categories. To reuse and share code callback functions can simply call each other. There is just on catch, the function generic_cb must be called once, and just once. Below a structure for solving this for 'fashion', each 'fashion' feed will call the 'fashion_cb' function ( configured in the feed configuration ) unless it need some special handling having it's own callback ( and the shared one)
<?php
Filtering on titlefunction mytitle_cb(&$item) {
generic_cb($item);
|
