You are here:  » Help replace


Help replace

Submitted by esogut on Sun, 2007-12-23 19:01 in

array(
'AF' => 'Afghanistan',
'AX' => 'Åland Islands',
'AL' => 'Albania',
'DZ' => 'Algeria',
'AS' => 'American Samoa',
'AD' => 'Andorra',
'AO' => 'Angola',
'AI' => 'Anguilla'
);

how can i make a filter to change like category or brand if its is DZ to replace that with Algeria.
pls help me...

and i search the forum because i got problem with html entities but it's all over de feed in the title,description,category,brand. like this : '214tztal Arena' , 'S246lden Hochs246lden'

Submitted by support on Fri, 2007-12-28 13:16

Hi,

To replace country codes with the country names, you can easily do this by adding "Search and Replace" filters against the category and brand fields. For example, simply register a Search and Replace filter against the category field, searching for "AI" and replace with "Anguilla". If you are looking to do this against every country and every feed then this would take a very long time, so it would be better to do it in code. This is straight forward, and you can apply the transformation in includes/admin.php within the function that imports each product record.

To do this, search for the following comment (line 185 in the distribution):

/* apply standard filters */

...and then add the following code immediately after this point:

$countryCodes = $array(
'AF' => 'Afghanistan',
'AX' => 'Åland Islands',
'AL' => 'Albania',
'DZ' => 'Algeria',
'AS' => 'American Samoa',
'AD' => 'Andorra',
'AO' => 'Angola',
'AI' => 'Anguilla'
);
foreach($countryCodes as $code => $country)
{
  // replace in brand:
  $record[$admin_importFeed["field_brand"]] = str_replace($code,$country,$record[$admin_importFeed["field_brand"]]);
  // replace in category:
  $record[$admin_importFeed["field_category"]] = str_replace($code,$country,$record[$admin_importFeed["field_category"]]);
}

That should do the trick!

With regards to HTML entities; the reason that these are not displayed correctly is because the & and ; characters are normally stripped because they can cause problems throughout the site. This is particularly true with product names, which are used to generate search engine friendly URLs.

However, you can easily modify the import routine to allow these characters in. Within the same section of code as the above modification is applied, look for the calls to the tapestry_normalise() function for each of the fields. For example, the description is "normalised" (made safe) by the following code (line 165 in the distribution):

$record[$admin_importFeed["field_description"]] = tapestry_normalise($record[$admin_importFeed["field_description"]],",'\'\.%!");

The list of characters in the second parameter is a list of allowed characters in addition to the usually permitted characters. Therefore, to allow HTML entities, add the & and ; character to this list; like this:

$record[$admin_importFeed["field_description"]] = tapestry_normalise($record[$admin_importFeed["field_description"]],",'\'\.%!&;");

Hope this helps!
Cheers,
David.

Submitted by wesse249 on Mon, 2015-10-12 18:29

Hello David,

How does above option works with 15/01A

Greetings Jan roel

Submitted by support on Tue, 2015-10-13 08:11

Hello Jan,

To do the same thing in 15/01A, look for the following comment at line 245:

  /* apply user filters */

...and insert the code immediately before this point, using the $importRecord array instead of $record e.g.

$countryCodes = $array(
'AF' => 'Afghanistan',
'AX' => 'Åland Islands',
'AL' => 'Albania',
'DZ' => 'Algeria',
'AS' => 'American Samoa',
'AD' => 'Andorra',
'AO' => 'Angola',
'AI' => 'Anguilla'
);
foreach($countryCodes as $code => $country)
{
  // replace in brand:
  $importRecord["brand"] = str_replace($code,$country,$importRecord["brand"]);
  // replace in category:
  $importRecord["category"] = str_replace($code,$country,$importRecord["category"]);
}

The calls to tapestry_normalise() for category and brand if you needed to allow additional characters can be found at lines 199 and 225 respectively.

Cheers,
David.
--
PriceTapestry.com