You are here:  » Adding Inch cymbal?


Adding Inch cymbal?

Submitted by paul30 on Sat, 2009-02-21 05:10 in

Hello David, I searched the forum, but still could not get a clear answer, so here we go:

I am dealing with musical instruments, so there are quite a few Inch cymbals in product names (all of which are stripped, and I understand why [we dont want to mess the URLs])

The problem is that some product names just do not look good without the " sign. Drums and Cymbals for instance.

So I was wondering perhaps there is a SAFE and easy way to add the ability for product names to have the " sign and to strip them from URLs via htaccess? or with php?

I am looking to have product names like:

Meinl Byzance Dark Crash Cymbal 14"
Meinl Byzance Dark Crash Cymbal 15"
Meinl Byzance Dark Crash Cymbal 16"
Meinl Byzance Dark Crash Cymbal 17"

etc...

Thanks a lot in advance!
Paul

Submitted by support on Sat, 2009-02-21 09:11

Hello Paul,

The first thing to do is simply to permit the quote sign during import. To do this, look for the following code on line 159 of includes/admin.php:

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

...and REPLACE this with:

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

Next, you also need to permit the character at the top of products.php - look for the following code on line 4:

  $q = (isset($_GET["q"])?tapestry_normalise($_GET["q"],":\."):"");

...and REPLACE that with

  $q = (isset($_GET["q"])?tapestry_normalise($_GET["q"],":\.\""):"");

That should be all you need to do, but having done this check all your links and pages to make sure everything works properly, and if not - the best thing to do is if you could email me a link to your site I'll take a look out and work out exactly what else needs to be done...

Cheers,
David.

Submitted by Keeop on Sat, 2009-02-21 16:37

Hi Paul,

What I have done to address these type of issues is to create another field in the database to act as an alias for the 'Name' field. Then as part of the import routine, you can run the normal processing and normalising on the 'Name' field but import the 'Name Alias' field as-is. You can then just do a search and replace through your tapestry .php files and replace anywhere the 'Name' field is displayed with the new 'Name Alias' field.

This way, the urls stay the same, and therefore are guaranteed to work, but the displayed product name can have any characters you like in it which is essential for any products that rely on measurements as it can be misleading selling 12 Kg of something when it is really 1.2Kg! In fact, I was asked to remove one merchant's products from one of my sites for this very reason.

You can also do the same for Brands and Categories if required and this sort of 'aliasing' is used by Wordpress, Joomla etc. in order to have meaningful article titles but correctly formatted urls.

Cheers.
Keeop

Submitted by support on Sat, 2009-02-21 16:39

Thanks Keeop,

Just to add - instructions for adding new fields are in..

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

Cheers,
David.

Submitted by daem0n on Sun, 2009-02-22 05:48

Hi guys,

Is there any more detail to the name alias method? I've created new fields in my database but obviously I can't replace all "name" fields with my new "name alias" field otherwise the URL will be changed also. Which ones do I NOT want to change? And do I have to ADD any new code for this to work?

I'm going to keep working on it in the meantime before this is posted so who knows...I'll report back when/if I figure it out.

Thanks, -Joe

Submitted by paul30 on Sun, 2009-02-22 06:09

David and Keeop, thank you very much for your replies.

The method above does work, but does break urls, and Keeops idea sounds like a perfect match that can take care of all non alphanumeric characters in names problem.

I like it a lot, but wouldn't it be easier to modify it on the URL level?

Here is what I mean:

Lets say we have a product name as : Snare Drum 5.5" x 14" - currently that will be cleaned up to "Snare Drum 55 x 14" in order to construct URL as: Snare-Drum-55-x-14.html

I am not following the script to the dot, but obviously the URL is constructed from the name, so wouldn't it be easer to just construct the url by stripping the "EXTRA" characters from the name, and than following the current routine?

something like:

function cl_name($str) {
$str = str_replace(".","",$str);
$str = str_replace("\"","",$str);
return $str;
}
$row['name'] = 'Snare Drum 5.5" x 14"';
print cl_name($row['name']); // returns: Snare Drum 55 x 14

Please advice if that method is easier to incorporate than the one Keeop mentioned...

Again, thanks a lot in advance!
Paul

Submitted by Harry on Sun, 2009-02-22 15:19

OK, to realize Keeop´s solution a step by step description would be very helpful for most people here.

1) Step one is to add a database field to the products table called 'Name Alias'.

Who can point out the next steps? What are the changes in includes/admin.php ?

Submitted by support on Sun, 2009-02-22 20:13

Hi everyone,

Bear with me on this, I'll work it through on my test server (tomorrow morning I think now) then post a step-by-step guide...

Cheers,
David.

Submitted by Keeop on Sun, 2009-02-22 22:59

Hi Paul,

I'm trying to work out why I used the database method rather than just processing the url, but I can't really remember! Anyway, all I can think of is related to the extra processing/peformance.

I have added a lot of extra processing to remove any stray html entities and characters from the 'Name' field as certain feeds were a bit problematic with strange or illegal characters. So, I figured it would be better to do all this at import rather than in real-time when people are on the site.

To be honest, I don't know if there's really be much in it but most of the mods I am making I'm trying to incorporate at import so I don't need to manipulate the database too much at run time.

It will be interesting to see what David comes up with as I'm sure this will be the best way of doing it!

Cheers.
Keeop

Submitted by daem0n on Mon, 2009-02-23 05:16

Thanks Keeop and David, I gave-up and am looking forward to your replies :)

Submitted by support on Mon, 2009-02-23 11:05

Hi everyone,

OK, this is actually more straight forward than adding a whole new field with the corresponding registration forms etc., as it will use the same field registered for the product name. So first step is to add a new field "name_display" to the products table. The SQL to achieve this is:

ALTER TABLE `products` ADD `name_display` VARCHAR( 255 ) NOT NULL;

If you are using a MySQL admin tool such as phpMyAdmin, you can enter this directly from the SQL tab - although don't forget to adjust the table name if you are using a prefix. Alternatively, the following script, run in the main Price Tapestry directory will do the job:

dbmod.php

<?php
  set_time_limit
(0);
  require(
"includes/common.php");
  
$sql "ALTER TABLE `".$config_databaseTablePrefix."products` ADD `name_display` VARCHAR( 255 ) NOT NULL;";
  
database_queryModify($sql,$result);
  print 
"Done.";
?>

With that in place, the main bulk of the modification is to the admin__importRecordHandler() function in includes/admin.php. Now, because normalisation / filters etc. work on the actual value in the record, we need to make a copy of the un-modified product name field very early on. To do this, find the following comment at around line 158:

    /* apply standard filters */

...and ADD the following line immediately ABOVE the comment:

    $name_display = $record[$admin_importFeed["field_name"]];

And then to insert $name_display into the database, first look for the following code around line 263 (within the SQL construction):

        name='%s',

...and REPLACE this with:

        name='%s',
        name_display='%s',

...and for the corresponding value, look for the following code on line 274:

        database_safe($record[$admin_importFeed["field_name"]]),

...and REPLACE this with:

        database_safe($record[$admin_importFeed["field_name"]]),
        database_safe($name_display),

Now all that's left is to replace wherever "name" is used with "name_display" within the HTML files. This is best done simply using Search & Replace in your text editor, searching for "name" and replacing with "name_display" as follows:

html/searchresults.php (3 instances)
html/featured.php (2 instances)
html/product.php (2 instances)

...and that should make a good start...!

Cheers,
David.

Submitted by Harry on Mon, 2009-02-23 11:24

I want to do one suggestion.
There should be now a little minimum normalisation on the name_display field which strips out all html tags like <b> from the product name.

Submitted by support on Mon, 2009-02-23 11:27

Hi Harry,

That's straight forward - instead of:

    $name_display = $record[$admin_importFeed["field_name"]];

...use:

    $name_display = strip_tags($record[$admin_importFeed["field_name"]]);

Cheers,
David.

Submitted by Keeop on Mon, 2009-02-23 12:33

Hi David,

Phew! That's pretty much what I've done so thanks for jotting down those instructions. If anyone wants a more complete tidy-up on their 'Display Name', here's the code I'm using:

 $someCharacters = array("\"", "'", ",", "\\");
 $search = array ("&rsquo;","&lsquo", "&apos;");
 $replaceSav = array ("'", "'", "'");
 $name_display = str_replace($someCharacters, "",$record[$admin_importFeed["field_name"]]);
 $name_display = str_replace("&amp;", "&", $name_display);
 $name_display = str_replace($search, $replaceSav, $name_display);
 $name_display = strip_tags($name_display);
 $name_display = html_entity_decode($name_display);

This lot seems to tidy things up quite well. If it looks a bit messy I've copied some lines in from included functions just to put it all in once place for you to see.

Cheers.
Keeop

Submitted by support on Mon, 2009-02-23 12:35

Thanks, Keeop.

I edited your code to use the same variable name as the instructions above ($name_display) so people can use this without modification...

Cheers,
David.

Submitted by Harry on Mon, 2009-02-23 13:46

Maybe I´m to stupid to understand, but why do you want to use something like
$name_display = str_replace("&amp;", "&", $name_display); ?

As I understand it replaces all &amp; with &, but
don´t we wish to have the &amp in the display name on our html page?

Regards,
Harry

Submitted by Keeop on Mon, 2009-02-23 15:56

Hi Harry,

You're quite correct with what the code does but replacing the html tag with '&' seems to help when following up with the 'strip_tags' and 'html_entity_decode' calls. I personally don't want any rubbish html entities or tags in my display name which could affect formatting and also searching - I have changed the indexing and search to search through the 'Display_Name' rather than 'Name' so I don't want any html codes in there.

I only posted the code as I have found it strips out all the stuff I don't want and others may want the same results. Up to you what you want to allow through!

Cheers.
Keeop.

Submitted by support on Mon, 2009-02-23 19:13

Hi everyone,

If you want user filters to apply to the display name as well as the URL safe version, it is necessary to move the code around slightly.

All that's required is to take the following 2 lines:

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

...and move them (in the same order) below the "Apply User Filters" section, in other words, immediately BEFORE the following comment:

    /* apply extras */

Cheers,
David.

Submitted by daem0n on Tue, 2009-02-24 05:57

Thanks a lot guys, works great! :)

-Joe

Submitted by daem0n on Fri, 2009-04-10 06:27

Just a new update on this modification. Everything has been working out really well so far.

I did notice two products today that are not showing-up or being found. I noticed that they have the "TM" symbol in their titles/names. The TM symbol is replaced with the hex/ascii box that shows-up when characters aren't processed properly. I searched the database for the products in question and noticed that the name, searchname, and alias fields all have included the "TM" in them.

I managed to fix how it is displayed but I can't fix the URL (or search?) part of it. I edited the admin.php file (in /includes/):
$someCharacters = array(",", "\\");
$search = array ("’","&lsquo", "'");
$replaceSav = array ("'", "'", "'");
$nmalias = str_replace($someCharacters, "",$record[$admin_importFeed["field_name"]]);
$nmalias = str_replace("&", "&", $nmalias);
$nmalias = str_replace("™", "(TM)", $nmalias);

Do you guys have any suggestions on how to fix these products (or any others that show-up in the future like this)?

Submitted by support on Fri, 2009-04-10 09:44

Hi Joe,

Could you email me a link to a page showing the problem, and also your includes/filter.php and i'll modify search.php to support hex character substitution...

Cheers,
David.

Submitted by babrees on Tue, 2009-04-14 06:03

 $someCharacters = array("\"", "'", ",", "\\");
 $search = array ("&rsquo;","&lsquo", "&apos;");
 $replaceSav = array ("'", "'", "'");
 $name_display = str_replace($someCharacters, "",$record[$admin_importFeed["field_name"]]);
 $name_display = str_replace("&amp;", "&", $name_display);
 $name_display = str_replace($search, $replaceSav, $name_display);
 $name_display = strip_tags($name_display);
 $name_display = html_entity_decode($name_display);

Could you please tell us exactly where we put this?

---------
Jill

Submitted by support on Tue, 2009-04-14 08:43

Hi Jill,

The above would need to go within the admin__importRecordHandler() in includes/admin.php, just before the SQL to insert a product (look for the comment /* create product record */).

Cheers,
David.

Submitted by stevewales20 on Sat, 2011-02-26 12:39

Hmmm looking to implement this into the newest release version. Have the variable names been changed?

Submitted by stevewales20 on Sat, 2011-02-26 14:07

For anyone interested in doing this on the latest distribution 12/10A:

Underneath:

/* create product record */
    $importRecordSQL = "";

Add:

/* Allow certain characters in name */
      $someCharacters = array("\"", "'", ",", "\\");
  $search = array ("&rsquo;","&lsquo", "&apos;");
  $replaceSav = array ("'", "'", "'");
  $name_display = str_replace($someCharacters, "",$importRecord["name"]);
  $name_display = str_replace("&amp;", "&", $name_display);
  $name_display = str_replace($search, $replaceSav, $name_display);
  $name_display = strip_tags($name_display);
  $name_display = html_entity_decode($name_display);

Basically the $record[$admin_importFeed["field_name"]] is now become $importRecord["name"]

Thanks to everyone that's had input into this. I believe it's working a treat :)
Cheers
Steve