You are here:  » Text after product name filter

Support Forum



Text after product name filter

Submitted by jonny5 on Mon, 2008-10-27 15:37 in

Hi David,

I want to add some extra text after the product name but only if it is in a certain category.

is this possible?

Submitted by support on Mon, 2008-10-27 16:07

Hi Jonny,

If you want to do this globally it would be easier done in the import record handler that as a filter. For example, in includes/admin.php, where you currently have this code starting at line 158:

    /* apply standard filters */
    $record[$admin_importFeed["field_name"]] = tapestry_normalise($record[$admin_importFeed["field_name"]]);

...if you replace this with:

    /* apply standard filters */
    $record[$admin_importFeed["field_name"]] = tapestry_normalise($record[$admin_importFeed["field_name"]]);
    if ($record[$admin_importFeed["field_category"]]=="Special Category")
    {
      $record[$admin_importFeed["field_name"]] .= " Extra Text Here";
    }

(just change "Special Category" to the category that you want the extra text appended for)

Cheers,
David.

Submitted by jonny5 on Tue, 2008-10-28 15:01

i only really need to do this on certain feeds so was hoping to do this as a filter , as it would be certain ratailers and i might not know the category until i have seen the feed, does that make sense?

Submitted by support on Tue, 2008-10-28 17:46

Hi Jonny,

Sure - have a go with this new filter - "Category Append". Add the code below to includes/filter.php. Then add a new "Category Append" filter to the Product Name, enter the category value to check for and the text to append if it matches!

  $filter_names["catAppend"] = "Category Append";
  function filter_catAppendConfigure($filter_data)
  {
    print "If category is:<br />";
    print "<input type='text' name='cat' value='".widget_safe($filter_data["cat"])."' />";
    widget_errorGet("cat");
    print "<br /><br />";
    print "append this text:<br />";
    print "<input type='text' name='append' value='".widget_safe($filter_data["append"])."' />";
    widget_errorGet("append");
  }
  function filter_catAppendValidate($filter_data)
  {
    if (!$filter_data["cat"])
    {
      widget_errorSet("cat","required field");
    }
    if (!$filter_data["append"])
    {
      widget_errorSet("append","required field");
    }
  }
  function filter_catAppendExec($filter_data,$text)
  {
    global $filter_record;
    global $admin_importFeed;
    if ($filter_record[$admin_importFeed["field_category"]]==$filter_data["cat"])
    {
      $text .= $filter_data["append"];
    }
    return $text;
  }

Cheers,
David.

Submitted by jonny5 on Wed, 2008-10-29 20:40

thats great ,

i have some feeds and they have say 8 categories with toys in , eg outdoor toys, boys toys

is it possible to just add one filter that picks up any with Toys in?

can i just add *toys

Submitted by support on Thu, 2008-10-30 09:59

Hi Jonny,

Have a go with this version which will enable you to specify the category to match as a regular expression (case insensitive), meaning you can do all sorts of things. Firstly, to specify a list of categories, use:

(category 1|category 2|category 3)

...or for a wildcard as in your post;

.*toys.*

(. means any character, and the * means zero or more times)

  $filter_names["catAppend"] = "Category Append";
  function filter_catAppendConfigure($filter_data)
  {
    print "If category is:<br />";
    print "<input type='text' name='cat' value='".widget_safe($filter_data["cat"])."' />";
    widget_errorGet("cat");
    print "<br /><br />";
    print "append this text:<br />";
    print "<input type='text' name='append' value='".widget_safe($filter_data["append"])."' />";
    widget_errorGet("append");
  }
  function filter_catAppendValidate($filter_data)
  {
    if (!$filter_data["cat"])
    {
      widget_errorSet("cat","required field");
    }
    if (!$filter_data["append"])
    {
      widget_errorSet("append","required field");
    }
  }
  function filter_catAppendExec($filter_data,$text)
  {
    global $filter_record;
    global $admin_importFeed;
    if (eregi($filter_data["cat"],$filter_record[$admin_importFeed["field_category"]]))
    {
      $text .= $filter_data["append"];
    }
    return $text;
  }

Cheers,
David.

Submitted by jonny5 on Thu, 2008-10-30 10:26

I just get the below when i click filter

Parse error: syntax error, unexpected '{' in /home/sites/site.co.uk/public_html/includes/filter.php on line 285

????

Submitted by support on Thu, 2008-10-30 10:53

Hi Jonny,

There was a missing ) on the end of the eregi line - i've corrected this in the above post.

Cheers,
David.

Submitted by jonny5 on Fri, 2008-10-31 11:37

Hi David , its working (sort of )

i re import the feed and the text is added to the end of the product name , so if I then goto all categories and pick the category , it displays the products with the added text at the end (search.php) , if I then click a product to display the product page the link just refreshes and searches for that product and displays the search page again.

does that make sense?

Submitted by support on Fri, 2008-10-31 13:20

Hello Jonny,

It is possible that the text you have added is breaking the URL (i.e. not URL safe). Can you post an example of the text you are appending using this filter?

Cheers,
David.

Submitted by jonny5 on Fri, 2008-10-31 13:25

adding "CD" but with a space ie " CD" so that the name reads "girls aloud CD" instead of "girls aloudCD"

is it the space do you think ?

Submitted by support on Fri, 2008-10-31 13:27

That should be fine - could you post an example URL or email me a link if you don't want to post it on the forum...

Cheers,
David.