You are here:  » Detailed Instructions for Filters


Detailed Instructions for Filters

Submitted by bwhelan1 on Fri, 2006-06-23 17:18 in

With Commission Junction feeds, fields in the "ADVERTISERCATEGORY" column commonly come with categories and subcategories separated by a slash or comma. What is the best way to handle this using the filters?

I also noticed that spaces and underscores are stripped off from the categories and the only way I found to get the space between words in the category is to use a hyphen. I haven't tried it yet but should the find & replace filter be used for this or is there another way?

I browsed your site but could not find any detailed instructions for the filter option.

Submitted by support on Sat, 2006-06-24 09:37

Hi,

Better filter documentation is something i've been meaning to add for a while, so i've worked on that this morning. The new page is here: http://www.pricetapestry.com/node/321

With regards to certain characters being removed; this is part of what I call "Normalisation" and is done to make sure that anything that is imported is not going to break the functionality of the site.

If you want to remove the normalisation of the category field, you can comment out line 170 of includes/admin.php, which contains the following code:

$record[$admin_importFeed["field_category"]] = tapestry_normalise($record[$admin_importFeed["field_category"]]);

...however this is not recommended as there may be unpredictable side effects that arrise if you are not controlling which characters are permitted within the category field. The tapestry_normalise() function is in includes/tapestry.php.

If the Commission Junction feeds that you are working with contain a complex category field that is not just a simple category name then I don't think the basic filters will be sufficient to extract the information you require.

It is quite straight forward however to write custom filters than can process specific anomolies that you have to deal with. For a related case, I provided code for a "Split" filter that would return the contents of a field up to the first match of the entered text, which in the case of the CJ category field could be the first comma. The code is show below; which you would need to paste into includes/filter.php

<?php
  
/*************************************************/
  /* splitBefore                                   */
  /*************************************************/
  
$filter_names["splitBefore"] = "Split Before";
  function 
filter_splitBeforeConfigure($filter_data)
  {
    print 
"Split Character or String:<br />";
    print 
"<input type='text' size='40' name='text' value='".widget_safe($filter_data["text"])."' />";
    
widget_errorGet("text");
  }
  function 
filter_splitBeforeValidate($filter_data)
  {
    if (!
$filter_data["text"])
    {
      
widget_errorSet("text","required field");
    }
  }
  function 
filter_splitBeforeExec($filter_data,$text)
  {
    return 
trim(substr($text,strpos($text,$filter_data["text"])));
  }
?>

After adding this code you will have the new option to select "Text Before" in filter select box. If you then select the Category field from your Commission Junction feed, and enter "," (without the quotes) this should return the first top level category for that product.

Hope this helps!
David.

Submitted by bwhelan1 on Wed, 2006-06-28 01:16

David,

Thanks for taking the time on this. I was wrong about the comma, the character was actually a forward slash. I tried the filtuer using a"/" instead of a "," and it didn't work. Any suggestions? Below is an example.

Taking data in the category field that looks like this:
Lighting/Wall Lanterns/Sea Gull Lighting

And filtering it to look like this:
Lignting

Thanks,
Bill

Submitted by support on Wed, 2006-06-28 08:38

My appologies, Bill - that code is incorrect for SplitBefore - it will return everything after the character rather than before it. The code should be as follows:

  /*************************************************/
  /* splitBefore */
  /*************************************************/
  $filter_names["splitBefore"] = "Split Before";
  function filter_splitBeforeConfigure($filter_data)
  {
    print "Split Character or String:<br />";
    print "<input type='text' size='40' name='text' value='".widget_safe($filter_data["text"])."' />";
    widget_errorGet("text");
  }
  function filter_splitBeforeValidate($filter_data)
  {
    if (!$filter_data["text"])
    {
      widget_errorSet("text","required field");
    }
  }
  function filter_splitBeforeExec($filter_data,$text)
  {
    $pos = strpos($text,$filter_data["text"]);
    if ($pos !== false)
    {
      return trim(substr($text,0,strpos($text,$filter_data["text"])));
    }
    else
    {
      return $text;
    }
  }

Cheers,
David.