You are here:  » Problem with Text After Filter when using %FIELD%


Problem with Text After Filter when using %FIELD%

Submitted by Convergence on Tue, 2013-04-16 19:49 in

Greetings,

Discovered today that when using the 'Text After' filter to add text from a field, and if that field is blank, that the field name is inserted in it's place.

Any way for the filter to ignore empty fields?

(Have not noticed this on 'Text Before' but am guessing the same thing would occur.

Thanks!

Submitted by support on Wed, 2013-04-17 07:48

Hi,

Ah - this would happen if a field specified in %FIELD% doesn't exist in the record, but is easily fixed with a preg_replace() to "mop up" any untranslated placeholders.

To do this, edit includes/filter.php and look for the following code at line 13:

    return $text;

...and REPLACE with:

    return preg_replace('/%(.*)%/U','',$text);

Cheers,
David.
--
PriceTapestry.com

Submitted by Convergence on Sat, 2013-07-27 20:59

Hi David,

Ah the joys of modding mods :)

Had a few installs where this had not been implemented. However, discovered there is a conflict between this mod and the following:

http://www.pricetapestry.com/node/4819

It's removing %DATETIME% from the "Buy URLs".

Suggestions?

Thanks!

Submitted by support on Sun, 2013-07-28 09:31

Hi Convergence,

Ah yes - tidiest solution would be to use a different delimiter for the DATETIME placeholder; so if in your Text After filter instead of

%DATETIME%

...use:

{DATETIME}

And then in the mod to jump.php, in place of:

  $product = $rows[0];
  $product["buy_url"] = str_replace("%DATETIME%",date("jMY-His"),$product["buy_url"]);

...use:

  $product = $rows[0];
  $product["buy_url"] = str_replace("{DATETIME}",date("jMY-His"),$product["buy_url"]);

Cheers,
David.
--
PriceTapestry.com

Submitted by Convergence on Sun, 2013-07-28 22:33

Wonderful!

Is there a way to change all occurrences in our "pt_filters" table via phpMyAdmin running a query? We would like to change %DATETIME% to {DATETIME}. Otherwise we are going to need to manually change around a 1000 manually over multiple installs.

Thanks, again!

Submitted by support on Mon, 2013-07-29 08:20

Hi Convergence,

Make sure you have a backup first!!!

Query would be:

UPDATE `pt_filters` SET data = REPLACE(data,'%DATETIME%','{DATETIME}')

Cheers,
David.
--
PriceTapestry.com

Submitted by sirmanu on Mon, 2017-06-19 23:40

Hi David.
One question about placeholders.
I have one filter (name case) for brand (SAMSUNG => Samsung)
Then, the brand is "text before" product name.
However, the brand is not "name case" and remain with capital letters into the product name.
How can I fix that? What I am doing wrong?
Regards!

Submitted by support on Tue, 2017-06-20 09:43

Hi,

Filters operate on the values being prepared for import ($importRecord) rather than the raw feed record, so what you could do is modify the filter_recordPlaceholders() function to support using {field} to refer to the values in $importRecord and that way, you'll be able to Text Before / After with the values affected by previous filters.

To do this, first edit includes/admin.php and look for the following code at line 148:

    global $filter_record;

...and REPLACE with:

    global $filter_record;
    global $importRecord;

And then edit includes/filter.php and look for the following code at line 13:

    return $text;

...and REPLACE with:

    global $importRecord;
    if (strpos($text,"{")!==FALSE)
    {
      foreach($importRecord as $k => $v)
      {
        $text = str_replace("{".$k."}",$v,$text);
      }
    }
    return $text;

You'll then be able to use %FIELD% to refer to the parsed record, or {field} to refer to the database fields as already affected by previous filters...

Cheers,
David.
--
PriceTapestry.com