You are here:  » Additonal custom categories in


Additonal custom categories in

Submitted by idea12 on Wed, 2012-10-03 13:43 in

Hi David,

I have a website with the topic: "Footware" (for example) and would like to have many categories, which can be filtered like this:

Choose Color:

red
blue
green

Choose Size:

36
38
40
..

Choose style:

modern
old-fashion
..

If somebody is looking for modern green shoes of the size 38, he should simply choose the values and submit the search button to obtain the results.

My problem is: "Color" and "Size" are already delivered with the feed, but some attributes like "Style" are not delivered and I would like to define the values of these by myself. It should work in that way, that during the mapping of a product I have a box with the name "Custom style" and can write my content in the box (for example "modern"). So in addition to the boxes "Custom Category" and "Custom Brands" at the product mapping site I would like to have my custom boxes on which I can apply the search filter. It is possible to do that and if yes: How?

Thank you!

Submitted by support on Wed, 2012-10-03 14:28

Hi,

The main instructions for adding custom fields can be found here - however before going ahead but after reading the main instructions; see this comment in the thread which describes creating a custom field that works like category or brand on Feed Registration Step 2, whereby you can either register a field or enter a fixed value.

With that in place; the next step is to create custom override fields as part of Product Mapping; and that is described here. It is quite a few changes per field - but you'll very quickly find the sections that need duplicating for each field you wish to add and then it's just a case of copy / paste following by changing the field name. When studying this last mod, ignore the underscore in the custom field names so that particular example "meta_keywords" is a custom field just as you would add "style".

Finally, the majority of the user-interface side of things is covered by the SidebarFilters.zip modification. This modification contains replacement search.php and html/searchresults.php with drop-down search refinement filters displayed on the search results page. Again, it is a case of copying each instance of code relating to a particular filter, and pasting in with your custom field name, so in both files, it would be a case of locate each block of code containing:

categoryFilter

copy, paste, and replace each instance of "category" with "style". Again there's quite a few sections; but you'll very quickly learn where each one is when it comes to adding additional filters, and if you're not sure of course email me your existing versions and I'll make the changes for you.

The final stage is to create your "advanced" search form. With the sidebar filters version of search.php, drop-down boxes to add filters before searching can be added. For example, to add a style filter, edit html/searchform.php and look for the following code at line 4:

  <input type='submit' value='<?php print translate("Search"); ?>' />

...and REPLACE with:

  <?php
  if (!isset($where)) $where = "1";
  $sql1 = "SELECT DISTINCT(style) FROM `".$config_databaseTablePrefix."products` WHERE ".$where." AND style <> ''";
  if (database_querySelect($sql1,$rows1))
  {
    print "<label form='cf'>Choose style:</label><br />";
    print "<select style='width:150px;' name='styleFilter'>";
    print "<option value=''>All</option>";
    foreach($rows1 as $row)
    {
      $selected = ($_GET["styleFilter"]==$row["style"]?"selected='selected'":"");
      print "<option value='".htmlentities($row["style"],ENT_QUOTES,$config_charset)."' ".$selected.">".$row["style"]."</option>";
    }
    print "</select>&nbsp;";
  }
  ?>
  <input type='submit' value='<?php print translate("Search"); ?>' />

Coded in that way; drop-downs on the "advanced search" form would logically take the place of the sidebar version of the filters; which if you're happy with the way that works use only the search.php from the SidebarFilters.zip.

Hope this helps! I appreciate that's a lot to take in; any questions just let me know...

Cheers,
David.
--
PriceTapestry.com

Submitted by idea12 on Wed, 2012-10-03 17:40

Hi David,

Thank you for the detailed answer. I'm happy that my plan is possible und will start to implement your instructions.

Cheers

Submitted by idea12 on Wed, 2012-10-03 19:55

Hi again,

I have one question: Should I make changes also to the admin/feeds_register_step2.php file?

Cheers
Ida

Submitted by support on Thu, 2012-10-04 08:13

Hello Ida,

For completeness, even if you will only be specifying custom values in Product Mapping I would make the changes in admin/feeds_register_step2.php as they correspond with changes in includes/admin.php...

Cheers,
David.
--
PriceTapestry.com

Submitted by idea12 on Sun, 2012-10-07 17:44

Hello David,

I implemented the changes you described above, and the import of the feeds with the new fields is fine. But I obtain the following error during the mapping of a product:

[UPDATE `pt_productsmap` SET alternates = '\n=Betten Bett Leder Polsterbett schwarz 140x200', description = '', category = '', brand = '', image_url = '', stil = '' WHERE id ='23'][Unknown column 'stil' in 'field list']
Warning: Cannot modify header information - headers already sent by (output started at /www/htdocs/w00f2454/Sofa/Auswahl/includes/database.php:55) in /www/htdocs/w00f2454/Sofa/Auswahl/admin/productsmap_configure.php on line 106
------------------

So if I try to edit the file admin/productsmap_configure.php with my own "stil" field (see code below) it is not possible to do the mapping. What can be the reason?
Thanks again for your great support!

$sql = "UPDATE `".$config_databaseTablePrefix."productsmap` SET

alternates = '".database_safe($alternates)."',
description = '".database_safe(widget_posted($_POST["description"]))."',
category = '".database_safe(widget_posted($_POST["category"]))."',
brand = '".database_safe(widget_posted($_POST["brand"]))."',
image_url = '".database_safe(widget_posted($_POST["image_url"]))."',
stil = '".database_safe(widget_posted($_POST["stil"]))."'
WHERE id ='".database_safe($id)."'";

Submitted by support on Mon, 2012-10-08 09:35

Hi,

It looks like it just needs a final dbmod.php to add the `stil` field to your productsmap table. Create a file dbmod.php as follows:

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

...then browse to dbmod.php once to add the new field and that should be all it is!

Cheers,
David.
--
PriceTapestry.com

Submitted by idea12 on Thu, 2012-10-11 19:21

Hi David,

Your suggestion above solved the problem with the error during mapping (Thank you!). Also the values inserted in the box "stil" during mapping can be seen in the productsmap table. That's great! But, unfortunately I can filter only the values used from the Shops. The searchfilter seems not to be aware of the fact that my own mapped values of "stil" are existing... What can I do now?

Cheers,
Ida

Submitted by support on Fri, 2012-10-12 09:01

Hello Ida,

There is a final modiciation required in includes/admin.php to check for and use Product Mapping specified values. In that file, look for the following code at line 309:

if ($admin_importProductMappingsOverrides[$importRecord["name"]]["image_url"]) $importRecord["image_url"] = $admin_importProductMappingsOverrides[$importRecord["name"]]["image_url"];

...and REPLACE with:

if ($admin_importProductMappingsOverrides[$importRecord["name"]]["image_url"]) $importRecord["image_url"] = $admin_importProductMappingsOverrides[$importRecord["name"]]["image_url"];
if ($admin_importProductMappingsOverrides[$importRecord["name"]]["stil"]) $importRecord["stil"] = $admin_importProductMappingsOverrides[$importRecord["name"]]["stil"];

And finally the following code at line 483:

$admin_importProductMappingsOverrides[$productsmap["name"]]["image_url"] = (($productsmap["image_url"])?$productsmap["image_url"]:"");

...and REPALCE with:

$admin_importProductMappingsOverrides[$productsmap["name"]]["image_url"] = (($productsmap["image_url"])?$productsmap["image_url"]:"");
$admin_importProductMappingsOverrides[$productsmap["name"]]["stil"] = (($productsmap["stil"])?$productsmap["stil"]:"");

...re-import, and that should do the trick!

Cheers,
David.
--
PriceTapestry.com

Submitted by idea12 on Fri, 2012-10-12 16:32

You are the best! That really did the trick. Thank you very much - you are a dream-support!