You are here:  » Setting default import methods for text

Support Forum



Setting default import methods for text

Submitted by chrisst1 on Sat, 2008-02-16 12:00 in

Hi David

Is there any way to set up PT to import using specific text case for certain fields by default without using filters?

Product heading using "ucwords" = The Big Shop
Product description using "ucfirst" = This is a sentence. This is another sentence! This is the fourth sentence? No, this is the fourth sentence.

I've had a look through the forum but could not find close match.

Chris

Submitted by support on Sat, 2008-02-16 12:53

Hi Chris,

This can be reasonably easily done by modifying the import record handler in includes/admin.php to perform the modifications to each record as they imported. For the product name, look for the following code on line 159:

$record[$admin_importFeed["field_name"]] = tapestry_normalise($record[$admin_importFeed["field_name"]]);

Replace this with the following code:

$record[$admin_importFeed["field_name"]] = ucwords(tapestry_normalise($record[$admin_importFeed["field_name"]]));

The description is slightly more complicated. The normal processing is done by the following code on line 165 of the same file:

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

To upper case the first letter of each sentence, try REPLACING the above line with the following block of code. I've done this using a regular expression rather than trying to explode the string on each different sentence terminator and then ucfirst()'ing each sentence:

      $record[$admin_importFeed["field_description"]] = tapestry_normalise($record[$admin_importFeed["field_description"]],",'\'\.%!?");
      $description = ucfirst(strtolower(trim($record[$admin_importFeed["field_description"]])));
      $description = preg_replace('/([\.!?]) (.)/e',"'\\1 '.strtoupper('\\2')",$description);
      $record[$admin_importFeed["field_description"]] = trim($description);

There is one minor change to the first line of this mod from the original line and that is to allow the ? character into the description (it is stripped by default). Remember to re-import your feeds for this change to take effect.

Cheers,
David.

Submitted by chrisst1 on Sat, 2008-02-16 15:39

Many thanks David

Great response as usual, this should save us some time and cut out having to filter each feed.

Chris

Submitted by webie on Mon, 2008-02-18 14:07

Hi Dave,

I did use this last night all looked good until this morning I checked the back end of the database with navicat and found that for the product name ie pickabook feed i found name were upper case even after using your code here is the code have i done this correct many thanks.

Darren

<?php
/* apply standard filters */
$record[$admin_importFeed["field_name"]] = ucwords(tapestry_normalise($record[$admin_importFeed["field_name"]]));
$record[$admin_importFeed["field_name"]] = trim($record[$admin_importFeed["field_name"]]);
    if ($admin_importFeed["field_description"])
    {
  $record[$admin_importFeed["field_description"]] = strip_tags($record[$admin_importFeed["field_description"]]);
  $record[$admin_importFeed["field_description"]] = tapestry_normalise($record[$admin_importFeed["field_description"]],",'\'\.%!?");
  $description = ucfirst(strtolower(trim($record[$admin_importFeed["field_description"]])));
  $description = preg_replace('/([\.!?]) (.)/e',"'\\1 '.strtoupper('\\2')",$description);
  $record[$admin_importFeed["field_description"]] = trim($description);
    }
?>

Submitted by support on Mon, 2008-02-18 14:45

Hi Darren,

I understand - this will happen where the name is already all in uppercase, as ucwords doesn't affect the case of other characters, only the first.

It's easily fixed with a strtolower() inline. Instead of:

/* apply standard filters */
$record[$admin_importFeed["field_name"]] = ucwords(tapestry_normalise($record[$admin_importFeed["field_name"]]));

...use:

/* apply standard filters */
$record[$admin_importFeed["field_name"]] = ucwords(strtolower(tapestry_normalise($record[$admin_importFeed["field_name"]])));

That should do the trick,
Cheers,
David.

Submitted by webie on Mon, 2008-02-18 15:15

Hi Dave,

Many thanks once again support is top class

all the best

Darren

Submitted by chrisst1 on Mon, 2008-02-18 15:57

Hi David

Whilst implementing the above I noticed that my admin.php code is several lines shorter than the current downloadable one, am I safe to upgrade this file or will alterations need doing elsewhere if I do?

Chris

Submitted by support on Mon, 2008-02-18 16:04

Hi Chris,

The extension is likely due to the new "Product Mapping" feature; so using the latest one without upgrading the database and /admin/* would likely cause problems.

You will be safe just making the modifications in the places described. If you do want to upgrade to benefit from the Product Mapping, you can just upgrade includes/ and admin/, and then browse to:

setup.php?installDB=1

..and that will add the new Product Mapping table.

Cheers,
David.

Submitted by chrisst1 on Mon, 2008-02-18 16:08

Thanks David

Chris

Submitted by richard on Sun, 2010-03-28 16:35

Hi David

When I import an xml feed, I assign the product name to the MPN field and then use the "text before" filter to insert the brand before the MPN.

Secondly, to get the product title to uppercase, I amended the includes/admin file as follows:

    $record[$admin_importFeed["field_name"]] = strtoupper(tapestry_normalise($record[$admin_importFeed["field_name"]]));
      $record[$admin_importFeed["field_brand"]] = strtoupper(tapestry_normalise($record[$admin_importFeed["field_brand"]]));

However, the product name does not convert to uppercase for instances where I use the "text before" filter despite converting brand and name to uppercase.

Can you please advise what I am doing wrong.

Many thanks

Richard

Submitted by support on Mon, 2010-03-29 08:32

Hi Richard,

It sounds like the code may have been added before the user filters have been applied. What I would suggest is just strtoupper()'ing the name field after the user filters, which is immediately before the following comment at line 193 in includes/admin.php

    /* apply extras */

At this point, the single line..

$record[$admin_importFeed["field_name"]] = strtoupper(tapestry_normalise($record[$admin_importFeed["field_name"]]));

...should do the trick!

Cheers,
David.

Submitted by richard on Mon, 2010-03-29 11:05

Hi Dave

Works a treat.

MANY THANKS yet again!

Regards

Richard