You are here:  » Rename a mapped product name


Rename a mapped product name

Submitted by chrisst1 on Tue, 2011-09-27 10:51 in

Hi David

Is it possible to add a name field to productsmap_configure.php so that the name can be edited/renamed rather than deleting and starting again.

Chris

Submitted by support on Tue, 2011-09-27 11:41

Hi Chris,

Sure - here's a patch to do this - but I would strongly recommend making a backup using the Database Tool (from the Admin menu) first!!

In admin/productsmap_configure.php look for the following code at line 41:

    if ($_POST["alternates"])

...and REPLACE with:

    $_POST["name"] = widget_posted($_POST["name"]);
    if ($_POST["name"] <> $productmap["name"])
    {
      $sql = "SELECT id FROM `".$config_databaseTablePrefix."productsmap` WHERE name='".database_safe($_POST["name"])."' AND id<>'".database_safe($id)."'";
      if (!database_querySelect($sql,$result))
      {
        $sql = "UPDATE `".$config_databaseTablePrefix."productsmap` SET name='".database_safe($_POST["name"])."' WHERE id='".database_safe($id)."'";
        database_queryModify($sql,$result);
      }
    }
    if ($_POST["alternates"])

And finally, look for the following code at line 131:

    print "<input type='submit' name='submit' value='Save' />&nbsp;";

....and REPLACE with:

    print "<strong>Rename Mapping:</strong><br />";
    print "<input type='text' name='name' value='".widget_safe($productmap["name"])."' />";
    print "<br /><br />";
    print "<input type='submit' name='submit' value='Save' />&nbsp;";

A "Rename Mapping" box will then appear just above the Save / Cancel buttons. Note that if a new name is entered that already exists the rename process will simply silently fail but any other changes made will still be saved.

Cheers,
David.
--
PriceTapestry.com

Submitted by chrisst1 on Tue, 2011-09-27 13:16

Hi David

Thanks, that was spot on and worked fine.

Chris

Submitted by stonecold111 on Tue, 2014-01-28 15:59

Hi David,
There's a problem with apostrophes in product titles.
Going back to edit products with an apostrophe, I find that in the rename box, the apostrophe gets cut off as well as the text after it, for example:

"Alex's Revenge" would become "Alex"

Submitted by support on Tue, 2014-01-28 16:12

Hi,

Thanks for pointing that out. To correct the problem, edit includes/widget.php and look for the following code at line 133:

  return htmlspecialchars($text);

...and REPLACE with:

  return htmlspecialchars($text,ENT_QUOTES);

Cheers,
David.
--
PriceTapestry.com

Submitted by Mark Hennessy on Sun, 2014-07-27 15:16

Hi David, just wondering how to go about this on 14/06A?

The code seems a little different. Am I now replacing?

print "<input type='submit' name='submit' id='formSubmit' value='Save' />&nbsp;";

Submitted by support on Sun, 2014-07-27 15:49

Hi Mark,

Equivalent changes for 14/01A;

In admin/productsmap_configure.php look for the following code at line 39:

    if ($_POST["alternates"])

...and REPLACE with:

    if ($_POST["name"] <> $productmap["name"])
    {
      $sql = "SELECT id FROM `".$config_databaseTablePrefix."productsmap` WHERE name='".database_safe($_POST["name"])."' AND id<>'".database_safe($id)."'";
      if (!database_querySelect($sql,$result))
      {
        $sql = "UPDATE `".$config_databaseTablePrefix."productsmap` SET name='".database_safe($_POST["name"])."' WHERE id='".database_safe($id)."'";
        database_queryModify($sql,$result);
      }
    }
    if ($_POST["alternates"])

And finally, look for the following code at line 111:

  widget_formButtons(array("Save"=>TRUE),TRUE);

....and REPLACE with:

  widget_textBox("Rename Mapping","name",FALSE,$productmap["name"],"",6);
  widget_formButtons(array("Save"=>TRUE),TRUE);

(I'm preparing my reply to your email regarding some more significant changes you made previously - no need to send me this file in response, the changes should be confined to the helper tool...)

Cheers,
David.
--
PriceTapestry.com

Submitted by Mark Hennessy on Sun, 2014-07-27 16:42

Works perfect as well! Thank you :)

Submitted by Dale on Thu, 2015-08-13 13:29

Hi David

Does the same code apply for 15/01A as I seem to be getting the following: Fatal error: Call to undefined function widget_posted()

Kind regards
Dale

Submitted by support on Thu, 2015-08-13 13:35

Hi Dale,

widget_posted() has been deprecated as all $_POST fields are now cleansed automatically by includes/widget.php so you can simply remove the line with the call to widget_posted() - corrected above also.

Cheers,
David.
--
PriceTapestry.com

Submitted by Dale on Thu, 2015-08-13 13:49

Great, thanks!