You are here:  » Custom Product fields


Custom Product fields

Submitted by NiceGuyEddie on Wed, 2014-02-19 22:47 in

Hi,

One of my merchant product feeds does not have very good product info. So, what I want to do is create custom fields for these products, insert the product info in these fields manually (via phpmyadmin) and make them searchable.

Reading through various threads in the forum I am reasonably sure I can accomplish this, however, when I reimport the merchant product feed, will these custom fields be overwritten and the custom information deleted?

Regards

Submitted by support on Thu, 2014-02-20 09:01

What I would suggest is implementing your custom fields as per the standard instructions. To save time if you already know the list of fields you want to add (field1, field2 etc.) you can add them to the database in a single dbmod.php script e.g.

<?php
  require("includes/common.php");
  $fields = array("field1","field2","field3");
  foreach($fields as $field)
  {
    $sql = "ALTER TABLE `".$config_databaseTablePrefix."feeds`
            ADD `field_".$field."` VARCHAR(255) NOT NULL";
    database_queryModify($sql,$result);
    $sql = "ALTER TABLE `".$config_databaseTablePrefix."products`
            ADD `".$field."` VARCHAR(255) NOT NULL";
    database_queryModify($sql,$result);
  }
  print "Done.";
?>

(and then it's just the update to $config_fieldSet in config.advanced.php required to complete the process)

You'll then be able to register and import your new fields as normal by mapping them on Feed Registration Step 2 as normal, and this way, they will be preserved whenever you update.

Indexes and separate search code could be added, but the easiest way to make the new fields searchable would be to append them to the description using a Text After filter against the Description field, and in the text box on the configuration page for the filter using %field1% %field2% etc. placeholders to pull those values in.

Finally, make the description field searchable by changing line 10 of config.advanced.php as follows:

  $config_searchDescription = TRUE;

...and then re-running setup.php to add the (name,description) full text index.

Hope this helps!

Cheers,
David.
--
PriceTapestry.com

Submitted by NiceGuyEddie on Thu, 2014-02-20 14:21

Hi David,

As always, thanks for the support.

I have gone through all steps here and everything seems ok. However, when I re-import the feed, any custom data I have entered in the new fields via phpmyadmin is gone.

I may not have been clear in my original question. What I want to do is enter some product technical data that is not in the merchant feed, while preserving this data for individual products when the feed is reimported. Is this possible?

Submitted by support on Thu, 2014-02-20 14:42

Hi,

My apologies I mis-read that you were editing your feeds manually but of course not the case; so instead, what I would suggest rather than modifying the import procedure to update instead of delete (as this can result in a fragmented database and impact on performance), what I would suggest is updating Product Mapping so that you can specify a product that you wish to maintain custom data for, enter the value on the configuration page for the mapping, and then at every import the custom values are set to those values.

It requires modification in a few places, so rather than try to describe it if you could let me know the list of custom field names that you have added, I'll patch the relevant files and then forward them to you by email to try...

Cheers,
David.
--
PriceTapestry.com

Submitted by NiceGuyEddie on Thu, 2014-02-20 15:03

Hi,

the custom fields are: cpu, os, screen, ram, hdd and gpu

Cheers

Paul

Submitted by support on Thu, 2014-02-20 15:42

Thanks Paul,

Patch on its way; don't forget that with the custom fields populated in the database they will all be available for display within your main product page / price comparison table as described on the standard instructions for custom fields page...

Cheers,
David.
--
PriceTapestry.com

Submitted by NiceGuyEddie on Fri, 2014-02-21 00:47

Hi David,

I appear to have run into a problem.

Everything appears to be ok with the product mapping function. When I insert the data for the new custom fields and save, the products map table is updated with the new information in the database.

However, when I run the merchants product feed import , it does not import the products that I have modified into the products database.

Any ideas?

Cheers

Paul

Submitted by support on Fri, 2014-02-21 08:53

Hi Paul,

Please could you post the current $config_fieldSet array from your config.advanced.php (lines 12-19 plus the additional lines for your custom fields) and I'll cross reference that against the $importRecord being created at import time....

Cheers,
David.
--
PriceTapestry.com

Submitted by NiceGuyEddie on Fri, 2014-02-21 10:51

This is the array from my config.advanced.php

  $config_fieldSet = array();
  $config_fieldSet["name"] = "Product Name";
  $config_fieldSet["description"] = "Product Description";
  $config_fieldSet["image_url"] = "Image URL";
  $config_fieldSet["buy_url"] = "Buy URL";
  $config_fieldSet["price"] = "Price";
  $config_fieldSet["category"] = "Category";
  $config_fieldSet["brand"] = "Brand";

Should I have added the lines for my custom fields to this array?

Submitted by support on Fri, 2014-02-21 11:10

Hi Paul,

Yes - for completeness, if you REPLACE the above with:

  $config_fieldSet = array();
  $config_fieldSet["name"] = "Product Name";
  $config_fieldSet["description"] = "Product Description";
  $config_fieldSet["image_url"] = "Image URL";
  $config_fieldSet["buy_url"] = "Buy URL";
  $config_fieldSet["price"] = "Price";
  $config_fieldSet["category"] = "Category";
  $config_fieldSet["brand"] = "Brand";
  $config_fieldSet["cpu"] = "CPU";
  $config_fieldSet["os"] = "Operating System";
  $config_fieldSet["screen"] = "Screen Size";
  $config_fieldSet["ram"] = "RAM";
  $config_fieldSet["hdd"] = "HDD";
  $config_fieldSet["gpu"] = "GPU";

And then after uploading, run the following "universal" dbmod.php script which just double checks and will create if necessary all the custom fields on `pt_feeds` and `pt_products`:

<?php
  
require("includes/common.php");
  
$config_databaseDebugMode FALSE;
  
$ignore = array("name","description","image_url","buy_url","price","category","brand");
  foreach(
$config_fieldSet as $field => $v)
  {
    if (
in_array($field,$ignore)) continue;
    
$sql "ALTER TABLE `".$config_databaseTablePrefix."feeds`
              ADD `field_"
.$field."` VARCHAR(255) NOT NULL";
    
database_queryModify($sql,$result);
    
$sql "ALTER TABLE `".$config_databaseTablePrefix."products`
              ADD `"
.$field."` VARCHAR(255) NOT NULL";
    
database_queryModify($sql,$result);
  }
  print 
"Done.";
?>

Cheers,
David.
--
PriceTapestry.com

Submitted by NiceGuyEddie on Fri, 2014-02-21 12:17

Hi David,

With the changes, everything is working.

Thanks for the support!

Cheers

Paul

Submitted by Brice on Sat, 2018-01-13 22:51

To make an optional field searchable: "text box on the configuration page for the filter using %field1% %field2% etc"

If I wanted to take my registration Optional Field "MPN" and make it searchable would I be doing the above by changing %field1% to just MPN? So in the end it would be :

Text after Description ()

Text

MPN

Then perform Setup.php

total noob obviously

Submitted by support on Sun, 2018-01-14 11:52

Hello Brice,

Appending custom fields to the description and then enabling search description as described above is the easiest way to make custom fields searchable however the placeholder support in the Text After (and Text Before) filters by default only supports %fieldname% where fieldname is the original feed field name (as shown in the sample data below the form on Feed Registration Step 2).

That would mean that the filter would have to be added on a per feed basis; however if you apply the mods described in this comment this will add support for placeholders with curly brackets and the database field name, which will mean you can then add a Global Filter to the Description field, and assuming your database field name is `mpn`, on the configuration page for the Text After filter use something like:

 MPN: {mpn}

(of course you can just use {mpn} on its own but the above would separate the mpn from the description where using - notice the leading SPACE to ensure that the text is separated from the description)

As above make sure search description is enabled at line 10 of config.advanced.php:

  $config_searchDescription = TRUE;

...and after enabling, run setup.php again to create the new FULLTEXT index. (running setup.php a second time won't undo any of your feed registrations etc.)

Cheers,
David.
--
PriceTapestry.com