Greetings,
Many merchants are adding color and/or size to their product names. At the same time they will have the size and/or color in separate fields, say Option17 and Option18
Product name in the feed will be Widget Blue Large. Want to remove the color and size.
Is it possible to have a filter than can use the content of a cell to remove that variable from the product name?
Something like:
Delete from ProductName %Option17%
Leaving: Widget Large
Then we can run another filter:
Delete from ProductName %Option18%
Leaving: Widget
Or possibly a filter than can combine the two like: Delete from ProductName RegExp
(%Option17%|%Option18%)
Thoughts?
Awesome David!
Question, will it allow us to do this?
(%Option17%|word1|word2)
Or would we need to use the original filter for that (renamed of course)
That will work fine - anything not %something% won't be touched by the filter code...
Cheers,
David.
--
PriceTapestry.com
Hi DAvid,
Now I'm confused.
What I was asking is will using (%optin17%|red|blue) replace all three if they exist?
Correct!
So let's say in the particular record of a feed to which that filter was being applied, the value of the 'optin17' field was 'green', the actual regular expression that would be used by the filter would be (green|red|blue)
Cheers,
David.
--
PriceTapestry.com
Hi David,
Never could get this to work. Here is my filter:
/*************************************************/
/* searchReplaceRegExp */
/*************************************************/
$filter_names["searchReplaceRegExp"] = "Search and Replace RegExp FIELD";
function filter_searchReplaceRegExpConfigure($filter_data)
{
print "Search (Perl RegExp):<br />";
print "<input type='text' name='search' value='".widget_safe($filter_data["search"])."' />";
widget_errorGet("search");
print "<br /><br />";
print "Replace:<br />";
print "<input type='text' name='replace' value='".widget_safe($filter_data["replace"])."' />";
widget_errorGet("replace");
}
function filter_searchReplaceRegExpValidate($filter_data)
{
if (!$filter_data["search"])
{
widget_errorSet("search","required field");
}
}
function filter_searchReplaceRegExpExec($filter_data,$text)
{
return trim(preg_replace(filter_recordPlaceholders($text),($filter_data["search"]),$filter_data["replace"],$text));
}
Keep getting these errors in the logs when we do a slow import from within admin:
PHP Warning: preg_replace() [<a href='function.preg-replace'>function.preg-replace</a>]: Delimiter must not be alphanumeric or backslash in /home/username/public_html/path/to/includes/filter.php on line 518
PHP Warning: preg_replace() [<a href='function.preg-replace'>function.preg-replace</a>]: Unknown modifier '1' in /home/username/public_html/path/to/includes/filter.php on line 518
The last error code changes by letter over and over during the slow import:
PHP Warning: preg_replace() [<a href='function.preg-replace'>function.preg-replace</a>]: Unknown modifier 'T' in /home/username/public_html/path/to/includes/filter.php on line 518
PHP Warning: preg_replace() [<a href='function.preg-replace'>function.preg-replace</a>]: Unknown modifier 'R' in /home/username/public_html/path/to/includes/filter.php on line 518
PHP Warning: preg_replace() [<a href='function.preg-replace'>function.preg-replace</a>]: Unknown modifier 'Z' in /home/username/public_html/path/to/includes/filter.php on line 518
Line 518 is the line you had me replace above.
return trim(preg_replace(filter_recordPlaceholders($text),($filter_data["search"]),$filter_data["replace"],$text));
Your thoughts?
Hi Convergence,
My apologies, the modification to the filter was incorrect, last line should just be:
return trim(preg_replace(filter_recordPlaceholders($filter_data["search"]),$filter_data["replace"],$text));
Cheers,
David.
--
PriceTapestry.com
Hi!
Sure - there's a Search and Replace RegExp filter in this comment, and if you replace the second to last line of the new filter code as follows:
return trim(preg_replace(filter_recordPlaceholders($text),($filter_data["search"]),$filter_data["replace"],$text));
...then the regular expression will first be processed by the same code that let's you use %FIELD% in the Text Before / Text After filters, so you can then use exactly as you suggest e.g.
(%Option17%|%Option18%)
Cheers,
David.
--
PriceTapestry.com