You are here:  » Filter: set if empty


Filter: set if empty

Submitted by sirmanu on Tue, 2018-04-10 09:52 in

Hi David.
I have a feed with columns EAN and UPC.
Usually (95% of the feed), the EAN is correctly filled.
HOwever, sometimes is empty and the UPC appears.
Is any filter where I can take UPC only when EAN is empty and UPC is not?

Thanks!

Submitted by support on Tue, 2018-04-10 10:06

Hi,

As per filtering for the brand twice in product name this could be solved by also adding a Search and Replace RegExp with %fieldname% placeholder support. To add the new filter, add the following code to includes/filter.php:

  /*************************************************/
  /* searchReplaceRegExpPlaceholder */
  /*************************************************/
  $filter_names["searchReplaceRegExp"] = "Search and Replace (RegExp/Placeholder)";
  function filter_searchReplaceRegExpPlaceholderConfigure($filter_data)
  {
    widget_textBox("Search","search",TRUE,$filter_data["search"],"",3);
    widget_textBox("Replace","replace",FALSE,$filter_data["replace"],"",3);
  }
  function filter_searchReplaceRegExpPlaceholderValidate($filter_data)
  {
    if (!$filter_data["search"])
    {
      widget_errorSet("search","required field");
    }
  }
  function filter_searchReplaceRegExpPlaceholderExec($filter_data,$text)
  {
    $filter_data["search"] = filter_recordPlaceholders($filter_data["search"]);
    $filter_data["replace"] = filter_recordPlaceholders($filter_data["replace"]);
    return trim(preg_replace($filter_data["search"],$filter_data["replace"],$text));
  }

With that in place, add a new Search and Replace (RegExp/Placeholder) filter to the EAN field and for Search use:

/^$/

(In a regular expression ^ is the beginning of line anchor and $ is the end of line anchor - forward slashes used as delimiters in this case - so this will only match if the EAN field is empty)

...and for Replace use:

%upc%

...where upc is the actual field name of the field containing the UPC in the feed...

Hope this helps!

Cheers,
David.
--
PriceTapestry.com

Submitted by sirmanu on Tue, 2018-04-10 14:46

Great David, both filters worked as expected.
However, I had to use /^$/ to avoid warning for PHP.

Submitted by support on Tue, 2018-04-10 14:59

Ah yes, should have included the delimiters sorry - corrected and clarified above...

Cheers,
David.
--
PriceTapestry.com