I am adding a lot of custom fields and some of them don't come from the feeds. I enter some information by hand and I have scripts that collect and load other data. I am looking for the best solution for keeping my information safe when I reload feeds - I don't want to delete it. It looks like I have at least two options: 1) add new columns to the normal PT tables and implement the "update instead of delete" solution, or 2) create a 2nd product table for my data and add a join to all product table queries to include my custom data. I would also like to keep old products after they are removed from the feed. I have several sites, I make frequent changes, and I also use the WP plugin on some of the sites, so I would like to use the solution that will be easy to maintain and copy to new installations. Do you have any suggestions on which approach would be best? One of my biggest goals is to keep the changes to the core PT scripts to a minimum, so I can easily take a new release and apply my code. I am also concerned about performance on larger installations.
Thanks for any suggestions you can offer!
Gregor
Thank you for the reply and the code. I have a couple questions...
- Do mapped products stay in the table forever (until deleted)? If a unique product is removed from the feed, it would be removed from all list and product pages wouldn't it? (I guess keeping dead products on the site might be a totally unrelated problem)
- Would there be a way to easily find mapped products to edit/update? Does the mapped products page show all mapped products on one page or does it page? I've never had very many mapped products, but if I use this method I will have tens of thousands of mapped products on some sites.
For some reason, using the product mapping table doesn't sit well with me, but I will look into it. What concerns do you have regarding the other options (update tables instead of delete / 2nd product table)?
Thanks so much for your help,
Gregor
Hi Gregor,
Yes - the `productsmap` table is persistent, even if a product doesn't ultimately get imported because it no longer exists in the feed the productsmap record would remain so that it is still in place a merchant re-instates the product.
The Product Mapping tool displays all records on one page; but it would be straight forward to add paging and a search facility to find records if required.
Performing an update rather than delete / insert is an option; the only potential issue for that I think is the management of the records would have be written from scratch rather than basing it on the products map table...
Cheers,
David.
--
PriceTapestry.com
Hi Gregor,
In order to preserve your custom info perhaps the best thing to do would be to duplicate the way custom description, image_url category and brand are implemented in Product Mapping. Then, simply create a mapping for any product that you want to setup your custom data for (you don't actually need to have anything in the alternatives box, it can be left blank) and edit / modify the details there.
All that would be required is a field of the same name in `productsmap` just as you have added to `products`, so let's say you have the custom field "custom1" the following dbmod.php would do the trick:
<?php
require("includes/common.php");
$sql = "ALTER TABLE `".$config_databaseTablePrefix."productsmap`
ADD `custom1` VARCHAR(255) NOT NULL";
database_queryModify($sql,$result);
print "Done.";
?>
Next, in admin/productsmap_configure.php look for the following code at line 72:
description = '".database_safe(widget_posted($_POST["description"]))."',
...and REPLACE with:
custom1 = '".database_safe(widget_posted($_POST["custom1"]))."',
description = '".database_safe(widget_posted($_POST["description"]))."',
And then at line 131:
print "<input type='submit' name='submit' value='Save' /> ";
...REPLACE with:
print "Custom Field 1:<br />";
print "<input type='text' name='custom1' value='".widget_safe($productmap["custom1"])."' />";
print "<br /><br />";
print "<input type='submit' name='submit' value='Save' /> ";
Then, in includes/admin.php look for the following code at line 303:
if ($admin_importProductMappingsOverrides[$importRecord["name"]]["description"]) $importRecord["description"] = $admin_importProductMappingsOverrides[$importRecord["name"]]["description"];
...and REPLACE with:
if ($admin_importProductMappingsOverrides[$importRecord["name"]]["custom1"]) $importRecord["custom1"] = $admin_importProductMappingsOverrides[$importRecord["name"]]["custom1"];
Finally look for the following code at line 478:
$admin_importProductMappingsOverrides[$productsmap["name"]]["description"] = (($productsmap["description"])?$productsmap["description"]:"");
...and REPLACE with
$admin_importProductMappingsOverrides[$productsmap["name"]]["custom1"] = (($productsmap["custom1"])?$productsmap["custom1"]:"");
$admin_importProductMappingsOverrides[$productsmap["name"]]["description"] = (($productsmap["description"])?$productsmap["description"]:"");
Hope this helps!
Cheers,
David.
--
PriceTapestry.com