You are here:  » Remove sizes from name (Regex?)


Remove sizes from name (Regex?)

Submitted by sirmanu on Thu, 2017-10-19 10:11 in

Hi David.
As I post several months ago, I am using a mod for import duplicates name. The main reason is that I have a custom field with colour and size, and my dupe_hash is appending the SKU for unique products for each merchant.
However, some merchants have unique names for each variation. Example

- Reebok Ahary Runner, black, 37.5 EU
- Reebok Ahary Runner, black, 38 EU
- Reebok Ahary Runner, black, 39 EU
- Reebok Ahary Runner, white, 37.5 EU

So rather than group together from low to high (as Amazon, for example), it keeps a unique URL for each product. That is not good for SEO, and also, from my point of view, impractical.

I am looking for a filter (maybe is already posted), for removing at least sizes with placeholders from the name. Maybe later, I will think about removing colour.

I know I can do it with search and replace (%size%). However, the problem is that sometimes is:
- Reebok Ahary Runner, black, size 37.5 EU (field_size = 37.5 EU)
- Reebok Ahary Runner, black, 37.5 EU (field_size = 37.5 EU)
- Reebok Ahary Runner, black, 26 EU (8.5 UK) (field_size = 26 EU) (without 8.5 UK!)

How can I have a filter that removes the sizes only when some of the previous conditions are met? The final name should be: "Reebok Ahary Runner, black" only if field size is in the name.

Thanks!

Submitted by support on Thu, 2017-10-19 11:40

Hi,

There is a Search and Replace RegExp filter in this comment that should do the trick. You can specify multiple values to match using pipe separation, and for each value be sure to use word boundary markers (\b) and decimal point must be escaped with \ as it matches any character by default. For example, by specifying a list of values;

/(\b37\.5 EU\b|\b38 EU\b|\b38\.5 EU\b|\b39 EU\b)/

But where the format is predictable, you could also have a go with matching EU - again with word boundaries e.g.

/\b.* EU\b/

In both cases, leave the REPLACE box empty and that should do the trick...

Cheers,
David.
--
PriceTapestry.com

Submitted by sirmanu on Thu, 2017-10-19 17:02

Sorry, maybe I didn't explain well.
I don't know the size, the size is a field in the CSV. That is why I asked about placeholders!
Maybe I have to modify the previous filter to accept placeholders?

Submitted by support on Fri, 2017-10-20 08:27

Ah, in that case, what about modifying the Search and Replace filter to pass the search expression through the filter_recordPlaceholders() function...

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

    return trim(str_replace($filter_data["search"],$filter_data["replace"],$text));

...and REPLACE with:

    $filter_data["search"] = filter_recordPlaceholders($filter_data["search"]);
    return trim(str_replace($filter_data["search"],$filter_data["replace"],$text));

You'll then be able to add a Search and Replace filter to the Product Name field, and in the Search box, use %SIZE% where "SIZE" is the exact field name (Case Sensitive) in the feed that you will have mapped to the `size` field during Feed Registration Step 2.

However, that might require individual filters per feed (unless the size field happens to be called "size" in every feed!) in which case, it's no problem to modify the filter_recordPlaceholders function to support feed or database fields.

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 back in 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 either %fieldname% for a feed field (as parsed), or {field} for a database field e.g. {field}

Hope this helps!

Cheers,
David.
--
PriceTapestry.com